31 using namespace basis;
62 #define LOG(to_print) EMERGENCY_LOG(program_wide_logger::get(), astring(to_print))
73 test_string_table() {}
81 virtual int execute();
91 outcome added = syms.add(name, to_add);
108 ASSERT_EQUAL(*found, to_find,
"string in table should be correct");
114 void test_string_table::test_1()
117 #ifdef TEST_SIZE_TABLE
121 guards::alert_message(
astring(astring::SPRINTF,
"we should effectively "
122 "have swamped out the size of other code in the program now. the size "
123 "should represent %d string_table instantiations. take the current "
124 "memory size (minus maybe 2 megs) and divide by %d and you will have "
125 "a fairly accurate cost for instantiating a string table. hit a key.",
129 #elif defined(__UNIX__)
142 #ifdef DEBUG_STRING_TABLE
143 LOG(
astring(astring::SPRINTF,
"index %d", qq));
146 astring freud(
"Sigmund Freud was a very freaked dude.");
147 ADD(syms, freudname, freud);
149 astring borg(
"You will be assimilated.");
150 ADD(syms, borgname, borg);
152 astring x(
"The great unknown superhero cartoon.");
154 astring aname(
"fleeny-brickle");
155 astring a(
"lallax menick publum.");
158 astring ax(
"Lizzy Borden has a very large hatchet.");
159 ADD(syms, axname, ax);
161 astring bloink(
"this is a short and stupid string");
162 ADD(syms, bloinkname, bloink);
164 astring fax(
"alligators in my teacup.");
165 ADD(syms, faxname, fax);
166 astring zname(
"eagle ovaries");
167 astring z(
"malfeasors beware");
170 FIND(syms, freudname, freud);
171 FIND(syms, borgname, borg);
172 FIND(syms, xname, x);
173 FIND(syms, aname, a);
174 FIND(syms, axname, ax);
175 FIND(syms, bloinkname, bloink);
176 FIND(syms, faxname, fax);
177 FIND(syms, zname, z);
182 name = string_manipulation::make_random_name(40, 108);
183 content = string_manipulation::make_random_name(300, 1000);
184 ADD(syms, name, content);
185 FIND(syms, name, content);
196 ASSERT_TRUE(mary == syms,
"copy test should compare properly");
199 ASSERT_TRUE(syms == chronos,
"copy test original should not be harmed");
205 fred.
add(
"urp",
"rarp");
206 fred.
add(
"hyurgh",
"ralph");
208 med.
add(
"urp",
"rarp");
209 med.
add(
"hyurgh",
"ralph");
214 fred.
add(
"urp",
"rarp");
215 fred.
add(
"gurp",
"flaarp");
219 ASSERT_TRUE(hyurgh,
"hyurgh should not go missing");
220 #ifdef DEBUG_STRING_TABLE
221 LOG(
astring(
"got urp as ") + (urp? *urp :
"empty!!!!"));
222 LOG(
astring(
"got hyurgh as ") + (hyurgh? *hyurgh :
"empty!!!!"));
228 #ifdef DEBUG_STRING_TABLE
229 LOG(
astring(
"got urp_val as ") + (urp_val.
t()? urp_val :
"empty!!!!"));
233 #ifdef DEBUG_STRING_TABLE
235 LOG(
"now packing the symbol table...");
239 syms.
pack(packed_form);
243 #ifdef DEBUG_STRING_TABLE
244 LOG(
"now unpacking from packed form");
247 ASSERT_TRUE(new_syms.
unpack(packed_form),
"unpack test should succeed in unpacking");
252 #ifdef DEBUG_STRING_TABLE
255 ASSERT_FALSE(! (syms == new_syms),
"unpacked test symbol tables should be same");
258 #ifdef DEBUG_STRING_TABLE
259 LOG(
"now deleting old symbol table...");
262 #ifdef DEBUG_STRING_TABLE
264 LOG(
"packing the symbol table again...");
268 new_syms.
pack(packed_again);
272 #ifdef DEBUG_STRING_TABLE
273 LOG(
"now unpacking from packed form again...");
276 newer_syms.
unpack(packed_again);
280 #ifdef DEBUG_STRING_TABLE
281 LOG(
astring(astring::SPRINTF,
"got the unpacked form, and dumping "
284 ASSERT_TRUE(new_syms == newer_syms,
"unpacked test should not be different symbol tables");
287 #ifdef DEBUG_STRING_TABLE
288 LOG(
"now deleting new and newer symbol table...");
295 int test_string_table::execute()
297 #ifdef DEBUG_STRING_TABLE
298 LOG(
astring(
"starting test: ") + time_stamp::notarize(
false));
301 #ifdef DEBUG_STRING_TABLE
302 LOG(
astring(
"done test: ") + time_stamp::notarize(
false));
310 return final_report();
#define FIND(name, value)
The application_shell is a base object for console programs.
Represents a sequential, ordered, contiguous collection of objects.
Provides a dynamically resizable ASCII character string.
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
bool t() const
t() is a shortcut for the string being "true", as in non-empty.
int find(char to_find, int position=0, bool reverse=false) const
Locates "to_find" in "this".
A very common template for a dynamic array of bytes.
the "common" class defines our common_outcomes.
Outcomes describe the state of completion for an operation.
Provides a symbol_table that holds strings as the content.
virtual bool unpack(basis::byte_array &packed_form)
Restores the packable from the "packed_form".
basis::astring text_form() const
prints the contents of the table into the returned string.
virtual void pack(basis::byte_array &packed_form) const
Creates a packed form of the packable object in "packed_form".
contents * find(const basis::astring &name) const
returns the contents held for "name" or NULL_POINTER if it wasn't found.
basis::outcome add(const basis::astring &name, const contents &storage)
Enters a symbol name into the table along with some contents.
Represents a point in time relative to the operating system startup time.
void reset()
sets the stamp time back to now.
time_representation value() const
returns the time_stamp in terms of the lower level type.
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
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.
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
unsigned int un_int
Abbreviated name for unsigned integers.
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.
A dynamic container class that holds any kind of object via pointers.
Useful support functions for unit testing, especially within hoople.
const int test_iterations
const int MAXIMUM_RANDOM_ADDS
const int TEST_SIZE_TABLE_COUNT
const int FIND_ITERATIONS
#define ASSERT_EQUAL(a, b, test_name)
#define ASSERT_TRUE(a, test_name)
#define ASSERT_FALSE(a, test_name)
#define ASSERT_INEQUAL(a, b, test_name)