RTBKit  0.9
Open-source framework to create real-time ad bidding systems.
soa/types/testing/localdate_test.cc
00001 /* date_test.cc
00002    Copyright (c) 2010 Datacratic.  All rights reserved.
00003 */
00004 
00005 #define BOOST_TEST_MAIN
00006 #define BOOST_TEST_DYN_LINK
00007 
00008 #include <boost/test/unit_test.hpp>
00009 #include "jml/arch/exception.h"
00010 #include "jml/arch/exception_handler.h"
00011 
00012 #include "soa/types/localdate.h"
00013 
00014 using namespace std;
00015 using namespace Datacratic;
00016 
00017 
00018 BOOST_AUTO_TEST_CASE( test_constructor )
00019 {
00020     ML::Set_Trace_Exceptions trace(false);
00021 
00022     /* default constructor */
00023     LocalDate d;
00024     BOOST_CHECK_EQUAL(d.secondsSinceEpoch(), 0.0);
00025     BOOST_CHECK_EQUAL(d.tzOffset(), 0);
00026     BOOST_CHECK_EQUAL(d.timezone(), "UTC");
00027 
00028     /* valid and invalid timezone names */
00029     BOOST_CHECK_THROW(d = LocalDate(0.0, "NoWhereIsNamedLikeThis"),
00030                       ML::Exception);
00031     BOOST_CHECK_NO_THROW(d = LocalDate(0.0, "America/Montreal"));
00032 
00033     /* Jan 1, 1970 00:00 UTC = Dec 31, 1969 19:00 EST */
00034     d = LocalDate(0.0, "America/Montreal");
00035     BOOST_CHECK_EQUAL(d.tzOffset(), (-1 * 5 * 3600));
00036     BOOST_CHECK_EQUAL(d.timezone(), "America/Montreal");
00037 }
00038 
00039 BOOST_AUTO_TEST_CASE( test_time_getters )
00040 {
00041     /* UTC, 2012-12-10 17:24:14 = 1355160254  */
00042     LocalDate d(1355160254);
00043     BOOST_CHECK_EQUAL(d.hour(), 17);
00044     BOOST_CHECK_EQUAL(d.dayOfMonth(), 10);
00045     BOOST_CHECK_EQUAL(d.year(), 2012);
00046 
00047     /* America/Montreal, 2012-12-10 12:23:30 = 1355160210 */
00048     d = LocalDate(1355160210, "America/Montreal");
00049     BOOST_CHECK_EQUAL(d.hour(), 12);
00050     BOOST_CHECK_EQUAL(d.dayOfMonth(), 10);
00051     BOOST_CHECK_EQUAL(d.year(), 2012);
00052 }
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator