00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <spl/Debug.h>
00018 #include <spl/DateTime.h>
00019 #include <spl/Log.h>
00020
00021 #ifdef DEBUG
00022
00023 static void _TestDateTime1()
00024 {
00025 DateTime dt;
00026 DEBUG_CLEAR_MEM_CHECK_POINTS();
00027 DEBUG_DUMP_MEM_LEAKS();
00028 UNIT_ASSERT_MEM_NOTED("DateTime test 1.0");
00029
00030 UNIT_ASSERT("DateTime now", dt.Year() > 2007);
00031
00032 Log::SWriteOkFail( "DateTime test 1" );
00033 }
00034
00035 static void _TestDateTime2()
00036 {
00037 DateTime dt(1999, 1, 31);
00038
00039 UNIT_ASSERT("DateTime y", dt.Year() == 1999);
00040 UNIT_ASSERT("DateTime m", dt.Month() == 1);
00041 UNIT_ASSERT("DateTime d", dt.Day() == 31);
00042 UNIT_ASSERT("DateTime leap year", !dt.IsLeapYear());
00043
00044 time_t t = dt.ToSysTime();
00045 DateTime dt2(t);
00046
00047 UNIT_ASSERT("Date time_t", dt.Equals(dt2));
00048
00049 DEBUG_CLEAR_MEM_CHECK_POINTS();
00050 DEBUG_DUMP_MEM_LEAKS();
00051 UNIT_ASSERT_MEM_NOTED("DateTime test 2.0");
00052
00053 Log::SWriteOkFail( "DateTime test 2" );
00054 }
00055
00056 static void _TestDateTime3()
00057 {
00058 DateTime dt(1999, 12, 31);
00059 DateTime dt2(2000, 1, 31);
00060
00061 UNIT_ASSERT("Date eqaual", !dt.Equals(dt2));
00062
00063 UNIT_ASSERT("Date diff d", 31 == dt2.DiffInDays(dt));
00064 UNIT_ASSERT("Date diff h", 31*24 == dt2.DiffInHours(dt));
00065 UNIT_ASSERT("Date diff m", 31*24*60 == dt2.DiffInMinutes(dt));
00066
00067 DEBUG_CLEAR_MEM_CHECK_POINTS();
00068 DEBUG_DUMP_MEM_LEAKS();
00069 UNIT_ASSERT_MEM_NOTED("DateTime test 3.0");
00070
00071 Log::SWriteOkFail( "DateTime test 3" );
00072 }
00073
00074 void _TestDateTime()
00075 {
00076 _TestDateTime1();
00077 _TestDateTime2();
00078 _TestDateTime3();
00079 }
00080
00081 #endif