feisty meow concerns codebase 2.140
test_earth_time.cpp
Go to the documentation of this file.
1/*
2* Name : test_earth_time *
3* Author : Chris Koeritz *
4**
5* Copyright (c) 2007-$now By Author. This program is free software; you can *
6* redistribute it and/or modify it under the terms of the GNU General Public *
7* License as published by the Free Software Foundation; either version 2 of *
8* the License or (at your option) any later version. This is online at: *
9* http://www.fsf.org/copyleft/gpl.html *
10* Please send any updates to: fred@gruntose.com *
11*/
12
13#define DEBUG_EARTH_TIME
14 // set this to enable debugging features of the string class.
15
17#include <basis/functions.h>
18#include <basis/guards.h>
19#include <basis/astring.h>
20#include <loggers/file_logger.h>
21#include <mathematics/chaos.h>
23#include <timely/earth_time.h>
24#include <timely/time_stamp.h>
25#include <unit_test/unit_base.h>
26
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30
31using namespace application;
32using namespace basis;
33using namespace mathematics;
34using namespace filesystem;
35using namespace loggers;
36using namespace structures;
37using namespace textual;
38using namespace timely;
39using namespace unit_test;
40
41#undef LOG
42#define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
43#undef BASE_LOG
44#define BASE_LOG(s) STAMPED_EMERGENCY_LOG(program_wide_logger::get(), s)
45
48 // the way we like to see our seconds get printed out.
49
51
52class test_earth_time : virtual public unit_base, virtual public application_shell
53{
54public:
55 test_earth_time() {}
56 DEFINE_CLASS_NAME("test_earth_time");
57
58 virtual int execute();
59
60 void run_test_01();
61 void run_test_02();
62 void run_test_03();
63};
64
66
67void test_earth_time::run_test_01()
68{
69 FUNCDEF("run_test_01");
70 // this test makes sure that clock_time's normalize is working as expected.
71
72 time_locus checker_1(clock_time(12, 0, 60), day_in_year(), 2007);
73 clock_time::normalize(checker_1);
74 time_locus compare_1(clock_time(12, 1, 0), day_in_year(), 2007);
75//BASE_LOG(astring("a=") + checker_1.text_form(TIME_FORMAT));
76//BASE_LOG(astring("b=") + compare_1.text_form(TIME_FORMAT));
77 ASSERT_EQUAL(checker_1, compare_1, "normalize should not fail test 1");
78
79 time_locus checker_2(clock_time(12, 0, -1), day_in_year(), 2007);
80 clock_time::normalize(checker_2);
81 time_locus compare_2(clock_time(11, 59, 59), day_in_year(), 2007);
82 ASSERT_EQUAL(checker_2, compare_2, "normalize should not fail test 2");
83
84 time_locus checker_3(clock_time(11, 59, 61), day_in_year(), 2007);
85 clock_time::normalize(checker_3);
86 time_locus compare_3(clock_time(12, 00, 01), day_in_year(), 2007);
87 ASSERT_EQUAL(checker_3, compare_3, "normalize should not fail test 3");
88
89 time_locus checker_4(clock_time(12, 54, -61), day_in_year(), 2007);
90 clock_time::normalize(checker_4);
91 time_locus compare_4(clock_time(12, 52, 59), day_in_year(), 2007);
92 ASSERT_EQUAL(checker_4, compare_4, "normalize should not fail test 4");
93
94 time_locus checker_5(clock_time(12, -32, -62), day_in_year(), 2007);
95 clock_time::normalize(checker_5);
96 time_locus compare_5(clock_time(11, 26, 58), day_in_year(), 2007);
97 ASSERT_EQUAL(checker_5, compare_5, "normalize should not fail test 5");
98}
99
100void test_earth_time::run_test_02()
101{
102 FUNCDEF("run_test_02");
103 // this test makes sure that day_in_year's normalize is working as expected.
104
105 time_locus checker_1(clock_time(0, 0, -1), day_in_year(JANUARY, 1), 2007);
106 time_locus::normalize(checker_1);
107 time_locus compare_1(clock_time(23, 59, 59), day_in_year(DECEMBER, 31), 2006);
108//BASE_LOG(astring("a=") + checker_1.text_form(TIME_FORMAT));
109//BASE_LOG(astring("b=") + compare_1.text_form(TIME_FORMAT));
110 ASSERT_EQUAL(checker_1, compare_1, "normalize should not fail test 1");
111
112 time_locus checker_2(clock_time(23, 59, 60), day_in_year(DECEMBER, 31), 2007);
113 time_locus::normalize(checker_2);
114 time_locus compare_2(clock_time(0, 0, 0), day_in_year(JANUARY, 1), 2008);
115 ASSERT_EQUAL(checker_2, compare_2, "normalize should not fail test 2");
116
117
118//add more cases!
119// test leap years
120// test lotso things.
121
122}
123
124void test_earth_time::run_test_03()
125{
126 FUNCDEF("run_test_03");
127 // test out the now and greenwich_now methods.
128
129//hmmm: what are some ways to test this?
130
131 time_locus curr_now = now();
133
134 time_locus curr_green = greenwich_now();
136
137
138}
139
140int test_earth_time::execute()
141{
142 FUNCDEF("execute");
143
144 run_test_01();
145 run_test_02();
146 run_test_03();
147
148 critical_events::alert_message(astring(class_name()) + ": works for those functions tested.");
149
150 return final_report();
151}
152
154
155HOOPLE_MAIN(test_earth_time, )
156
The application_shell is a base object for console programs.
virtual int execute()=0
< retrieves the command line from the /proc hierarchy on linux.
Provides a dynamically resizable ASCII character string.
Definition astring.h:35
static void alert_message(const char *info, const char *title="Alert Message")
shows the message in "info", with an optional "title" on the message.
A specific point in time as represented by a 24 hour clock.
Definition earth_time.h:85
static time_number normalize(clock_time &to_fix)
@ MERIDIAN
default: uses 12 hour with AM/PM and no seconds.
Definition earth_time.h:115
@ MILITARY
use military 24 hour time.
Definition earth_time.h:116
@ MILLISECONDS
milliseconds are fourth field (after secs).
Definition earth_time.h:119
@ SECONDS
include the number of seconds as a third field.
Definition earth_time.h:118
An object that represents a particular day in a year.
Definition earth_time.h:141
@ LONG_MONTH
uses full month name.
Definition earth_time.h:173
@ INCLUDE_DAY
adds the name of the day.
Definition earth_time.h:174
An object that represents a particular point in time.
Definition earth_time.h:192
static time_number normalize(time_locus &to_fix)
Same as text_form() above, but stores into "to_stuff".
@ LONG_YEAR
default: full four digit year (problems in 9999).
Definition earth_time.h:222
basis::astring text_form_long(int t=clock_time::MERIDIAN, int d=day_in_year::SHORT_MONTH, int y=LONG_YEAR) const
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition enhance_cpp.h:42
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition enhance_cpp.h:54
Provides macros that implement the 'main' program of an application.
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Definition hoople_main.h:61
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
Definition array.h:30
A platform independent way to obtain the timestamp of a file.
A logger that sends to the console screen using the standard output device.
An extension to floating point primitives providing approximate equality.
Definition averager.h:21
A dynamic container class that holds any kind of object via pointers.
Definition amorph.h:55
#include <time.h>
time_locus greenwich_now()
returns Greenwich Mean Time (their now).
time_locus now()
returns our current locus in the time continuum.
@ DECEMBER
Definition earth_time.h:42
@ JANUARY
Definition earth_time.h:41
Useful support functions for unit testing, especially within hoople.
Definition unit_base.cpp:35
const int TIME_FORMAT
#define LOG(s)
#define ASSERT_EQUAL(a, b, test_name)
Definition unit_base.h:38