aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-12-04 23:33:23 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-12-05 11:29:56 +0200
commitf333016241010d32224e671006dfcd47c9e4be9e (patch)
tree798076a115963ba7472456ebbcf4fbaf55ac4f0b
parent8bba70a624cc79f6c0a8b29009f9b8d05e906b2a (diff)
Test updated PostgreSQL date-time mappings which handle microsecond resolutions
-rw-r--r--boost/pgsql/date-time/driver.cxx22
-rw-r--r--qt/pgsql/date-time/driver.cxx103
2 files changed, 56 insertions, 69 deletions
diff --git a/boost/pgsql/date-time/driver.cxx b/boost/pgsql/date-time/driver.cxx
index d261add..6827bd6 100644
--- a/boost/pgsql/date-time/driver.cxx
+++ b/boost/pgsql/date-time/driver.cxx
@@ -50,24 +50,20 @@ main (int argc, char* argv[])
o.dates.push_back (date (max_date_time));
o.dates.push_back (date (min_date_time));
- o.times.push_back (second_clock::local_time ());
+ o.times.push_back (microsec_clock::local_time ());
o.times.push_back (not_a_date_time);
o.times.push_back (pos_infin);
o.times.push_back (neg_infin);
-
- // Boost seems to handle 64 bit std::time_t incorrectly.
- // Insert 32 bit minimum and maximum UNIX time values for now.
- //
- // o.times.push_back (date (max_date_time));
- // o.times.push_back (date (min_date_time));
- //
-
- o.times.push_back (ptime (date (1901, 12, 14), time_duration (0, 0, 0)));
- o.times.push_back (ptime (date (2038, 1, 19), time_duration (3, 14, 7)));
+ o.times.push_back (ptime (date (max_date_time),
+ time_duration (16, 23, 0, 123456)));
+ o.times.push_back (ptime (date (min_date_time),
+ time_duration (3, 14, 7, 123456)));
+ o.times.push_back (ptime (date (1969, 12, 31), // Before PG epoch.
+ time_duration (23, 59, 59, 123000)));
o.durations.push_back (time_duration (0, 0, 0));
- o.durations.push_back (time_duration (12, 3, 4));
- o.durations.push_back (time_duration (23, 59, 59));
+ o.durations.push_back (time_duration (12, 3, 4, 123456));
+ o.durations.push_back (time_duration (23, 59, 59, 123456));
o.durations.push_back (not_a_date_time);
{
diff --git a/qt/pgsql/date-time/driver.cxx b/qt/pgsql/date-time/driver.cxx
index fde15a6..c1f41f0 100644
--- a/qt/pgsql/date-time/driver.cxx
+++ b/qt/pgsql/date-time/driver.cxx
@@ -38,59 +38,68 @@ main (int argc, char* argv[])
// Check persistence of null values.
//
- object o1;
{
- transaction t (db->begin ());
- db->persist (o1);
- t.commit ();
- }
+ object o;
- {
- transaction t (db->begin ());
- auto_ptr<object> ol1 (db->load<object> (o1.id));
- t.commit ();
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
- assert (ol1->is_null ());
- }
+ {
+ transaction t (db->begin ());
+ auto_ptr<object> ol (db->load<object> (o.id));
+ t.commit ();
- QDateTime ct (QDateTime::currentDateTime ());
- QDateTime ct_no_ms = QDateTime (QDate (ct.date ().year (),
- ct.date ().month (),
- ct.date ().day ()),
- QTime (ct.time ().hour (),
- ct.time ().minute (),
- ct.time ().second ()));
+ assert (ol->is_null ());
+ }
+ }
// Check persistence of valid dates and times.
//
- object o2;
- {
- o2.date = ct.date ();
- o2.time = ct_no_ms.time ();
- o2.date_time = ct_no_ms;
-
- transaction t (db->begin ());
- db->persist (o2);
- t.commit ();
- }
-
{
- transaction t (db->begin ());
- auto_ptr<object> ol2 (db->load<object> (o2.id));
- t.commit ();
+ QDateTime ct (QDateTime::currentDateTime ());
- assert (*ol2 == o2);
+ object o;
+ o.date = ct.date ();
+ o.time = ct.time ();
+ o.date_time = ct;
+
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ auto_ptr<object> ol (db->load<object> (o.id));
+ t.commit ();
+
+ assert (*ol == o);
+ }
}
- // Test out of range values for QDateTime traits.
+ // Test a QDateTime value before PG epoch.
//
{
object o;
- o.date_time = QDateTime (QDate (1969, 12, 31),
- QTime (23, 59, 59),
- Qt::UTC);
+ o.date_time = QDateTime (QDate (1969, 12, 31), QTime (23, 59, 59, 123));
+
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ auto_ptr<object> ol (db->load<object> (o.id));
+ t.commit ();
- assert (test_out_of_range_value (o, *db));
+ assert (*ol == o);
+ }
}
}
catch (const odb::exception& e)
@@ -99,21 +108,3 @@ main (int argc, char* argv[])
return 1;
}
}
-
-bool
-test_out_of_range_value (object& x, database& db)
-{
- try
- {
- transaction t (db.begin ());
- db.persist (x);
- t.rollback ();
-
- return false;
- }
- catch (const odb::qt::date_time::value_out_of_range&)
- {
- }
-
- return true;
-}