feisty meow concerns codebase 2.140
test_system_preconditions.cpp
Go to the documentation of this file.
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
17#include <basis/astring.h>
18#include <basis/enhance_cpp.h>
19#include <basis/functions.h>
20#include <basis/guards.h>
26#include <unit_test/unit_base.h>
27
28#include <stdio.h>
29
30using namespace application;
31using namespace basis;
32using namespace configuration;
33using namespace loggers;
34using namespace system_checkup;
35using namespace structures;
36using namespace unit_test;
37
38class test_system_preconditions : virtual public unit_base, virtual public application_shell
39{
40public:
41 test_system_preconditions() : application_shell() {}
42 DEFINE_CLASS_NAME("test_system_preconditions");
43 virtual int execute();
44};
45
47
48#undef UNIT_BASE_THIS_OBJECT
49#define UNIT_BASE_THIS_OBJECT c_parent
50
51class burpee
52{
53public:
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
62protected:
63 unit_base &c_parent;
64
65private:
66 astring *my_string;
67};
68
69#undef UNIT_BASE_THIS_OBJECT
70
72
73#define UNIT_BASE_THIS_OBJECT c_parent
74
75class florba : public burpee
76{
77public:
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
87private:
88 astring *second_string;
89};
90
91#undef UNIT_BASE_THIS_OBJECT
92
94
95// back to default now.
96#define UNIT_BASE_THIS_OBJECT (*this)
97
98struct 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
104int 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 = NULL_POINTER;
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.
146 "required system characteristics should be found");
147
148#ifdef __WIN32__
149 known_operating_systems os = determine_OS();
150 astring os_report = "This OS is: ";
151 os_report += opsystem_name(os);
152 os_report += "\n";
153 printf(os_report.s());
154#endif
155
157 printf("OS version: %s\n", os_ver.text_form().s());
158
159 return final_report();
160}
161
162HOOPLE_MAIN(test_system_preconditions, )
163
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
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
Definition astring.h:113
Defines installation-specific locations in the file system.
static structures::version get_OS_version()
returns the operating system's version information.
Holds a file's version identifier.
virtual basis::astring text_form() const
#define NULL_POINTER
The value representing a pointer to nothing.
Definition definitions.h:32
#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
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
Definition functions.h:121
A logger that sends to the console screen using the standard output device.
A dynamic container class that holds any kind of object via pointers.
Definition amorph.h:55
bool check_system_characteristics(unit_base &testing)
Definition checkup.cpp:30
Useful support functions for unit testing, especially within hoople.
Definition unit_base.cpp:35
#define ASSERT_EQUAL(a, b, test_name)
Definition unit_base.h:38
#define ASSERT_TRUE(a, test_name)
Definition unit_base.h:46
#define ASSERT_FALSE(a, test_name)
Definition unit_base.h:50
Aids in achievement of platform independence.