feisty meow concerns codebase 2.140
test_section_manager.cpp
Go to the documentation of this file.
1/*
2* Name : test_section_manager
3* Author : Chris Koeritz
4* Purpose: Tests that the section manager is writing sections properly and keeping its
5 table of contents correctly.
6**
7* Copyright (c) 2000-$now By Author. This program is free software; you can *
8* redistribute it and/or modify it under the terms of the GNU General Public *
9* License as published by the Free Software Foundation; either version 2 of *
10* the License or (at your option) any later version. This is online at: *
11* http://www.fsf.org/copyleft/gpl.html *
12* Please send any updates to: fred@gruntose.com *
13*/
14
15//#define DEBUG_SECTION_MANAGER
16 // uncomment for debugging version.
17
19#include <basis/astring.h>
20#include <basis/environment.h>
21#include <basis/guards.h>
27#include <unit_test/unit_base.h>
28
29using namespace application;
30using namespace basis;
31using namespace configuration;
32using namespace filesystem;
33using namespace loggers;
34using namespace mathematics;
35using namespace structures;
36using namespace textual;
37using namespace timely;
38using namespace unit_test;
39
40#define LOG(to_print) EMERGENCY_LOG(program_wide_logger().get(), astring(to_print))
41
42//#ifdef DEBUG_SECTION_MANAGER
43// #include <stdio.h>
44//#endif
45
46class test_section_manager : public virtual unit_base, virtual public application_shell
47{
48public:
49 test_section_manager() {}
50 DEFINE_CLASS_NAME("test_section_manager");
51 virtual int execute();
52};
53
55
56int test_section_manager::execute()
57{
58 FUNCDEF("execute");
59
60 // prepare the storage area for ini config.
61 environment::set("ALLUSERSPROFILE", environment::get("TEMPORARIES_PILE"));
62
63 {
64 astring TEST = "First Test";
65 ini_configurator ini("t_section_manager_1.ini", ini_configurator::AUTO_STORE);
66 section_manager mangler(ini, "TOC", "BORK:");
67 // clean up the ini file for our testing....
68 string_array names;
69 if (mangler.get_section_names(names)) {
70 for (int i = 0; i < names.length(); i++) mangler.zap_section(names[i]);
71 ini.delete_section("TOC"); // remove table of contents.
72 }
73
74 // now add some entries...
75 string_table contents1;
76 contents1.add("oink", "bozoot");
77 contents1.add("gink", "rinkum");
78 contents1.add("sorty", "figulat");
79 contents1.add("crinkish", "wazir");
80 ASSERT_TRUE(mangler.add_section("burny", contents1),
81 TEST + ": couldn't add the first section!");
82 string_table temp_1;
83 ASSERT_TRUE(mangler.find_section("burny", temp_1),
84 TEST + ": couldn't retrieve the first section!");
85#ifdef DEBUG_SECTION_MANAGER
86 printf("first section has:\n%s\n", temp_1.text_form().s());
87 printf("we want:\n%s\n", contents1.text_form().s());
88#endif
89 ASSERT_EQUAL(temp_1, contents1, TEST + ": first section's contents are incorrect!");
90 contents1.add("glurp", "locutusburger");
91 ASSERT_FALSE(mangler.add_section("burny", contents1),
92 TEST + ": incorrectly allowing re-add of first section!");
93 ASSERT_TRUE(mangler.replace_section("burny", contents1),
94 TEST + ": failing to replace first section!");
95 temp_1.reset();
96 ASSERT_TRUE(mangler.find_section("burny", temp_1),
97 TEST + ": couldn't retrieve the first section (2)!");
98 ASSERT_EQUAL(temp_1, contents1, TEST + ": first section's contents are incorrect (2)!");
99
100 string_table contents2;
101 contents2.add("tsingha", "tsinglo");
102 contents2.add("chunk", "midgets");
103 contents2.add("burn", "barns in texas");
104 contents2.add("chump", "will not be elected");
105 contents2.add("geezerplant", "water weekly");
106 ASSERT_TRUE(mangler.add_section("itchy", contents2),
107 TEST + ": couldn't add the second section!");
108 string_table temp_2;
109 ASSERT_TRUE(mangler.find_section("itchy", temp_2),
110 TEST + ": couldn't retrieve the second section!");
111 ASSERT_EQUAL(temp_2, contents2, TEST + ": second section's contents are incorrect!");
112 // test that first section is still there with second having been added.
113 ASSERT_TRUE(mangler.find_section("burny", temp_1),
114 TEST + ": couldn't retrieve the first section (3)!");
115 ASSERT_EQUAL(temp_1, contents1, TEST + ": first section's contents are incorrect (3)!");
116
117//more!
118 }
119 {
120// astring TEST = "Second Test";
121 }
122
123 critical_events::alert_message(astring(class_name()) + ": works for those functions tested.");
124
125 return final_report();
126}
127
129
130HOOPLE_MAIN(test_section_manager, );
131
The application_shell is a base object for console programs.
virtual int execute()=0
< retrieves the command line from the /proc hierarchy on linux.
int length() const
Returns the current reported length of the allocated C array.
Definition array.h:115
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
static astring get(const astring &variable_name)
looks up the "variable_name" in the current environment variables.
static bool set(const astring &variable_name, const astring &value)
adds or creates "variable_name" in the environment.
Supports a configurator-based interface on text initialization files.
Tracks a collection of related configurations in a configurator.
static void alert_message(const char *info, const char *title="Alert Message")
shows the message in "info", with an optional "title" on the message.
An array of strings with some additional helpful methods.
Provides a symbol_table that holds strings as the content.
basis::astring text_form() const
prints the contents of the table into the returned string.
basis::outcome add(const basis::astring &name, const contents &storage)
Enters a symbol name into the table along with some contents.
#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>
Useful support functions for unit testing, especially within hoople.
Definition unit_base.cpp:35
#define TEST(action)
#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