25 using namespace basis;
26 using namespace nodes;
39 bogotre(
const char *start =
NULL_POINTER) : who_cares(42), i_sure_dont(
'l'),
40 another_useless_int(23) {
42 if (to_init.
length() < 1) to_init +=
"ack";
50 virtual abyte *held()
const {
return (
abyte *)the_actual_string; }
51 virtual void print()
const {
52 #ifdef DEBUG_TEST_TREE
53 printf(the_actual_string);
58 char the_actual_string[500];
61 int another_useless_int;
76 virtual int execute();
77 static void print_node(
larch *curr_node);
85 #undef UNIT_BASE_THIS_OBJECT
86 #define UNIT_BASE_THIS_OBJECT (*dynamic_cast<unit_base *>(application_shell::single_instance()))
89 {
return strlen(the_actual_string) + 1 +
sizeof(int) * 2 +
sizeof(
abyte); }
106 int(1 +
sizeof(who_cares) +
sizeof(i_sure_dont) +
sizeof(another_useless_int)),
107 "size of package should be correct");
113 "should retrieve another_...");
115 ASSERT_EQUAL(who_cares, 42,
"bogotre_unpack - right value held in first int");
116 ASSERT_EQUAL(i_sure_dont,
'l',
"bogotre_unpack - right character held");
117 ASSERT_EQUAL(another_useless_int, 23,
"bogotre_unpack - right value held in second int");
128 void test_tree::print_node(
larch *curr_node)
132 bogotre *real_curr =
dynamic_cast<bogotre *
>(curr_node);
133 ASSERT_TRUE(real_curr,
"contents shouldn't be nil");
134 astring to_examine((
char *)real_curr->held());
135 #ifdef DEBUG_TEST_TREE
137 printf(to_examine.s());
143 #undef UNIT_BASE_THIS_OBJECT
144 #define UNIT_BASE_THIS_OBJECT (*this)
149 { move =
dynamic_cast<larch *
>(skip.
next());
return move; }
151 void test_tree::apply(
larch *apply_to,
applier *to_apply,
155 for (
traveller skippy = apply_to->start(order);
156 next(curr, apply_to, skippy); ) to_apply(curr);
159 int test_tree::execute()
184 #ifdef DEBUG_TEST_TREE
187 apply(e9, print_node, tree::infix);
188 #ifdef DEBUG_TEST_TREE
189 printf(
"\nprefix is ");
191 apply(e9, print_node, tree::prefix);
192 #ifdef DEBUG_TEST_TREE
193 printf(
"\npostfix is ");
195 apply(e9, print_node, tree::postfix);
196 #ifdef DEBUG_TEST_TREE
198 printf(
"branches is ");
200 apply(e9, print_node, tree::to_branches);
201 #ifdef DEBUG_TEST_TREE
203 printf(
"branches reversed is ");
205 apply(e9, print_node, tree::reverse_branches);
206 #ifdef DEBUG_TEST_TREE
208 printf(
"before first pack");
211 int sizzle = e9->packed_size();
213 ASSERT_EQUAL(sizzle, packed_e9.length(),
"packed size should agree with results");
214 #ifdef DEBUG_TEST_TREE
215 printf(
"after first pack, size is %d\n", packed_e9.length());
218 new_e9->unpack(packed_e9);
219 #ifdef DEBUG_TEST_TREE
220 printf(
"New tree after unpacking is (infix order):\n");
222 apply(new_e9, print_node, tree::infix);
223 #ifdef DEBUG_TEST_TREE
275 #ifdef DEBUG_TEST_TREE
276 printf(
"deleting\n");
302 return final_report();
The application_shell is a base object for console programs.
int length() const
Returns the current reported length of the allocated C array.
Provides a dynamically resizable ASCII character string.
void pack(byte_array &target) const
stores this string in the "target". it can later be unpacked again.
void stuff(char *to_stuff, int count) const
a synonym for copy().
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.
A very common template for a dynamic array of bytes.
A base class for objects that can pack into an array of bytes.
tree * next()
Returns a pointer to the next tree in the direction of traversal.
A dynamically linked tree with an arbitrary number of branches.
#define formal(parameter)
This macro just eats what it's passed; it marks unused formal parameters.
#define NULL_POINTER
The value representing a pointer to nothing.
#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 char abyte
A fairly important unit which is seldom defined...
type minimum(type a, type b)
maximum returns the greater of two values.
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.
bool unpack(basis::byte_array &packed_form, set< contents > &to_unpack)
provides a way to unpack any set that stores packable objects.
void attach(byte_array &packed_form, const byte_array &to_attach)
Packs a byte_array "to_attach" into "packed_form".
void pack(basis::byte_array &packed_form, const set< contents > &to_pack)
provides a way to pack any set that stores packable objects.
bool detach(byte_array &packed_form, byte_array &to_detach)
Unpacks a byte_array "to_detach" from "packed_form".
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.
const int test_iterations
void() applier(larch *apply_to)
#define ASSERT_EQUAL(a, b, test_name)
#define ASSERT_TRUE(a, test_name)
#define ASSERT_FALSE(a, test_name)