• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

test/TestDateTime.cpp

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
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