first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / core / library / tests_basis / test_system_preconditions.cpp
1 /*
2 *  Name   : test_system_preconditions
3 *  Author : Chris Koeritz
4 **
5 * Copyright (c) 1993-$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 #include "checkup.h"
14
15 #include <application/hoople_main.h>
16 #include <application/windoze_helper.h>
17 #include <basis/astring.h>
18 #include <basis/enhance_cpp.h>
19 #include <basis/functions.h>
20 #include <basis/guards.h>
21 #include <configuration/application_configuration.h>
22 #include <loggers/critical_events.h>
23 #include <loggers/console_logger.h>
24 #include <structures/version_record.h>
25 #include <structures/static_memory_gremlin.h>
26 #include <unit_test/unit_base.h>
27
28 #include <stdio.h>
29
30 using namespace application;
31 using namespace basis;
32 using namespace configuration;
33 using namespace loggers;
34 using namespace system_checkup;
35 using namespace structures;
36 using namespace unit_test;
37
38 class test_system_preconditions : virtual public unit_base, virtual public application_shell
39 {
40 public:
41   test_system_preconditions() : application_shell() {}
42   DEFINE_CLASS_NAME("test_system_preconditions");
43   virtual int execute();
44 };
45
46 //////////////
47
48 #undef UNIT_BASE_THIS_OBJECT
49 #define UNIT_BASE_THIS_OBJECT c_parent
50
51 class burpee
52 {
53 public:
54   burpee(unit_base &parent) : c_parent(parent), my_string(new astring) { *my_string = "balrog"; }
55   DEFINE_CLASS_NAME("burpee");
56   virtual ~burpee() {
57     FUNCDEF("destructor");
58     WHACK(my_string);
59     ASSERT_FALSE(my_string, "whack test should not fail to clear string");
60   }
61
62 protected:
63   unit_base &c_parent;
64
65 private:
66   astring *my_string;
67 };
68
69 #undef UNIT_BASE_THIS_OBJECT 
70
71 //////////////
72
73 #define UNIT_BASE_THIS_OBJECT c_parent
74
75 class florba : public burpee
76 {
77 public:
78   florba(unit_base &parent) : burpee(parent), second_string(new astring)
79       { *second_string = "loquacious"; }
80   DEFINE_CLASS_NAME("florba");
81   virtual ~florba() {
82     FUNCDEF("destructor");
83     WHACK(second_string); 
84     ASSERT_FALSE(second_string, "whack test should clear string in derived class");
85   }
86
87 private:
88   astring *second_string;
89 };
90
91 #undef UNIT_BASE_THIS_OBJECT 
92
93 //////////////
94
95 // back to default now.
96 #define UNIT_BASE_THIS_OBJECT (*this)
97
98 struct testing_file_struct : public FILE {};
99
100 // NOTE: an important part of this test program is running it under something
101 // like boundschecker to ensure that there are no memory leaks caused by
102 // invoking WHACK.  apparently diab 3 is unable to implement WHACK correctly.
103
104 int test_system_preconditions::execute()
105 {
106   FUNCDEF("execute")
107   // let's see what this system is called.
108   log(astring("The name of this software system is: ")
109       + application_configuration::software_product_name());
110   ASSERT_TRUE(strlen(application_configuration::software_product_name()),
111       "product should not be blank");
112
113   // and what this program is called.
114   log(astring("The application is called: ") + application_configuration::application_name());
115   ASSERT_TRUE(application_configuration::application_name().length(),
116       "application name should not be blank");
117
118   // testing compiler's ansi c++ compliance.
119   for (int q = 0; q < 198; q++) {
120     int treno = q;
121     int malfoy = treno * 3;
122 //    log(a_sprintf("%d", malfoy));
123   }
124   // this should not be an error.  the scope of q should be within the loop and
125   // not outside of it.
126   int q = 24;
127   ASSERT_FALSE(q > 190, "no weirdness should happen with compiler scoping");
128
129   // test that the WHACK function operates properly.
130   burpee *chunko = new burpee(*this);
131   florba *lorkas = new florba(*this);
132   burpee *alias = lorkas;
133
134   WHACK(chunko);
135   WHACK(alias);
136   ASSERT_FALSE(chunko, "chunko whack test should succeed");
137   ASSERT_FALSE(alias, "aliased lorkas whack test should succeed");
138   ASSERT_TRUE(lorkas, "original lorkas should not have been cleared");
139   lorkas = NIL;
140
141   ASSERT_EQUAL((int)sizeof(testing_file_struct), (int)sizeof(FILE),
142       "struct size test, sizeof testing_file_struct and sizeof FILE should not differ");
143
144   // now do the crucial tests on the OS, platform, compiler, etc.
145   ASSERT_TRUE(check_system_characteristics(*this),
146       "required system characteristics should be found");
147
148 #ifdef __WIN32__
149   known_operating_systems os = determine_OS();
150   if (os == WIN_95)
151     printf("This is windows 95.\n");
152   else if (os == WIN_NT)
153     printf("This is windows NT.\n");
154   else if (os == WIN_2K)
155     printf("This is windows 2000.\n");
156   else if (os == WIN_XP)
157     printf("This is windows XP.\n");
158   else 
159     printf("This OS is unknown.\n");
160 #endif
161
162   version os_ver = application_configuration::get_OS_version();
163   printf("OS version: %s\n", os_ver.text_form().s());
164
165   return final_report();
166 }
167
168 HOOPLE_MAIN(test_system_preconditions, )
169