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 {
53 printf(the_actual_string);
58 char the_actual_string[500];
61 int another_useless_int;
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()))
88int bogotre::packed_size()
const
89{
return strlen(the_actual_string) + 1 +
sizeof(int) * 2 +
sizeof(
abyte); }
91void bogotre::pack(
byte_array &packed_form)
const
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");
128void 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; }
151void 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);
159int test_tree::execute()
184#ifdef DEBUG_TEST_TREE
188#ifdef DEBUG_TEST_TREE
189 printf(
"\nprefix is ");
192#ifdef DEBUG_TEST_TREE
193 printf(
"\npostfix is ");
196#ifdef DEBUG_TEST_TREE
198 printf(
"branches is ");
201#ifdef DEBUG_TEST_TREE
203 printf(
"branches reversed is ");
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");
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.
virtual int execute()=0
< retrieves the command line from the /proc hierarchy on linux.
application_shell()
constructs an application_shell to serve as the root of the program.
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.
virtual int packed_size() const =0
Estimates the space needed for the packed structure.
virtual bool unpack(byte_array &packed_form)=0
Restores the packable from the "packed_form".
virtual void pack(byte_array &packed_form) const =0
Creates a packed form of the packable object in "packed_form".
tree * next()
Returns a pointer to the next tree in the direction of traversal.
A dynamically linked tree with an arbitrary number of branches.
iterator start(traversal_directions direction) const
Returns a fresh iterator positioned at this tree node.
#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.
void attach(byte_array &packed_form, const byte_array &to_attach)
Packs a byte_array "to_attach" into "packed_form".
bool detach(byte_array &packed_form, byte_array &to_detach)
Unpacks a byte_array "to_detach" from "packed_form".
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)