2 * Name : test_file_time
3 * Author : Chris Koeritz
4 * Copyright (c) 1991-$now By Author. This program is free software; you can *
5 * http://www.fsf.org/copyleft/gpl.html *
6 * Please send any updates to: fred@gruntose.com *
7 \*****************************************************************************/
9 #include <application/hoople_main.h>
10 #include <basis/enhance_cpp.h>
11 #include <basis/functions.h>
12 #include <basis/astring.h>
13 #include <filesystem/file_time.h>
14 #include <loggers/program_wide_logger.h>
15 #include <loggers/critical_events.h>
16 #include <mathematics/chaos.h>
17 #include <timely/time_stamp.h>
18 #include <unit_test/unit_base.h>
26 using namespace application;
27 using namespace basis;
28 using namespace filesystem;
29 using namespace loggers;
30 using namespace mathematics;
31 using namespace timely;
32 using namespace unit_test;
34 //#define DEBUG_TEST_FILE_INFO
35 // uncomment for noisy version.
37 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
39 static chaos a_randomizer;
43 class test_file_time : public application_shell, public unit_base
46 test_file_time() : application_shell(), unit_base() {}
48 DEFINE_CLASS_NAME("test_file_time");
50 virtual int execute();
55 int test_file_time::execute()
63 astring toppy("c:/ntldr"); // will work for any modern windows OS.
66 // test storing info via the constructor.
67 file_time absurdity_time(toppy);
68 FILE *topdir = fopen(toppy.s(), "r");
69 file_time nutty_time(topdir);
71 int filenum = fileno(topdir);
72 int stat_okay = fstat(filenum, &sbuffer);
73 ASSERT_FALSE(stat_okay, "failure to read filetime");
74 file_time goofy_time(sbuffer.st_mtime);
76 file_time testing(goofy_time); // copy ctor.
77 // test that they all got the same idea from the file.
78 ASSERT_EQUAL(absurdity_time, nutty_time, "filename vs. FILE ctor");
79 ASSERT_EQUAL(absurdity_time, goofy_time, "filename vs. time_t ctor");
80 ASSERT_EQUAL(absurdity_time, testing, "filename vs. copy ctor");
81 ASSERT_EQUAL(nutty_time, goofy_time, "FILE vs. time_t ctor");
82 ASSERT_EQUAL(nutty_time, testing, "FILE vs. copy ctor");
83 // one reversed direction check.
84 ASSERT_EQUAL(goofy_time, absurdity_time, "time_t vs. filename ctor");
86 // test packing the object and packed_size.
88 int size = testing.packed_size();
90 ASSERT_EQUAL(size, packed.length(), "packed size accuracy");
92 ASSERT_TRUE(unstuffy.unpack(packed), "unpacking");
93 ASSERT_EQUAL((double)testing.raw(), (double)unstuffy.raw(), "unpacked contents should be equal to prior");
95 // test the text_form method.
97 testing.text_form(text);
98 ASSERT_INEQUAL(text.length(), 0, "text_form produces text");
100 // test validity after unpacking.
101 ASSERT_EQUAL(unstuffy, goofy_time, "constructor file size");
103 return final_report();
106 HOOPLE_MAIN(test_file_time, )