t_earth_time.cpp

Go to the documentation of this file.
00001 /*****************************************************************************\
00002 *                                                                             *
00003 *  Name   : test_earth_time                                                   *
00004 *  Author : Chris Koeritz                                                     *
00005 *                                                                             *
00006 *******************************************************************************
00007 * Copyright (c) 2007-$now By Author.  This program is free software; you can  *
00008 * redistribute it and/or modify it under the terms of the GNU General Public  *
00009 * License as published by the Free Software Foundation; either version 2 of   *
00010 * the License or (at your option) any later version.  This is online at:      *
00011 *     http://www.fsf.org/copyleft/gpl.html                                    *
00012 * Please send any updates to: fred@gruntose.com                               *
00013 \*****************************************************************************/
00014 
00015 #define DEBUG_EARTH_TIME
00016   // set this to enable debugging features of the string class.
00017 
00018 #include <basis/chaos.h>
00019 #include <basis/earth_time.h>
00020 #include <basis/function.h>
00021 #include <basis/guards.h>
00022 #include <basis/istring.h>
00023 #include <mechanisms/time_stamp.h>
00024 #include <opsystem/application_shell.h>
00025 #include <loggers/file_logger.h>
00026 #include <data_struct/static_memory_gremlin.h>
00027 
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030 #include <string.h>
00031 
00032 using namespace basis;
00033 using namespace earth_time;
00034 
00035 #undef LOG
00036 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger(), s)
00037 #undef BASE_LOG
00038 #define BASE_LOG(s) STAMPED_EMERGENCY_LOG(program_wide_logger(), s)
00039 
00040 const int TIME_FORMAT = clock_time::MERIDIAN | clock_time::SECONDS
00041     | clock_time::MILLISECONDS;
00042   // the way we like to see our seconds get printed out.
00043 
00045 
00046 class test_earth_time : public application_shell
00047 {
00048 public:
00049   test_earth_time() : application_shell(static_class_name()) {}
00050   ~test_earth_time() {}
00051   IMPLEMENT_CLASS_NAME("test_earth_time");
00052 
00053   virtual int execute();
00054 
00055   int run_test_01();
00056   int run_test_02();
00057 
00058 private:
00059   chaos _rando;  // randomizer.
00060 };
00061 
00063 
00064 int test_earth_time::run_test_01()
00065 {
00066   FUNCDEF("run_test_01");
00067   // this test makes sure that clock_time's normalize is working as expected.
00068 
00069   time_locus checker_1(clock_time(12, 0, 60), day_in_year(), 2007);
00070   clock_time::normalize(checker_1);
00071   time_locus compare_1(clock_time(12, 1, 0), day_in_year(), 2007);
00072 //BASE_LOG(istring("a=") + checker_1.text_form(TIME_FORMAT));
00073 //BASE_LOG(istring("b=") + compare_1.text_form(TIME_FORMAT));
00074   if (checker_1 != compare_1)
00075     deadly_error(class_name(), func, "normalize failed test 1");
00076 
00077   time_locus checker_2(clock_time(12, 0, -1), day_in_year(), 2007);
00078   clock_time::normalize(checker_2);
00079   time_locus compare_2(clock_time(11, 59, 59), day_in_year(), 2007);
00080   if (checker_2 != compare_2)
00081     deadly_error(class_name(), func, "normalize failed test 2");
00082 
00083   time_locus checker_3(clock_time(11, 59, 61), day_in_year(), 2007);
00084   clock_time::normalize(checker_3);
00085   time_locus compare_3(clock_time(12, 00, 01), day_in_year(), 2007);
00086   if (checker_3 != compare_3)
00087     deadly_error(class_name(), func, "normalize failed test 3");
00088 
00089   time_locus checker_4(clock_time(12, 54, -61), day_in_year(), 2007);
00090   clock_time::normalize(checker_4);
00091   time_locus compare_4(clock_time(12, 52, 59), day_in_year(), 2007);
00092   if (checker_4 != compare_4)
00093     deadly_error(class_name(), func, "normalize failed test 4");
00094 
00095   time_locus checker_5(clock_time(12, -32, -62), day_in_year(), 2007);
00096   clock_time::normalize(checker_5);
00097   time_locus compare_5(clock_time(11, 26, 58), day_in_year(), 2007);
00098   if (checker_5 != compare_5)
00099     deadly_error(class_name(), func, "normalize failed test 5");
00100 
00101   return 0;
00102 }
00103 
00104 int test_earth_time::run_test_02()
00105 {
00106   FUNCDEF("run_test_02");
00107   // this test makes sure that day_in_year's normalize is working as expected.
00108 
00109   time_locus checker_1(clock_time(0, 0, -1), day_in_year(JANUARY, 1), 2007);
00110   time_locus::normalize(checker_1);
00111   time_locus compare_1(clock_time(23, 59, 59), day_in_year(DECEMBER, 31), 2006);
00112 //BASE_LOG(istring("a=") + checker_1.text_form(TIME_FORMAT));
00113 //BASE_LOG(istring("b=") + compare_1.text_form(TIME_FORMAT));
00114   if (checker_1 != compare_1)
00115     deadly_error(class_name(), func, "normalize failed test 1");
00116 
00117   time_locus checker_2(clock_time(23, 59, 60), day_in_year(DECEMBER, 31), 2007);
00118   time_locus::normalize(checker_2);
00119   time_locus compare_2(clock_time(0, 0, 0), day_in_year(JANUARY, 1), 2008);
00120   if (checker_2 != compare_2)
00121     deadly_error(class_name(), func, "normalize failed test 2");
00122 
00123 
00124 //add more cases!
00125 //  test leap years
00126 //  test lotso things.
00127 
00128   return 0;
00129 }
00130 
00131 int test_earth_time::execute()
00132 {
00133   FUNCDEF("execute");
00134 
00135   int to_return = run_test_01();
00136   if (to_return) {
00137 //add an error counter.
00138   }
00139 
00140   to_return = run_test_02(); 
00141 //  if (to_return) add an error counter.
00142 
00143   istring to_print("earth_time:: works for those functions tested.");
00144   guards::alert_message(to_print.s());
00145   return 0;
00146 }
00147 
00149 
00150 HOOPLE_MAIN(test_earth_time, )
00151 

Generated on Fri Nov 21 04:30:05 2008 for HOOPLE Libraries by  doxygen 1.5.1