Skip to content

Commit

Permalink
Added unit test to read longtext columns as std::string
Browse files Browse the repository at this point in the history
  • Loading branch information
hmartinez82 committed May 31, 2022
1 parent b6a9e1d commit 5d39826
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Data/MySQL/testsuite/src/MySQLTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,14 @@ void MySQLTest::testLongBLOB()
_pExecutor->longBlob();
}

void MySQLTest::testLongTEXT()
{
if (!_pSession) fail ("Test not available.");

recreatePersonLongBLOBTable();
_pExecutor->longText();
}

void MySQLTest::testJSON()
{
if (!_pSession) fail("Test not available.");
Expand Down Expand Up @@ -966,6 +974,7 @@ CppUnit::Test* MySQLTest::suite()
//CppUnit_addTest(pSuite, MySQLTest, testBLOB);
CppUnit_addTest(pSuite, MySQLTest, testBLOBStmt);
CppUnit_addTest(pSuite, MySQLTest, testLongBLOB);
CppUnit_addTest(pSuite, MySQLTest, testLongTEXT);
CppUnit_addTest(pSuite, MySQLTest, testJSON);
CppUnit_addTest(pSuite, MySQLTest, testUnsignedInts);
CppUnit_addTest(pSuite, MySQLTest, testFloat);
Expand Down
1 change: 1 addition & 0 deletions Data/MySQL/testsuite/src/MySQLTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class MySQLTest: public CppUnit::TestCase
void testBLOB();
void testBLOBStmt();
void testLongBLOB();
void testLongTEXT();
void testJSON();

void testUnsignedInts();
Expand Down
25 changes: 25 additions & 0 deletions Data/MySQL/testsuite/src/SQLExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,31 @@ void SQLExecutor::longBlob()
poco_assert (res == biography);
}

void SQLExecutor::longText()
{
std::string funct = "longText()";
std::string lastName("lastname");
std::string firstName("firstname");
std::string address("Address");
std::string biography("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", 123);

int count = 0;
Statement ins = (*_pSession << "INSERT INTO Person VALUES (?,?,?,?)", use(lastName), use(firstName), use(address), use(biography));
ins.execute();
try { *_pSession << "SELECT COUNT(*) FROM Person", into(count), now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
assertTrue (count == 1);

std::string longTextRes;
poco_assert (longTextRes.size() == 0);
Statement stmt = (*_pSession << "SELECT Biography FROM Person", into(longTextRes));
try { stmt.execute(); }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
poco_assert (longTextRes == biography);
}

void SQLExecutor::json()
{
std::string funct = "json()";
Expand Down
1 change: 1 addition & 0 deletions Data/MySQL/testsuite/src/SQLExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class SQLExecutor: public CppUnit::TestCase
void time();
void timestamp();
void longBlob();
void longText();
void json();
void unsignedInts();
void floats();
Expand Down

0 comments on commit 5d39826

Please sign in to comment.