27 using namespace basis;
33 #define GENERATE_TEST_NAME(group, message) \
34 (astring(group) + " test group: " + message)
36 #define TRY_ON(type, value, group) { \
37 byte_array temp_array; \
38 attach(temp_array, type(value)); \
41 ASSERT_TRUE(detach(temp_array, output), \
42 GENERATE_TEST_NAME(group, "should unpack " #type " okay")); \
43 ASSERT_TRUE(output == type(value), \
44 GENERATE_TEST_NAME(group, #type " value should match")); \
45 ASSERT_FALSE(temp_array.length(), \
46 GENERATE_TEST_NAME(group, #type " detached should be empty")); \
49 #define TRY_ON_OBSCURE(type, value, group) { \
50 byte_array temp_array; \
51 obscure_attach(temp_array, type(value)); \
54 ASSERT_TRUE(obscure_detach(temp_array, output), \
55 GENERATE_TEST_NAME(group, "should obscure unpack " #type " okay")); \
56 ASSERT_TRUE(output == type(value), \
57 GENERATE_TEST_NAME(group, #type " value should obscure match")); \
58 ASSERT_FALSE(temp_array.length(), \
59 GENERATE_TEST_NAME(group, #type " obscure detached should be empty")); \
62 #define TRY_ON_F(type, value, group) { \
63 byte_array temp_array; \
64 attach(temp_array, type(value)); \
67 ASSERT_TRUE(detach(temp_array, output), \
68 GENERATE_TEST_NAME(group, "should unpack " #type " fine")); \
72 int exponent_1, exponent_2; \
73 double mantissa_1 = frexp(output, &exponent_1); \
74 double mantissa_2 = frexp(output, &exponent_2); \
75 ASSERT_FALSE( (mantissa_1 != mantissa_2) || (exponent_1 != exponent_2), \
76 GENERATE_TEST_NAME(group, #type " value should match just so")); \
77 ASSERT_FALSE(temp_array.length(), \
78 GENERATE_TEST_NAME(group, #type " detached should have no data left")); \
85 ~test_object_packing() {}
94 int test_object_packing::execute()
116 #define TEST "second"
165 const int MAX_FLOAT_ITERS = 100;
167 while (iters++ < MAX_FLOAT_ITERS) {
171 double rand_float = (dividend / divisor) * multiplier;
173 rand_float = -1.0 * rand_float;
174 TRY_ON_F(
double, rand_float,
"third--loop");
181 #define TEST "fourth"
183 const char *tunnel_vision =
"plants can make good friends.";
184 const char *fresnel_lense =
"chimney sweeps carry some soot.";
185 const char *snoopy =
"small white dog with black spots.";
188 double perky_doodle = 3799.283e10;
189 const char *emptyish =
"";
193 attach(stored, tunnel_vision);
195 attach(stored, perky_doodle);
196 attach(stored, fresnel_lense);
242 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.
A very common template for a dynamic array of bytes.
#define MINBYTE
Minimum unsigned byte value.
#define MINCHAR
Minimum byte-based character value.
#define MAXBYTE
Maximum unsigned byte value.
#define MAXINT16
Maximum 32-bit integer value.
#define MAXCHAR
Maximum byte-based character value.
#define MAXINT32
Maximum 32-bit integer value.
#define MININT16
Minimum 32-bit integer value.
#define MININT32
Minimum 32-bit integer value.
#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.
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...
void attach(byte_array &packed_form, const char *to_attach)
Packs a character string "to_attach" into "packed_form".
unsigned int un_int
Abbreviated name for unsigned integers.
bool detach(byte_array &packed_form, astring &to_detach)
Unpacks a character string "to_attach" from "packed_form".
unsigned short un_short
Abbreviated name for unsigned short integers.
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.
#define GENERATE_TEST_NAME(group, message)
#define TRY_ON_F(type, value, group)
#define TRY_ON(type, value, group)
HOOPLE_MAIN(test_object_packing,)
#define TRY_ON_OBSCURE(type, value, group)
#define ASSERT_EQUAL(a, b, test_name)
#define ASSERT_TRUE(a, test_name)
#define ASSERT_FALSE(a, test_name)