BAM
Abstract Machine for Bottom-Up Evaluation with the Push Method
rtest.h
Go to the documentation of this file.
1 // ============================================================================
2 // Project: Deductive Database
3 // Filename: rtest.h
4 // Purpose: Superclass for Standard Tests of Relation-like Data Structures
5 // Last Change: 04.08.2017
6 // Language: C++
7 // EMail: brass@informatik.uni-halle.de
8 // WWW: http://www.informatik.uni-halle.de/~brass/
9 // Address: Feldschloesschen 15, D-06120 Halle (Saale), GERMANY
10 // Copyright: (c) 2016-2017 by Stefan Brass
11 // License: See file "LICENSE" for copying conditions.
12 // Note: There is no warranty at all - this code may contain bugs.
13 // ============================================================================
14 
15 
22 //=============================================================================
23 // Include File Frame:
24 //=============================================================================
25 
26 #ifndef RTEST_INCLUDED
27 #define RTEST_INCLUDED
28 
29 //=============================================================================
30 // Used Types and Macros:
31 //=============================================================================
32 
33 #ifndef VER_INCLUDED
34 #include "../base/ver.h"
35 #endif
36 
37 #ifndef STR_INCLUDED
38 #include "../base/str.h"
39 #endif
40 
41 #ifndef CHECK_INCLUDED
42 #include "../base/check.h"
43 #endif
44 
45 #ifndef RELSIZE_INCLUDED
46 #include "../rel/relsize.h"
47 #endif
48 
49 #ifndef REL_INCLUDED
50 #include "../rel/rel.h"
51 #endif
52 
53 
54 //=============================================================================
55 // Private Constants:
56 //=============================================================================
57 
58 //-----------------------------------------------------------------------------
59 // RTEST_MAGIC: Magic number (identifies objects of this class).
60 //-----------------------------------------------------------------------------
61 
62 static const long RTEST_MAGIC = 0x5254450AL; // 'RTE\n'
63 
64 //-----------------------------------------------------------------------------
65 // RTEST_ROW_SIZE: Size of the string buffer for the problematic row.
66 //-----------------------------------------------------------------------------
67 
68 static const int RTEST_ROW_SIZE = 80;
69 
70 
71 //=============================================================================
72 // Class Declaration:
73 //=============================================================================
74 
81 class rtest_c {
82  public:
83 
84 //-----------------------------------------------------------------------------
85 // Constructor, Destructor:
86 //-----------------------------------------------------------------------------
87 
88  // Constructor:
89  rtest_c(rel_t rel);
90 
91  // Destructor:
92  ~rtest_c();
93 
94 //-----------------------------------------------------------------------------
95 // Abstract Methods Required by this Class:
96 //-----------------------------------------------------------------------------
97 
103  virtual int insert() = 0;
104 
110  virtual int lookup() = 0;
111 
112 
118  virtual int size_value(relsize_t relsize) = 0;
119 
120 
121 //-----------------------------------------------------------------------------
122 // Methods for accessing attributes (basic test data):
123 //-----------------------------------------------------------------------------
124 
125  //---------------------------------------------------------------------
129  //---------------------------------------------------------------------
130 
131  rel_t rel() {
132 
133  // Check this object:
134  CHECK_VALID("rtest_c::rel");
135 
136  // Return number of bound arguments:
137  return Rel;
138  }
139 
140 
141  //---------------------------------------------------------------------
149  //---------------------------------------------------------------------
150 
151  int num_rows() {
152 
153  // Check this object:
154  CHECK_VALID("rtest_c::num_rows");
155 
156  // Return number of inserted rows:
157  return NumRows;
158  }
159 
160 
161  //---------------------------------------------------------------------
175  //---------------------------------------------------------------------
176 
178 
179  // Check this object:
180  CHECK_VALID("rtest_c::error_row");
181 
182  // There must be an error if this function is called:
183  CHECK(ErrorRow[0] != '\0',
184  "rtest_c::error_row: No error detected");
185 
186  // Return row at which the error was detected:
187  return ErrorRow;
188  }
189 
190 
191 //-----------------------------------------------------------------------------
192 // Methods to be called by subclasses to store data in this object:
193 //-----------------------------------------------------------------------------
194 
195  protected:
196 
197  //---------------------------------------------------------------------
207  //---------------------------------------------------------------------
208 
209  void inserted_rows(int n) {
210 
211  // Check this object:
212  CHECK_VALID("rtest_c::inserted_rows");
213 
214  // Check parameter:
215  CHECK(n >= 0,
216  "rtest_c::inserted_rows: n must be non-negative");
217 
218  // Increase number of rows:
219  NumRows += n;
220  }
221 
222  //---------------------------------------------------------------------
226  //---------------------------------------------------------------------
227 
228  void error_row_open() {
229 
230  // Check this object:
231  CHECK_VALID("rtest_c::error_row_open");
232 
233  // Initialize string buffer attributes:
234  ErrorRowPtr = ErrorRow;
235  ErrorRowFree = RTEST_ROW_SIZE - 1;
236  ErrorRowCol = 0;
237 
238  // Write opening paranthesis:
239  if(ErrorRowFree >= 1) {
240  *ErrorRowPtr++ = '[';
241  ErrorRowFree--;
242  }
243 
244  // Ensure that string is always null-terminated:
245  *ErrorRowPtr = '\0';
246  }
247 
248  //---------------------------------------------------------------------
254  //---------------------------------------------------------------------
255 
256  void error_row_int(int val) {
257 
258  // Check this object:
259  CHECK_VALID("rtest_c::error_row_int");
260 
261  // If this is not the first column, write separator:
262  if(ErrorRowCol > 0 && ErrorRowFree >= 2) {
263  *ErrorRowPtr++ = ',';
264  ErrorRowFree--;
265  *ErrorRowPtr++ = ' ';
266  ErrorRowFree--;
267  }
268 
269  // write integer value:
270  int chars = str_int(ErrorRowPtr, ErrorRowFree, val);
271  ErrorRowPtr += chars;
272  ErrorRowFree -= chars;
273  ErrorRowCol++;
274 
275  // Ensure that string is always null-terminated:
276  *ErrorRowPtr = '\0';
277  }
278 
279  //---------------------------------------------------------------------
283  //---------------------------------------------------------------------
284 
286 
287  // Check this object:
288  CHECK_VALID("rtest_c::error_row_close");
289 
290  // Write closing paranthesis:
291  if(ErrorRowFree >= 1) {
292  *ErrorRowPtr++ = ']';
293  ErrorRowFree--;
294  }
295 
296  // Ensure that string is always null-terminated:
297  *ErrorRowPtr = '\0';
298  }
299 
300 //-----------------------------------------------------------------------------
301 // Debugging Support:
302 //-----------------------------------------------------------------------------
303 
304 #if VER_DEBUG
305  public:
306  // Integrity check:
307  str_t check() const;
308 
309  private:
310  // Magic number (identifies objects of this class for debugging).
311  long Magic; // Must be "RTEST_MAGIC".
312 #endif
313 
314 #if VER_DUMP
315  public:
316  // Display data structure:
317  virtual void dump(str_t headline = STR_NULL) const;
318 #endif
319 
320 //-----------------------------------------------------------------------------
321 // Copy-constructor and assignment operator are not supported for this class:
322 //-----------------------------------------------------------------------------
323 
324  private:
325 
326  rtest_c(const rtest_c& obj); // Not implemented
327  rtest_c& operator=(const rtest_c& obj); // Not implemented
328 
329 
330 //-----------------------------------------------------------------------------
331 // Attributes:
332 //-----------------------------------------------------------------------------
333 
334  private:
335 
336  // Relation to be tested:
337  rel_t Rel;
338 
339  // Number of rows that were successfully inserted (relation size):
340  int NumRows;
341 
342  // Row, for which an operation failed (if an error was detected):
343  char ErrorRow[RTEST_ROW_SIZE];
344 
345  // Pointer to next free place in the buffer:
346  char *ErrorRowPtr;
347 
348  // Number of free places in the buffer (- 1 for terminating '\0'):
349  int ErrorRowFree;
350 
351  // Number of column values already in the buffer:
352  int ErrorRowCol;
353 
354 //=============================================================================
355 // End of Class:
356 //=============================================================================
357 
358 };
359 
360 //-----------------------------------------------------------------------------
361 // Define pointer type:
362 //-----------------------------------------------------------------------------
363 
364 typedef rtest_c *rtest_t;
365 
366 //-----------------------------------------------------------------------------
367 // Define null pointer:
368 //-----------------------------------------------------------------------------
369 
370 #define RTEST_NULL (static_cast<rtest_t>(0))
371 
372 //=============================================================================
373 // End of Include File:
374 //=============================================================================
375 
376 #endif
377 
virtual int lookup()=0
virtual int size_value(relsize_t relsize)=0
int str_int(char *buf, int buf_len, int n)
Definition: str.cpp:250
void inserted_rows(int n)
Definition: rtest.h:209
Abstract superclass for Standard Tests/Benchmarks of relation-like data structures with insert() and ...
Definition: rtest.h:81
Definition: rel.h:72
void error_row_int(int val)
Definition: rtest.h:256
str_t error_row()
Definition: rtest.h:177
#define CHECK_VALID(EX)
Definition: check.h:85
const char * str_t
Definition: str.h:41
rel_t rel()
Definition: rtest.h:131
void error_row_open()
Definition: rtest.h:228
void error_row_close()
Definition: rtest.h:285
#define STR_NULL
Definition: str.h:52
virtual int insert()=0
#define CHECK(EX, MSG)
Definition: check.h:69
int num_rows()
Definition: rtest.h:151