1 /*****************************************************************************\
3 * Name : octopus_entity tester *
4 * Author : Chris Koeritz *
8 * Checks that the octopus_entity class is behaving as expected. *
10 *******************************************************************************
11 * Copyright (c) 2002-$now By Author. This program is free software; you can *
12 * redistribute it and/or modify it under the terms of the GNU General Public *
13 * License as published by the Free Software Foundation; either version 2 of *
14 * the License or (at your option) any later version. This is online at: *
15 * http://www.fsf.org/copyleft/gpl.html *
16 * Please send any updates to: fred@gruntose.com *
17 \*****************************************************************************/
19 #include <basis/byte_array.h>
20 #include <mathematics/chaos.h>
21 #include <basis/guards.h>
22 #include <basis/astring.h>
23 #include <octopus/entity_defs.h>
24 #include <application/application_shell.h>
25 #include <loggers/console_logger.h>
26 #include <loggers/file_logger.h>
27 #include <structures/static_memory_gremlin.h>
28 #include <sockets/tcpip_stack.h>
29 #include <textual/string_manipulation.h>
37 const int ITERATE_EACH_TEST = 1000;
38 // the number of times to repeat each test operation.
40 class test_entity : public application_shell
43 test_entity() : application_shell(class_name()) {}
44 DEFINE_CLASS_NAME("test_entity");
45 virtual int execute();
48 int test_entity::execute()
51 SET_DEFAULT_COMBO_LOGGER;
54 octopus_entity blankie;
56 deadly_error(class_name(), "emptiness test",
57 "the blank entity was not seen as empty.");
58 octopus_entity fullish("gurp", 28, 39, 4);
60 deadly_error(class_name(), "emptiness test",
61 "the non-blank entity was seen as empty.");
63 for (int i = 0; i < ITERATE_EACH_TEST; i++) {
64 // test the basic filling of the values in an entity.
65 octopus_entity blank_ent;
66 int sequencer = rando.inclusive(1, MAXINT - 10);
67 int add_in = rando.inclusive(0, MAXINT - 10);
68 octopus_entity filled_ent(stack.hostname(), application_configuration::process_id(), sequencer,
70 blank_ent = octopus_entity(stack.hostname(), application_configuration::process_id(), sequencer,
72 if (blank_ent != filled_ent)
73 deadly_error(class_name(), "simple reset test",
74 "failed to resolve to same id");
75 astring text1 = filled_ent.to_text();
76 astring text2 = blank_ent.to_text();
78 deadly_error(class_name(), "to_text test", "strings are different");
80 octopus_entity georgio = octopus_entity::from_text(text2);
81 ///log(georgio.to_text());
82 if (georgio != filled_ent)
83 deadly_error(class_name(), "from_text test",
84 "entity is different after from_text");
86 octopus_request_id fudnix(filled_ent, 8232390);
87 astring text3 = fudnix.to_text();
88 octopus_request_id resur = octopus_request_id::from_text(text3);
90 deadly_error(class_name(), "from_text test",
91 "request id is different after from_text");
93 blank_ent = octopus_entity(); // reset it again forcefully.
94 blank_ent = octopus_entity(filled_ent.hostname(), filled_ent.process_id(),
95 filled_ent.sequencer(), filled_ent.add_in());
96 if (blank_ent != filled_ent)
97 deadly_error(class_name(), "reset from attribs test",
98 "failed to resolve to same id");
99 // log(a_sprintf("%d: ", i + 1) + filled_ent.mangled_form());
102 filled_ent.pack(chunk1);
103 octopus_entity unpacked1;
104 unpacked1.unpack(chunk1);
105 if (unpacked1 != filled_ent)
106 deadly_error(class_name(), "pack/unpack test",
107 "failed to return same values");
109 // test of entity packing and size calculation.
110 octopus_entity ent(string_manipulation::make_random_name(1, 428),
111 randomizer().inclusive(0, MAXINT/2),
112 randomizer().inclusive(0, MAXINT/2),
113 randomizer().inclusive(0, MAXINT/2));
114 octopus_request_id bobo(ent, randomizer().inclusive(0, MAXINT/2));
115 int packed_estimate = bobo.packed_size();
116 byte_array packed_bobo;
117 bobo.pack(packed_bobo);
118 if (packed_bobo.length() != packed_estimate)
119 deadly_error(class_name(), "entity packed_size test",
120 "calculated incorrect packed size");
124 log("octopus_entity:: works for those functions tested.");
128 //hmmm: tests the octopus entity object,
129 // can do exact text check if want but that's not guaranteed to be useful
132 HOOPLE_MAIN(test_entity, )