feisty meow concerns codebase 2.140
test_bin.cpp
Go to the documentation of this file.
1/*****************************************************************************\
2* *
3* Name : entity_data_bin tester *
4* Author : Chris Koeritz *
5* *
6* Purpose: *
7* *
8* Checks that the entity_data_bin class is behaving as expected. *
9* *
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\*****************************************************************************/
18
21#include <basis/byte_array.h>
22#include <basis/functions.h>
23#include <basis/guards.h>
24#include <basis/astring.h>
27#include <mathematics/chaos.h>
29#include <octopus/entity_defs.h>
33#include <unit_test/unit_base.h>
34
35#include <stdio.h>
36
37using namespace application;
38using namespace basis;
39using namespace loggers;
40using namespace octopi;
41using namespace textual;
42using namespace unit_test;
43
44const int ITEM_COUNT = 10000;
45 // the number of times to repeat each test operation.
46
47#define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), astring(s))
48#define BASE_LOG(s) EMERGENCY_LOG(program_wide_logger::get(), astring(s))
49
50class test_bin : virtual public unit_base, virtual public application_shell
51{
52public:
53 test_bin() : application_shell() {}
54 DEFINE_CLASS_NAME("test_bin");
55 int execute();
56};
57
59
60int test_bin::execute()
61{
62 FUNCDEF("execute");
63 char c = '\0';
64
66
68
69 enum test_types { ANY = 1, ENT, ID };
70
71 for (int q = ANY; q <= ID; q++) {
72LOG(a_sprintf("test type %d beginning...%c", q, c));
73 // using c just shuts up warnings.
74//LOG("note memory usage and hit a key:");
75//c = getchar();
76
78 for (int i = 1; i <= ITEM_COUNT; i++) {
79 // test the basic filling of the values in an entity.
80 octopus_request_id req_id;
81 int sequencer = randomizer().inclusive(1, MAXINT32 - 10);
82 int add_in = randomizer().inclusive(0, MAXINT32 - 10);
83 int process_id = randomizer().inclusive(0, MAXINT32 - 10);
85 process_id, sequencer, add_in);
86 req_id._request_num = randomizer().inclusive(1, MAXINT32 - 10);
87 infoton *torp = new security_infoton;
88 bing->add_item(torp, req_id);
89 item_list += req_id;
90
91 if (! (i % 50) ) {
92 printf("^");
93 fflush(NULL_POINTER);
94 }
95 }
97 LOG("");
98
99 int items_seen = 0;
100
102 if (q == ANY) {
103 while (item_list.length()) {
105 infoton *found = bing->acquire_for_any(id);
106 if (!found)
107 deadly_error(class_name(), "ANY", "item was missing");
108 WHACK(found);
109 items_seen++;
110 if (! (items_seen % 50) ) {
111 printf("v");
112 fflush(NULL_POINTER);
113 }
114 bool saw_it = false;
115 for (int q = 0; q < item_list.length(); q++) {
116 if (item_list[q] == id) {
117 saw_it = true;
118 item_list.zap(q, q);
119 break;
120 }
121 }
122 if (!saw_it)
123 deadly_error(class_name(), "ANY", "didn't see id for the item");
124 }
125 } else if (q == ENT) {
126 while (item_list.length()) {
128 infoton *found = bing->acquire_for_entity(item_list[0]._entity, id);
129 if (!found)
130 deadly_error(class_name(), "ENT", "item was missing");
131 WHACK(found);
132 items_seen++;
133 if (! (items_seen % 50) ) {
134 printf("v");
135 fflush(NULL_POINTER);
136 }
137 bool saw_it = false;
138 for (int q = 0; q < item_list.length(); q++) {
139 if (item_list[q] == id) {
140 saw_it = true;
141 item_list.zap(q, q);
142 break;
143 }
144 }
145 if (!saw_it)
146 deadly_error(class_name(), "ENT", "didn't see id for the item");
147 }
148 } else if (q == ID) {
149 for (int j = 0; j < item_list.length(); j++) {
150 infoton *found = bing->acquire_for_identifier(item_list[j]);
151 if (!found)
152 deadly_error(class_name(), "ENT", "item was missing");
153 WHACK(found);
154 items_seen++;
155 if (! (items_seen % 50) ) {
156 printf("v");
157 fflush(NULL_POINTER);
158 }
159 item_list.zap(j, j);
160 j--; // skip back.
161 }
162 } else {
163 deadly_error(class_name(), "looping", "bad enum value");
164 }
166 LOG("");
167 item_list.reset();
168 item_list.shrink();
169
170 if (bing->entities())
171 deadly_error(class_name(), "check left", "there are still contents in table!");
172
173 bing->clean_out_deadwood();
174
175LOG(a_sprintf("test type %d ending...", q));
176//LOG("note memory usage and hit a key:");
177//c = getchar();
178 }
179
180 WHACK(bing);
181LOG("done testing, zapped bin, now should be low memory.");
182//c = getchar();
183
184 LOG("octopus_entity:: works for those functions tested.");
185 return 0;
186}
187
188HOOPLE_MAIN(test_bin, )
189
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.
a_sprintf is a specialization of astring that provides printf style support.
Definition astring.h:440
Represents a sequential, ordered, contiguous collection of objects.
Definition array.h:54
void reset(int number=0, const contents *initial_contents=NULL_POINTER)
Resizes this array and sets the contents from an array of contents.
Definition array.h:349
outcome shrink()
Cuts loose any allocated space that is beyond the real length.
Definition array.h:463
int length() const
Returns the current reported length of the allocated C array.
Definition array.h:115
outcome zap(int start, int end)
Deletes from "this" the objects inclusively between "start" and "end".
Definition array.h:769
virtual textual::parser_bits::line_ending eol()
observes how line endings are to be printed.
Definition eol_aware.h:34
static loggers::standard_log_base & get()
Provided by the startup code within each application for logging.
Stores a set of infotons grouped by the entity that owns them.
bool add_item(infoton *to_add, const octopus_request_id &id)
infoton * acquire_for_any(octopus_request_id &id)
infoton * acquire_for_identifier(const octopus_request_id &id)
void clean_out_deadwood(int decay_interval=4 *basis::MINUTE_ms)
infoton * acquire_for_entity(const octopus_entity &requester, octopus_request_id &id)
An infoton is an individual request parcel with accompanying information.
Definition infoton.h:32
Provides a way of identifying users of an octopus object.
Definition entity_defs.h:35
Identifies requests made on an octopus by users.
int _request_num
the item number from the entity.
octopus_entity _entity
the entity.
Encapsulates security activities (login, logout, refresh).
@ CRLF_AT_END
DOS standard is CRLF_AT_END ("\r\n").
Definition parser_bits.h:33
@ NO_ENDING
No additional characters added as line endings.
Definition parser_bits.h:34
static basis::astring make_random_name(int min=1, int max=64)
creates a random name, where the letters are between 'a' and 'z'.
#define deadly_error(c, f, i)
#define NULL_POINTER
The value representing a pointer to nothing.
Definition definitions.h:32
#define MAXINT32
Maximum 32-bit integer value.
Definition definitions.h:75
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition enhance_cpp.h:42
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition enhance_cpp.h:54
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.
Definition hoople_main.h:61
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
Definition array.h:30
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
Definition functions.h:121
const int MEGABYTE
Number of bytes in a megabyte.
A logger that sends to the console screen using the standard output device.
Useful support functions for unit testing, especially within hoople.
Definition unit_base.cpp:35
#define LOG(s)
Definition test_bin.cpp:47
const int ITEM_COUNT
Definition test_bin.cpp:44
#define randomizer()