Skip to content

Commit

Permalink
separate tests for Date/Time
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-f committed Dec 15, 2012
1 parent 8832c2e commit e837015
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ XML/testsuite/rss.xml
Icon?
ehthumbs.db
Thumbs.db
*~

# VS generated files #
######################
Expand Down
5 changes: 5 additions & 0 deletions Data/MySQL/src/ResultMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,13 @@ namespace
case MYSQL_TYPE_LONGLONG:
if (unsig) return Poco::Data::MetaColumn::FDT_UINT64;
return Poco::Data::MetaColumn::FDT_INT64;

case MYSQL_TYPE_DATE:
return Poco::Data::MetaColumn::FDT_DATE;

case MYSQL_TYPE_TIME:
return Poco::Data::MetaColumn::FDT_TIME;

case MYSQL_TYPE_DATETIME:
return Poco::Data::MetaColumn::FDT_TIMESTAMP;

Expand Down
22 changes: 22 additions & 0 deletions Data/MySQL/testsuite/src/MySQLTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ void MySQLTest::testDateTime()

recreatePersonDateTimeTable();
_pExecutor->dateTime();
recreatePersonDateTable();
_pExecutor->date();
recreatePersonTimeTable();
_pExecutor->time();
}


Expand Down Expand Up @@ -715,6 +719,24 @@ void MySQLTest::recreatePersonDateTimeTable()
}


void MySQLTest::recreatePersonDateTable()
{
dropTable("Person");
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Birthday DATE)", now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreatePersonDateTable()"); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreatePersonDateTable()"); }
}


void MySQLTest::recreatePersonTimeTable()
{
dropTable("Person");
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Birthday TIME)", now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreatePersonTimeTable()"); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreatePersonTimeTable()"); }
}


void MySQLTest::recreateIntsTable()
{
dropTable("Strings");
Expand Down
2 changes: 2 additions & 0 deletions Data/MySQL/testsuite/src/MySQLTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class MySQLTest: public CppUnit::TestCase
void recreatePersonTable();
void recreatePersonBLOBTable();
void recreatePersonDateTimeTable();
void recreatePersonDateTable();
void recreatePersonTimeTable();
void recreateStringsTable();
void recreateIntsTable();
void recreateFloatsTable();
Expand Down
114 changes: 86 additions & 28 deletions Data/MySQL/testsuite/src/SQLExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include "Poco/Any.h"
#include "Poco/Exception.h"
#include "Poco/Data/LOB.h"
#include "Poco/Data/Date.h"
#include "Poco/Data/Time.h"
#include "Poco/Data/StatementImpl.h"
#include "Poco/Data/RecordSet.h"
#include "Poco/Data/Transaction.h"
Expand Down Expand Up @@ -1253,58 +1255,69 @@ void SQLExecutor::emptyDB()
}


void SQLExecutor::blob(int bigSize)
void SQLExecutor::dateTime()
{
std::string funct = "blob()";
std::string lastName("lastname");
std::string firstName("firstname");
std::string address("Address");

Poco::Data::CLOB img("0123456789", 10);
std::string funct = "dateTime()";
std::string lastName("Bart");
std::string firstName("Simpson");
std::string address("Springfield");
DateTime birthday(1980, 4, 1, 5, 45, 12);

int count = 0;
try { *_pSession << "INSERT INTO Person VALUES (?,?,?,?)", use(lastName), use(firstName), use(address), use(img), now; }
try { *_pSession << "INSERT INTO Person VALUES (?,?,?,?)", use(lastName), use(firstName), use(address), use(birthday), now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
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); }
assert (count == 1);

Poco::Data::CLOB res;
assert (res.size() == 0);
try { *_pSession << "SELECT Image FROM Person", into(res), now; }
DateTime bd;
assert (bd != birthday);
try { *_pSession << "SELECT Birthday FROM Person", into(bd), now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
assert (res == img);

Poco::Data::CLOB big;
std::vector<char> v(bigSize, 'x');
big.assignRaw(&v[0], (std::size_t) v.size());
assert (bd == birthday);

std::cout << std::endl << RecordSet(*_pSession, "SELECT * FROM Person");
}

assert (big.size() == (std::size_t) bigSize);

try { *_pSession << "DELETE FROM Person", now; }
void SQLExecutor::date()
{
std::string funct = "date()";
std::string lastName("Bart");
std::string firstName("Simpson");
std::string address("Springfield");
Date birthday(1980, 4, 1);

int count = 0;
try { *_pSession << "INSERT INTO Person VALUES (?,?,?,?)", use(lastName), use(firstName), use(address), use(birthday), now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }

try { *_pSession << "INSERT INTO Person VALUES(?,?,?,?)", use(lastName), use(firstName), use(address), use(big), now; }
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); }

try { *_pSession << "SELECT Image FROM Person", into(res), now; }
assert (count == 1);

Date bd;
assert (bd != birthday);
try { *_pSession << "SELECT Birthday FROM Person", into(bd), now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
assert (res == big);
assert (bd == birthday);

std::cout << std::endl << RecordSet(*_pSession, "SELECT * FROM Person");
}


void SQLExecutor::dateTime()
void SQLExecutor::time()
{
std::string funct = "dateTime()";
std::string funct = "date()";
std::string lastName("Bart");
std::string firstName("Simpson");
std::string address("Springfield");
DateTime birthday(1980, 4, 1, 5, 45, 12);
Time birthday(1, 2, 3);

int count = 0;
try { *_pSession << "INSERT INTO Person VALUES (?,?,?,?)", use(lastName), use(firstName), use(address), use(birthday), now; }
Expand All @@ -1315,7 +1328,7 @@ void SQLExecutor::dateTime()
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
assert (count == 1);

DateTime bd;
Time bd;
assert (bd != birthday);
try { *_pSession << "SELECT Birthday FROM Person", into(bd), now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
Expand All @@ -1326,6 +1339,51 @@ void SQLExecutor::dateTime()
}


void SQLExecutor::blob(int bigSize)
{
std::string funct = "blob()";
std::string lastName("lastname");
std::string firstName("firstname");
std::string address("Address");

Poco::Data::CLOB img("0123456789", 10);
int count = 0;
try { *_pSession << "INSERT INTO Person VALUES (?,?,?,?)", use(lastName), use(firstName), use(address), use(img), now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
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); }
assert (count == 1);

Poco::Data::CLOB res;
assert (res.size() == 0);
try { *_pSession << "SELECT Image FROM Person", into(res), now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
assert (res == img);

Poco::Data::CLOB big;
std::vector<char> v(bigSize, 'x');
big.assignRaw(&v[0], (std::size_t) v.size());

assert (big.size() == (std::size_t) bigSize);

try { *_pSession << "DELETE FROM Person", now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }

try { *_pSession << "INSERT INTO Person VALUES(?,?,?,?)", use(lastName), use(firstName), use(address), use(big), now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }

try { *_pSession << "SELECT Image FROM Person", into(res), now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
assert (res == big);
}


void SQLExecutor::blobStmt()
{
std::string funct = "blobStmt()";
Expand Down
2 changes: 2 additions & 0 deletions Data/MySQL/testsuite/src/SQLExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class SQLExecutor: public CppUnit::TestCase
void blob(int bigSize = 1024);
void blobStmt();
void dateTime();
void date();
void time();
void floats();
void doubles();
void tuples();
Expand Down

0 comments on commit e837015

Please sign in to comment.