add BLOB SQLite test

This commit is contained in:
Alex Fabijanic 2020-01-15 20:15:57 +01:00
parent b02b2c12f9
commit 7be832bac2
2 changed files with 44 additions and 0 deletions

43
Data/SQLite/testsuite/src/SQLiteTest.cpp Normal file → Executable file
View File

@ -54,6 +54,7 @@ using Poco::Data::SQLChannel;
using Poco::Data::LimitException;
using Poco::Data::ConnectionFailedException;
using Poco::Data::CLOB;
using Poco::Data::BLOB;
using Poco::Data::Date;
using Poco::Data::Time;
using Poco::Data::Transaction;
@ -1418,6 +1419,47 @@ void SQLiteTest::testCLOB()
}
void SQLiteTest::testBLOB()
{
std::string lastName("lastname");
std::string firstName("firstname");
std::string address("Address");
Session tmp(Poco::Data::SQLite::Connector::KEY, "dummy.db");
tmp << "DROP TABLE IF EXISTS Person", now;
tmp << "CREATE TABLE IF NOT EXISTS Person (LastName VARCHAR(30), FirstName VARCHAR, Address VARCHAR, Image BLOB)", now;
typedef struct
{
int i = 0;
Poco::Int64 i64 = 1;
float f = 2.5;
double d = 3.5;
char c[16] = {0};
} DataStruct;
DataStruct ds;
strcpy(ds.c, "123456789ABCDEF");
BLOB img(reinterpret_cast<unsigned char*>(&ds), sizeof(ds));
assertTrue(img.size() == sizeof(ds));
int count = 0;
tmp << "INSERT INTO PERSON VALUES(:ln, :fn, :ad, :img)", use(lastName), use(firstName), use(address), use(img), now;
tmp << "SELECT COUNT(*) FROM PERSON", into(count), now;
assertTrue(count == 1);
BLOB res;
assertTrue(res.size() == 0);
tmp << "SELECT Image FROM Person WHERE LastName == :ln", bind("lastname"), into(res), now;
assertTrue(res.size() == img.size());
assertTrue(0 == std::memcmp(res.rawContent(), img.rawContent(), sizeof(img)));
assertTrue(0 == std::memcmp(res.rawContent(), &ds, sizeof(ds)));
DataStruct dsCopy;
std::memcpy(&dsCopy, res.rawContent(), sizeof(dsCopy));
assertTrue(ds.i == dsCopy.i);
assertTrue(ds.i64 == dsCopy.i64);
assertTrue(ds.f == dsCopy.f);
assertTrue(ds.d == dsCopy.d);
assertTrue(std::string(ds.c) == std::string(dsCopy.c));
}
void SQLiteTest::testTuple10()
{
Session tmp (Poco::Data::SQLite::Connector::KEY, "dummy.db");
@ -3432,6 +3474,7 @@ CppUnit::Test* SQLiteTest::suite()
CppUnit_addTest(pSuite, SQLiteTest, testSingleSelect);
CppUnit_addTest(pSuite, SQLiteTest, testEmptyDB);
CppUnit_addTest(pSuite, SQLiteTest, testCLOB);
CppUnit_addTest(pSuite, SQLiteTest, testBLOB);
CppUnit_addTest(pSuite, SQLiteTest, testTuple10);
CppUnit_addTest(pSuite, SQLiteTest, testTupleVector10);
CppUnit_addTest(pSuite, SQLiteTest, testTuple9);

1
Data/SQLite/testsuite/src/SQLiteTest.h Normal file → Executable file
View File

@ -76,6 +76,7 @@ public:
void testEmptyDB();
void testCLOB();
void testBLOB();
void testTuple1();
void testTupleVector1();