305{
308
313
314 const char* hostname =
NULL;
316
317
318
319
321
323
327 return -1;
328 }
329
331
333
335 printf(
"Starting tests:\n");
337
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
350
351 test->SetPrintError(
true);
352
354
357 printf(
"This ODB is read-only!\n");
358 }
359
361 printf(
"Test create-and-read of all data types (set default values):\n");
363
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
383
387
391
395
396 std::string svalue = "test string";
397 test->RS(
"string", &svalue,
true);
398 printf(
"RS() string: \"%s\"\n", svalue.c_str());
399
401 printf(
"Test write of all data types (overwrite default values):\n");
403
405
421 test->WS(
"string",
ws.c_str());
422
424 printf(
"Test read of new values for all data types:\n");
426
429 printf(
"int: %d -> %d -> %d\n", ivalue,
wi,
ri);
430
433 printf(
"float: %f -> %f -> %f\n", fvalue,
wf,
rf);
434
437 printf(
"double: %f -> %f -> %f\n", dvalue,
wd,
rd);
438
442
446
450
454
455 std::string
rs =
"rs";
457 printf(
"string: \"%s\" -> \"%s\" -> \"%s\"\n", svalue.c_str(),
ws.c_str(),
rs.c_str());
458
460 printf(
"Test read arrays of all data types:\n");
462
463 {
464 printf(
"read int array ia:\n");
469 test->RIA(
"ia", &
ia,
true);
470 printf(
"RIA() returned: ");
473 }
474
475 {
476 printf(
"read non-existant array ia-noexist:\n");
481 test->RIA(
"ia-noexist", &
ia);
482 printf(
"RIA() returned: ");
485 }
486
487 {
488
490 test->RIA(
"ia10zero", &
ia,
true, 10);
491
495 test->RIA(
"ia10", &
ia,
true, 10);
496 }
497
498 {
499
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);
510 }
511
512 {
513 std::vector<double>
da;
518 test->RDA(
"da", &
da,
true, 0);
519 }
520
521 {
522 std::vector<float>
fa;
528 test->RFA(
"fa", &
fa,
true, 0);
529 }
530
531 {
532 std::vector<bool>
ba;
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
548 sa.clear();
549 sa.push_back("xx1");
550 sa.push_back("xx2");
551 test->RSA(
"sa10", &sa,
true, 10, 32);
552
553 test->RSA(
"createsa10",
NULL,
true, 10, 32);
554 }
555
557 printf(
"Test string sizes:\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
602 printf(
"Test creating and resizing arrays:\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
623 printf(
"Test array index access:\n");
625
626 {
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++) {
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
649 printf(
"Test string array index access:\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";
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
676 printf(
"Test string truncation:\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
694 printf(
"Test against subdirectory:\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);
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: ");
723 }
724
726 printf(
"Test special cases:\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);
735
736 {
737 std::vector<double>
da;
738 printf(
"test RDA() of integer array:\n");
739
740 test->RDA(
"ia10", &
da,
false, 0);
741 printf(
"RDA() returned: ");
744 }
745
746 {
747 printf(
"test RD() of integer array:\n");
748
749 double v = 999.9;
750 test->RD(
"ia10", &v);
751 printf(
"RD() returned %f\n", v);
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);
761 }
762
763 {
764 printf(
"test RIA() of non-array int:\n");
767 printf(
"RIA() returned: ");
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);
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);
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);
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);
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());
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());
815
816 printf(
"test write invalid index -1:\n");
817 test->WIAI(
"ia10", -1, 10);
819
820 printf(
"test string write invalid index -1:\n");
821 test->WSAI(
"sa10", -1,
"aaa");
823
825 printf(
"Test Chdir():\n");
827
828 {
829 printf(
"test Chdir(true):\n");
830 MVOdb* dir =
test->Chdir(
"test_subdir",
true);
831
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);
840 }
841
842 {
843 printf(
"test Chdir(\"not a dir\", true):\n");
845
847 }
848
849 {
850 printf(
"test Chdir(\"not a dir\", false):\n");
852 printf(
" returned %p\n", dir);
854 }
855 }
856#endif
857
860
863 printf(
"Tests passed OK\n");
865 } else {
869 }
870
871 return 0;
872}
std::string error_message
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
void print_da(const std::vector< double > &da)
bool report_fail(const char *text)
void print_ia(const std::vector< int > &ia)
std::string toString(int i)