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
44//const int ITEM_COUNT = 10000;
45const int ITEM_COUNT = 1000;
46 // the number of times to repeat each test operation.
47
48#define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), astring(s))
49#define BASE_LOG(s) EMERGENCY_LOG(program_wide_logger::get(), astring(s))
50
51class test_bin : virtual public unit_base, virtual public application_shell
52{
53public:
54 test_bin() : application_shell() {}
55 DEFINE_CLASS_NAME("test_bin");
56 int execute();
57};
58
60
61int test_bin::execute()
62{
63 FUNCDEF("execute");
64 char c = '\0';
65
67
69
70 enum test_types { ANY = 1, ENT, ID };
71
72 for (int q = ANY; q <= ID; q++) {
73LOG(a_sprintf("test type %d beginning...%c", q, c));
74 // using c just shuts up warnings.
75//LOG("note memory usage and hit a key:");
76//c = getchar();
77
79 for (int i = 1; i <= ITEM_COUNT; i++) {
80 // test the basic filling of the values in an entity.
81 octopus_request_id req_id;
82 int sequencer = randomizer().inclusive(1, MAXINT32 - 10);
83 int add_in = randomizer().inclusive(0, MAXINT32 - 10);
84 int process_id = randomizer().inclusive(0, MAXINT32 - 10);
86 process_id, sequencer, add_in);
87 req_id._request_num = randomizer().inclusive(1, MAXINT32 - 10);
88 infoton *torp = new security_infoton;
89 bing->add_item(torp, req_id);
90 item_list += req_id;
91
92 if (! (i % 50) ) {
93 printf("^");
94 fflush(NULL_POINTER);
95 }
96 }
98 LOG("");
99
100 int items_seen = 0;
101
103 if (q == ANY) {
104 while (item_list.length()) {
106 infoton *found = bing->acquire_for_any(id);
107 if (!found)
108 deadly_error(class_name(), "ANY", "item was missing");
109 WHACK(found);
110 items_seen++;
111 if (! (items_seen % 50) ) {
112 printf("v");
113 fflush(NULL_POINTER);
114 }
115 bool saw_it = false;
116 for (int q = 0; q < item_list.length(); q++) {
117 if (item_list[q] == id) {
118 saw_it = true;
119 item_list.zap(q, q);
120 break;
121 }
122 }
123 if (!saw_it)
124 deadly_error(class_name(), "ANY", "didn't see id for the item");
125 }
126 } else if (q == ENT) {
127 while (item_list.length()) {
129 infoton *found = bing->acquire_for_entity(item_list[0]._entity, id);
130 if (!found)
131 deadly_error(class_name(), "ENT", "item was missing");
132 WHACK(found);
133 items_seen++;
134 if (! (items_seen % 50) ) {
135 printf("v");
136 fflush(NULL_POINTER);
137 }
138 bool saw_it = false;
139 for (int q = 0; q < item_list.length(); q++) {
140 if (item_list[q] == id) {
141 saw_it = true;
142 item_list.zap(q, q);
143 break;
144 }
145 }
146 if (!saw_it)
147 deadly_error(class_name(), "ENT", "didn't see id for the item");
148 }
149 } else if (q == ID) {
150 for (int j = 0; j < item_list.length(); j++) {
151 infoton *found = bing->acquire_for_identifier(item_list[j]);
152 if (!found)
153 deadly_error(class_name(), "ENT", "item was missing");
154 WHACK(found);
155 items_seen++;
156 if (! (items_seen % 50) ) {
157 printf("v");
158 fflush(NULL_POINTER);
159 }
160 item_list.zap(j, j);
161 j--; // skip back.
162 }
163 } else {
164 deadly_error(class_name(), "looping", "bad enum value");
165 }
167 LOG("");
168 item_list.reset();
169 item_list.shrink();
170
171 if (bing->entities())
172 deadly_error(class_name(), "check left", "there are still contents in table!");
173
174 bing->clean_out_deadwood();
175
176LOG(a_sprintf("test type %d ending...", q));
177//LOG("note memory usage and hit a key:");
178//c = getchar();
179 }
180
181 WHACK(bing);
182LOG("done testing, zapped bin, now should be low memory.");
183//c = getchar();
184
185 LOG("octopus_entity:: works for those functions tested.");
186 return 0;
187}
188
189HOOPLE_MAIN(test_bin, )
190
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:48
const int ITEM_COUNT
Definition test_bin.cpp:45
#define randomizer()