21 sprintf(buf,
"%d",
i);
28 printf(
"int[%d] has [", size);
29 for (
int i=0;
i<size;
i++) {
40 printf(
"int[%d] has [", size);
41 for (
int i=0;
i<size;
i++) {
53 printf(
"FAIL: %s\n", text);
60 printf(
"FAIL: %s\n", text.c_str());
69 printf(
"rmdir(%s)\n", path);
89 printf(
"mkdir(%s)\n", path);
101 printf(
"mkdir_fail(%s)\n", path);
105 if (
status == fail_status)
108 return report_fail(
msprintf(
"test_mkdir_fail: Create subdirectory \"%s\" failed, unexpcted status %d instead of %d\n", path,
status, fail_status));
113 printf(
"chdir(%s)\n", path);
127 printf(
"delete_key(%s)\n", path);
147 printf(
"delete(%s)\n", path);
161 printf(
"find_fail(%s)\n", path);
165 if (
status == fail_status)
168 return report_fail(
msprintf(
"test_find_fail: Unexpected db_find_link(%s) status %d instead of %d\n", path,
status, fail_status));
175 printf(
"find_key_fail(%s)\n", path);
179 if (
status == fail_status)
182 return report_fail(
msprintf(
"test_find_key_fail: Unexpected db_find_key(%s) status %d instead of %d\n", path,
status, fail_status));
187 printf(
"symlink(%s) to \"%s\"\n", path, link_target);
199 printf(
"symlink_fail(%s) to \"%s\"\n", path, link_target);
203 if (
status == fail_status)
206 return report_fail(
msprintf(
"test_symlink_fail: db_create_link(%s) status %d instead of %d\n", path,
status, fail_status));
209bool test_enum(
const std::vector<HNDLE>& hlist,
const std::vector<KEY>& klist)
211 printf(
"test_enum\n");
213 if (hlist.size() != klist.size()) {
219 size_t expected_size = 6;
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));
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);
233 printf(
"test_enum_links\n");
235 if (hlist.size() != klist.size()) {
241 size_t expected_size = 6;
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));
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);
299 ok &=
test_mkdir(
hDB, hROOT,
"test_delete_key_dir/test/test/test_mkdir");
309 ok &=
test_mkdir(
hDB, hROOT,
"test_delete_dir/test/test/test_mkdir");
318 ok &=
test_symlink(
hDB, 0,
"/test_odb/test_symlink",
"/test_odb/test_mkdir");
322 ok &=
test_symlink(
hDB, 0,
"/test_odb/test_symlink_to_symlink",
"/test_odb/test_symlink");
329 ok &=
test_symlink(
hDB, 0,
"/test_odb/test_symlink1",
"/test_odb/test_symlink1_target");
339 ok &=
test_symlink(
hDB, 0,
"/test_odb/test_symlink2",
"/test_odb/test_symlink2_target");
353 ok &=
test_symlink(
hDB, 0,
"/test_odb/test_symlink1",
"/test_odb/test_symlink_target");
354 ok &=
test_symlink(
hDB, 0,
"/test_odb/test_symlink2",
"/test_odb/test_symlink_target");
364 ok &=
test_symlink(
hDB, 0,
"/test_odb/test_link_to_link1",
"/test_odb/test_link_to_link");
365 ok &=
test_symlink(
hDB, 0,
"/test_odb/test_link_to_link2",
"/test_odb/test_link_to_link1");
376 ok &=
test_symlink(
hDB, 0,
"/test_odb/test_symlink_dir1/test_symlink",
"/test_odb/test_symlink_dir2");
384 ok &=
test_symlink(
hDB, 0,
"/test_odb/test_circular_link/test_link",
"/test_odb/test_circular_link");
385 ok &=
test_symlink(
hDB, 0,
"/test_odb/test_circular_link1",
"/test_odb/test_circular_link");
396 std::vector<HNDLE> hlist;
397 std::vector<KEY> klist;
421 std::vector<HNDLE> hlist;
422 std::vector<KEY> klist;
448int main(
int argc,
char *argv[])
453 signal(SIGILL, SIG_DFL);
454 signal(SIGBUS, SIG_DFL);
455 signal(SIGSEGV, SIG_DFL);
456 signal(SIGPIPE, SIG_DFL);
458 const char* hostname = NULL;
459 const char* exptname = NULL;
468 r = mfe->
Connect(
"test_odb", hostname, exptname);
471 fprintf(stderr,
"Cannot connect to MIDAS, error %s\n", r.
error_message.c_str());
480 printf(
"Starting tests:\n");
490 printf(
"Tests passed OK\n");
494 printf(
"Number of FAILED tests: %d\n",
gCountFail);
int fDB
ODB database handle.
TMFeResult Connect(const char *progname=NULL, const char *hostname=NULL, const char *exptname=NULL)
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 EXPRT db_enum(HNDLE hDB, HNDLE hKeyRoot, std::vector< HNDLE > *sub_handles, std::vector< KEY > *sub_keys, bool follow_links)
INT db_create_key(HNDLE hDB, HNDLE hKey, const char *key_name, DWORD type)
INT db_delete(HNDLE hDB, HNDLE hKeyRoot, const char *odb_path)
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,...)
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)
bool test_enum_links(const std::vector< HNDLE > &hlist, const std::vector< KEY > &klist)
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_enum(const std::vector< HNDLE > &hlist, const std::vector< KEY > &klist)
bool test_delete_key(HNDLE hDB, HNDLE hROOT, const char *path)
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)
bool test_delete(HNDLE hDB, HNDLE hROOT, const char *path)