30 printf(
"int[%d] has [", size);
31 for (
int i=0;
i<size;
i++) {
42 printf(
"int[%d] has [", size);
43 for (
int i=0;
i<size;
i++) {
55 printf(
"FAIL: %s\n", text);
62 printf(
"FAIL: %s\n", text.c_str());
71 printf(
"rmdir(%s)\n", path);
91 printf(
"mkdir(%s)\n", path);
103 printf(
"mkdir_fail(%s)\n", path);
115 printf(
"chdir(%s)\n", path);
129 printf(
"delete(%s)\n", path);
151 printf(
"find_fail(%s)\n", path);
165 printf(
"find_key_fail(%s)\n", path);
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");
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");
285 ok &=
test_symlink(
hDB, 0,
"/test_odb/test_symlink_dir1/test_symlink",
"/test_odb/test_symlink_dir2");
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");
314 const char* hostname =
NULL;
335 printf(
"Starting tests:\n");
343 odb->RI(
"runinfo/run number", &runno);
345 printf(
"read run number (RI): %d\n", runno);
347 MVOdb*
test = odb->Chdir(
"test_mvodb",
true);
351 test->SetPrintError(
true);
357 printf(
"This ODB is read-only!\n");
361 printf(
"Test create-and-read of all data types (set default values):\n");
369 test->RI(
"int", &ivalue,
true);
370 printf(
"RI() int: %d\n", ivalue);
373 test->RF(
"float", &fvalue,
true);
374 printf(
"RF() float: %f\n", fvalue);
377 test->RD(
"double", &dvalue,
true);
378 printf(
"RD() double: %f\n", dvalue);
396 std::string svalue =
"test string";
397 test->RS(
"string", &svalue,
true);
398 printf(
"RS() string: \"%s\"\n", svalue.c_str());
401 printf(
"Test write of all data types (overwrite default values):\n");
421 test->WS(
"string",
ws.c_str());
424 printf(
"Test read of new values for all data types:\n");
429 printf(
"int: %d -> %d -> %d\n", ivalue,
wi,
ri);
433 printf(
"float: %f -> %f -> %f\n", fvalue,
wf,
rf);
437 printf(
"double: %f -> %f -> %f\n", dvalue,
wd,
rd);
455 std::string
rs =
"rs";
457 printf(
"string: \"%s\" -> \"%s\" -> \"%s\"\n", svalue.c_str(),
ws.c_str(),
rs.c_str());
460 printf(
"Test read arrays of all data types:\n");
464 printf(
"read int array ia:\n");
469 test->RIA(
"ia", &
ia,
true);
470 printf(
"RIA() returned: ");
476 printf(
"read non-existant array ia-noexist:\n");
481 test->RIA(
"ia-noexist", &
ia);
482 printf(
"RIA() returned: ");
490 test->RIA(
"ia10zero", &
ia,
true, 10);
495 test->RIA(
"ia10", &
ia,
true, 10);
500 test->RIA(
"createia10",
NULL,
true, 10);
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);
513 std::vector<double>
da;
518 test->RDA(
"da", &
da,
true, 0);
522 std::vector<float>
fa;
528 test->RFA(
"fa", &
fa,
true, 0);
532 std::vector<bool>
ba;
536 test->RBA(
"ba", &
ba,
true, 0);
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);
551 test->RSA(
"sa10", &sa,
true, 10, 32);
553 test->RSA(
"createsa10",
NULL,
true, 10, 32);
557 printf(
"Test string sizes:\n");
561 test->WS(
"test_size",
"12345");
563 test->RS(
"test_size", &s);
564 printf(
"read test_size [%s]\n", s.c_str());
567 test->WS(
"test_size_32",
"1234567890", 32);
569 test->RS(
"test_size_32", &s);
570 printf(
"read test_size_32 [%s]\n", s.c_str());
573 test->WS(
"test_size_5",
"1234567890", 5);
575 test->RS(
"test_size_5", &s);
576 printf(
"read test_size_5 [%s]\n", s.c_str());
579 std::string s =
"1234567890";
580 test->RS(
"test_rsize", &s,
true);
581 printf(
"read test_rsize [%s]\n", s.c_str());
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());
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());
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());
602 printf(
"Test creating and resizing arrays:\n");
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);
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);
623 printf(
"Test array index access:\n");
631 test->WIA(
"index_ia",
ia);
632 for (
int i=0;
i<5;
i++) {
634 test->RIAI(
"index_ia",
i, &ivalue);
635 printf(
"index %d value %d\n",
i, ivalue);
637 for (
int i=0;
i<4;
i++) {
639 test->WIAI(
"index_ia",
i, ivalue);
641 for (
int i=0;
i<5;
i++) {
643 test->RIAI(
"index_ia",
i, &ivalue);
644 printf(
"index %d value %d\n",
i, ivalue);
649 printf(
"Test string array index access:\n");
653 std::vector<std::string> sa;
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());
663 for (
int i=0;
i<4;
i++) {
664 std::string s =
"sa_qqq";
666 test->WSAI(
"index_sa",
i, s.c_str());
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());
676 printf(
"Test string truncation:\n");
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());
694 printf(
"Test against subdirectory:\n");
698 printf(
"Creating subdir\n");
699 MVOdb* subdir =
test->Chdir(
"subdir",
true);
700 printf(
"Creating subdir/i\n");
704 test->RI(
"subdir", &
i);
706 test->WI(
"subdir", 10);
715 printf(
"RIA() returned: ");
718 printf(
"RIA(subdir, create=true)\n");
719 test->RIA(
"subdir", &
ia,
true);
720 printf(
"RIA() returned: ");
726 printf(
"Test special cases:\n");
730 printf(
"test RI() of non existant variable:\n");
732 test->RI(
"nonexistant", &ivalue);
733 printf(
"RI() returned ivalue %d\n", ivalue);
737 std::vector<double>
da;
738 printf(
"test RDA() of integer array:\n");
740 test->RDA(
"ia10", &
da,
false, 0);
741 printf(
"RDA() returned: ");
747 printf(
"test RD() of integer array:\n");
750 test->RD(
"ia10", &v);
751 printf(
"RD() returned %f\n", v);
756 printf(
"test RI() of array ia10:\n");
758 test->RI(
"ia10", &ivalue);
759 printf(
"RI() returned ivalue %d\n", ivalue);
764 printf(
"test RIA() of non-array int:\n");
767 printf(
"RIA() returned: ");
773 printf(
"test index 0 of non-array int:\n");
775 test->RIAI(
"int", 0, &ivalue);
776 printf(
"RIAI() returned ivalue %d\n", ivalue);
781 printf(
"test index of non-array int:\n");
783 test->RIAI(
"int", 10, &ivalue);
784 printf(
"RIAI() returned ivalue %d\n", ivalue);
789 printf(
"test invalid index -1 of array ia10:\n");
791 test->RIAI(
"ia10", -1, &ivalue);
792 printf(
"RIAI() returned ivalue %d\n", ivalue);
797 printf(
"test invalid index 999 of array ia10:\n");
799 test->RIAI(
"ia10", 999, &ivalue);
800 printf(
"RIAI() returned ivalue %d\n", ivalue);
804 printf(
"test string array invalid index -1:\n");
806 test->RSAI(
"sa10", -1, &svalue);
807 printf(
"RSAI() returned [%s]\n", svalue.c_str());
810 printf(
"test string array invalid index 999:\n");
812 test->RSAI(
"sa10", 999, &svalue);
813 printf(
"RSAI() returned [%s]\n", svalue.c_str());
816 printf(
"test write invalid index -1:\n");
817 test->WIAI(
"ia10", -1, 10);
820 printf(
"test string write invalid index -1:\n");
821 test->WSAI(
"sa10", -1,
"aaa");
825 printf(
"Test Chdir():\n");
829 printf(
"test Chdir(true):\n");
830 MVOdb* dir =
test->Chdir(
"test_subdir",
true);
836 printf(
"test Chdir(false):\n");
837 MVOdb* dir =
test->Chdir(
"non-existant-subdir",
false);
838 printf(
"Chdir() returned %p\n", dir);
843 printf(
"test Chdir(\"not a dir\", true):\n");
850 printf(
"test Chdir(\"not a dir\", false):\n");
852 printf(
" returned %p\n", dir);
863 printf(
"Tests passed OK\n");
std::string error_message
INT db_delete_key(HNDLE hDB, HNDLE hKey, BOOL follow_links)
INT db_find_link(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
INT db_create_key(HNDLE hDB, HNDLE hKey, const char *key_name, DWORD type)
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
INT db_create_link(HNDLE hDB, HNDLE hKey, const char *link_name, const char *destination)
std::string msprintf(const char *format,...)
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
bool test_delete(HNDLE hDB, HNDLE hROOT, const char *path, BOOL follow_links=FALSE)
void print_da(const std::vector< double > &da)
bool test_find_fail(HNDLE hDB, HNDLE hROOT, const char *path, int fail_status)
bool test_mkdir(HNDLE hDB, HNDLE hROOT, const char *path)
bool test_symlink(HNDLE hDB, HNDLE hROOT, const char *path, const char *link_target)
bool test_mkdir_fail(HNDLE hDB, HNDLE hROOT, const char *path, int fail_status)
bool test_find_key_fail(HNDLE hDB, HNDLE hROOT, const char *path, int fail_status)
bool report_fail(const char *text)
void print_ia(const std::vector< int > &ia)
bool test_symlink_fail(HNDLE hDB, HNDLE hROOT, const char *path, const char *link_target, int fail_status)
bool test_chdir(HNDLE hDB, HNDLE hROOT, const char *path, HNDLE *phKey)
bool rmdir(HNDLE hDB, HNDLE hROOT, const char *path)
std::string toString(int i)