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()
60 // just open the root directory on unix; always works.
64 // windows cannot fopen a directory. this blows. so we pick a file
65 // that should work for most windowses.
66 astring toppy("c:/Windows/notepad.exe");
69 // test storing info via the constructor.
70 file_time absurdity_time(toppy);
71 FILE *topdir = fopen(toppy.s(), "r");
72 ASSERT_INEQUAL(topdir, NULL_POINTER, "opening topdir for testing");
73 if (topdir == NULL_POINTER) {
76 file_time nutty_time(topdir);
78 int filenum = fileno(topdir);
80 int stat_okay = fstat(filenum, &sbuffer);
81 ASSERT_FALSE(stat_okay, "failure to read filetime");
82 file_time goofy_time(sbuffer.st_mtime);
84 file_time testing(goofy_time); // copy ctor.
85 // test that they all got the same idea from the file.
86 ASSERT_EQUAL(absurdity_time, nutty_time, "filename vs. FILE ctor");
87 ASSERT_EQUAL(absurdity_time, goofy_time, "filename vs. time_t ctor");
88 ASSERT_EQUAL(absurdity_time, testing, "filename vs. copy ctor");
89 ASSERT_EQUAL(nutty_time, goofy_time, "FILE vs. time_t ctor");
90 ASSERT_EQUAL(nutty_time, testing, "FILE vs. copy ctor");
91 // one reversed direction check.
92 ASSERT_EQUAL(goofy_time, absurdity_time, "time_t vs. filename ctor");
94 // test packing the object and packed_size.
96 int size = testing.packed_size();
98 ASSERT_EQUAL(size, packed.length(), "packed size accuracy");
100 ASSERT_TRUE(unstuffy.unpack(packed), "unpacking");
101 ASSERT_EQUAL((double)testing.raw(), (double)unstuffy.raw(), "unpacked contents should be equal to prior");
103 // test the text_form method.
105 testing.text_form(text);
106 ASSERT_INEQUAL(text.length(), 0, "text_form produces text");
108 // test validity after unpacking.
109 ASSERT_EQUAL(unstuffy, goofy_time, "constructor file size");
111 return final_report();
114 HOOPLE_MAIN(test_file_time, )