MIDAS
Loading...
Searching...
No Matches
test_odb.cxx
Go to the documentation of this file.
1//
2// test_mvodb.cxx --- test ODB access functions
3//
4// K.Olchanski
5//
6
7#include <stdio.h>
8#include <sys/time.h>
9#include <iostream>
10#include <assert.h>
11#include <signal.h>
12#include <string.h>
13#include <stdlib.h> // exit()
14
15#include "tmfe.h"
16#include "midas.h"
17
18std::string toString(int i)
19{
20 char buf[256];
21 sprintf(buf, "%d", i);
22 return buf;
23}
24
25void print_ia(const std::vector<int> &ia)
26{
27 int size = ia.size();
28 printf("int[%d] has [", size);
29 for (int i=0; i<size; i++) {
30 if (i>0)
31 printf(", ");
32 printf("%d", ia[i]);
33 }
34 printf("]");
35}
36
37void print_da(const std::vector<double> &da)
38{
39 int size = da.size();
40 printf("int[%d] has [", size);
41 for (int i=0; i<size; i++) {
42 if (i>0)
43 printf(", ");
44 printf("%f", da[i]);
45 }
46 printf("]");
47}
48
49static int gCountFail = 0;
50
51bool report_fail(const char* text)
52{
53 printf("FAIL: %s\n", text);
54 gCountFail++;
55 return false;
56}
57
58bool report_fail(const std::string& text)
59{
60 printf("FAIL: %s\n", text.c_str());
61 gCountFail++;
62 return false;
63}
64
65bool rmdir(HNDLE hDB, HNDLE hROOT, const char* path)
66{
67 HNDLE hKey;
68
69 printf("rmdir(%s)\n", path);
70
71 int status = db_find_link(hDB, hROOT, path, &hKey);
72
73 if (status == DB_NO_KEY)
74 return true;
75
76 if (status != DB_SUCCESS)
77 return report_fail(msprintf("test_mkdir: Cannot delete subdirectory \"%s\", db_find_link() status %d\n", path, status));
78
80
81 if (status == DB_SUCCESS)
82 return true;
83
84 return report_fail(msprintf("test_mkdir: Delete subdirectory \"%s\" failed, status %d\n", path, status));
85}
86
87bool test_mkdir(HNDLE hDB, HNDLE hROOT, const char* path)
88{
89 printf("mkdir(%s)\n", path);
90
91 int status = db_create_key(hDB, hROOT, path, TID_KEY);
92
93 if (status == DB_SUCCESS)
94 return true;
95
96 return report_fail(msprintf("test_mkdir: Create subdirectory \"%s\" failed, status %d\n", path, status));
97}
98
99bool test_mkdir_fail(HNDLE hDB, HNDLE hROOT, const char* path, int fail_status)
100{
101 printf("mkdir_fail(%s)\n", path);
102
103 int status = db_create_key(hDB, hROOT, path, TID_KEY);
104
105 if (status == fail_status)
106 return true;
107
108 return report_fail(msprintf("test_mkdir_fail: Create subdirectory \"%s\" failed, unexpcted status %d instead of %d\n", path, status, fail_status));
109}
110
111bool test_chdir(HNDLE hDB, HNDLE hROOT, const char* path, HNDLE* phKey)
112{
113 printf("chdir(%s)\n", path);
114
115 int status = db_find_link(hDB, hROOT, path, phKey);
116
117 if (status == DB_SUCCESS)
118 return true;
119
120 return report_fail(msprintf("test_mkdir: Cannot find subdirectory \"%s\", db_find_link() status %d\n", path, status));
121}
122
123bool test_delete_key(HNDLE hDB, HNDLE hROOT, const char* path)
124{
125 HNDLE hKey;
126
127 printf("delete_key(%s)\n", path);
128
129 int status = db_find_link(hDB, hROOT, path, &hKey);
130
131 if (status == DB_NO_KEY)
132 return true;
133
134 if (status != DB_SUCCESS)
135 return report_fail(msprintf("test_delete_key: Cannot delete \"%s\", db_find_link() status %d\n", path, status));
136
138
139 if (status == DB_SUCCESS)
140 return true;
141
142 return report_fail(msprintf("test_delete_key: Delete \"%s\" failed, status %d\n", path, status));
143}
144
145bool test_delete(HNDLE hDB, HNDLE hROOT, const char* path)
146{
147 printf("delete(%s)\n", path);
148
149 int status = db_delete(hDB, hROOT, path);
150
151 if (status == DB_SUCCESS)
152 return true;
153
154 return report_fail(msprintf("test_delete: Delete \"%s\" failed, status %d\n", path, status));
155}
156
157bool test_find_fail(HNDLE hDB, HNDLE hROOT, const char* path, int fail_status)
158{
159 HNDLE hKey;
160
161 printf("find_fail(%s)\n", path);
162
163 int status = db_find_link(hDB, hROOT, path, &hKey);
164
165 if (status == fail_status)
166 return true;
167
168 return report_fail(msprintf("test_find_fail: Unexpected db_find_link(%s) status %d instead of %d\n", path, status, fail_status));
169}
170
171bool test_find_key_fail(HNDLE hDB, HNDLE hROOT, const char* path, int fail_status)
172{
173 HNDLE hKey;
174
175 printf("find_key_fail(%s)\n", path);
176
177 int status = db_find_key(hDB, hROOT, path, &hKey);
178
179 if (status == fail_status)
180 return true;
181
182 return report_fail(msprintf("test_find_key_fail: Unexpected db_find_key(%s) status %d instead of %d\n", path, status, fail_status));
183}
184
185bool test_symlink(HNDLE hDB, HNDLE hROOT, const char* path, const char* link_target)
186{
187 printf("symlink(%s) to \"%s\"\n", path, link_target);
188
189 int status = db_create_link(hDB, hROOT, path, link_target);
190
191 if (status == DB_SUCCESS)
192 return true;
193
194 return report_fail(msprintf("test_symlink: db_create_link(%s) status %d\n", path, status));
195}
196
197bool test_symlink_fail(HNDLE hDB, HNDLE hROOT, const char* path, const char* link_target, int fail_status)
198{
199 printf("symlink_fail(%s) to \"%s\"\n", path, link_target);
200
201 int status = db_create_link(hDB, hROOT, path, link_target);
202
203 if (status == fail_status)
204 return true;
205
206 return report_fail(msprintf("test_symlink_fail: db_create_link(%s) status %d instead of %d\n", path, status, fail_status));
207}
208
209bool test_enum(const std::vector<HNDLE>& hlist, const std::vector<KEY>& klist)
210{
211 printf("test_enum\n");
212
213 if (hlist.size() != klist.size()) {
214 return report_fail(msprintf("test_enum: hlist and klist size mismatch\n"));
215 }
216
217 bool ok = true;
218
219 size_t expected_size = 9;
220
221 if (klist.size() != expected_size)
222 ok &= report_fail(msprintf("test_enum: klist size %zu different from expected %zu\n", klist.size(), expected_size));
223
224 for (size_t i=0; i<klist.size(); i++) {
225 printf("key %zu: \"%s\" tid %d, num_values %d\n", i, klist[i].name, klist[i].type, klist[i].num_values);
226 }
227
228 return ok;
229}
230
231bool test_enum_links(const std::vector<HNDLE>& hlist, const std::vector<KEY>& klist)
232{
233 printf("test_enum_links\n");
234
235 if (hlist.size() != klist.size()) {
236 return report_fail(msprintf("test_enum: hlist and klist size mismatch\n"));
237 }
238
239 bool ok = true;
240
241 size_t expected_size = 9;
242
243 if (klist.size() != expected_size)
244 ok &= report_fail(msprintf("test_enum: klist size %zu different from expected %zu\n", klist.size(), expected_size));
245
246 for (size_t i=0; i<klist.size(); i++) {
247 printf("key %zu: \"%s\" tid %d, num_values %d\n", i, klist[i].name, klist[i].type, klist[i].num_values);
248 }
249
250 return ok;
251}
252
254{
255 printf("test_symlink_to_array\n");
256
257 bool ok = true;
258 int status;
259
260 std::vector ia{ 10, 11, 12, 13, 14 };
261
262 odb->WIA("test_odb/ia5", ia);
263
264 int iii = 0;
265
266 odb->RIAI("test_odb/ia5", 0, &iii); if (iii != 10) ok &= report_fail(msprintf("test_symlink_to_array: array read unexpected value %d\n", iii));
267 odb->RIAI("test_odb/ia5", 1, &iii); if (iii != 11) ok &= report_fail(msprintf("test_symlink_to_array: array read unexpected value %d\n", iii));
268 odb->RIAI("test_odb/ia5", 2, &iii); if (iii != 12) ok &= report_fail(msprintf("test_symlink_to_array: array read unexpected value %d\n", iii));
269
270 ok &= test_symlink(hDB, 0, "/test_odb/symlink_to_ia5", "/test_odb/ia5");
271
272 odb->RIAI("test_odb/symlink_to_ia5", 0, &iii); if (iii != 10) ok &= report_fail(msprintf("test_symlink_to_array: array read unexpected value %d\n", iii));
273 odb->RIAI("test_odb/symlink_to_ia5", 1, &iii); if (iii != 11) ok &= report_fail(msprintf("test_symlink_to_array: array read unexpected value %d\n", iii));
274 odb->RIAI("test_odb/symlink_to_ia5", 2, &iii); if (iii != 12) ok &= report_fail(msprintf("test_symlink_to_array: array read unexpected value %d\n", iii));
275
276 ok &= test_symlink(hDB, 0, "/test_odb/symlink_to_ia5_2", "/test_odb/ia5[2]");
277
278#if 0
279 iii = 0;
280 odb->RI("test_odb/symlink_to_ia5_2", &iii); if (iii != 12) ok &= report_fail(msprintf("test_symlink_to_array: symlink to array element read unexpected value %d\n", iii));
281
282 iii = 0;
283 odb->RIAI("test_odb/symlink_to_ia5_2", 0, &iii); if (iii != 12) ok &= report_fail(msprintf("test_symlink_to_array: symlink to array element read index 0 unexpected value %d\n", iii));
284 iii = 0;
285 odb->RIAI("test_odb/symlink_to_ia5_2", 1, &iii); if (iii != 12) ok &= report_fail(msprintf("test_symlink_to_array: symlink to array element read index 1 unexpected value %d\n", iii));
286#endif
287
288 int ibuf[256];
289 int size = sizeof(ibuf);
290
291#if 0
292 status = db_get_value(hDB, 0, "/test_odb/symlink_to_ia5", ibuf, &size, TID_INT, FALSE);
293
294 if (status != DB_SUCCESS) {
295 ok &= report_fail(msprintf("test_symlink_to_array: db_get_value() status %d\n", status));
296 } else if (size != 5*sizeof(int)) {
297 ok &= report_fail(msprintf("test_symlink_to_array: db_get_value() returned wrong size %d\n", size));
298 } else {
299 for (int i=0; i<5; i++) {
300 if (ibuf[i] != 10+i) {
301 ok &= report_fail(msprintf("test_symlink_to_array: db_get_value() returned wrong value %d at %d\n", ibuf[i], i));
302 }
303 }
304 }
305#endif
306
307 HNDLE hKey;
308
309 status = db_find_key(hDB, 0, "/test_odb/symlink_to_ia5", &hKey);
310
311 if (status != DB_SUCCESS) {
312 ok &= report_fail(msprintf("test_symlink_to_array: symlink to array db_find_key() status %d\n", status));
313 } else {
314 size = sizeof(ibuf);
315
316 status = db_get_data(hDB, hKey, ibuf, &size, TID_INT);
317
318 if (status != DB_SUCCESS) {
319 ok &= report_fail(msprintf("test_symlink_to_array: symlink to array db_get_data() status %d\n", status));
320 } else if (size != 5*sizeof(int)) {
321 ok &= report_fail(msprintf("test_symlink_to_array: symlink to array db_get_data() returned wrong size %d\n", size));
322 } else {
323 for (int i=0; i<5; i++) {
324 if (ibuf[i] != 10+i) {
325 ok &= report_fail(msprintf("test_symlink_to_array: symlink to array db_get_data() returned wrong value %d at %d\n", ibuf[i], i));
326 }
327 }
328 }
329 }
330
331 status = db_find_key(hDB, 0, "/test_odb/symlink_to_ia5_2", &hKey);
332
333 if (status != DB_SUCCESS) {
334 ok &= report_fail(msprintf("test_symlink_to_array: symlink to array element db_find_key() status %d\n", status));
335 } else {
336 size = sizeof(ibuf);
337
338 status = db_get_data(hDB, hKey, ibuf, &size, TID_INT);
339
340 if (status != DB_SUCCESS) {
341 ok &= report_fail(msprintf("test_symlink_to_array: symlink to array element db_get_data() status %d\n", status));
342 } else if (size != sizeof(int)) {
343 ok &= report_fail(msprintf("test_symlink_to_array: symlink to array element db_get_data() returned wrong size %d\n", size));
344 } else if (ibuf[0] != 12) {
345 ok &= report_fail(msprintf("test_symlink_to_array: symlink to array element db_get_data() returned wrong value %d\n", ibuf[0]));
346 }
347 }
348
349#if 0
350 size = sizeof(ibuf);
351
352 status = db_get_value(hDB, 0, "/test_odb/symlink_to_ia5_2", ibuf, &size, TID_INT, FALSE);
353
354 if (status != DB_SUCCESS) {
355 ok &= report_fail(msprintf("test_symlink_to_array: symlink to array element db_get_value() status %d\n", status));
356 } else if (size != 5*sizeof(int)) {
357 ok &= report_fail(msprintf("test_symlink_to_array: symlink to array element db_get_value() returned wrong size %d\n", size));
358 } else {
359 for (int i=0; i<5; i++) {
360 if (ibuf[i] != 10+i) {
361 ok &= report_fail(msprintf("test_symlink_to_array: symlink to array element db_get_value() returned wrong value %d at %d\n", ibuf[i], i));
362 }
363 }
364 }
365#endif
366
367 return ok;
368}
369
370bool test_all(HNDLE hDB, MVOdb* odb)
371{
372 bool ok = true;
373
374 ok &= rmdir(hDB, 0, "test_odb");
375
376 if (!ok)
377 return false;
378
379 ok &= test_mkdir(hDB, 0, "test_odb");
380
381 if (!ok)
382 return false;
383
384 HNDLE hROOT = 0;
385
386 ok &= test_chdir(hDB, 0, "test_odb", &hROOT);
387
388 if (!ok)
389 return false;
390
391 ok &= test_find_fail(hDB, hROOT, "does-not-exist", DB_NO_KEY);
392 ok &= test_find_fail(hDB, hROOT, "/does-not-exist", DB_NO_KEY);
393
394 ok &= test_find_fail(hDB, 0, "/System", DB_SUCCESS); // exists at top level
395 ok &= test_find_fail(hDB, hROOT, "/System", DB_NO_KEY); // but not in our subdirectory
396
397 ok &= test_mkdir(hDB, hROOT, "test_mkdir");
398 ok &= test_mkdir_fail(hDB, hROOT, "/test_mkdir", DB_KEY_EXIST); // unexpected, leading slash is ignored?
399
400 // test db_create_key()
401
402 ok &= test_mkdir_fail(hDB, hROOT, "invalid_name[", DB_INVALID_NAME);
403 ok &= test_mkdir_fail(hDB, hROOT, "invalid_name]", DB_INVALID_NAME);
404 ok &= test_mkdir_fail(hDB, hROOT, "", DB_INVALID_NAME);
405 ok &= test_mkdir_fail(hDB, hROOT, "/", DB_INVALID_NAME);
406 ok &= test_mkdir_fail(hDB, hROOT, "//", DB_INVALID_NAME);
407 ok &= test_mkdir_fail(hDB, hROOT, "invalid//invalid", DB_INVALID_NAME);
408 //ok &= test_mkdir_fail(hDB, hROOT, NULL, DB_INVALID_NAME); -- core dump if rpc_is_remote()
409
410 // test db_delete_key()
411
412 ok &= test_mkdir(hDB, hROOT, "test_delete_key");
413 ok &= test_delete_key(hDB, hROOT, "test_delete_key");
414 ok &= test_find_fail(hDB, hROOT, "test_delete_key", DB_NO_KEY); // deleted
415
416 ok &= test_mkdir(hDB, hROOT, "test_delete_key_dir/test/test/test_mkdir"); // multi-level create and delete
417 ok &= test_delete_key(hDB, hROOT, "test_delete_key_dir");
418 ok &= test_find_fail(hDB, hROOT, "test_delete_key_dir", DB_NO_KEY); // deleted
419
420 // test db_delete()
421
422 ok &= test_mkdir(hDB, hROOT, "test_delete");
423 ok &= test_delete(hDB, hROOT, "test_delete");
424 ok &= test_find_fail(hDB, hROOT, "test_delete", DB_NO_KEY); // deleted
425
426 ok &= test_mkdir(hDB, hROOT, "test_delete_dir/test/test/test_mkdir"); // multi-level create and delete
427 ok &= test_delete(hDB, hROOT, "test_delete_dir");
428 ok &= test_find_fail(hDB, hROOT, "test_delete_dir", DB_NO_KEY); // deleted
429
430 // test symlinks
431
432 ok &= test_symlink_fail(hDB, hROOT, "test_symlink_fail", "/does-not-exist", DB_NO_KEY);
433 ok &= test_symlink_fail(hDB, hROOT, "test_symlink_fail", "no-leading-slash", DB_INVALID_NAME);
434 ok &= test_symlink_fail(hDB, hROOT, "test_symlink", "/test_odb/test_mkdir", DB_NO_KEY); // unexpected
435 ok &= test_symlink(hDB, 0, "/test_odb/test_symlink", "/test_odb/test_mkdir");
436
437 // test symlink to symlink
438
439 ok &= test_symlink(hDB, 0, "/test_odb/test_symlink_to_symlink", "/test_odb/test_symlink");
440
441 //
442 // test symlink to array elements
443 //
444
445 ok &= test_symlink_to_array(hDB, odb);
446
447 //
448 // test db_delete_key of symlink
449 //
450
451 ok &= test_mkdir(hDB, 0, "/test_odb/test_symlink1_target");
452 ok &= test_symlink(hDB, 0, "/test_odb/test_symlink1", "/test_odb/test_symlink1_target");
453 ok &= test_delete_key(hDB, hROOT, "test_symlink1"); // delete symlink
454 ok &= test_find_fail(hDB, hROOT, "test_symlink1", DB_NO_KEY); // symlinks deleted
455 ok &= test_find_fail(hDB, hROOT, "test_symlink1_target", DB_SUCCESS); // symlink target remains
456
457 //
458 // test db_delete_key of symlink
459 //
460
461 ok &= test_mkdir(hDB, 0, "/test_odb/test_symlink2_target");
462 ok &= test_symlink(hDB, 0, "/test_odb/test_symlink2", "/test_odb/test_symlink2_target");
463 ok &= test_delete(hDB, hROOT, "test_symlink2"); // delete symlink
464 ok &= test_find_fail(hDB, hROOT, "test_symlink2", DB_NO_KEY); // symlinks deleted
465 ok &= test_find_fail(hDB, hROOT, "test_symlink2_target", DB_SUCCESS); // symlink target remains
466
467#if 0
468 //
469 // test db_delete_key with follow_links set to true
470 //
471
472 // delete(false) deletes the symlink,
473 // delete(true) deletes the link target, and the link
474
475 ok &= test_mkdir(hDB, 0, "/test_odb/test_symlink_target");
476 ok &= test_symlink(hDB, 0, "/test_odb/test_symlink1", "/test_odb/test_symlink_target");
477 ok &= test_symlink(hDB, 0, "/test_odb/test_symlink2", "/test_odb/test_symlink_target");
478 ok &= test_delete(hDB, hROOT, "test_symlink1"); // delete symlink
479 ok &= test_delete(hDB, hROOT, "test_symlink2", true); // delete symlink target
480 ok &= test_find_fail(hDB, hROOT, "test_symlink_target", DB_NO_KEY); // deleted
481 ok &= test_find_fail(hDB, hROOT, "test_symlink1", DB_NO_KEY); // deleted
482 ok &= test_find_fail(hDB, hROOT, "test_symlink2", DB_NO_KEY); // dangling link
483
484 // chained links, target of last link is deleted, intermediate link remain (dangling)
485
486 ok &= test_mkdir(hDB, 0, "/test_odb/test_link_to_link");
487 ok &= test_symlink(hDB, 0, "/test_odb/test_link_to_link1", "/test_odb/test_link_to_link");
488 ok &= test_symlink(hDB, 0, "/test_odb/test_link_to_link2", "/test_odb/test_link_to_link1");
489 ok &= test_delete(hDB, hROOT, "test_link_to_link2", true); // delete symlink target
490 ok &= test_find_fail(hDB, hROOT, "test_link_to_link", DB_NO_KEY); // deleted
491 ok &= test_find_fail(hDB, hROOT, "test_link_to_link1", DB_SUCCESS); // unexpectedly not deleted
492 ok &= test_find_fail(hDB, hROOT, "test_link_to_link2", DB_NO_KEY); // deleted
493 ok &= test_find_key_fail(hDB, hROOT, "test_link_to_link1", DB_INVALID_LINK); // dangling link
494
495 // subdirectory has a link to something else, it is also deleted
496
497 ok &= test_mkdir(hDB, 0, "/test_odb/test_symlink_dir1");
498 ok &= test_mkdir(hDB, 0, "/test_odb/test_symlink_dir2");
499 ok &= test_symlink(hDB, 0, "/test_odb/test_symlink_dir1/test_symlink", "/test_odb/test_symlink_dir2");
500 ok &= test_delete(hDB, hROOT, "test_symlink_dir1", true); // delete symlink target
501 ok &= test_find_fail(hDB, hROOT, "test_symlink_dir1", DB_NO_KEY); // deleted
502 ok &= test_find_fail(hDB, hROOT, "test_symlink_dir2", DB_NO_KEY); // deleted
503
504 // test delete of circular links
505
506 ok &= test_mkdir(hDB, 0, "/test_odb/test_circular_link");
507 ok &= test_symlink(hDB, 0, "/test_odb/test_circular_link/test_link", "/test_odb/test_circular_link");
508 ok &= test_symlink(hDB, 0, "/test_odb/test_circular_link1", "/test_odb/test_circular_link");
509 ok &= test_delete(hDB, hROOT, "test_circular_link1", true); // delete symlink target
510 ok &= test_find_fail(hDB, hROOT, "test_circular_link", DB_NO_KEY); // deleted
511 ok &= test_find_fail(hDB, hROOT, "test_circular_link1", DB_NO_KEY); // deleted
512#endif
513
514
515 // test db_enum
516
517 {
518 int status;
519 HNDLE hKeyRoot;
520 std::vector<HNDLE> hlist;
521 std::vector<KEY> klist;
522
523 status = db_enum(hDB, 0, "/test_odb", &hlist, &klist);
524
525 if (status != DB_SUCCESS) {
526 ok &= report_fail(msprintf("test_enum: db_enum(path) status %d\n", status));
527 }
528
529 ok &= test_enum(hlist, klist);
530
531 status = db_find_key(hDB, 0, "/test_odb", &hKeyRoot);
532
533 status = db_enum(hDB, hKeyRoot, &hlist, &klist);
534
535 if (status != DB_SUCCESS) {
536 ok &= report_fail(msprintf("test_enum: db_enum(hkey) status %d\n", status));
537 }
538
539 ok &= test_enum(hlist, klist);
540 }
541
542 {
543 int status;
544 HNDLE hKeyRoot;
545 std::vector<HNDLE> hlist;
546 std::vector<KEY> klist;
547
548 status = db_enum(hDB, 0, "/test_odb", &hlist, &klist, false);
549
550 if (status != DB_SUCCESS) {
551 ok &= report_fail(msprintf("test_enum: db_enum(path) status %d\n", status));
552 }
553
554 ok &= test_enum_links(hlist, klist);
555
556 status = db_find_link(hDB, 0, "/test_odb", &hKeyRoot);
557
558 status = db_enum(hDB, hKeyRoot, &hlist, &klist, false);
559
560 if (status != DB_SUCCESS) {
561 ok &= report_fail(msprintf("test_enum: db_enum(hkey) status %d\n", status));
562 }
563
564 ok &= test_enum_links(hlist, klist);
565 }
566
567 return ok;
568}
569
570// Main function call
571
572int main(int argc, char *argv[])
573{
574 setbuf(stdout,NULL);
575 setbuf(stderr,NULL);
576
577 signal(SIGILL, SIG_DFL);
578 signal(SIGBUS, SIG_DFL);
579 signal(SIGSEGV, SIG_DFL);
580 signal(SIGPIPE, SIG_DFL);
581
582 const char* hostname = NULL;
583 const char* exptname = NULL;
584
585 if (argc > 1)
586 hostname = argv[1];
587
588 TMFE* mfe = TMFE::Instance();
589
590 TMFeResult r;
591
592 r = mfe->Connect("test_odb", hostname, exptname);
593
594 if (r.error_flag) {
595 fprintf(stderr,"Cannot connect to MIDAS, error %s\n", r.error_message.c_str());
596 return -1;
597 }
598
599 HNDLE hDB = mfe->fDB;
600
601 bool ok = true;
602
603 printf("\n");
604 printf("Starting tests:\n");
605 printf("\n");
606
607 ok &= test_all(hDB, mfe->fOdbRoot);
608
609 if (mfe)
610 mfe->Disconnect();
611
612 if (ok) {
613 printf("\n");
614 printf("Tests passed OK\n");
615 printf("\n");
616 } else {
617 printf("\n");
618 printf("Number of FAILED tests: %d\n", gCountFail);
619 printf("\n");
620 }
621
622 return 0;
623}
624
625//end
626
627/* emacs
628 * Local Variables:
629 * tab-width: 8
630 * c-basic-offset: 3
631 * indent-tabs-mode: nil
632 * End:
633 */
#define FALSE
Definition cfortran.h:309
Definition tmfe.h:383
int fDB
ODB database handle.
Definition tmfe.h:396
TMFeResult Connect(const char *progname=NULL, const char *hostname=NULL, const char *exptname=NULL)
Definition tmfe.cxx:65
static TMFE * Instance()
Definition tmfe.cxx:57
MVOdb * fOdbRoot
ODB root.
Definition tmfe.h:397
TMFeResult Disconnect()
Definition tmfe.cxx:154
bool error_flag
Definition tmfe.h:89
std::string error_message
Definition tmfe.h:91
#define DB_KEY_EXIST
Definition midas.h:642
#define DB_SUCCESS
Definition midas.h:632
#define DB_INVALID_NAME
Definition midas.h:635
#define DB_NO_KEY
Definition midas.h:643
#define DB_INVALID_LINK
Definition midas.h:653
#define TID_KEY
Definition midas.h:349
#define TID_INT
Definition midas.h:338
INT db_delete_key(HNDLE hDB, HNDLE hKey, BOOL follow_links)
Definition odb.cxx:4428
INT db_find_link(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
Definition odb.cxx:4788
INT db_get_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, void *data, INT *buf_size, DWORD type, BOOL create)
Definition odb.cxx:5680
INT EXPRT db_enum(HNDLE hDB, HNDLE hKeyRoot, std::vector< HNDLE > *sub_handles, std::vector< KEY > *sub_keys, bool follow_links)
Definition odb.cxx:6263
INT db_get_data(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, DWORD type)
Definition odb.cxx:7058
INT db_create_key(HNDLE hDB, HNDLE hKey, const char *key_name, DWORD type)
Definition odb.cxx:3887
INT db_delete(HNDLE hDB, HNDLE hKeyRoot, const char *odb_path)
Definition odb.cxx:4494
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
Definition odb.cxx:4751
INT db_create_link(HNDLE hDB, HNDLE hKey, const char *link_name, const char *destination)
Definition odb.cxx:4183
int main()
Definition hwtest.cxx:23
HNDLE hKey
INT type
Definition mana.cxx:269
HNDLE hDB
main ODB handle
Definition mana.cxx:207
INT i
Definition mdump.cxx:32
std::string msprintf(const char *format,...)
Definition midas.cxx:419
INT HNDLE
Definition midas.h:132
#define name(x)
Definition midas_macro.h:24
DWORD status
Definition odbhist.cxx:39
void print_da(const std::vector< double > &da)
Definition test_odb.cxx:37
bool test_find_fail(HNDLE hDB, HNDLE hROOT, const char *path, int fail_status)
Definition test_odb.cxx:157
static int gCountFail
Definition test_odb.cxx:49
bool test_mkdir(HNDLE hDB, HNDLE hROOT, const char *path)
Definition test_odb.cxx:87
bool test_symlink(HNDLE hDB, HNDLE hROOT, const char *path, const char *link_target)
Definition test_odb.cxx:185
bool test_mkdir_fail(HNDLE hDB, HNDLE hROOT, const char *path, int fail_status)
Definition test_odb.cxx:99
bool test_find_key_fail(HNDLE hDB, HNDLE hROOT, const char *path, int fail_status)
Definition test_odb.cxx:171
bool report_fail(const char *text)
Definition test_odb.cxx:51
bool test_enum_links(const std::vector< HNDLE > &hlist, const std::vector< KEY > &klist)
Definition test_odb.cxx:231
void print_ia(const std::vector< int > &ia)
Definition test_odb.cxx:25
bool test_symlink_fail(HNDLE hDB, HNDLE hROOT, const char *path, const char *link_target, int fail_status)
Definition test_odb.cxx:197
bool test_enum(const std::vector< HNDLE > &hlist, const std::vector< KEY > &klist)
Definition test_odb.cxx:209
bool test_delete_key(HNDLE hDB, HNDLE hROOT, const char *path)
Definition test_odb.cxx:123
bool test_chdir(HNDLE hDB, HNDLE hROOT, const char *path, HNDLE *phKey)
Definition test_odb.cxx:111
bool rmdir(HNDLE hDB, HNDLE hROOT, const char *path)
Definition test_odb.cxx:65
std::string toString(int i)
Definition test_odb.cxx:18
bool test_all(HNDLE hDB, MVOdb *odb)
Definition test_odb.cxx:370
bool test_delete(HNDLE hDB, HNDLE hROOT, const char *path)
Definition test_odb.cxx:145
bool test_symlink_to_array(HNDLE hDB, MVOdb *odb)
Definition test_odb.cxx:253