mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-08 06:42:55 +01:00
committed Data
This commit is contained in:
133
Data/testsuite/src/Binder.cpp
Normal file
133
Data/testsuite/src/Binder.cpp
Normal file
@@ -0,0 +1,133 @@
|
||||
//
|
||||
// Binder.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/Binder.cpp#3 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Binder.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace Test {
|
||||
|
||||
|
||||
Binder::Binder()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Binder::~Binder()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Poco::Int8 &val)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Poco::UInt8 &val)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Poco::Int16 &val)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Poco::UInt16 &val)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Poco::Int32 &val)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Poco::UInt32 &val)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Poco::Int64 &val)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Poco::UInt64 &val)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const bool &val)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const float &val)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const double &val)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const char &val)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const char* const &pVal)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const std::string& val)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Poco::Data::BLOB& val)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Binder::reset()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::Test
|
||||
109
Data/testsuite/src/Binder.h
Normal file
109
Data/testsuite/src/Binder.h
Normal file
@@ -0,0 +1,109 @@
|
||||
//
|
||||
// Binder.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/Binder.h#3 $
|
||||
//
|
||||
// Definition of the Binder class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_Test_Binder_INCLUDED
|
||||
#define Data_Test_Binder_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/AbstractBinder.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace Test {
|
||||
|
||||
|
||||
class Binder: public Poco::Data::AbstractBinder
|
||||
/// A no-op implementation of AbstractBinder for testing.
|
||||
{
|
||||
public:
|
||||
Binder();
|
||||
/// Creates the Binder.
|
||||
|
||||
~Binder();
|
||||
/// Destroys the Binder.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Int8 &val);
|
||||
/// Binds an Int8.
|
||||
|
||||
void bind(std::size_t pos, const Poco::UInt8 &val);
|
||||
/// Binds an UInt8.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Int16 &val);
|
||||
/// Binds an Int16.
|
||||
|
||||
void bind(std::size_t pos, const Poco::UInt16 &val);
|
||||
/// Binds an UInt16.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Int32 &val);
|
||||
/// Binds an Int32.
|
||||
|
||||
void bind(std::size_t pos, const Poco::UInt32 &val);
|
||||
/// Binds an UInt32.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Int64 &val);
|
||||
/// Binds an Int64.
|
||||
|
||||
void bind(std::size_t pos, const Poco::UInt64 &val);
|
||||
/// Binds an UInt64.
|
||||
|
||||
void bind(std::size_t pos, const bool &val);
|
||||
/// Binds a boolean.
|
||||
|
||||
void bind(std::size_t pos, const float &val);
|
||||
/// Binds a float.
|
||||
|
||||
void bind(std::size_t pos, const double &val);
|
||||
/// Binds a double.
|
||||
|
||||
void bind(std::size_t pos, const char &val);
|
||||
/// Binds a single character.
|
||||
|
||||
void bind(std::size_t pos, const char* const &pVal);
|
||||
/// Binds a const char ptr.
|
||||
|
||||
void bind(std::size_t pos, const std::string& val);
|
||||
/// Binds a string.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Data::BLOB& val);
|
||||
/// Binds a BLOB.
|
||||
|
||||
void reset();
|
||||
};
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::Test
|
||||
|
||||
|
||||
#endif // Data_Test_Binder_INCLUDED
|
||||
443
Data/testsuite/src/DataTest.cpp
Normal file
443
Data/testsuite/src/DataTest.cpp
Normal file
@@ -0,0 +1,443 @@
|
||||
//
|
||||
// DataTest.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/DataTest.cpp#8 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "DataTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Data/Common.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Data/BLOBStream.h"
|
||||
#include "Poco/Data/MetaColumn.h"
|
||||
#include "Poco/Data/Column.h"
|
||||
#include "SessionInstantiator.h"
|
||||
#include "Poco/BinaryReader.h"
|
||||
#include "Poco/BinaryWriter.h"
|
||||
#include "Poco/Types.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
using namespace Poco::Data;
|
||||
|
||||
using Poco::BinaryReader;
|
||||
using Poco::BinaryWriter;
|
||||
using Poco::UInt32;
|
||||
using Poco::Int64;
|
||||
using Poco::UInt64;
|
||||
using Poco::InvalidAccessException;
|
||||
using Poco::RangeException;
|
||||
|
||||
|
||||
DataTest::DataTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
Poco::Data::Test::SessionInstantiator::addToFactory();
|
||||
}
|
||||
|
||||
|
||||
DataTest::~DataTest()
|
||||
{
|
||||
Poco::Data::Test::SessionInstantiator::removeFromFactory();
|
||||
}
|
||||
|
||||
|
||||
void DataTest::testSession()
|
||||
{
|
||||
Session sess(SessionFactory::instance().create("test", "cs"));
|
||||
sess << "DROP TABLE IF EXISTS Test", now;
|
||||
int count;
|
||||
sess << "SELECT COUNT(*) FROM PERSON", into(count), now;
|
||||
|
||||
std::string str;
|
||||
Statement stmt = (sess << "SELECT * FROM Strings", into(str), limit(50));
|
||||
stmt.execute();
|
||||
}
|
||||
|
||||
|
||||
void DataTest::testFeatures()
|
||||
{
|
||||
Session sess(SessionFactory::instance().create("test", "cs"));
|
||||
|
||||
sess.setFeature("f1", true);
|
||||
assert (sess.getFeature("f1"));
|
||||
assert (sess.getFeature("f2"));
|
||||
|
||||
try
|
||||
{
|
||||
sess.setFeature("f2", false);
|
||||
}
|
||||
catch (NotImplementedException&)
|
||||
{
|
||||
}
|
||||
|
||||
sess.setFeature("f3", false);
|
||||
assert (!sess.getFeature("f2"));
|
||||
|
||||
try
|
||||
{
|
||||
sess.setFeature("f3", true);
|
||||
}
|
||||
catch (NotImplementedException&)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
sess.setFeature("f4", false);
|
||||
}
|
||||
catch (NotSupportedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DataTest::testProperties()
|
||||
{
|
||||
Session sess(SessionFactory::instance().create("test", "cs"));
|
||||
|
||||
sess.setProperty("p1", 1);
|
||||
Poco::Any v1 = sess.getProperty("p1");
|
||||
assert (Poco::AnyCast<int>(v1) == 1);
|
||||
Poco::Any v2 = sess.getProperty("p2");
|
||||
assert (Poco::AnyCast<int>(v2) == 1);
|
||||
|
||||
try
|
||||
{
|
||||
sess.setProperty("p2", 2);
|
||||
}
|
||||
catch (NotImplementedException&)
|
||||
{
|
||||
}
|
||||
|
||||
sess.setProperty("p3", 2);
|
||||
v1 = sess.getProperty("p2");
|
||||
assert (Poco::AnyCast<int>(v1) == 2);
|
||||
|
||||
try
|
||||
{
|
||||
sess.setProperty("p3", 3);
|
||||
}
|
||||
catch (NotImplementedException&)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
sess.setProperty("p4", 4);
|
||||
}
|
||||
catch (NotSupportedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DataTest::testBLOB()
|
||||
{
|
||||
std::string strDigit = "1234567890";
|
||||
std::string strAlpha = "abcdefghijklmnopqrstuvwxyz";
|
||||
std::vector<char> vecAlpha(strAlpha.begin(), strAlpha.end());
|
||||
std::vector<char> vecDigit(strDigit.begin(), strDigit.end());
|
||||
|
||||
BLOB blobNumStr(strDigit.c_str(), strDigit.size());
|
||||
assert (blobNumStr.size() == strDigit.size());
|
||||
assert (0 == strncmp(strDigit.c_str(), blobNumStr.rawContent(), blobNumStr.size()));
|
||||
assert (*blobNumStr.begin() == '1');
|
||||
assert (*(blobNumStr.end()-1) == '0');
|
||||
BLOB blobNumVec(vecDigit);
|
||||
assert (blobNumVec.size() == vecDigit.size());
|
||||
assert (blobNumVec == blobNumStr);
|
||||
blobNumVec.swap(blobNumStr);
|
||||
assert (blobNumVec.size() == blobNumStr.size());
|
||||
assert (blobNumVec == blobNumStr);
|
||||
|
||||
BLOB blobChrStr(strAlpha.c_str(), strAlpha.size());
|
||||
BLOB blobChrVec(vecAlpha);
|
||||
assert (blobChrStr.size() == strAlpha.size());
|
||||
assert (0 == strncmp(strAlpha.c_str(), blobChrStr.rawContent(), blobChrStr.size()));
|
||||
assert (*blobChrStr.begin() == 'a');
|
||||
assert (*(blobChrStr.end()-1) == 'z');
|
||||
assert (blobChrStr == blobChrVec);
|
||||
|
||||
blobNumStr.swap(blobChrStr);
|
||||
assert (blobNumStr != blobChrStr);
|
||||
assert (&blobNumStr != &blobChrStr);
|
||||
assert (blobNumStr.content() != blobChrStr.content());
|
||||
assert (&blobNumStr.content() != &blobChrStr.content());
|
||||
assert (blobNumStr == blobChrVec);
|
||||
}
|
||||
|
||||
|
||||
void DataTest::testBLOBStreams()
|
||||
{
|
||||
BLOB blob;
|
||||
assert (0 == blob.size());
|
||||
|
||||
BLOBOutputStream bos(blob);
|
||||
BinaryWriter bw(bos);
|
||||
|
||||
assert (0 == blob.size());
|
||||
writeToBLOB(bw);
|
||||
assert (blob.size() > 0);
|
||||
|
||||
BLOBInputStream bis(blob);
|
||||
BinaryReader br(bis);
|
||||
|
||||
readFromBLOB(br);
|
||||
}
|
||||
|
||||
|
||||
void DataTest::writeToBLOB(BinaryWriter& writer)
|
||||
{
|
||||
writer << true;
|
||||
writer << false;
|
||||
writer << 'a';
|
||||
|
||||
writer << (short) -100;
|
||||
writer << (unsigned short) 50000;
|
||||
writer << -123456;
|
||||
writer << (unsigned) 123456;
|
||||
writer << (long) -1234567890;
|
||||
writer << (unsigned long) 1234567890;
|
||||
|
||||
writer << (Int64) -1234567890;
|
||||
writer << (UInt64) 1234567890;
|
||||
|
||||
writer << (float) 1.5;
|
||||
writer << (double) -1.5;
|
||||
|
||||
writer << "foo";
|
||||
writer << "";
|
||||
|
||||
writer << std::string("bar");
|
||||
writer << std::string();
|
||||
|
||||
writer.write7BitEncoded((UInt32) 100);
|
||||
writer.write7BitEncoded((UInt32) 1000);
|
||||
writer.write7BitEncoded((UInt32) 10000);
|
||||
writer.write7BitEncoded((UInt32) 100000);
|
||||
writer.write7BitEncoded((UInt32) 1000000);
|
||||
|
||||
writer.write7BitEncoded((UInt64) 100);
|
||||
writer.write7BitEncoded((UInt64) 1000);
|
||||
writer.write7BitEncoded((UInt64) 10000);
|
||||
writer.write7BitEncoded((UInt64) 100000);
|
||||
writer.write7BitEncoded((UInt64) 1000000);
|
||||
|
||||
writer.writeRaw("RAW");
|
||||
}
|
||||
|
||||
|
||||
void DataTest::readFromBLOB(BinaryReader& reader)
|
||||
{
|
||||
bool b = false;
|
||||
reader >> b;
|
||||
assert (b);
|
||||
reader >> b;
|
||||
assert (!b);
|
||||
|
||||
char c = ' ';
|
||||
reader >> c;
|
||||
assert (c == 'a');
|
||||
|
||||
short shortv = 0;
|
||||
reader >> shortv;
|
||||
assert (shortv == -100);
|
||||
|
||||
unsigned short ushortv = 0;
|
||||
reader >> ushortv;
|
||||
assert (ushortv == 50000);
|
||||
|
||||
int intv = 0;
|
||||
reader >> intv;
|
||||
assert (intv == -123456);
|
||||
|
||||
unsigned uintv = 0;
|
||||
reader >> uintv;
|
||||
assert (uintv == 123456);
|
||||
|
||||
long longv = 0;
|
||||
reader >> longv;
|
||||
assert (longv == -1234567890);
|
||||
|
||||
unsigned long ulongv = 0;
|
||||
reader >> ulongv;
|
||||
assert (ulongv == 1234567890);
|
||||
|
||||
Int64 int64v = 0;
|
||||
reader >> int64v;
|
||||
assert (int64v == -1234567890);
|
||||
|
||||
UInt64 uint64v = 0;
|
||||
reader >> uint64v;
|
||||
assert (uint64v == 1234567890);
|
||||
|
||||
float floatv = 0.0;
|
||||
reader >> floatv;
|
||||
assert (floatv == 1.5);
|
||||
|
||||
double doublev = 0.0;
|
||||
reader >> doublev;
|
||||
assert (doublev == -1.5);
|
||||
|
||||
std::string str;
|
||||
reader >> str;
|
||||
assert (str == "foo");
|
||||
reader >> str;
|
||||
assert (str == "");
|
||||
|
||||
reader >> str;
|
||||
assert (str == "bar");
|
||||
reader >> str;
|
||||
assert (str == "");
|
||||
|
||||
UInt32 uint32v;
|
||||
reader.read7BitEncoded(uint32v);
|
||||
assert (uint32v == 100);
|
||||
reader.read7BitEncoded(uint32v);
|
||||
assert (uint32v == 1000);
|
||||
reader.read7BitEncoded(uint32v);
|
||||
assert (uint32v == 10000);
|
||||
reader.read7BitEncoded(uint32v);
|
||||
assert (uint32v == 100000);
|
||||
reader.read7BitEncoded(uint32v);
|
||||
assert (uint32v == 1000000);
|
||||
|
||||
reader.read7BitEncoded(uint64v);
|
||||
assert (uint64v == 100);
|
||||
reader.read7BitEncoded(uint64v);
|
||||
assert (uint64v == 1000);
|
||||
reader.read7BitEncoded(uint64v);
|
||||
assert (uint64v == 10000);
|
||||
reader.read7BitEncoded(uint64v);
|
||||
assert (uint64v == 100000);
|
||||
reader.read7BitEncoded(uint64v);
|
||||
assert (uint64v == 1000000);
|
||||
|
||||
reader.readRaw(3, str);
|
||||
assert (str == "RAW");
|
||||
}
|
||||
|
||||
|
||||
void DataTest::testColumn()
|
||||
{
|
||||
MetaColumn mc(1, "mc", MetaColumn::FDT_DOUBLE, 2, 3, true);
|
||||
|
||||
assert (mc.name() == "mc");
|
||||
assert (mc.position() == 1);
|
||||
assert (mc.length() == 2);
|
||||
assert (mc.precision() == 3);
|
||||
assert (mc.type() == MetaColumn::FDT_DOUBLE);
|
||||
assert (mc.isNullable());
|
||||
|
||||
std::vector<int>* pData = new std::vector<int>;
|
||||
pData->push_back(1);
|
||||
pData->push_back(2);
|
||||
pData->push_back(3);
|
||||
pData->push_back(4);
|
||||
pData->push_back(5);
|
||||
|
||||
Column<int> c(mc, pData);
|
||||
|
||||
assert (c.rowCount() == 5);
|
||||
assert (c[1] == 1);
|
||||
assert (c[2] == 2);
|
||||
assert (c[3] == 3);
|
||||
assert (c[4] == 4);
|
||||
assert (c[5] == 5);
|
||||
assert (c.name() == "mc");
|
||||
assert (c.position() == 1);
|
||||
assert (c.length() == 2);
|
||||
assert (c.precision() == 3);
|
||||
assert (c.type() == MetaColumn::FDT_DOUBLE);
|
||||
|
||||
try
|
||||
{
|
||||
int i = c[100];
|
||||
fail ("must fail");
|
||||
}
|
||||
catch (RangeException&) { }
|
||||
|
||||
Column<int> c1 = c;
|
||||
|
||||
assert (c1.rowCount() == 5);
|
||||
assert (c1[1] == 1);
|
||||
assert (c1[2] == 2);
|
||||
assert (c1[3] == 3);
|
||||
assert (c1[4] == 4);
|
||||
assert (c1[5] == 5);
|
||||
|
||||
Column<int> c2(c1);
|
||||
|
||||
assert (c2.rowCount() == 5);
|
||||
assert (c2[1] == 1);
|
||||
assert (c2[2] == 2);
|
||||
assert (c2[3] == 3);
|
||||
assert (c2[4] == 4);
|
||||
assert (c2[5] == 5);
|
||||
|
||||
std::vector<int> vi;
|
||||
vi.assign(c.begin(), c.end());
|
||||
assert (vi.size() == 5);
|
||||
assert (vi[0] == 1);
|
||||
assert (vi[1] == 2);
|
||||
assert (vi[2] == 3);
|
||||
assert (vi[3] == 4);
|
||||
assert (vi[4] == 5);
|
||||
|
||||
c.reset();
|
||||
assert (c.rowCount() == 0);
|
||||
assert (c1.rowCount() == 0);
|
||||
assert (c2.rowCount() == 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DataTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DataTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* DataTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DataTest");
|
||||
|
||||
CppUnit_addTest(pSuite, DataTest, testSession);
|
||||
CppUnit_addTest(pSuite, DataTest, testFeatures);
|
||||
CppUnit_addTest(pSuite, DataTest, testProperties);
|
||||
CppUnit_addTest(pSuite, DataTest, testBLOB);
|
||||
CppUnit_addTest(pSuite, DataTest, testBLOBStreams);
|
||||
CppUnit_addTest(pSuite, DataTest, testColumn);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
69
Data/testsuite/src/DataTest.h
Normal file
69
Data/testsuite/src/DataTest.h
Normal file
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// DataTest.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/DataTest.h#5 $
|
||||
//
|
||||
// Definition of the DataTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef DataTest_INCLUDED
|
||||
#define DataTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/Data.h"
|
||||
#include "Poco/BinaryReader.h"
|
||||
#include "Poco/BinaryWriter.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class DataTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
DataTest(const std::string& name);
|
||||
~DataTest();
|
||||
|
||||
void testSession();
|
||||
void testFeatures();
|
||||
void testProperties();
|
||||
void testBLOB();
|
||||
void testBLOBStreams();
|
||||
void testColumn();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
void writeToBLOB(Poco::BinaryWriter& writer);
|
||||
void readFromBLOB(Poco::BinaryReader& reader);
|
||||
};
|
||||
|
||||
|
||||
#endif // DataTest_INCLUDED
|
||||
46
Data/testsuite/src/DataTestSuite.cpp
Normal file
46
Data/testsuite/src/DataTestSuite.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// DataTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/DataTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "DataTestSuite.h"
|
||||
#include "DataTest.h"
|
||||
#include "SessionPoolTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* DataTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DataTestSuite");
|
||||
|
||||
pSuite->addTest(DataTest::suite());
|
||||
pSuite->addTest(SessionPoolTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
49
Data/testsuite/src/DataTestSuite.h
Normal file
49
Data/testsuite/src/DataTestSuite.h
Normal file
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// DataTestSuite.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/DataTestSuite.h#1 $
|
||||
//
|
||||
// Definition of the DataTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef DataTestSuite_INCLUDED
|
||||
#define DataTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class DataTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // DataTestSuite_INCLUDED
|
||||
39
Data/testsuite/src/Driver.cpp
Normal file
39
Data/testsuite/src/Driver.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// Driver.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/Driver.cpp#1 $
|
||||
//
|
||||
// Console-based test driver for Poco Data.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "CppUnit/TestRunner.h"
|
||||
#include "DataTestSuite.h"
|
||||
|
||||
|
||||
CppUnitMain(DataTestSuite)
|
||||
150
Data/testsuite/src/Extractor.cpp
Normal file
150
Data/testsuite/src/Extractor.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
//
|
||||
// Extractor.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/Extractor.cpp#3 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Extractor.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace Test {
|
||||
|
||||
|
||||
Extractor::Extractor()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Extractor::~Extractor()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int8& val)
|
||||
{
|
||||
val = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt8& val)
|
||||
{
|
||||
val = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int16& val)
|
||||
{
|
||||
val = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt16& val)
|
||||
{
|
||||
val = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int32& val)
|
||||
{
|
||||
val = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt32& val)
|
||||
{
|
||||
val = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int64& val)
|
||||
{
|
||||
val = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt64& val)
|
||||
{
|
||||
val = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, bool& val)
|
||||
{
|
||||
val = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, float& val)
|
||||
{
|
||||
val = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, double& val)
|
||||
{
|
||||
val = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, char& val)
|
||||
{
|
||||
val = '\0';
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, std::string& val)
|
||||
{
|
||||
val = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Data::BLOB& val)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::Test
|
||||
111
Data/testsuite/src/Extractor.h
Normal file
111
Data/testsuite/src/Extractor.h
Normal file
@@ -0,0 +1,111 @@
|
||||
//
|
||||
// Extractor.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/Extractor.h#4 $
|
||||
//
|
||||
// Definition of the Extractor class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_Test_Extractor_INCLUDED
|
||||
#define Data_Test_Extractor_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/AbstractExtractor.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace Test {
|
||||
|
||||
|
||||
class Extractor: public Poco::Data::AbstractExtractor
|
||||
/// A no-op implementation of AbstractExtractor for testing.
|
||||
{
|
||||
public:
|
||||
Extractor();
|
||||
/// Creates the Extractor.
|
||||
|
||||
~Extractor();
|
||||
/// Destroys the Extractor.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Int8& val);
|
||||
/// Extracts an Int8.
|
||||
|
||||
bool extract(std::size_t pos, Poco::UInt8& val);
|
||||
/// Extracts an UInt8.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Int16& val);
|
||||
/// Extracts an Int16.
|
||||
|
||||
bool extract(std::size_t pos, Poco::UInt16& val);
|
||||
/// Extracts an UInt16.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Int32& val);
|
||||
/// Extracts an Int32.
|
||||
|
||||
bool extract(std::size_t pos, Poco::UInt32& val);
|
||||
/// Extracts an UInt32.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Int64& val);
|
||||
/// Extracts an Int64.
|
||||
|
||||
bool extract(std::size_t pos, Poco::UInt64& val);
|
||||
/// Extracts an UInt64.
|
||||
|
||||
bool extract(std::size_t pos, bool& val);
|
||||
/// Extracts a boolean.
|
||||
|
||||
bool extract(std::size_t pos, float& val);
|
||||
/// Extracts a float.
|
||||
|
||||
bool extract(std::size_t pos, double& val);
|
||||
/// Extracts a double.
|
||||
|
||||
bool extract(std::size_t pos, char& val);
|
||||
/// Extracts a single character.
|
||||
|
||||
bool extract(std::size_t pos, std::string& val);
|
||||
/// Extracts a string.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Data::BLOB& val);
|
||||
/// Extracts a BLOB.
|
||||
|
||||
void reset();
|
||||
};
|
||||
|
||||
|
||||
inline void Extractor::reset()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::Test
|
||||
|
||||
|
||||
#endif // Data_Test_Extractor_INCLUDED
|
||||
128
Data/testsuite/src/Preparation.cpp
Normal file
128
Data/testsuite/src/Preparation.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
//
|
||||
// Preparation.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/Preparation.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Preparation.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace Test {
|
||||
|
||||
|
||||
Preparation::Preparation()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Preparation::~Preparation()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Preparation::prepare(std::size_t pos, Poco::Int8)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Preparation::prepare(std::size_t pos, Poco::UInt8)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Preparation::prepare(std::size_t pos, Poco::Int16)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Preparation::prepare(std::size_t pos, Poco::UInt16)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Preparation::prepare(std::size_t pos, Poco::Int32)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Preparation::prepare(std::size_t pos, Poco::UInt32)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Preparation::prepare(std::size_t pos, Poco::Int64)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Preparation::prepare(std::size_t pos, Poco::UInt64)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Preparation::prepare(std::size_t pos, bool)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Preparation::prepare(std::size_t pos, float)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Preparation::prepare(std::size_t pos, double)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Preparation::prepare(std::size_t pos, char)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Preparation::prepare(std::size_t pos, const std::string&)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Preparation::prepare(std::size_t pos, const Poco::Data::BLOB&)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Preparation::prepare(std::size_t pos, const Poco::Any&)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::Test
|
||||
108
Data/testsuite/src/Preparation.h
Normal file
108
Data/testsuite/src/Preparation.h
Normal file
@@ -0,0 +1,108 @@
|
||||
//
|
||||
// Preparation.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/Preparation.h#2 $
|
||||
//
|
||||
// Definition of the Preparation class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_Test_Preparation_INCLUDED
|
||||
#define Data_Test_Preparation_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/AbstractPreparation.h"
|
||||
#include "Poco/Any.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace Test {
|
||||
|
||||
|
||||
class Preparation: public Poco::Data::AbstractPreparation
|
||||
/// A no-op implementation of AbstractPreparation for testing.
|
||||
{
|
||||
public:
|
||||
Preparation();
|
||||
/// Creates the Preparation.
|
||||
|
||||
~Preparation();
|
||||
/// Destroys the Preparation.
|
||||
|
||||
void prepare(std::size_t pos, Poco::Int8);
|
||||
/// Extracts an Int8.
|
||||
|
||||
void prepare(std::size_t pos, Poco::UInt8);
|
||||
/// Extracts an UInt8.
|
||||
|
||||
void prepare(std::size_t pos, Poco::Int16);
|
||||
/// Extracts an Int16.
|
||||
|
||||
void prepare(std::size_t pos, Poco::UInt16);
|
||||
/// Extracts an UInt16.
|
||||
|
||||
void prepare(std::size_t pos, Poco::Int32);
|
||||
/// Extracts an Int32.
|
||||
|
||||
void prepare(std::size_t pos, Poco::UInt32);
|
||||
/// Extracts an UInt32.
|
||||
|
||||
void prepare(std::size_t pos, Poco::Int64);
|
||||
/// Extracts an Int64.
|
||||
|
||||
void prepare(std::size_t pos, Poco::UInt64);
|
||||
/// Extracts an UInt64.
|
||||
|
||||
void prepare(std::size_t pos, bool);
|
||||
/// Extracts a boolean.
|
||||
|
||||
void prepare(std::size_t pos, float);
|
||||
/// Extracts a float.
|
||||
|
||||
void prepare(std::size_t pos, double);
|
||||
/// Extracts a double.
|
||||
|
||||
void prepare(std::size_t pos, char);
|
||||
/// Extracts a single character.
|
||||
|
||||
void prepare(std::size_t pos, const std::string&);
|
||||
/// Extracts a string.
|
||||
|
||||
void prepare(std::size_t pos, const Poco::Data::BLOB&);
|
||||
/// Extracts a BLOB.
|
||||
|
||||
void prepare(std::size_t pos, const Poco::Any&);
|
||||
/// Extracts an Any.
|
||||
};
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::Test
|
||||
|
||||
|
||||
#endif // Data_Test_Preparation_INCLUDED
|
||||
130
Data/testsuite/src/SessionImpl.cpp
Normal file
130
Data/testsuite/src/SessionImpl.cpp
Normal file
@@ -0,0 +1,130 @@
|
||||
//
|
||||
// SessionImpl.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/SessionImpl.cpp#3 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "SessionImpl.h"
|
||||
#include "TestStatementImpl.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace Test {
|
||||
|
||||
|
||||
SessionImpl::SessionImpl(const std::string& init):
|
||||
_init(init),
|
||||
_f(false),
|
||||
_connected(true)
|
||||
{
|
||||
addFeature("f1", &SessionImpl::setF, &SessionImpl::getF);
|
||||
addFeature("f2", 0, &SessionImpl::getF);
|
||||
addFeature("f3", &SessionImpl::setF, 0);
|
||||
addFeature("connected", &SessionImpl::setConnected, &SessionImpl::getConnected);
|
||||
addProperty("p1", &SessionImpl::setP, &SessionImpl::getP);
|
||||
addProperty("p2", 0, &SessionImpl::getP);
|
||||
addProperty("p3", &SessionImpl::setP, &SessionImpl::getP);
|
||||
}
|
||||
|
||||
|
||||
SessionImpl::~SessionImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Poco::Data::StatementImpl* SessionImpl::createStatementImpl()
|
||||
{
|
||||
return new TestStatementImpl;
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::begin()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::commit()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::rollback()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::close()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool SessionImpl::isConnected()
|
||||
{
|
||||
return _connected;
|
||||
}
|
||||
|
||||
|
||||
bool SessionImpl::getConnected(const std::string& name)
|
||||
{
|
||||
return _connected;
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::setConnected(const std::string& name, bool value)
|
||||
{
|
||||
_connected = value;
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::setF(const std::string& name, bool value)
|
||||
{
|
||||
_f = value;
|
||||
}
|
||||
|
||||
|
||||
bool SessionImpl::getF(const std::string& name)
|
||||
{
|
||||
return _f;
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::setP(const std::string& name, const Poco::Any& value)
|
||||
{
|
||||
_p = value;
|
||||
}
|
||||
|
||||
|
||||
Poco::Any SessionImpl::getP(const std::string& name)
|
||||
{
|
||||
return _p;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::Test
|
||||
100
Data/testsuite/src/SessionImpl.h
Normal file
100
Data/testsuite/src/SessionImpl.h
Normal file
@@ -0,0 +1,100 @@
|
||||
//
|
||||
// SessionImpl.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/SessionImpl.h#2 $
|
||||
//
|
||||
// Definition of the SessionImpl class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_Test_SessionImpl_INCLUDED
|
||||
#define Data_Test_SessionImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/AbstractSessionImpl.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "Binder.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace Test {
|
||||
|
||||
|
||||
class SessionImpl: public Poco::Data::AbstractSessionImpl<SessionImpl>
|
||||
/// A no-op implementation of SessionImpl for testing.
|
||||
{
|
||||
public:
|
||||
SessionImpl(const std::string& init);
|
||||
/// Creates the SessionImpl. Opens a connection to the database.
|
||||
|
||||
~SessionImpl();
|
||||
/// Destroys the SessionImpl.
|
||||
|
||||
Poco::Data::StatementImpl* createStatementImpl();
|
||||
/// Returns an test StatementImpl.
|
||||
|
||||
void begin();
|
||||
/// Starts a transaction.
|
||||
|
||||
void commit();
|
||||
/// Commits and ends a transaction.
|
||||
|
||||
void rollback();
|
||||
/// Aborts a transaction.
|
||||
|
||||
void close();
|
||||
/// Closes the session.
|
||||
|
||||
bool isConnected();
|
||||
/// Returns true if session is connected to the database,
|
||||
/// false otherwise.
|
||||
|
||||
void setConnected(const std::string& name, bool value);
|
||||
bool getConnected(const std::string& name);
|
||||
/// Sets/gets the connected property.
|
||||
/// This is normally done by implementation
|
||||
/// when a database connection loss is detected.
|
||||
|
||||
void setF(const std::string& name, bool value);
|
||||
bool getF(const std::string& name);
|
||||
void setP(const std::string& name, const Poco::Any& value);
|
||||
Poco::Any getP(const std::string& name);
|
||||
|
||||
private:
|
||||
std::string _init;
|
||||
bool _f;
|
||||
Poco::Any _p;
|
||||
bool _connected;
|
||||
};
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::Test
|
||||
|
||||
|
||||
#endif // Data_Test_SessionImpl_INCLUDED
|
||||
74
Data/testsuite/src/SessionInstantiator.cpp
Normal file
74
Data/testsuite/src/SessionInstantiator.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
//
|
||||
// SessionInstantiator.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/SessionInstantiator.cpp#1 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "SessionInstantiator.h"
|
||||
#include "SessionImpl.h"
|
||||
#include "Poco/Data/SessionFactory.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace Test {
|
||||
|
||||
|
||||
const std::string SessionInstantiator::KEY("test");
|
||||
|
||||
|
||||
SessionInstantiator::SessionInstantiator()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SessionInstantiator::~SessionInstantiator()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Poco::AutoPtr<Poco::Data::SessionImpl> SessionInstantiator::create(const std::string& initString)
|
||||
{
|
||||
return Poco::AutoPtr<Poco::Data::SessionImpl>(new SessionImpl(initString));
|
||||
}
|
||||
|
||||
|
||||
void SessionInstantiator::addToFactory()
|
||||
{
|
||||
Poco::Data::SessionFactory::instance().add(KEY, new SessionInstantiator());
|
||||
}
|
||||
|
||||
|
||||
void SessionInstantiator::removeFromFactory()
|
||||
{
|
||||
Poco::Data::SessionFactory::instance().remove(KEY);
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::Test
|
||||
74
Data/testsuite/src/SessionInstantiator.h
Normal file
74
Data/testsuite/src/SessionInstantiator.h
Normal file
@@ -0,0 +1,74 @@
|
||||
//
|
||||
// SessionInstantiator.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/SessionInstantiator.h#1 $
|
||||
//
|
||||
// Definition of the SessionInstantiator class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_Test_SessionInstantiator_INCLUDED
|
||||
#define Data_Test_SessionInstantiator_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SessionInstantiator.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace Test {
|
||||
|
||||
|
||||
class SessionInstantiator: public Poco::Data::SessionInstantiator
|
||||
/// SessionInstantiator instantiates SessionImpl objects for testing.
|
||||
{
|
||||
public:
|
||||
static const std::string KEY;
|
||||
/// Keyword for creating test sessions.
|
||||
|
||||
SessionInstantiator();
|
||||
/// Creates the SessionInstantiator.
|
||||
|
||||
~SessionInstantiator();
|
||||
/// Destroys the SessionInstantiator.
|
||||
|
||||
Poco::AutoPtr<Poco::Data::SessionImpl> create(const std::string& initString);
|
||||
/// Creates a test SessionImpl object and initializes it with the given initString.
|
||||
|
||||
static void addToFactory();
|
||||
/// Registers the SessionInstantiator under the Keyword SessionInstantiator::KEY at the Poco::Data::SessionFactory.
|
||||
|
||||
static void removeFromFactory();
|
||||
/// Unregisters the SessionInstantiator under the Keyword SessionInstantiator::KEY at the Poco::Data::SessionFactory.
|
||||
};
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::Test
|
||||
|
||||
|
||||
#endif // Data_Test_SessionInstantiator_INCLUDED
|
||||
204
Data/testsuite/src/SessionPoolTest.cpp
Normal file
204
Data/testsuite/src/SessionPoolTest.cpp
Normal file
@@ -0,0 +1,204 @@
|
||||
//
|
||||
// SessionPoolTest.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/SessionPoolTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "SessionPoolTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Data/Common.h"
|
||||
#include "Poco/Data/SessionPool.h"
|
||||
#include "Poco/Thread.h"
|
||||
#include "SessionInstantiator.h"
|
||||
|
||||
|
||||
using namespace Poco::Data;
|
||||
using Poco::Thread;
|
||||
|
||||
|
||||
SessionPoolTest::SessionPoolTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
Poco::Data::Test::SessionInstantiator::addToFactory();
|
||||
}
|
||||
|
||||
|
||||
SessionPoolTest::~SessionPoolTest()
|
||||
{
|
||||
Poco::Data::Test::SessionInstantiator::removeFromFactory();
|
||||
}
|
||||
|
||||
|
||||
void SessionPoolTest::testSessionPool()
|
||||
{
|
||||
SessionPool pool("test", "cs", 1, 4, 5);
|
||||
|
||||
assert (pool.capacity() == 4);
|
||||
assert (pool.allocated() == 0);
|
||||
assert (pool.idle() == 0);
|
||||
assert (pool.available() == 4);
|
||||
assert (pool.dead() == 0);
|
||||
assert (pool.allocated() == pool.used() + pool.idle());
|
||||
Session s1(pool.get());
|
||||
|
||||
assert (pool.capacity() == 4);
|
||||
assert (pool.allocated() == 1);
|
||||
assert (pool.idle() == 0);
|
||||
assert (pool.available() == 3);
|
||||
assert (pool.dead() == 0);
|
||||
assert (pool.allocated() == pool.used() + pool.idle());
|
||||
|
||||
Session s2(pool.get());
|
||||
|
||||
assert (pool.capacity() == 4);
|
||||
assert (pool.allocated() == 2);
|
||||
assert (pool.idle() == 0);
|
||||
assert (pool.available() == 2);
|
||||
assert (pool.dead() == 0);
|
||||
assert (pool.allocated() == pool.used() + pool.idle());
|
||||
|
||||
{
|
||||
Session s3(pool.get());
|
||||
|
||||
assert (pool.capacity() == 4);
|
||||
assert (pool.allocated() == 3);
|
||||
assert (pool.idle() == 0);
|
||||
assert (pool.available() == 1);
|
||||
assert (pool.dead() == 0);
|
||||
assert (pool.allocated() == pool.used() + pool.idle());
|
||||
}
|
||||
|
||||
assert (pool.capacity() == 4);
|
||||
assert (pool.allocated() == 3);
|
||||
assert (pool.idle() == 1);
|
||||
assert (pool.available() == 2);
|
||||
assert (pool.dead() == 0);
|
||||
assert (pool.allocated() == pool.used() + pool.idle());
|
||||
|
||||
Session s4(pool.get());
|
||||
|
||||
assert (pool.capacity() == 4);
|
||||
assert (pool.allocated() == 3);
|
||||
assert (pool.idle() == 0);
|
||||
assert (pool.available() == 1);
|
||||
assert (pool.dead() == 0);
|
||||
assert (pool.allocated() == pool.used() + pool.idle());
|
||||
|
||||
Session s5(pool.get());
|
||||
|
||||
assert (pool.capacity() == 4);
|
||||
assert (pool.allocated() == 4);
|
||||
assert (pool.idle() == 0);
|
||||
assert (pool.available() == 0);
|
||||
assert (pool.dead() == 0);
|
||||
assert (pool.allocated() == pool.used() + pool.idle());
|
||||
|
||||
try
|
||||
{
|
||||
Session s6(pool.get());
|
||||
fail("pool exhausted - must throw");
|
||||
}
|
||||
catch (SessionPoolExhaustedException&)
|
||||
{
|
||||
}
|
||||
|
||||
s5.close();
|
||||
assert (pool.capacity() == 4);
|
||||
assert (pool.allocated() == 4);
|
||||
assert (pool.idle() == 1);
|
||||
assert (pool.available() == 1);
|
||||
assert (pool.dead() == 0);
|
||||
assert (pool.allocated() == pool.used() + pool.idle());
|
||||
|
||||
try
|
||||
{
|
||||
s5 << "DROP TABLE IF EXISTS Test", now;
|
||||
fail("session unusable - must throw");
|
||||
}
|
||||
catch (SessionUnavailableException&)
|
||||
{
|
||||
}
|
||||
|
||||
s4.close();
|
||||
assert (pool.capacity() == 4);
|
||||
assert (pool.allocated() == 4);
|
||||
assert (pool.idle() == 2);
|
||||
assert (pool.available() == 2);
|
||||
assert (pool.dead() == 0);
|
||||
assert (pool.allocated() == pool.used() + pool.idle());
|
||||
|
||||
Thread::sleep(10000); // time to clean up idle sessions
|
||||
|
||||
assert (pool.capacity() == 4);
|
||||
assert (pool.allocated() == 2);
|
||||
assert (pool.idle() == 0);
|
||||
assert (pool.available() == 2);
|
||||
assert (pool.dead() == 0);
|
||||
assert (pool.allocated() == pool.used() + pool.idle());
|
||||
|
||||
Session s6(pool.get());
|
||||
|
||||
assert (pool.capacity() == 4);
|
||||
assert (pool.allocated() == 3);
|
||||
assert (pool.idle() == 0);
|
||||
assert (pool.available() == 1);
|
||||
assert (pool.dead() == 0);
|
||||
assert (pool.allocated() == pool.used() + pool.idle());
|
||||
|
||||
s6.setFeature("connected", false);
|
||||
assert (pool.dead() == 1);
|
||||
|
||||
s6.close();
|
||||
assert (pool.capacity() == 4);
|
||||
assert (pool.allocated() == 2);
|
||||
assert (pool.idle() == 0);
|
||||
assert (pool.available() == 2);
|
||||
assert (pool.dead() == 0);
|
||||
assert (pool.allocated() == pool.used() + pool.idle());
|
||||
}
|
||||
|
||||
|
||||
void SessionPoolTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SessionPoolTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* SessionPoolTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SessionPoolTest");
|
||||
|
||||
CppUnit_addTest(pSuite, SessionPoolTest, testSessionPool);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
60
Data/testsuite/src/SessionPoolTest.h
Normal file
60
Data/testsuite/src/SessionPoolTest.h
Normal file
@@ -0,0 +1,60 @@
|
||||
//
|
||||
// SessionPoolTest.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/SessionPoolTest.h#1 $
|
||||
//
|
||||
// Definition of the SessionPoolTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SessionPoolTest_INCLUDED
|
||||
#define SessionPoolTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/Data.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class SessionPoolTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
SessionPoolTest(const std::string& name);
|
||||
~SessionPoolTest();
|
||||
|
||||
void testSessionPool();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // SessionPoolTest_INCLUDED
|
||||
104
Data/testsuite/src/StatementImpl.cpp
Normal file
104
Data/testsuite/src/StatementImpl.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
//
|
||||
// StatementImpl.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/StatementImpl.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "StatementImpl.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace Test {
|
||||
|
||||
|
||||
StatementImpl::StatementImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
StatementImpl::~StatementImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void StatementImpl::compileImpl()
|
||||
{
|
||||
// prepare binding
|
||||
_ptrBinder = new Binder;
|
||||
_ptrExtractor = new Extractor;
|
||||
_ptrPrepare = new Preparation();
|
||||
}
|
||||
|
||||
|
||||
bool StatementImpl::canBind() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void StatementImpl::bindImpl()
|
||||
{
|
||||
// bind
|
||||
typedef Poco::Data::AbstractBindingVec Bindings;
|
||||
Bindings& binds = bindings();
|
||||
if (binds.empty())
|
||||
return;
|
||||
|
||||
Bindings::iterator it = binds.begin();
|
||||
Bindings::iterator itEnd = binds.end();
|
||||
std::size_t pos = 0;
|
||||
for (; it != itEnd && (*it)->canBind(); ++it)
|
||||
{
|
||||
(*it)->bind(pos);
|
||||
pos += (*it)->numOfColumnsHandled();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool StatementImpl::hasNext()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void StatementImpl::next()
|
||||
{
|
||||
Poco::Data::AbstractExtractionVec::iterator it = extractions().begin();
|
||||
Poco::Data::AbstractExtractionVec::iterator itEnd = extractions().end();
|
||||
std::size_t pos = 0;
|
||||
for (; it != itEnd; ++it)
|
||||
{
|
||||
(*it)->extract(pos);
|
||||
pos += (*it)->numOfColumnsHandled();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::Test
|
||||
113
Data/testsuite/src/StatementImpl.h
Normal file
113
Data/testsuite/src/StatementImpl.h
Normal file
@@ -0,0 +1,113 @@
|
||||
//
|
||||
// StatementImpl.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/StatementImpl.h#2 $
|
||||
//
|
||||
// Definition of the StatementImpl class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_Test_StatementImpl_INCLUDED
|
||||
#define Data_Test_StatementImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/StatementImpl.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "Binder.h"
|
||||
#include "Extractor.h"
|
||||
#include "Preparation.h"
|
||||
|
||||
|
||||
struct sqlite3;
|
||||
struct sqlite3_stmt;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace Test {
|
||||
|
||||
|
||||
class StatementImpl: public Poco::Data::StatementImpl
|
||||
/// A no-op implementation of StatementImpl for testing.
|
||||
{
|
||||
public:
|
||||
StatementImpl();
|
||||
/// Creates the StatementImpl.
|
||||
|
||||
~StatementImpl();
|
||||
/// Destroys the StatementImpl.
|
||||
|
||||
protected:
|
||||
bool hasNext();
|
||||
/// Returns true if a call to next() will return data.
|
||||
|
||||
void next();
|
||||
/// Retrieves the next row from the resultset.
|
||||
/// Will throw, if the resultset is empty.
|
||||
|
||||
bool canBind() const;
|
||||
/// Returns true if a valid statement is set and we can bind.
|
||||
|
||||
void compileImpl();
|
||||
/// Compiles the statement, doesn't bind yet
|
||||
|
||||
void bindImpl();
|
||||
/// Binds parameters
|
||||
|
||||
AbstractExtractor& extractor();
|
||||
/// Returns the concrete extractor used by the statement.
|
||||
|
||||
AbstractBinder& binder();
|
||||
/// Returns the concrete binder used by the statement.
|
||||
|
||||
private:
|
||||
Poco::SharedPtr<Binder> _ptrBinder;
|
||||
Poco::SharedPtr<Extractor> _ptrExtractor;
|
||||
Poco::SharedPtr<Preparation> _ptrPrepare;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline AbstractExtractor& StatementImpl::extractor()
|
||||
{
|
||||
return *_ptrExtractor;
|
||||
}
|
||||
|
||||
|
||||
inline AbstractBinder& StatementImpl::binder()
|
||||
{
|
||||
return *_ptrBinder;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::Test
|
||||
|
||||
|
||||
#endif // Data_Test_StatementImpl_INCLUDED
|
||||
117
Data/testsuite/src/TestStatementImpl.cpp
Normal file
117
Data/testsuite/src/TestStatementImpl.cpp
Normal file
@@ -0,0 +1,117 @@
|
||||
//
|
||||
// TestStatementImpl.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/TestStatementImpl.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "TestStatementImpl.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace Test {
|
||||
|
||||
|
||||
TestStatementImpl::TestStatementImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TestStatementImpl::~TestStatementImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TestStatementImpl::compileImpl()
|
||||
{
|
||||
// prepare binding
|
||||
_ptrBinder = new Binder;
|
||||
_ptrExtractor = new Extractor;
|
||||
_ptrPrepare = new Preparation;
|
||||
}
|
||||
|
||||
|
||||
bool TestStatementImpl::canBind() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void TestStatementImpl::bindImpl()
|
||||
{
|
||||
// bind
|
||||
typedef Poco::Data::AbstractBindingVec Bindings;
|
||||
Bindings& binds = bindings();
|
||||
if (binds.empty())
|
||||
return;
|
||||
|
||||
Bindings::iterator it = binds.begin();
|
||||
Bindings::iterator itEnd = binds.end();
|
||||
std::size_t pos = 0;
|
||||
for (; it != itEnd && (*it)->canBind(); ++it)
|
||||
{
|
||||
(*it)->bind(pos);
|
||||
pos += (*it)->numOfColumnsHandled();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Poco::UInt32 TestStatementImpl::columnsReturned() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const MetaColumn& TestStatementImpl::metaColumn(Poco::UInt32 pos) const
|
||||
{
|
||||
static MetaColumn c(pos, "", MetaColumn::FDT_BOOL, 0);
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
bool TestStatementImpl::hasNext()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void TestStatementImpl::next()
|
||||
{
|
||||
Poco::Data::AbstractExtractionVec::iterator it = extractions().begin();
|
||||
Poco::Data::AbstractExtractionVec::iterator itEnd = extractions().end();
|
||||
std::size_t pos = 0;
|
||||
for (; it != itEnd; ++it)
|
||||
{
|
||||
(*it)->extract(pos);
|
||||
pos += (*it)->numOfColumnsHandled();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::Test
|
||||
120
Data/testsuite/src/TestStatementImpl.h
Normal file
120
Data/testsuite/src/TestStatementImpl.h
Normal file
@@ -0,0 +1,120 @@
|
||||
//
|
||||
// TestStatementImpl.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/TestStatementImpl.h#2 $
|
||||
//
|
||||
// Definition of the TestStatementImpl class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_Test_TestStatementImpl_INCLUDED
|
||||
#define Data_Test_TestStatementImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/StatementImpl.h"
|
||||
#include "Poco/Data/MetaColumn.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "Binder.h"
|
||||
#include "Extractor.h"
|
||||
#include "Preparation.h"
|
||||
|
||||
|
||||
struct sqlite3;
|
||||
struct sqlite3_stmt;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace Test {
|
||||
|
||||
|
||||
class TestStatementImpl: public Poco::Data::StatementImpl
|
||||
/// A no-op implementation of TestStatementImpl for testing.
|
||||
{
|
||||
public:
|
||||
TestStatementImpl();
|
||||
/// Creates the TestStatementImpl.
|
||||
|
||||
~TestStatementImpl();
|
||||
/// Destroys the TestStatementImpl.
|
||||
|
||||
protected:
|
||||
Poco::UInt32 columnsReturned() const;
|
||||
/// Returns number of columns returned by query.
|
||||
|
||||
const MetaColumn& metaColumn(Poco::UInt32 pos) const;
|
||||
/// Returns column meta data.
|
||||
|
||||
bool hasNext();
|
||||
/// Returns true if a call to next() will return data.
|
||||
|
||||
void next();
|
||||
/// Retrieves the next row from the resultset.
|
||||
/// Will throw, if the resultset is empty.
|
||||
|
||||
bool canBind() const;
|
||||
/// Returns true if a valid statement is set and we can bind.
|
||||
|
||||
void compileImpl();
|
||||
/// Compiles the statement, doesn't bind yet
|
||||
|
||||
void bindImpl();
|
||||
/// Binds parameters
|
||||
|
||||
AbstractExtractor& extractor();
|
||||
/// Returns the concrete extractor used by the statement.
|
||||
|
||||
AbstractBinder& binder();
|
||||
/// Returns the concrete binder used by the statement.
|
||||
|
||||
private:
|
||||
Poco::SharedPtr<Binder> _ptrBinder;
|
||||
Poco::SharedPtr<Extractor> _ptrExtractor;
|
||||
Poco::SharedPtr<Preparation> _ptrPrepare;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline AbstractExtractor& TestStatementImpl::extractor()
|
||||
{
|
||||
return *_ptrExtractor;
|
||||
}
|
||||
|
||||
|
||||
inline AbstractBinder& TestStatementImpl::binder()
|
||||
{
|
||||
return *_ptrBinder;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::Test
|
||||
|
||||
|
||||
#endif // Data_Test_TestStatementImpl_INCLUDED
|
||||
50
Data/testsuite/src/WinDriver.cpp
Normal file
50
Data/testsuite/src/WinDriver.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// WinDriver.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/testsuite/src/WinDriver.cpp#1 $
|
||||
//
|
||||
// Windows test driver for Poco Data.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "WinTestRunner/WinTestRunner.h"
|
||||
#include "DataTestSuite.h"
|
||||
|
||||
|
||||
class TestDriver: public CppUnit::WinTestRunnerApp
|
||||
{
|
||||
void TestMain()
|
||||
{
|
||||
CppUnit::WinTestRunner runner;
|
||||
runner.addTest(DataTestSuite::suite());
|
||||
runner.run();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
TestDriver theDriver;
|
||||
Reference in New Issue
Block a user