mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-01 09:24:55 +02:00
Add copyStreamRange to StreamCopier (#4474)
* feat(Foundation): StreamCopier copyStreamRange #4413 * chore(ci): disable instalation of unused databases in odbc job --------- Co-authored-by: Pavle <pavle@debian-gnu-linux-11.localdomain> Co-authored-by: Alex Fabijanic <alex@pocoproject.org>
This commit is contained in:
parent
6b3aab0624
commit
8119259c89
44
.github/workflows/ci.yml
vendored
44
.github/workflows/ci.yml
vendored
@ -660,27 +660,27 @@ jobs:
|
|||||||
linux-gcc-make-odbc:
|
linux-gcc-make-odbc:
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
services:
|
services:
|
||||||
mysql:
|
#mysql:
|
||||||
image: mysql:8.1.0
|
# image: mysql:8.1.0
|
||||||
env:
|
# env:
|
||||||
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
# MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
||||||
MYSQL_USER: pocotest
|
# MYSQL_USER: pocotest
|
||||||
MYSQL_PASSWORD: pocotest
|
# MYSQL_PASSWORD: pocotest
|
||||||
MYSQL_DATABASE: pocotest
|
# MYSQL_DATABASE: pocotest
|
||||||
ports:
|
# ports:
|
||||||
- 3306:3306
|
# - 3306:3306
|
||||||
postgres:
|
#postgres:
|
||||||
image: postgres:16.0
|
# image: postgres:16.0
|
||||||
env:
|
# env:
|
||||||
POSTGRES_PASSWORD: postgres
|
# POSTGRES_PASSWORD: postgres
|
||||||
ports:
|
# ports:
|
||||||
- 5432:5432
|
# - 5432:5432
|
||||||
oracle:
|
#oracle:
|
||||||
image: container-registry.oracle.com/database/express:21.3.0-xe
|
# image: container-registry.oracle.com/database/express:21.3.0-xe
|
||||||
env:
|
# env:
|
||||||
ORACLE_PWD: poco
|
# ORACLE_PWD: poco
|
||||||
ports:
|
# ports:
|
||||||
- 1521:1521
|
# - 1521:1521
|
||||||
sqlserver:
|
sqlserver:
|
||||||
image: mcr.microsoft.com/mssql/server:2022-latest
|
image: mcr.microsoft.com/mssql/server:2022-latest
|
||||||
env:
|
env:
|
||||||
@ -691,7 +691,7 @@ jobs:
|
|||||||
- 1433:1433
|
- 1433:1433
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- run: sudo apt -y update && sudo apt -y install libssl-dev unixodbc-dev libmysqlclient-dev mysql-client alien libaio1 gnupg2 curl #odbc-postgresql
|
- run: sudo apt -y update && sudo apt -y install libssl-dev unixodbc-dev alien libaio1 gnupg2 curl # libmysqlclient-dev mysql-client odbc-postgresql
|
||||||
- run: ./configure --everything --no-samples --omit=ActiveRecord,ApacheConnector,CppParser,Crypto,Data/MySQL,Data/PostgreSQL,Data/SQLite,Encodings,JSON,JWT,MongoDB,Net,NetSSL_OpenSSL,NetSSL_Win,PDF,PageCompiler,PocoDoc,ProGen,Prometheus,Redis,SevenZip,Util,XML,Zip && make all -s -j4 && sudo make install
|
- run: ./configure --everything --no-samples --omit=ActiveRecord,ApacheConnector,CppParser,Crypto,Data/MySQL,Data/PostgreSQL,Data/SQLite,Encodings,JSON,JWT,MongoDB,Net,NetSSL_OpenSSL,NetSSL_Win,PDF,PageCompiler,PocoDoc,ProGen,Prometheus,Redis,SevenZip,Util,XML,Zip && make all -s -j4 && sudo make install
|
||||||
# - name: Setup MySQL ODBC connector
|
# - name: Setup MySQL ODBC connector
|
||||||
# run: |
|
# run: |
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
|
#include "Poco/Buffer.h"
|
||||||
#include <istream>
|
#include <istream>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
@ -47,6 +48,21 @@ public:
|
|||||||
/// integer is used to count the number of bytes copied.
|
/// integer is used to count the number of bytes copied.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static std::streamsize copyStreamRange(std::istream& istr, std::ostream& ostr, std::streampos rangeStart, std::streamsize rangeLength, std::size_t bufferSize = 8192);
|
||||||
|
/// Writes range of bytes readable from istr to ostr, using an internal buffer.
|
||||||
|
///
|
||||||
|
/// Returns the number of bytes copied.
|
||||||
|
|
||||||
|
#if defined(POCO_HAVE_INT64)
|
||||||
|
static Poco::UInt64 copyStreamRange64(std::istream& istr, std::ostream& ostr, std::streampos rangeStart, std::streamsize rangeLength, std::size_t bufferSize = 8192);
|
||||||
|
/// Writes range of bytes readable from istr to ostr, using an internal buffer.
|
||||||
|
///
|
||||||
|
/// Returns the number of bytes copied as a 64-bit unsigned integer.
|
||||||
|
///
|
||||||
|
/// Note: the only difference to copyStreamRange() is that a 64-bit unsigned
|
||||||
|
/// integer is used to count the number of bytes copied.
|
||||||
|
#endif
|
||||||
|
|
||||||
static std::streamsize copyStreamUnbuffered(std::istream& istr, std::ostream& ostr);
|
static std::streamsize copyStreamUnbuffered(std::istream& istr, std::ostream& ostr);
|
||||||
/// Writes all bytes readable from istr to ostr.
|
/// Writes all bytes readable from istr to ostr.
|
||||||
///
|
///
|
||||||
@ -62,6 +78,21 @@ public:
|
|||||||
/// integer is used to count the number of bytes copied.
|
/// integer is used to count the number of bytes copied.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static std::streamsize copyStreamRangeUnbuffered(std::istream& istr, std::ostream& ostr, std::streampos rangeStart, std::streamsize rangeLength);
|
||||||
|
/// Writes range of bytes readable from istr to ostr.
|
||||||
|
///
|
||||||
|
/// Returns the number of bytes copied.
|
||||||
|
|
||||||
|
#if defined(POCO_HAVE_INT64)
|
||||||
|
static Poco::UInt64 copyStreamRangeUnbuffered64(std::istream& istr, std::ostream& ostr, std::streampos rangeStart, std::streamsize rangeLength);
|
||||||
|
/// Writes range of bytes readable from istr to ostr.
|
||||||
|
///
|
||||||
|
/// Returns the number of bytes copied as a 64-bit unsigned integer.
|
||||||
|
///
|
||||||
|
/// Note: the only difference to copyStreamRangeUnbuffered() is that a 64-bit unsigned
|
||||||
|
/// integer is used to count the number of bytes copied.
|
||||||
|
#endif
|
||||||
|
|
||||||
static std::streamsize copyToString(std::istream& istr, std::string& str, std::size_t bufferSize = 8192);
|
static std::streamsize copyToString(std::istream& istr, std::string& str, std::size_t bufferSize = 8192);
|
||||||
/// Appends all bytes readable from istr to the given string, using an internal buffer.
|
/// Appends all bytes readable from istr to the given string, using an internal buffer.
|
||||||
///
|
///
|
||||||
@ -76,6 +107,119 @@ public:
|
|||||||
/// Note: the only difference to copyToString() is that a 64-bit unsigned
|
/// Note: the only difference to copyToString() is that a 64-bit unsigned
|
||||||
/// integer is used to count the number of bytes copied.
|
/// integer is used to count the number of bytes copied.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
template <typename T>
|
||||||
|
static T copyStreamImpl(std::istream& istr, std::ostream& ostr, std::size_t bufferSize)
|
||||||
|
{
|
||||||
|
poco_assert (bufferSize > 0);
|
||||||
|
|
||||||
|
Buffer<char> buffer(bufferSize);
|
||||||
|
T len = 0;
|
||||||
|
istr.read(buffer.begin(), bufferSize);
|
||||||
|
std::streamsize n = istr.gcount();
|
||||||
|
while (n > 0)
|
||||||
|
{
|
||||||
|
len += n;
|
||||||
|
ostr.write(buffer.begin(), n);
|
||||||
|
if (istr && ostr)
|
||||||
|
{
|
||||||
|
istr.read(buffer.begin(), bufferSize);
|
||||||
|
n = istr.gcount();
|
||||||
|
}
|
||||||
|
else n = 0;
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static T copyStreamRangeImpl(std::istream& istr, std::ostream& ostr, std::streampos rangeStart, std::streamsize rangeLength, std::size_t bufferSize)
|
||||||
|
{
|
||||||
|
poco_assert (bufferSize > 0);
|
||||||
|
|
||||||
|
if (bufferSize > rangeLength)
|
||||||
|
bufferSize = rangeLength;
|
||||||
|
|
||||||
|
Buffer<char> buffer(bufferSize);
|
||||||
|
T len = 0;
|
||||||
|
if (istr)
|
||||||
|
{
|
||||||
|
istr.seekg(rangeStart);
|
||||||
|
istr.read(buffer.begin(), bufferSize);
|
||||||
|
std::streamsize n = istr.gcount();
|
||||||
|
while (n > 0)
|
||||||
|
{
|
||||||
|
len += n;
|
||||||
|
ostr.write(buffer.begin(), n);
|
||||||
|
if ((len < rangeLength) && istr && ostr)
|
||||||
|
{
|
||||||
|
if (bufferSize > (rangeLength - len))
|
||||||
|
bufferSize = rangeLength - len;
|
||||||
|
istr.read(buffer.begin(), bufferSize);
|
||||||
|
n = istr.gcount();
|
||||||
|
}
|
||||||
|
else n = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static T copyToStringImpl(std::istream& istr, std::string& str, std::size_t bufferSize)
|
||||||
|
{
|
||||||
|
poco_assert (bufferSize > 0);
|
||||||
|
|
||||||
|
Buffer<char> buffer(bufferSize);
|
||||||
|
T len = 0;
|
||||||
|
istr.read(buffer.begin(), bufferSize);
|
||||||
|
std::streamsize n = istr.gcount();
|
||||||
|
while (n > 0)
|
||||||
|
{
|
||||||
|
len += n;
|
||||||
|
str.append(buffer.begin(), static_cast<std::string::size_type>(n));
|
||||||
|
if (istr)
|
||||||
|
{
|
||||||
|
istr.read(buffer.begin(), bufferSize);
|
||||||
|
n = istr.gcount();
|
||||||
|
}
|
||||||
|
else n = 0;
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static T copyStreamUnbufferedImpl(std::istream& istr, std::ostream& ostr)
|
||||||
|
{
|
||||||
|
char c = 0;
|
||||||
|
T len = 0;
|
||||||
|
istr.get(c);
|
||||||
|
while (istr && ostr)
|
||||||
|
{
|
||||||
|
++len;
|
||||||
|
ostr.put(c);
|
||||||
|
istr.get(c);
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static T copyStreamRangeUnbufferedImpl(std::istream& istr, std::ostream& ostr, std::streampos rangeStart, std::streamsize rangeLength)
|
||||||
|
{
|
||||||
|
T len = 0;
|
||||||
|
char c = 0;
|
||||||
|
if (istr)
|
||||||
|
{
|
||||||
|
istr.seekg(rangeStart);
|
||||||
|
istr.get(c);
|
||||||
|
while (istr && ostr && (len < rangeLength))
|
||||||
|
{
|
||||||
|
ostr.put(c);
|
||||||
|
++len;
|
||||||
|
istr.get(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Poco/StreamCopier.h"
|
#include "Poco/StreamCopier.h"
|
||||||
#include "Poco/Buffer.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
@ -21,128 +20,69 @@ namespace Poco {
|
|||||||
|
|
||||||
std::streamsize StreamCopier::copyStream(std::istream& istr, std::ostream& ostr, std::size_t bufferSize)
|
std::streamsize StreamCopier::copyStream(std::istream& istr, std::ostream& ostr, std::size_t bufferSize)
|
||||||
{
|
{
|
||||||
poco_assert (bufferSize > 0);
|
return copyStreamImpl<std::streamsize>(istr, ostr, bufferSize);
|
||||||
|
|
||||||
Buffer<char> buffer(bufferSize);
|
|
||||||
std::streamsize len = 0;
|
|
||||||
istr.read(buffer.begin(), bufferSize);
|
|
||||||
std::streamsize n = istr.gcount();
|
|
||||||
while (n > 0)
|
|
||||||
{
|
|
||||||
len += n;
|
|
||||||
ostr.write(buffer.begin(), n);
|
|
||||||
if (istr && ostr)
|
|
||||||
{
|
|
||||||
istr.read(buffer.begin(), bufferSize);
|
|
||||||
n = istr.gcount();
|
|
||||||
}
|
|
||||||
else n = 0;
|
|
||||||
}
|
|
||||||
return len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(POCO_HAVE_INT64)
|
#if defined(POCO_HAVE_INT64)
|
||||||
Poco::UInt64 StreamCopier::copyStream64(std::istream& istr, std::ostream& ostr, std::size_t bufferSize)
|
Poco::UInt64 StreamCopier::copyStream64(std::istream& istr, std::ostream& ostr, std::size_t bufferSize)
|
||||||
{
|
{
|
||||||
poco_assert (bufferSize > 0);
|
return copyStreamImpl<Poco::UInt64>(istr, ostr, bufferSize);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
Buffer<char> buffer(bufferSize);
|
|
||||||
Poco::UInt64 len = 0;
|
std::streamsize StreamCopier::copyStreamRange(std::istream& istr, std::ostream& ostr, std::streampos rangeStart, std::streamsize rangeLength, std::size_t bufferSize)
|
||||||
istr.read(buffer.begin(), bufferSize);
|
{
|
||||||
std::streamsize n = istr.gcount();
|
return copyStreamRangeImpl<std::streamsize>(istr, ostr, rangeStart, rangeLength, bufferSize);
|
||||||
while (n > 0)
|
}
|
||||||
{
|
|
||||||
len += n;
|
|
||||||
ostr.write(buffer.begin(), n);
|
#if defined(POCO_HAVE_INT64)
|
||||||
if (istr && ostr)
|
Poco::UInt64 StreamCopier::copyStreamRange64(std::istream& istr, std::ostream& ostr, std::streampos rangeStart, std::streamsize rangeLength, std::size_t bufferSize)
|
||||||
{
|
{
|
||||||
istr.read(buffer.begin(), bufferSize);
|
return copyStreamRangeImpl<Poco::UInt64>(istr, ostr, rangeStart, rangeLength, bufferSize);
|
||||||
n = istr.gcount();
|
|
||||||
}
|
|
||||||
else n = 0;
|
|
||||||
}
|
|
||||||
return len;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
std::streamsize StreamCopier::copyToString(std::istream& istr, std::string& str, std::size_t bufferSize)
|
std::streamsize StreamCopier::copyToString(std::istream& istr, std::string& str, std::size_t bufferSize)
|
||||||
{
|
{
|
||||||
poco_assert (bufferSize > 0);
|
return copyToStringImpl<std::streamsize>(istr, str, bufferSize);
|
||||||
|
|
||||||
Buffer<char> buffer(bufferSize);
|
|
||||||
std::streamsize len = 0;
|
|
||||||
istr.read(buffer.begin(), bufferSize);
|
|
||||||
std::streamsize n = istr.gcount();
|
|
||||||
while (n > 0)
|
|
||||||
{
|
|
||||||
len += n;
|
|
||||||
str.append(buffer.begin(), static_cast<std::string::size_type>(n));
|
|
||||||
if (istr)
|
|
||||||
{
|
|
||||||
istr.read(buffer.begin(), bufferSize);
|
|
||||||
n = istr.gcount();
|
|
||||||
}
|
|
||||||
else n = 0;
|
|
||||||
}
|
|
||||||
return len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(POCO_HAVE_INT64)
|
#if defined(POCO_HAVE_INT64)
|
||||||
Poco::UInt64 StreamCopier::copyToString64(std::istream& istr, std::string& str, std::size_t bufferSize)
|
Poco::UInt64 StreamCopier::copyToString64(std::istream& istr, std::string& str, std::size_t bufferSize)
|
||||||
{
|
{
|
||||||
poco_assert (bufferSize > 0);
|
return copyToStringImpl<Poco::UInt64>(istr, str, bufferSize);
|
||||||
|
|
||||||
Buffer<char> buffer(bufferSize);
|
|
||||||
Poco::UInt64 len = 0;
|
|
||||||
istr.read(buffer.begin(), bufferSize);
|
|
||||||
std::streamsize n = istr.gcount();
|
|
||||||
while (n > 0)
|
|
||||||
{
|
|
||||||
len += n;
|
|
||||||
str.append(buffer.begin(), static_cast<std::string::size_type>(n));
|
|
||||||
if (istr)
|
|
||||||
{
|
|
||||||
istr.read(buffer.begin(), bufferSize);
|
|
||||||
n = istr.gcount();
|
|
||||||
}
|
|
||||||
else n = 0;
|
|
||||||
}
|
|
||||||
return len;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
std::streamsize StreamCopier::copyStreamUnbuffered(std::istream& istr, std::ostream& ostr)
|
std::streamsize StreamCopier::copyStreamUnbuffered(std::istream& istr, std::ostream& ostr)
|
||||||
{
|
{
|
||||||
char c = 0;
|
return copyStreamUnbufferedImpl<std::streamsize>(istr, ostr);
|
||||||
std::streamsize len = 0;
|
|
||||||
istr.get(c);
|
|
||||||
while (istr && ostr)
|
|
||||||
{
|
|
||||||
++len;
|
|
||||||
ostr.put(c);
|
|
||||||
istr.get(c);
|
|
||||||
}
|
|
||||||
return len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(POCO_HAVE_INT64)
|
#if defined(POCO_HAVE_INT64)
|
||||||
Poco::UInt64 StreamCopier::copyStreamUnbuffered64(std::istream& istr, std::ostream& ostr)
|
Poco::UInt64 StreamCopier::copyStreamUnbuffered64(std::istream& istr, std::ostream& ostr)
|
||||||
{
|
{
|
||||||
char c = 0;
|
return copyStreamUnbufferedImpl<Poco::UInt64>(istr, ostr);
|
||||||
Poco::UInt64 len = 0;
|
}
|
||||||
istr.get(c);
|
#endif
|
||||||
while (istr && ostr)
|
|
||||||
{
|
std::streamsize StreamCopier::copyStreamRangeUnbuffered(std::istream& istr, std::ostream& ostr, std::streampos rangeStart, std::streamsize rangeLength)
|
||||||
++len;
|
{
|
||||||
ostr.put(c);
|
return copyStreamRangeUnbufferedImpl<std::streamsize>(istr, ostr, rangeStart, rangeLength);
|
||||||
istr.get(c);
|
}
|
||||||
}
|
|
||||||
return len;
|
|
||||||
|
#if defined(POCO_HAVE_INT64)
|
||||||
|
Poco::UInt64 StreamCopier::copyStreamRangeUnbuffered64(std::istream& istr, std::ostream& ostr, std::streampos rangeStart, std::streamsize rangeLength)
|
||||||
|
{
|
||||||
|
return copyStreamRangeUnbufferedImpl<Poco::UInt64>(istr, ostr, rangeStart, rangeLength);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -93,6 +93,74 @@ void StreamCopierTest::testCopyToString()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void StreamCopierTest::testBufferedCopyRange()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
std::string src;
|
||||||
|
for (int i = 0; i < 512; ++i) src += char(i % 256);
|
||||||
|
std::istringstream istr(src);
|
||||||
|
std::ostringstream ostr;
|
||||||
|
std::streampos rangeStart = 100;
|
||||||
|
std::streamsize rangeLength = 20;
|
||||||
|
std::string subSrc = src.substr(100, 20);
|
||||||
|
std::streamsize n = StreamCopier::copyStreamRange(istr, ostr, rangeStart, rangeLength);
|
||||||
|
assertTrue (ostr.str() == subSrc);
|
||||||
|
assertTrue (n == subSrc.size());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::string src;
|
||||||
|
for (int i = 0; i < 512; ++i) src += char(i % 256);
|
||||||
|
std::istringstream istr(src);
|
||||||
|
std::ostringstream ostr;
|
||||||
|
std::streampos rangeStart = 100;
|
||||||
|
std::streamsize rangeLength = 20;
|
||||||
|
std::string subSrc = src.substr(100, 20);
|
||||||
|
std::streamsize n = StreamCopier::copyStreamRange(istr, ostr, rangeStart, rangeLength, 100);
|
||||||
|
assertTrue (ostr.str() == subSrc);
|
||||||
|
assertTrue (n == subSrc.size());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::string src;
|
||||||
|
for (int i = 0; i < 512; ++i) src += char(i % 256);
|
||||||
|
std::istringstream istr(src);
|
||||||
|
std::ostringstream ostr;
|
||||||
|
std::streampos rangeStart = 100;
|
||||||
|
std::streamsize rangeLength = 150;
|
||||||
|
std::string subSrc = src.substr(100, 150);
|
||||||
|
std::streamsize n = StreamCopier::copyStreamRange(istr, ostr, rangeStart, rangeLength, 100);
|
||||||
|
assertTrue (ostr.str() == subSrc);
|
||||||
|
assertTrue (n == subSrc.size());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::string src;
|
||||||
|
for (int i = 0; i < 512; ++i) src += char(i % 256);
|
||||||
|
std::istringstream istr(src);
|
||||||
|
std::ostringstream ostr;
|
||||||
|
std::streampos rangeStart = 100;
|
||||||
|
std::streamsize rangeLength = 128;
|
||||||
|
std::string subSrc = src.substr(100, 128);
|
||||||
|
std::streamsize n = StreamCopier::copyStreamRange(istr, ostr, rangeStart, rangeLength, 128);
|
||||||
|
assertTrue (ostr.str() == subSrc);
|
||||||
|
assertTrue (n == subSrc.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void StreamCopierTest::testUnbufferedCopyRange()
|
||||||
|
{
|
||||||
|
std::string src;
|
||||||
|
for (int i = 0; i < 255; ++i) src += char(i);
|
||||||
|
std::istringstream istr(src);
|
||||||
|
std::ostringstream ostr;
|
||||||
|
std::streampos rangeStart = 100;
|
||||||
|
std::streamsize rangeLength = 20;
|
||||||
|
std::string subSrc = src.substr(100, 20);
|
||||||
|
std::streamsize n = StreamCopier::copyStreamRangeUnbuffered(istr, ostr, rangeStart, rangeLength);
|
||||||
|
assertTrue (ostr.str() == subSrc);
|
||||||
|
assertTrue (n == subSrc.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(POCO_HAVE_INT64)
|
#if defined(POCO_HAVE_INT64)
|
||||||
void StreamCopierTest::testBufferedCopy64()
|
void StreamCopierTest::testBufferedCopy64()
|
||||||
{
|
{
|
||||||
@ -157,6 +225,74 @@ void StreamCopierTest::testCopyToString64()
|
|||||||
assertTrue (src == dest);
|
assertTrue (src == dest);
|
||||||
assertTrue (n == src.size());
|
assertTrue (n == src.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void StreamCopierTest::testBufferedCopyRange64()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
std::string src;
|
||||||
|
for (int i = 0; i < 512; ++i) src += char(i % 256);
|
||||||
|
std::istringstream istr(src);
|
||||||
|
std::ostringstream ostr;
|
||||||
|
std::streampos rangeStart = 100;
|
||||||
|
std::streamsize rangeLength = 20;
|
||||||
|
std::string subSrc = src.substr(100, 20);
|
||||||
|
Poco::UInt64 n = StreamCopier::copyStreamRange64(istr, ostr, rangeStart, rangeLength);
|
||||||
|
assertTrue (ostr.str() == subSrc);
|
||||||
|
assertTrue (n == subSrc.size());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::string src;
|
||||||
|
for (int i = 0; i < 512; ++i) src += char(i % 256);
|
||||||
|
std::istringstream istr(src);
|
||||||
|
std::ostringstream ostr;
|
||||||
|
std::streampos rangeStart = 100;
|
||||||
|
std::streamsize rangeLength = 20;
|
||||||
|
std::string subSrc = src.substr(100, 20);
|
||||||
|
Poco::UInt64 n = StreamCopier::copyStreamRange64(istr, ostr, rangeStart, rangeLength, 100);
|
||||||
|
assertTrue (ostr.str() == subSrc);
|
||||||
|
assertTrue (n == subSrc.size());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::string src;
|
||||||
|
for (int i = 0; i < 512; ++i) src += char(i % 256);
|
||||||
|
std::istringstream istr(src);
|
||||||
|
std::ostringstream ostr;
|
||||||
|
std::streampos rangeStart = 100;
|
||||||
|
std::streamsize rangeLength = 150;
|
||||||
|
std::string subSrc = src.substr(100, 150);
|
||||||
|
Poco::UInt64 n = StreamCopier::copyStreamRange64(istr, ostr, rangeStart, rangeLength, 100);
|
||||||
|
assertTrue (ostr.str() == subSrc);
|
||||||
|
assertTrue (n == subSrc.size());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::string src;
|
||||||
|
for (int i = 0; i < 512; ++i) src += char(i % 256);
|
||||||
|
std::istringstream istr(src);
|
||||||
|
std::ostringstream ostr;
|
||||||
|
std::streampos rangeStart = 100;
|
||||||
|
std::streamsize rangeLength = 128;
|
||||||
|
std::string subSrc = src.substr(100, 128);
|
||||||
|
Poco::UInt64 n = StreamCopier::copyStreamRange64(istr, ostr, rangeStart, rangeLength, 128);
|
||||||
|
assertTrue (ostr.str() == subSrc);
|
||||||
|
assertTrue (n == subSrc.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void StreamCopierTest::testUnbufferedCopyRange64()
|
||||||
|
{
|
||||||
|
std::string src;
|
||||||
|
for (int i = 0; i < 255; ++i) src += char(i);
|
||||||
|
std::istringstream istr(src);
|
||||||
|
std::ostringstream ostr;
|
||||||
|
std::streampos rangeStart = 100;
|
||||||
|
std::streamsize rangeLength = 20;
|
||||||
|
std::string subSrc = src.substr(100, 20);
|
||||||
|
Poco::UInt64 n = StreamCopier::copyStreamRangeUnbuffered64(istr, ostr, rangeStart, rangeLength);
|
||||||
|
assertTrue (ostr.str() == subSrc);
|
||||||
|
assertTrue (n == subSrc.size());
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -177,11 +313,15 @@ CppUnit::Test* StreamCopierTest::suite()
|
|||||||
CppUnit_addTest(pSuite, StreamCopierTest, testBufferedCopy);
|
CppUnit_addTest(pSuite, StreamCopierTest, testBufferedCopy);
|
||||||
CppUnit_addTest(pSuite, StreamCopierTest, testUnbufferedCopy);
|
CppUnit_addTest(pSuite, StreamCopierTest, testUnbufferedCopy);
|
||||||
CppUnit_addTest(pSuite, StreamCopierTest, testCopyToString);
|
CppUnit_addTest(pSuite, StreamCopierTest, testCopyToString);
|
||||||
|
CppUnit_addTest(pSuite, StreamCopierTest, testBufferedCopyRange);
|
||||||
|
CppUnit_addTest(pSuite, StreamCopierTest, testUnbufferedCopyRange);
|
||||||
|
|
||||||
#if defined(POCO_HAVE_INT64)
|
#if defined(POCO_HAVE_INT64)
|
||||||
CppUnit_addTest(pSuite, StreamCopierTest, testBufferedCopy64);
|
CppUnit_addTest(pSuite, StreamCopierTest, testBufferedCopy64);
|
||||||
CppUnit_addTest(pSuite, StreamCopierTest, testUnbufferedCopy64);
|
CppUnit_addTest(pSuite, StreamCopierTest, testUnbufferedCopy64);
|
||||||
CppUnit_addTest(pSuite, StreamCopierTest, testCopyToString64);
|
CppUnit_addTest(pSuite, StreamCopierTest, testCopyToString64);
|
||||||
|
CppUnit_addTest(pSuite, StreamCopierTest, testBufferedCopyRange64);
|
||||||
|
CppUnit_addTest(pSuite, StreamCopierTest, testUnbufferedCopyRange64);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
|
@ -27,10 +27,14 @@ public:
|
|||||||
void testBufferedCopy();
|
void testBufferedCopy();
|
||||||
void testUnbufferedCopy();
|
void testUnbufferedCopy();
|
||||||
void testCopyToString();
|
void testCopyToString();
|
||||||
|
void testBufferedCopyRange();
|
||||||
|
void testUnbufferedCopyRange();
|
||||||
#if defined(POCO_HAVE_INT64)
|
#if defined(POCO_HAVE_INT64)
|
||||||
void testBufferedCopy64();
|
void testBufferedCopy64();
|
||||||
void testUnbufferedCopy64();
|
void testUnbufferedCopy64();
|
||||||
void testCopyToString64();
|
void testCopyToString64();
|
||||||
|
void testBufferedCopyRange64();
|
||||||
|
void testUnbufferedCopyRange64();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user