29 using namespace basis;
46 #define LOG(to_print) EMERGENCY_LOG(program_wide_logger::get(), astring(to_print))
66 virtual void text_form(
base_string &state_fill)
const {
67 state_fill.
assign(
astring(class_name()) +
": uhhh not really implemented");
70 virtual bool equal_to(
const equalizable &s2)
const {
71 const my_table_def *to_compare =
dynamic_cast<const my_table_def *
>(&s2);
72 if (!to_compare)
return false;
73 if (symbols() != to_compare->symbols())
return false;
74 for (
int i = 0; i < symbols(); i++) {
75 if (name(i) != to_compare->name(i))
return false;
76 if (
operator [](i) != (*to_compare)[i])
return false;
90 bool operator ==(
const jethro &tc)
const {
return tc._truck == _truck; }
91 bool operator !=(
const jethro &tc)
const {
return !(*
this == tc); }
107 test_content() : _q(9) {}
109 test_content(
const astring &ted,
const astring &jed) : _q(4), _ted(ted),
115 _ted.
pack(packed_form);
116 _jed.
pack(packed_form);
122 if (!
detach(packed_form, _q))
return false;
123 if (!_ted.
unpack(packed_form))
return false;
124 if (!_jed.
unpack(packed_form))
return false;
128 bool operator ==(
const test_content &tc)
const {
129 if (tc._q != _q)
return false;
130 if (tc._ted != _ted)
return false;
131 if (tc._jed != _jed)
return false;
132 if (tc._ned.length() != _ned.
length())
return false;
133 for (
int i = 0; i < _ned.
length(); i++)
134 if (tc._ned[i] != _ned[i])
return false;
136 if (tc._med.rows() != _med.
rows())
return false;
137 if (tc._med.columns() != _med.
columns())
return false;
138 for (
int c = 0; c < _med.
columns(); c++)
139 for (
int r = 0; r < _med.
rows(); r++)
140 if (tc._med.get(r, c) != _med.
get(r, c))
return false;
144 bool operator !=(
const test_content &tc)
const {
return !operator ==(tc); }
146 operator int()
const {
return _q; }
156 virtual
void text_form(
base_string &state_fill)
const {
157 state_fill.assign(
astring(class_name()) +
": uhhh not really implemented");
160 virtual bool equal_to(
const equalizable &s2)
const {
161 const second_table_def *to_compare =
dynamic_cast<const second_table_def *
>(&s2);
162 if (symbols() != to_compare->symbols())
return false;
163 for (
int i = 0; i < symbols(); i++) {
164 if ((*
this)[i] != (*to_compare)[i])
return false;
175 test_symbol_table() {}
180 virtual int execute();
185 void ADD2(second_table_def &syms,
const astring &name,
const test_content &to_add);
190 void pack(
byte_array &packed_form,
const second_table_def &to_pack);
193 void test_byte_table();
194 void test_tc_table();
204 outcome added = syms.add(name, to_stuff);
210 int indy = syms.find(name);
217 ASSERT_TRUE(found,
"really should be in table after add");
221 ASSERT_EQUAL(*found, to_stuff,
"value should be right in table after add");
232 int indy = syms.find(name);
234 indy = syms.find(name);
240 int indy = syms.dep_find(name);
246 ASSERT_TRUE(found,
"second find should see item in table (new_find)");
255 attach(packed_form, to_pack.symbols());
258 for (
int i = 0; i < to_pack.symbols(); i++) {
259 to_pack.retrieve(i, name, content);
260 name.
pack(packed_form);
261 attach(packed_form, content);
269 if (!
detach(packed_form, syms))
return false;
272 for (
int i = 0; i < syms; i++) {
273 if (!name.
unpack(packed_form))
return false;
274 if (!
detach(packed_form, chunk))
return false;
275 ADD(to_unpack, name, (
char *)chunk.
observe());
282 attach(packed_form, to_pack.symbols());
284 test_content content;
285 for (
int i = 0; i < to_pack.symbols(); i++) {
286 to_pack.retrieve(i, name, content);
287 name.
pack(packed_form);
288 content.pack(packed_form);
296 if (!
detach(packed_form, syms))
return false;
299 for (
int i = 0; i < syms; i++) {
300 if (!name.
unpack(packed_form))
return false;
301 if (!chunk.unpack(packed_form))
return false;
302 to_unpack.add(name, chunk);
311 my_table_def to_return;
315 name = string_manipulation::make_random_name(40, 108);
316 content = string_manipulation::make_random_name(300, 1000);
318 to_return.add(name, to_stuff);
325 void test_symbol_table::test_byte_table()
329 my_table_def new_syms;
330 my_table_def newer_syms;
333 #ifdef DEBUG_SYMBOL_TABLE
334 LOG(
astring(astring::SPRINTF,
"index %d", qq));
337 astring freud(
"Sigmund Freud was a very freaked dude.");
338 ADD(syms, freudname, freud);
340 astring borg(
"You will be assimilated.");
341 ADD(syms, borgname, borg);
343 astring x(
"The great unknown superhero cartoon.");
345 astring aname(
"fleeny-brickle");
346 astring a(
"lallax menick publum.");
349 astring ax(
"Lizzy Borden has a very large hatchet.");
350 ADD(syms, axname, ax);
352 astring bloink(
"this is a short and stupid string");
353 ADD(syms, bloinkname, bloink);
355 astring fax(
"alligators in my teacup.");
356 ADD(syms, faxname, fax);
357 astring zname(
"eagle ovaries");
358 astring z(
"malfeasors beware");
361 FIND(syms, freudname, freud);
362 FIND(syms, borgname, borg);
363 FIND(syms, xname, x);
364 FIND(syms, aname, a);
365 FIND(syms, axname, ax);
366 FIND(syms, bloinkname, bloink);
367 FIND(syms, faxname, fax);
368 FIND(syms, zname, z);
373 name = string_manipulation::make_random_name(40, 108);
374 content = string_manipulation::make_random_name(300, 1000);
375 ADD(syms, name, content);
376 FIND(syms, name, content);
381 my_table_def copy1(syms);
383 my_table_def joe(copy1);
384 my_table_def joe2 = joe;
385 ASSERT_EQUAL(joe2, joe,
"copy test A: symbol tables should be same");
387 my_table_def joe4 = joe3;
388 my_table_def joe5 = joe4;
389 ASSERT_EQUAL(joe5, joe3,
"copy test A2: symbol tables should be same");
391 ASSERT_FALSE(! (syms == copy1),
"copy test B: symbol tables should be same still");
395 #ifdef DEBUG_SYMBOL_TABLE
397 LOG(
"now packing the symbol table...");
400 #ifdef DEBUG_SYMBOL_TABLE
401 LOG(
"now unpacking from packed form");
404 pack(packed_form, syms);
405 ASSERT_TRUE(
unpack(packed_form, new_syms),
"unpack test should not fail to unpack");
407 #ifdef DEBUG_SYMBOL_TABLE
410 ASSERT_FALSE(! (syms == new_syms),
"unpacked test symbol tables must be equal");
412 #ifdef DEBUG_SYMBOL_TABLE
414 LOG(
"packing the symbol table again...");
418 pack(packed_again, new_syms);
421 #ifdef DEBUG_SYMBOL_TABLE
422 LOG(
"now unpacking from packed form again...");
425 ASSERT_TRUE(
unpack(packed_again, newer_syms),
"newer unpacking should working be");
428 #ifdef DEBUG_SYMBOL_TABLE
432 "unpacked test these just aren't getting it but should be same");
438 void test_symbol_table::ADD2(second_table_def &syms,
const astring &name,
439 const test_content &to_add)
443 outcome added = syms.add(name, to_add);
444 ASSERT_EQUAL(added.value(),
common::IS_NEW, "new item should not already be in table");
449 int indy = syms.find(name);
452 indy = syms.find(name);
457 int indy = syms.dep_find(name);
462 test_content *found = syms.find(name);
463 ASSERT_TRUE(found,
"item shouldn't be nil that we found");
468 test_content content_out;
469 if (syms.retrieve(indy, name_out, content_out) != common::OKAY) {
470 ASSERT_EQUAL(name_out, name,
"name should be correct after retrieve");
471 ASSERT_EQUAL(content_out, to_add,
"content should be correct after retrieve");
477 void test_symbol_table::test_tc_table()
480 second_table_def syms;
481 second_table_def new_syms;
482 second_table_def newer_syms;
485 #ifdef DEBUG_SYMBOL_TABLE
486 LOG(
astring(astring::SPRINTF,
"index %d", qq));
489 test_content freud(
"Sigmund Freud was a very freaked dude.",
"flutenorf");
490 ADD2(syms, freudname, freud);
492 test_content borg(
"You will be assimilated.",
"alabaster");
493 ADD2(syms, borgname, borg);
495 test_content x(
"The great unknown superhero cartoon.",
"somnambulist");
496 ADD2(syms, xname, x);
497 astring aname(
"fleeny-brickle");
498 test_content a(
"lallax menick publum.",
"aglos bagnort pavlod");
499 ADD2(syms, aname, a);
501 test_content ax(
"Lizzy Borden has a very large hatchet.",
"chop");
502 ADD2(syms, axname, ax);
504 test_content bloink(
"this is a short and stupid string",
"not that short");
505 ADD2(syms, bloinkname, bloink);
507 test_content fax(
"alligators in my teacup.",
"lake placid");
508 ADD2(syms, faxname, fax);
509 astring zname(
"eagle ovaries");
510 test_content z(
"malfeasors beware",
"endangered");
511 ADD2(syms, zname, z);
515 second_table_def copy1(syms);
517 second_table_def joe(copy1);
518 second_table_def joe2 = joe;
519 ASSERT_EQUAL(joe2, joe,
"copy test C: should have same symbol tables");
521 ASSERT_FALSE(! (syms == copy1),
"copy test D: symbol tables shouldn't be different");
525 #ifdef DEBUG_SYMBOL_TABLE
528 LOG(
astring(
"This is the symbol table before any manipulation\n") + texto);
529 LOG(
"now packing the symbol table...");
532 #ifdef DEBUG_SYMBOL_TABLE
533 LOG(
"now unpacking from packed form");
536 pack(packed_form, syms);
537 ASSERT_TRUE(
unpack(packed_form, new_syms),
"crikey all these unpacks should work");
538 #ifdef DEBUG_SYMBOL_TABLE
539 new_syms.text_form(texto);
542 ASSERT_FALSE(! (syms == new_syms),
"unpacked test symbol tables should be equivalent");
544 #ifdef DEBUG_SYMBOL_TABLE
545 new_syms.text_form(texto);
546 LOG(
astring(
"got the unpacked form, and dumping it:\n") + texto);
547 LOG(
"packing the symbol table again...");
550 pack(packed_again, new_syms);
551 #ifdef DEBUG_SYMBOL_TABLE
552 LOG(
"now unpacking from packed form again...");
554 ASSERT_TRUE(
unpack(packed_again, newer_syms),
"unpacking should get back the goods");
555 #ifdef DEBUG_SYMBOL_TABLE
556 newer_syms.text_form(texto);
557 LOG(
astring(
"got the unpacked form, and dumping it:\n") + texto);
559 ASSERT_FALSE(! (new_syms == newer_syms),
"unpacked test symbol tables should stay same");
565 int test_symbol_table::execute()
567 #ifdef DEBUG_SYMBOL_TABLE
568 LOG(
astring(
"starting test 1: ") + time_stamp::notarize(
false));
571 #ifdef DEBUG_SYMBOL_TABLE
572 LOG(
astring(
"done test 1: ") + time_stamp::notarize(
false));
573 LOG(
astring(
"starting test 2: ") + time_stamp::notarize(
false));
577 #ifdef DEBUG_SYMBOL_TABLE
578 LOG(
astring(
"done test 2: ") + time_stamp::notarize(
false));
585 return final_report();
#define FIND(name, value)
The application_shell is a base object for console programs.
const contents * observe() const
Returns a pointer to the underlying C array of data.
int length() const
Returns the current reported length of the allocated C array.
Provides a dynamically resizable ASCII character string.
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
void pack(byte_array &target) const
stores this string in the "target". it can later be unpacked again.
int packed_size() const
Reports the size required to pack this string into a byte array.
virtual void text_form(base_string &state_fill) const
Provides a text view of all the important info owned by this object.
int length() const
Returns the current length of the string.
bool unpack(byte_array &source)
retrieves a string (packed with pack()) from "source" into this string.
Defines the base class for all string processing objects in hoople.
virtual base_string & assign(const base_string &s)=0
Sets the contents of this string to "s".
A very common template for a dynamic array of bytes.
the "common" class defines our common_outcomes.
Base class for object that can tell itself apart from other instances.
the base class of the most easily used and tested objects in the library.
A simple object that wraps a templated array of ints.
Outcomes describe the state of completion for an operation.
A base class for objects that can pack into an array of bytes.
contents & get(int row, int column)
Maintains a list of names, where each name has a type and 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.
bool operator!=(const T1 &x, const T2 &y)
unsigned char abyte
A fairly important unit which is seldom defined...
void attach(byte_array &packed_form, const char *to_attach)
Packs a character string "to_attach" into "packed_form".
bool detach(byte_array &packed_form, astring &to_detach)
Unpacks a character string "to_attach" from "packed_form".
bool negative(const type &a)
negative returns true if "a" is less than zero.
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.
bool unpack(basis::byte_array &packed_form, set< contents > &to_unpack)
provides a way to unpack any set that stores packable objects.
void pack(basis::byte_array &packed_form, const set< contents > &to_pack)
provides a way to pack any set that stores packable objects.
int packed_size(const byte_array &packed_form)
Reports the size required to pack a byte array into a byte array.
Useful support functions for unit testing, especially within hoople.
my_table_def creatapose()
const int test_iterations
const int MAXIMUM_RANDOM_ADDS
const int FIND_ITERATIONS
#define ASSERT_EQUAL(a, b, test_name)
#define ASSERT_TRUE(a, test_name)
#define ASSERT_FALSE(a, test_name)