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
18//#include "mvodb.h"
19
20std::string toString(int i)
21{
22 char buf[256];
23 sprintf(buf, "%d", i);
24 return buf;
25}
26
27void print_ia(const std::vector<int> &ia)
28{
29 int size = ia.size();
30 printf("int[%d] has [", size);
31 for (int i=0; i<size; i++) {
32 if (i>0)
33 printf(", ");
34 printf("%d", ia[i]);
35 }
36 printf("]");
37}
38
39void print_da(const std::vector<double> &da)
40{
41 int size = da.size();
42 printf("int[%d] has [", size);
43 for (int i=0; i<size; i++) {
44 if (i>0)
45 printf(", ");
46 printf("%f", da[i]);
47 }
48 printf("]");
49}
50
51static int gCountFail = 0;
52
53bool report_fail(const char* text)
54{
55 printf("FAIL: %s\n", text);
56 gCountFail++;
57 return false;
58}
59
60bool report_fail(const std::string& text)
61{
62 printf("FAIL: %s\n", text.c_str());
63 gCountFail++;
64 return false;
65}
66
67bool rmdir(HNDLE hDB, HNDLE hROOT, const char* path)
68{
69 HNDLE hKey;
70
71 printf("rmdir(%s)\n", path);
72
73 int status = db_find_link(hDB, hROOT, path, &hKey);
74
75 if (status == DB_NO_KEY)
76 return true;
77
78 if (status != DB_SUCCESS)
79 return report_fail(msprintf("test_mkdir: Cannot delete subdirectory \"%s\", db_find_link() status %d\n", path, status));
80
82
83 if (status == DB_SUCCESS)
84 return true;
85
86 return report_fail(msprintf("test_mkdir: Delete subdirectory \"%s\" failed, status %d\n", path, status));
87}
88
89bool test_mkdir(HNDLE hDB, HNDLE hROOT, const char* path)
90{
91 printf("mkdir(%s)\n", path);
92
93 int status = db_create_key(hDB, hROOT, path, TID_KEY);
94
95 if (status == DB_SUCCESS)
96 return true;
97
98 return report_fail(msprintf("test_mkdir: Create subdirectory \"%s\" failed, status %d\n", path, status));
99}
100
101bool test_mkdir_fail(HNDLE hDB, HNDLE hROOT, const char* path, int fail_status)
102{
103 printf("mkdir_fail(%s)\n", path);
104
105 int status = db_create_key(hDB, hROOT, path, TID_KEY);
106
107 if (status == fail_status)
108 return true;
109
110 return report_fail(msprintf("test_mkdir_fail: Create subdirectory \"%s\" failed, unexpcted status %d instead of %d\n", path, status, fail_status));
111}
112
113bool test_chdir(HNDLE hDB, HNDLE hROOT, const char* path, HNDLE* phKey)
114{
115 printf("chdir(%s)\n", path);
116
117 int status = db_find_link(hDB, hROOT, path, phKey);
118
119 if (status == DB_SUCCESS)
120 return true;
121
122 return report_fail(msprintf("test_mkdir: Cannot find subdirectory \"%s\", db_find_link() status %d\n", path, status));
123}
124
126{
127 HNDLE hKey;
128
129 printf("delete(%s)\n", path);
130
131 int status = db_find_link(hDB, hROOT, path, &hKey);
132
133 if (status == DB_NO_KEY)
134 return true;
135
136 if (status != DB_SUCCESS)
137 return report_fail(msprintf("test_delete: Cannot delete \"%s\", db_find_link() status %d\n", path, status));
138
140
141 if (status == DB_SUCCESS)
142 return true;
143
144 return report_fail(msprintf("test_delete: Delete \"%s\" failed, status %d\n", path, status));
145}
146
147bool test_find_fail(HNDLE hDB, HNDLE hROOT, const char* path, int fail_status)
148{
149 HNDLE hKey;
150
151 printf("find_fail(%s)\n", path);
152
153 int status = db_find_link(hDB, hROOT, path, &hKey);
154
155 if (status == fail_status)
156 return true;
157
158 return report_fail(msprintf("test_find_fail: Unexpected db_find_link(%s) status %d instead of %d\n", path, status, fail_status));
159}
160
161bool test_find_key_fail(HNDLE hDB, HNDLE hROOT, const char* path, int fail_status)
162{
163 HNDLE hKey;
164
165 printf("find_key_fail(%s)\n", path);
166
167 int status = db_find_key(hDB, hROOT, path, &hKey);
168
169 if (status == fail_status)
170 return true;
171
172 return report_fail(msprintf("test_find_key_fail: Unexpected db_find_key(%s) status %d instead of %d\n", path, status, fail_status));
173}
174
175bool test_symlink(HNDLE hDB, HNDLE hROOT, const char* path, const char* link_target)
176{
177 printf("symlink(%s) to \"%s\"\n", path, link_target);
178
180
181 if (status == DB_SUCCESS)
182 return true;
183
184 return report_fail(msprintf("test_symlink: db_create_link(%s) status %d\n", path, status));
185}
186
187bool test_symlink_fail(HNDLE hDB, HNDLE hROOT, const char* path, const char* link_target, int fail_status)
188{
189 printf("symlink_fail(%s) to \"%s\"\n", path, link_target);
190
192
193 if (status == fail_status)
194 return true;
195
196 return report_fail(msprintf("test_symlink_fail: db_create_link(%s) status %d instead of %d\n", path, status, fail_status));
197}
198
200{
201 bool ok = true;
202
203 ok &= rmdir(hDB, 0, "test_odb");
204
205 if (!ok)
206 return false;
207
208 ok &= test_mkdir(hDB, 0, "test_odb");
209
210 if (!ok)
211 return false;
212
213 HNDLE hROOT = 0;
214
215 ok &= test_chdir(hDB, 0, "test_odb", &hROOT);
216
217 if (!ok)
218 return false;
219
220 ok &= test_find_fail(hDB, hROOT, "does-not-exist", DB_NO_KEY);
221 ok &= test_find_fail(hDB, hROOT, "/does-not-exist", DB_NO_KEY);
222
223 ok &= test_find_fail(hDB, 0, "/System", DB_SUCCESS); // exists at top level
224 ok &= test_find_fail(hDB, hROOT, "/System", DB_NO_KEY); // but not in our subdirectory
225
226 ok &= test_mkdir(hDB, hROOT, "test_mkdir");
227 ok &= test_mkdir_fail(hDB, hROOT, "/test_mkdir", DB_KEY_EXIST); // unexpected, leading slash is ignored?
228
229 // test db_create_key()
230
231 ok &= test_mkdir_fail(hDB, hROOT, "invalid_name[", DB_INVALID_NAME);
232 ok &= test_mkdir_fail(hDB, hROOT, "invalid_name]", DB_INVALID_NAME);
236 ok &= test_mkdir_fail(hDB, hROOT, "invalid//invalid", DB_INVALID_NAME);
238
239 // test db_delete_key()
240
241 ok &= test_mkdir(hDB, hROOT, "test_delete");
242 ok &= test_delete(hDB, hROOT, "test_delete");
243
244 ok &= test_mkdir(hDB, hROOT, "test_dir/test/test/test_mkdir"); // multi-level create and delete
245 ok &= test_delete(hDB, hROOT, "test_dir");
246
247 // test symlinks
248
249 ok &= test_symlink_fail(hDB, hROOT, "test_symlink_fail", "/does-not-exist", DB_NO_KEY);
250 ok &= test_symlink_fail(hDB, hROOT, "test_symlink_fail", "no-leading-slash", DB_INVALID_NAME);
251 ok &= test_symlink_fail(hDB, hROOT, "test_symlink", "/test_odb/test_mkdir", DB_NO_KEY); // unexpected
252 ok &= test_symlink(hDB, 0, "/test_odb/test_symlink", "/test_odb/test_mkdir");
253
254 //
255 // test db_delete_key with follow_links set to true
256 //
257
258 // delete(false) deletes the symlink,
259 // delete(true) deletes the link target, and the link
260
261 ok &= test_mkdir(hDB, 0, "/test_odb/test_symlink_target");
262 ok &= test_symlink(hDB, 0, "/test_odb/test_symlink1", "/test_odb/test_symlink_target");
263 ok &= test_symlink(hDB, 0, "/test_odb/test_symlink2", "/test_odb/test_symlink_target");
264 ok &= test_delete(hDB, hROOT, "test_symlink1"); // delete symlink
265 ok &= test_delete(hDB, hROOT, "test_symlink2", true); // delete symlink target
266 ok &= test_find_fail(hDB, hROOT, "test_symlink_target", DB_NO_KEY); // deleted
267 ok &= test_find_fail(hDB, hROOT, "test_symlink1", DB_NO_KEY); // deleted
268 ok &= test_find_fail(hDB, hROOT, "test_symlink2", DB_NO_KEY); // dangling link
269
270 // chained links, target of last link is deleted, intermediate link remain (dangling)
271
272 ok &= test_mkdir(hDB, 0, "/test_odb/test_link_to_link");
273 ok &= test_symlink(hDB, 0, "/test_odb/test_link_to_link1", "/test_odb/test_link_to_link");
274 ok &= test_symlink(hDB, 0, "/test_odb/test_link_to_link2", "/test_odb/test_link_to_link1");
275 ok &= test_delete(hDB, hROOT, "test_link_to_link2", true); // delete symlink target
276 ok &= test_find_fail(hDB, hROOT, "test_link_to_link", DB_NO_KEY); // deleted
277 ok &= test_find_fail(hDB, hROOT, "test_link_to_link1", DB_SUCCESS); // unexpectedly not deleted
278 ok &= test_find_fail(hDB, hROOT, "test_link_to_link2", DB_NO_KEY); // deleted
279 ok &= test_find_key_fail(hDB, hROOT, "test_link_to_link1", DB_INVALID_LINK); // dangling link
280
281 // subdirectory has a link to something else, it is also deleted
282
283 ok &= test_mkdir(hDB, 0, "/test_odb/test_symlink_dir1");
284 ok &= test_mkdir(hDB, 0, "/test_odb/test_symlink_dir2");
285 ok &= test_symlink(hDB, 0, "/test_odb/test_symlink_dir1/test_symlink", "/test_odb/test_symlink_dir2");
286 ok &= test_delete(hDB, hROOT, "test_symlink_dir1", true); // delete symlink target
287 ok &= test_find_fail(hDB, hROOT, "test_symlink_dir1", DB_NO_KEY); // deleted
288 ok &= test_find_fail(hDB, hROOT, "test_symlink_dir2", DB_NO_KEY); // deleted
289
290 // test delete of circular links
291
292 ok &= test_mkdir(hDB, 0, "/test_odb/test_circular_link");
293 ok &= test_symlink(hDB, 0, "/test_odb/test_circular_link/test_link", "/test_odb/test_circular_link");
294 ok &= test_symlink(hDB, 0, "/test_odb/test_circular_link1", "/test_odb/test_circular_link");
295 ok &= test_delete(hDB, hROOT, "test_circular_link1", true); // delete symlink target
296 ok &= test_find_fail(hDB, hROOT, "test_circular_link", DB_NO_KEY); // deleted
297 ok &= test_find_fail(hDB, hROOT, "test_circular_link1", DB_NO_KEY); // deleted
298
299 return ok;
300}
301
302// Main function call
303
304int main(int argc, char *argv[])
305{
308
313
314 const char* hostname = NULL;
315 const char* exptname = NULL;
316
317 //MVOdb* odb = NULL;
318 //MVOdbError odberror;
319
321
322 TMFeResult r;
323
324 r = mfe->Connect("test_odb", hostname, exptname);
325 if (r.error_flag) {
326 fprintf(stderr,"Cannot connect to MIDAS, error %s\n", r.error_message.c_str());
327 return -1;
328 }
329
330 HNDLE hDB = mfe->fDB;
331
332 bool ok = true;
333
334 printf("\n");
335 printf("Starting tests:\n");
336 printf("\n");
337
338 ok &= test_all(hDB);
339
340#if 0
341 int runno = 1234;
342
343 odb->RI("runinfo/run number", &runno);
344
345 printf("read run number (RI): %d\n", runno);
346
347 MVOdb* test = odb->Chdir("test_mvodb", true);
348
349 assert(test != NULL);
350
351 test->SetPrintError(true);
352
353 bool isreadonly = test->IsReadOnly();
354
355 if (isreadonly) {
356 printf("\n");
357 printf("This ODB is read-only!\n");
358 }
359
360 printf("\n");
361 printf("Test create-and-read of all data types (set default values):\n");
362 printf("\n");
363
364 int cycle = 1;
365 test->RI("cycle", &cycle, true);
366 printf("RI() cycle: %d\n", cycle);
367
368 int ivalue = 1;
369 test->RI("int", &ivalue, true);
370 printf("RI() int: %d\n", ivalue);
371
372 float fvalue = 2.2;
373 test->RF("float", &fvalue, true);
374 printf("RF() float: %f\n", fvalue);
375
376 double dvalue = 3.3;
377 test->RD("double", &dvalue, true);
378 printf("RD() double: %f\n", dvalue);
379
380 bool bvalue_a = false;
381 test->RB("bool_a", &bvalue_a, true);
382 printf("bool_a: %d\n", bvalue_a);
383
384 bool bvalue_b = true;
385 test->RB("bool_b", &bvalue_b, true);
386 printf("bool_b: %d\n", bvalue_b);
387
388 uint16_t u16value = 0xabcd;
389 test->RU16("u16", &u16value, true);
390 printf("RU16() u16: 0x%04x\n", u16value);
391
392 uint32_t u32value = 0x12345678;
393 test->RU32("u32", &u32value, true);
394 printf("RU32() u32: 0x%08x\n", u32value);
395
396 std::string svalue = "test string";
397 test->RS("string", &svalue, true);
398 printf("RS() string: \"%s\"\n", svalue.c_str());
399
400 printf("\n");
401 printf("Test write of all data types (overwrite default values):\n");
402 printf("\n");
403
404 test->WI("cycle", cycle+1);
405
406 int wi = 10 + 100*cycle;
407 test->WI("int", wi);
408 float wf = 11.1 + 100*cycle;
409 test->WF("float", wf);
410 double wd = 22.2 + 100*cycle;
411 test->WD("double", wd);
412 bool wba = true;
413 test->WB("bool_a", wba);
414 bool wbb = false;
415 test->WB("bool_b", wbb);
416 uint16_t wu16 = 0xcdef;
417 test->WU16("u16", wu16);
418 uint32_t wu32 = 0xdeadf00d;
419 test->WU32("u32", wu32);
420 std::string ws = "write test string cycle " + toString(cycle);
421 test->WS("string", ws.c_str());
422
423 printf("\n");
424 printf("Test read of new values for all data types:\n");
425 printf("\n");
426
427 int ri = 1;
428 test->RI("int", &ri);
429 printf("int: %d -> %d -> %d\n", ivalue, wi, ri);
430
431 float rf = 2.2;
432 test->RF("float", &rf);
433 printf("float: %f -> %f -> %f\n", fvalue, wf, rf);
434
435 double rd = 3.3;
436 test->RD("double", &rd);
437 printf("double: %f -> %f -> %f\n", dvalue, wd, rd);
438
439 bool rba = false;
440 test->RB("bool_a", &rba);
441 printf("bool_a: %d -> %d -> %d\n", bvalue_a, wba, rba);
442
443 bool rbb = false;
444 test->RB("bool_b", &rbb);
445 printf("bool_b: %d -> %d -> %d\n", bvalue_b, wbb, rbb);
446
447 uint16_t ru16 = 0x4444;
448 test->RU16("u16", &ru16);
449 printf("u16: 0x%04x -> 0x%04x -> 0x%04x\n", u16value, wu16, ru16);
450
451 uint32_t ru32 = 0x55555555;
452 test->RU32("u32", &ru32);
453 printf("u32: 0x%08x -> 0x%08x -> 0x%08x\n", u32value, wu32, ru32);
454
455 std::string rs = "rs";
456 test->RS("string", &rs);
457 printf("string: \"%s\" -> \"%s\" -> \"%s\"\n", svalue.c_str(), ws.c_str(), rs.c_str());
458
459 printf("\n");
460 printf("Test read arrays of all data types:\n");
461 printf("\n");
462
463 {
464 printf("read int array ia:\n");
465 std::vector<int> ia;
466 ia.push_back(1);
467 ia.push_back(2);
468 ia.push_back(3);
469 test->RIA("ia", &ia, true);
470 printf("RIA() returned: ");
471 print_ia(ia);
472 printf("\n");
473 }
474
475 {
476 printf("read non-existant array ia-noexist:\n");
477 std::vector<int> ia;
478 ia.push_back(1);
479 ia.push_back(2);
480 ia.push_back(3);
481 test->RIA("ia-noexist", &ia);
482 printf("RIA() returned: ");
483 print_ia(ia);
484 printf("\n");
485 }
486
487 {
488 // create 10 element array, init to zero (ia is empty)
489 std::vector<int> ia;
490 test->RIA("ia10zero", &ia, true, 10);
491 // create 10 element array, init from ia
492 ia.clear();
493 ia.push_back(11);
494 ia.push_back(22);
495 test->RIA("ia10", &ia, true, 10);
496 }
497
498 {
499 // create 10 element array, init to zero (passed NULL instead of &ia)
500 test->RIA("createia10", NULL, true, 10);
501 }
502
503 {
504 std::vector<uint32_t> u32a;
505 u32a.push_back(0x11110000);
506 u32a.push_back(0x22220000);
507 u32a.push_back(0x33330000);
508 u32a.push_back(0x44440000);
509 test->RU32A("dwa", &u32a, true);
510 }
511
512 {
513 std::vector<double> da;
514 da.push_back(1.1);
515 da.push_back(1.2);
516 da.push_back(1.3);
517 da.push_back(1.4);
518 test->RDA("da", &da, true, 0);
519 }
520
521 {
522 std::vector<float> fa;
523 fa.push_back(2.1);
524 fa.push_back(2.2);
525 fa.push_back(2.3);
526 fa.push_back(20.3);
527 fa.push_back(21.3);
528 test->RFA("fa", &fa, true, 0);
529 }
530
531 {
532 std::vector<bool> ba;
533 ba.push_back(true);
534 ba.push_back(false);
535 ba.push_back(true);
536 test->RBA("ba", &ba, true, 0);
537 }
538
539 {
540 std::vector<std::string> sa;
541 sa.push_back("line1");
542 sa.push_back("line2");
543 sa.push_back("line3");
544 sa.push_back("line4");
545 test->RSA("sa", &sa, true, 0, 32);
546
547 // create 10 element array, init from ia
548 sa.clear();
549 sa.push_back("xx1");
550 sa.push_back("xx2");
551 test->RSA("sa10", &sa, true, 10, 32);
552 // create 10 element array, init to zero (passed NULL instead of &sa)
553 test->RSA("createsa10", NULL, true, 10, 32);
554 }
555
556 printf("\n");
557 printf("Test string sizes:\n");
558 printf("\n");
559
560 {
561 test->WS("test_size", "12345");
562 std::string s;
563 test->RS("test_size", &s);
564 printf("read test_size [%s]\n", s.c_str());
565 }
566 {
567 test->WS("test_size_32", "1234567890", 32);
568 std::string s;
569 test->RS("test_size_32", &s);
570 printf("read test_size_32 [%s]\n", s.c_str());
571 }
572 {
573 test->WS("test_size_5", "1234567890", 5);
574 std::string s;
575 test->RS("test_size_5", &s);
576 printf("read test_size_5 [%s]\n", s.c_str());
577 }
578 {
579 std::string s = "1234567890";
580 test->RS("test_rsize", &s, true);
581 printf("read test_rsize [%s]\n", s.c_str());
582 }
583 {
584 std::string s = "123456";
585 test->RS("test_size_r32", &s, true, 32);
586 printf("read test_size_r32 [%s]\n", s.c_str());
587 }
588 {
589 std::string s = "1234567890";
590 test->RS("test_size_r8", &s, true, 8);
591 printf("read test_size_r8 [%s]\n", s.c_str());
592 }
593 {
594 test->RSA("test_size_a8", NULL, true, 2, 8);
595 std::string s = "1234567890";
596 test->WSAI("test_size_a8", 0, s.c_str());
597 test->RSAI("test_size_a8", 0, &s);
598 printf("read test_size_a8 [%s]\n", s.c_str());
599 }
600
601 printf("\n");
602 printf("Test creating and resizing arrays:\n");
603 printf("\n");
604
605 {
606 test->RIA("create_ia15", NULL, true, 15);
607 test->RBA("create_ba12", NULL, true, 12);
608 test->RSA("create_sa5", NULL, true, 5, 32);
609 }
610 {
611 test->RIA("resize_ia10", NULL, true, 5);
612 test->RIA("resize_ia10", NULL, true, 10);
613 test->RSA("resize_sa3", NULL, true, 5, 32);
614 test->WSAI("resize_sa3", 0, "00000000");
615 test->WSAI("resize_sa3", 1, "11111111");
616 test->WSAI("resize_sa3", 2, "22222222");
617 test->WSAI("resize_sa3", 3, "33333333");
618 test->WSAI("resize_sa3", 4, "44444444");
619 test->RSA("resize_sa3", NULL, true, 3, 5);
620 }
621
622 printf("\n");
623 printf("Test array index access:\n");
624 printf("\n");
625
626 {
627 std::vector<int> ia;
628 ia.push_back(10);
629 ia.push_back(11);
630 ia.push_back(12);
631 test->WIA("index_ia", ia);
632 for (int i=0; i<5; i++) {
633 int ivalue = 999;
634 test->RIAI("index_ia", i, &ivalue);
635 printf("index %d value %d\n", i, ivalue);
636 }
637 for (int i=0; i<4; i++) {
638 int ivalue = 20+i;
639 test->WIAI("index_ia", i, ivalue);
640 }
641 for (int i=0; i<5; i++) {
642 int ivalue = 999;
643 test->RIAI("index_ia", i, &ivalue);
644 printf("index %d value %d\n", i, ivalue);
645 }
646 }
647
648 printf("\n");
649 printf("Test string array index access:\n");
650 printf("\n");
651
652 {
653 std::vector<std::string> sa;
654 sa.push_back("sa0");
655 sa.push_back("sa1");
656 sa.push_back("sa2");
657 test->WSA("index_sa", sa, 32);
658 for (int i=0; i<5; i++) {
659 std::string s = "aaa";
660 test->RSAI("index_sa", i, &s);
661 printf("index %d value [%s]\n", i, s.c_str());
662 }
663 for (int i=0; i<4; i++) {
664 std::string s = "sa_qqq";
665 s += toString(i);
666 test->WSAI("index_sa", i, s.c_str());
667 }
668 for (int i=0; i<5; i++) {
669 std::string s = "bbb";
670 test->RSAI("index_sa", i, &s);
671 printf("index %d value [%s]\n", i, s.c_str());
672 }
673 }
674
675 printf("\n");
676 printf("Test string truncation:\n");
677 printf("\n");
678
679 {
680 std::vector<std::string> sa;
681 sa.push_back("1234567890");
682 sa.push_back("aaa1");
683 sa.push_back("aaa2");
684 test->WSA("trunc_sa5", sa, 5);
685 test->WSAI("trunc_sa5", 1, "1234567890");
686 for (int i=0; i<5; i++) {
687 std::string s = "bbb";
688 test->RSAI("trunc_sa5", i, &s);
689 printf("index %d value [%s]\n", i, s.c_str());
690 }
691 }
692
693 printf("\n");
694 printf("Test against subdirectory:\n");
695 printf("\n");
696
697 {
698 printf("Creating subdir\n");
699 MVOdb* subdir = test->Chdir("subdir", true);
700 printf("Creating subdir/i\n");
701 subdir->WI("i", 10); // write something into subdir
702 int i = 1111;
703 printf("RI(subdir)\n");
704 test->RI("subdir", &i); // invalid read from a non-int
705 printf("WI(subdir)\n");
706 test->WI("subdir", 10); // invalid write into existing subdir
707 std::vector<int> ia;
708 ia.push_back(111);
709 ia.push_back(222);
710 ia.push_back(333);
711 printf("WIA(subdir)\n");
712 test->WIA("subdir", ia); // invalid write into existing subdir
713 printf("RIA(subdir)\n");
714 test->RIA("subdir", &ia); // invalid read from non-int-array
715 printf("RIA() returned: ");
716 print_ia(ia);
717 printf("\n");
718 printf("RIA(subdir, create=true)\n");
719 test->RIA("subdir", &ia, true); // invalid read from non-int-array
720 printf("RIA() returned: ");
721 print_ia(ia);
722 printf("\n");
723 }
724
725 printf("\n");
726 printf("Test special cases:\n");
727 printf("\n");
728
729 {
730 printf("test RI() of non existant variable:\n");
731 int ivalue = 999;
732 test->RI("nonexistant", &ivalue);
733 printf("RI() returned ivalue %d\n", ivalue);
734 printf("\n");
735
736 {
737 std::vector<double> da;
738 printf("test RDA() of integer array:\n");
739 // wrong data type: ODB is INT, we ask for DOUBLE
740 test->RDA("ia10", &da, false, 0);
741 printf("RDA() returned: ");
742 print_da(da);
743 printf("\n");
744 }
745
746 {
747 printf("test RD() of integer array:\n");
748 // wrong data type: ODB is INT, we ask for DOUBLE
749 double v = 999.9;
750 test->RD("ia10", &v);
751 printf("RD() returned %f\n", v);
752 printf("\n");
753 }
754
755 {
756 printf("test RI() of array ia10:\n");
757 int ivalue = 999;
758 test->RI("ia10", &ivalue);
759 printf("RI() returned ivalue %d\n", ivalue);
760 printf("\n");
761 }
762
763 {
764 printf("test RIA() of non-array int:\n");
765 std::vector<int> ia;
766 test->RIA("int", &ia);
767 printf("RIA() returned: ");
768 print_ia(ia);
769 printf("\n");
770 }
771
772 {
773 printf("test index 0 of non-array int:\n");
774 int ivalue = 999;
775 test->RIAI("int", 0, &ivalue);
776 printf("RIAI() returned ivalue %d\n", ivalue);
777 printf("\n");
778 }
779
780 {
781 printf("test index of non-array int:\n");
782 int ivalue = 999;
783 test->RIAI("int", 10, &ivalue);
784 printf("RIAI() returned ivalue %d\n", ivalue);
785 printf("\n");
786 }
787
788 {
789 printf("test invalid index -1 of array ia10:\n");
790 int ivalue = 999;
791 test->RIAI("ia10", -1, &ivalue);
792 printf("RIAI() returned ivalue %d\n", ivalue);
793 printf("\n");
794 }
795
796 {
797 printf("test invalid index 999 of array ia10:\n");
798 int ivalue = 999;
799 test->RIAI("ia10", 999, &ivalue);
800 printf("RIAI() returned ivalue %d\n", ivalue);
801 printf("\n");
802 }
803
804 printf("test string array invalid index -1:\n");
805 svalue = "aaa";
806 test->RSAI("sa10", -1, &svalue);
807 printf("RSAI() returned [%s]\n", svalue.c_str());
808 printf("\n");
809
810 printf("test string array invalid index 999:\n");
811 svalue = "aaa";
812 test->RSAI("sa10", 999, &svalue);
813 printf("RSAI() returned [%s]\n", svalue.c_str());
814 printf("\n");
815
816 printf("test write invalid index -1:\n");
817 test->WIAI("ia10", -1, 10);
818 printf("\n");
819
820 printf("test string write invalid index -1:\n");
821 test->WSAI("sa10", -1, "aaa");
822 printf("\n");
823
824 printf("\n");
825 printf("Test Chdir():\n");
826 printf("\n");
827
828 {
829 printf("test Chdir(true):\n");
830 MVOdb* dir = test->Chdir("test_subdir", true);
831 //printf("Chdir() returned %p\n", dir);
832 if (dir == NULL) report_fail("Chdir(new directory, true)");
833 }
834
835 {
836 printf("test Chdir(false):\n");
837 MVOdb* dir = test->Chdir("non-existant-subdir", false);
838 printf("Chdir() returned %p\n", dir);
839 if (dir != NULL) report_fail("Chdir(new directory, false)");
840 }
841
842 {
843 printf("test Chdir(\"not a dir\", true):\n");
844 MVOdb* dir = test->Chdir("ia10", true);
845 //printf("Chdir() returned %p\n", dir);
846 if (dir == NULL) report_fail("Chdir(not a directory, true)");
847 }
848
849 {
850 printf("test Chdir(\"not a dir\", false):\n");
851 MVOdb* dir = test->Chdir("ia10", false);
852 printf(" returned %p\n", dir);
853 if (dir != NULL) report_fail("Chdir(not a directory, false)");
854 }
855 }
856#endif
857
858 if (mfe)
859 mfe->Disconnect();
860
861 if (ok) {
862 printf("\n");
863 printf("Tests passed OK\n");
864 printf("\n");
865 } else {
866 printf("\n");
867 printf("Number of FAILED tests: %d\n", gCountFail);
868 printf("\n");
869 }
870
871 return 0;
872}
873
874//end
875/* emacs
876 * Local Variables:
877 * tab-width: 8
878 * c-basic-offset: 3
879 * indent-tabs-mode: nil
880 * End:
881 */
#define FALSE
Definition cfortran.h:309
Definition tmfe.h:381
static TMFE * Instance()
Definition tmfe.cxx:57
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
INT db_delete_key(HNDLE hDB, HNDLE hKey, BOOL follow_links)
Definition odb.cxx:3861
INT db_find_link(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
Definition odb.cxx:4279
INT db_create_key(HNDLE hDB, HNDLE hKey, const char *key_name, DWORD type)
Definition odb.cxx:3313
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
Definition odb.cxx:4084
INT db_create_link(HNDLE hDB, HNDLE hKey, const char *link_name, const char *destination)
Definition odb.cxx:3606
int main()
Definition hwtest.cxx:23
HNDLE hKey
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
DWORD BOOL
Definition midas.h:105
program test
Definition miniana.f:6
DWORD status
Definition odbhist.cxx:39
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
bool test_delete(HNDLE hDB, HNDLE hROOT, const char *path, BOOL follow_links=FALSE)
Definition test_odb.cxx:125
void print_da(const std::vector< double > &da)
Definition test_odb.cxx:39
bool test_find_fail(HNDLE hDB, HNDLE hROOT, const char *path, int fail_status)
Definition test_odb.cxx:147
static int gCountFail
Definition test_odb.cxx:51
bool test_mkdir(HNDLE hDB, HNDLE hROOT, const char *path)
Definition test_odb.cxx:89
bool test_symlink(HNDLE hDB, HNDLE hROOT, const char *path, const char *link_target)
Definition test_odb.cxx:175
bool test_mkdir_fail(HNDLE hDB, HNDLE hROOT, const char *path, int fail_status)
Definition test_odb.cxx:101
bool test_all(HNDLE hDB)
Definition test_odb.cxx:199
bool test_find_key_fail(HNDLE hDB, HNDLE hROOT, const char *path, int fail_status)
Definition test_odb.cxx:161
bool report_fail(const char *text)
Definition test_odb.cxx:53
void print_ia(const std::vector< int > &ia)
Definition test_odb.cxx:27
bool test_symlink_fail(HNDLE hDB, HNDLE hROOT, const char *path, const char *link_target, int fail_status)
Definition test_odb.cxx:187
bool test_chdir(HNDLE hDB, HNDLE hROOT, const char *path, HNDLE *phKey)
Definition test_odb.cxx:113
bool rmdir(HNDLE hDB, HNDLE hROOT, const char *path)
Definition test_odb.cxx:67
std::string toString(int i)
Definition test_odb.cxx:20