static int deinit_test(root_test_t *rt) { BEGIN(); TEST_VOID(su_root_destroy(rt->rt_root)); rt->rt_root = NULL; TEST_VOID(su_root_destroy(NULL)); su_deinit(); END(); }
static int clone_test(root_test_t rt[1]) { BEGIN(); rt->rt_fail_init = 0; rt->rt_fail_deinit = 0; rt->rt_success_init = 0; rt->rt_success_deinit = 0; TEST(su_clone_start(rt->rt_root, rt->rt_clone, rt, fail_init, fail_deinit), SU_FAILURE); TEST_1(rt->rt_fail_init); TEST_1(rt->rt_fail_deinit); TEST(su_clone_start(rt->rt_root, rt->rt_clone, rt, success_init, success_deinit), SU_SUCCESS); TEST_1(rt->rt_success_init); TEST_1(!rt->rt_success_deinit); TEST_VOID(su_clone_wait(rt->rt_root, rt->rt_clone)); TEST_1(rt->rt_success_deinit); END(); }
static bool test_root_key(Omega::Registry::IKey* pKey) { TEST(pKey->IsKey("System")); TEST(pKey->IsKey("Local User")); TEST(pKey->IsKey("All Users")); Omega::string_t strTestValue("TestValue_{0}"); strTestValue %= GetCurrentProcessId(); while (pKey->IsValue(strTestValue)) { strTestValue = "_" + strTestValue; } bool bCanWriteToRoot = true; try { TEST_VOID(pKey->SetValue(strTestValue,"Yes")); } catch (Omega::IAccessDeniedException* pE) { // We don't have permission - skip this test... pE->Release(); bCanWriteToRoot = false; } if (bCanWriteToRoot) { TEST_VOID(pKey->DeleteValue(strTestValue)); if (!test_key2(pKey,"")) return false; } // Test the private root keys test_privates(pKey,"System"); test_privates(pKey,"System/Sandbox"); test_privates(pKey,"All Users/Objects"); test_privates(pKey,"All Users/Objects/OIDs"); test_privates(pKey,"All Users/Applications"); test_privates(pKey,"Local User"); if (bCanWriteToRoot) test_privates(pKey,"System"); return true; }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ /*************************************************************** * parse standard options ***************************************************************/ if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); /*************************************************************** * perform global setup for test ***************************************************************/ setup(); /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); /*************************************************************** * check looping state if -c option given ***************************************************************/ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping. */ Tst_count = 0; /* * Call sync(2) */ TEST_VOID(sync()); /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "sync() Failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { /*************************************************************** * only perform functional verification if flag set (-f not given) ***************************************************************/ if (STD_FUNCTIONAL_TEST) { /* No Verification test, yet... */ tst_resm(TPASS, "sync() returned %ld", TEST_RETURN); } } } /* End for TEST_LOOPING */ /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); return 0; } /* End main */
static int test_lock(void) { su_home_t home[1] = { SU_HOME_INIT(home) }; BEGIN(); TEST(su_home_mutex_lock(home), -1); TEST(su_home_mutex_unlock(home), -1); TEST(su_home_lock(home), -1); TEST(su_home_trylock(home), -1); TEST(su_home_unlock(home), -1); TEST(su_home_init(home), 0); TEST(su_home_mutex_lock(home), 0); TEST(su_home_trylock(home), -1); TEST(su_home_mutex_unlock(home), 0); TEST(su_home_trylock(home), -1); TEST(su_home_threadsafe(home), 0); TEST(su_home_mutex_lock(home), 0); TEST(su_home_trylock(home), EBUSY); TEST(su_home_mutex_unlock(home), 0); TEST(su_home_lock(home), 0); TEST(su_home_trylock(home), EBUSY); TEST(su_home_unlock(home), 0); TEST(su_home_trylock(home), 0); TEST(su_home_unlock(home), 0); TEST_VOID(su_home_deinit(home)); END(); }
int main(int ac, char **av) { int lc; char *msg; char read_buffer[BUFSIZ]; /* buffer used to read data from file */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* * Call sync(2) to commit buffer data to disk. */ TEST_VOID(sync()); if (TEST_RETURN == -1) { tst_resm(TFAIL, "%s, Failed, errno=%d : %s", TCID, TEST_ERRNO, strerror(TEST_ERRNO)); } else { /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { /* Set the file ptr to b'nning of file */ if (lseek(fildes, 0, SEEK_SET) < 0) { tst_brkm(TFAIL, cleanup, "lseek() " "failed on %s, error=%d", TEMP_FILE, errno); } /* Read the contents of file */ if (read(fildes, read_buffer, sizeof(read_buffer)) > 0) { if (strcmp(read_buffer, write_buffer)) { tst_resm(TFAIL, "Data read " "from %s doesn't match " "with witten data", TEMP_FILE); } else { tst_resm(TPASS, "Functionality " "of sync() successful"); } } else { tst_brkm(TFAIL, cleanup, "read() Fails on %s, error=%d", TEMP_FILE, errno); } } else { tst_resm(TPASS, "call succeeded"); } } tst_count++; /* incr. TEST_LOOP counter */ } cleanup(); tst_exit(); }
static int test_auto(void) { BEGIN(); int i; su_home_t tmphome[SU_HOME_AUTO_SIZE(8000)]; char *b = NULL; su_home_stat_t hs[1]; TEST_1(!su_home_auto(tmphome, sizeof tmphome[0])); TEST_1(su_home_auto(tmphome, sizeof tmphome)); for (i = 0; i < 8192; i++) TEST_1(su_alloc(tmphome, 12)); TEST_VOID(su_home_deinit(tmphome)); TEST_1(su_home_auto(tmphome, sizeof tmphome)); su_home_init_stats(tmphome); for (i = 1; i < 8192; i++) { TEST_1(b = su_realloc(tmphome, b, i)); b[i - 1] = '\125'; } for (i = 1; i < 8192; i++) { TEST(b[i - 1], '\125'); } for (i = 1; i < 8192; i++) { TEST_1(b = su_realloc(tmphome, b, i)); b[i - 1] = '\125'; if ((i % 32) == 0) TEST_1(b = su_realloc(tmphome, b, 1)); } su_home_get_stats(tmphome, 0, hs, sizeof *hs); TEST64(hs->hs_allocs.hsa_preload + hs->hs_allocs.hsa_number, 8191 + 8191 + 8191 / 32); TEST64(hs->hs_frees.hsf_preload + hs->hs_frees.hsf_number, 8191 + 8191 + 8191 / 32 - 1); /* This test depends on macro SU_HOME_AUTO_SIZE() calculating offsetof(su_block_t, sub_nodes[7]) correctly with ((3 * sizeof (void *) + 4 * sizeof(unsigned) + 7 * (sizeof (long) + sizeof(void *)) + 7) */ TEST_1(hs->hs_frees.hsf_preload == hs->hs_allocs.hsa_preload); su_free(tmphome, b); for (i = 1; i < 8192; i++) TEST_1(b = su_alloc(tmphome, 1)); TEST_VOID(su_home_deinit(tmphome)); END(); }
/** Test basic memory home operations */ static int test_alloc(void) { exhome_t *h0, *h1, *h2, *h3; su_home_t home[1] = { SU_HOME_INIT(home) }; su_home_t home0[1]; enum { N = 40 }; void *m0[N], *m1[N], *m; char *c, *c0, *p0, *p1; int i; enum { destructed_once = 1 }; int d0, d1a, d1, d2, d3; BEGIN(); /* su_home_init() was not initializing suh_locks */ memset(home0, 0xff, sizeof home0); TEST(su_home_init(home0), 0); TEST_VOID(su_home_deinit(home0)); TEST_1(h0 = su_home_new(sizeof(*h0))); TEST_1(h1 = su_home_clone(h0->home, sizeof(*h1))); d0 = d1a = d1 = d2 = d3 = 0; h0->p = &d0; h1->p = &d1a; TEST(su_home_destructor(h0->home, exdestructor), 0); TEST(su_home_destructor(h1->home, exdestructor), 0); TEST_1(h2 = su_home_ref(h0->home)); su_home_unref(h0->home); TEST(d0, 0); for (i = 0; i < 128; i++) TEST_1(su_alloc(h0->home, 16)); for (i = 0; i < 128; i++) TEST_1(su_alloc(h1->home, 16)); su_home_unref(h1->home); TEST(d1a, destructed_once); TEST_1(h1 = su_home_clone(h0->home, sizeof(*h1))); TEST(su_home_destructor(h1->home, exdestructor), 0); h1->p = &d1; for (i = 0; i < 128; i++) TEST_1(su_alloc(h1->home, 16)); for (i = 0; i < 128; i++) TEST_1(su_alloc(h2->home, 16)); su_home_unref(h2->home); /* Should call destructor of cloned home, too */ TEST(d0, destructed_once); TEST(d1, destructed_once); TEST_1(h0 = su_home_new(sizeof(*h0))); TEST_1(h1 = su_home_clone(h0->home, sizeof(*h1))); TEST_1(h2 = su_home_clone(h1->home, sizeof(*h2))); TEST_1(h3 = su_home_clone(h2->home, sizeof(*h3))); TEST(su_home_threadsafe(h0->home), 0); for (i = 0; i < N; i++) { TEST_1(m0[i] = su_zalloc(h3->home, 20)); TEST_1(m1[i] = su_zalloc(h2->home, 20)); } TEST_1(m = su_zalloc(h2->home, 20)); TEST_1(su_in_home(h2->home, m)); TEST_1(!su_in_home(h2->home, (char *)m + 1)); TEST_1(!su_in_home(h2->home, (void *)(intptr_t)su_in_home)); TEST_1(!su_in_home(h3->home, m)); TEST_1(!su_in_home(NULL, m)); TEST_1(!su_in_home(h3->home, NULL)); TEST(su_home_move(home, NULL), 0); TEST(su_home_move(NULL, home), 0); TEST(su_home_move(home, h3->home), 0); TEST(su_home_move(h2->home, h3->home), 0); TEST(su_home_move(h1->home, h2->home), 0); su_home_preload(home, 1, 1024 + 2 * 8); TEST_1(c = su_zalloc(home, 64)); p0 = c; p1 = c + 1024; c0 = c; TEST_P(c = su_realloc(home, c0, 127), c0); TEST_1(c = c0 = su_zalloc(home, 1024 - 128)); TEST_1(p0 <= c); TEST_1(c < p1); TEST_P(c = su_realloc(home, c, 128), c0); TEST_P(c = su_realloc(home, c, 1023 - 128), c0); TEST_P(c = su_realloc(home, c, 1024 - 128), c0); TEST_1(c = su_realloc(home, c, 1024)); TEST_1(c = su_realloc(home, c, 2 * 1024)); TEST_P(c = su_realloc(home, p0, 126), p0); TEST_1(c = su_realloc(home, p0, 1024)); TEST_P(c = su_realloc(home, c, 0), NULL); su_home_check(home); su_home_deinit(home); su_home_check(h2->home); su_home_zap(h2->home); su_home_check(h0->home); su_home_zap(h0->home); { su_home_t h1[1]; memset(h1, 0, sizeof h1); TEST(su_home_init(h1), 0); TEST(su_home_threadsafe(h1), 0); TEST_1(su_home_ref(h1)); TEST_1(su_home_ref(h1)); TEST(su_home_destructor(h1, test_destructor), 0); TEST_1(!su_home_unref(h1)); TEST_1(!su_home_unref(h1)); TEST_1(su_home_unref(h1)); TEST(h1->suh_size, 13); } /* Test su_home_parent() */ TEST_1(h0 = su_home_new(sizeof *h0)); TEST_1(h1 = su_home_clone(h0->home, sizeof *h1)); TEST_1(h2 = su_home_clone(h1->home, sizeof *h2)); TEST_1(h3 = su_home_clone(h2->home, sizeof *h3)); TEST_P(su_home_parent(h0->home), NULL); TEST_P(su_home_parent(h1->home), h0); TEST_P(su_home_parent(h2->home), h1); TEST_P(su_home_parent(h3->home), h2); TEST(su_home_move(h0->home, h1->home), 0); TEST_P(su_home_parent(h2->home), h0); TEST_P(su_home_parent(h3->home), h2); TEST(su_home_move(h0->home, h2->home), 0); TEST_P(su_home_parent(h3->home), h0); su_home_move(NULL, h0->home); TEST_P(su_home_parent(h0->home), NULL); TEST_P(su_home_parent(h1->home), NULL); TEST_P(su_home_parent(h2->home), NULL); TEST_P(su_home_parent(h3->home), NULL); su_home_unref(h0->home); su_home_unref(h1->home); su_home_unref(h2->home); su_home_unref(h3->home); END(); }
static int test_strlst(void) { su_home_t home[1] = { SU_HOME_INIT(home) }; su_strlst_t *l, *l1, *l2; char *s; char foo[] = "foo"; char bar[] = "bar"; char baz[] = "baz"; su_home_stat_t parent[1], kids[2]; BEGIN(); parent->hs_size = (sizeof parent); kids[0].hs_size = (sizeof kids[0]); kids[1].hs_size = (sizeof kids[1]); su_home_init_stats(home); /* Test API for invalid arguments */ TEST_1(l = su_strlst_create(NULL)); TEST_1(l2 = su_strlst_dup(home, l)); TEST_VOID(su_strlst_destroy(l2)); TEST_1(!su_strlst_dup(home, NULL)); TEST_1(l1 = su_strlst_copy(home, l)); TEST_VOID(su_strlst_destroy(l1)); TEST_1(!su_strlst_copy(home, NULL)); TEST_VOID(su_strlst_destroy(NULL)); TEST_VOID(su_strlst_destroy(l)); TEST_1(!su_strlst_dup_append(NULL, "aa")); TEST_1(!su_strlst_append(NULL, "bee")); TEST_1(!su_strlst_item(NULL, 1)); TEST_1(!su_strlst_set_item(NULL, 1, "cee")); TEST_1(!su_strlst_remove(NULL, 1)); TEST_S(s = su_strlst_join(NULL, home, "a"), ""); TEST_VOID(su_free(home, s)); TEST_1(!su_strlst_split(home, NULL, ".")); TEST_1(s = su_strdup(home, "aaa")); TEST_1(l = su_strlst_split(home, s, NULL)); TEST_S(su_strlst_item(l, 0), "aaa"); TEST_VOID(su_strlst_destroy(l)); TEST_VOID(su_free(home, s)); TEST_1(!su_strlst_dup_split(home, NULL, ".")); TEST_1(l1 = su_strlst_dup_split(home, "aaa", "")); TEST_S(su_strlst_item(l1, 0), "aaa"); TEST_VOID(su_strlst_destroy(l1)); TEST_SIZE(su_strlst_len(NULL), 0); TEST_1(!su_strlst_get_array(NULL)); TEST_VOID(su_strlst_free_array(NULL, NULL)); TEST_1(l = su_strlst_create(home)); TEST_VOID(su_strlst_free_array(l, NULL)); TEST_S(su_strlst_dup_append(l, "oh"), "oh"); TEST_VOID(su_strlst_free_array(l, NULL)); TEST_VOID(su_strlst_destroy(l)); /* Test functionality */ TEST_1(l = su_strlst_create(home)); su_home_init_stats(su_strlst_home(l)); TEST_S(su_strlst_join(l, home, "bar"), ""); TEST_S(su_strlst_append(l, foo), "foo"); TEST_S(su_strlst_dup_append(l, bar), "bar"); TEST_S(su_strlst_append(l, baz), "baz"); TEST_S((s = su_strlst_join(l, home, "!")), "foo!bar!baz"); TEST_S(su_strlst_item(l, 0), foo); TEST_S(su_strlst_item(l, 1), bar); TEST_S(su_strlst_item(l, 2), baz); TEST_P(su_strlst_item(l, 3), NULL); TEST_P(su_strlst_item(l, (unsigned)-1), NULL); TEST_1(l1 = su_strlst_copy(su_strlst_home(l), l)); TEST_1(l2 = su_strlst_dup(su_strlst_home(l), l)); strcpy(foo, "hum"); strcpy(bar, "pah"); strcpy(baz, "hah"); TEST_S(su_strlst_dup_append(l1, "kuik"), "kuik"); TEST_S(su_strlst_dup_append(l2, "uik"), "uik"); TEST_S((s = su_strlst_join(l, home, ".")), "hum.bar.hah"); TEST_S((su_strlst_join(l1, home, ".")), "hum.bar.hah.kuik"); TEST_S((su_strlst_join(l2, home, ".")), "foo.bar.baz.uik"); su_strlst_destroy(l2); su_home_get_stats(su_strlst_home(l), 0, kids, sizeof kids); TEST_SIZE(kids->hs_clones, 2); TEST64(kids->hs_allocs.hsa_number, 3); TEST64(kids->hs_frees.hsf_number, 1); su_strlst_destroy(l); TEST_S(s, "hum.bar.hah"); TEST_1(l = su_strlst_create(home)); su_home_init_stats(su_strlst_home(l)); TEST_S(su_strlst_join(l, home, "bar"), ""); TEST_S(su_strlst_append(l, "a"), "a"); TEST_S(su_strlst_append(l, "b"), "b"); TEST_S(su_strlst_append(l, "c"), "c"); TEST_S(su_strlst_append(l, "d"), "d"); TEST_S(su_strlst_append(l, "e"), "e"); TEST_S(su_strlst_append(l, "f"), "f"); TEST_S(su_strlst_append(l, "g"), "g"); TEST_S(su_strlst_append(l, "h"), "h"); TEST_S(su_strlst_append(l, "i"), "i"); TEST_S(su_strlst_append(l, "j"), "j"); TEST_S((s = su_strlst_join(l, home, "")), "abcdefghij"); TEST_S(su_strlst_append(l, "a"), "a"); TEST_S(su_strlst_append(l, "b"), "b"); TEST_S(su_strlst_append(l, "c"), "c"); TEST_S(su_strlst_append(l, "d"), "d"); TEST_S(su_strlst_append(l, "e"), "e"); TEST_S(su_strlst_append(l, "f"), "f"); TEST_S(su_strlst_append(l, "g"), "g"); TEST_S(su_strlst_append(l, "h"), "h"); TEST_S(su_strlst_append(l, "i"), "i"); TEST_S(su_strlst_append(l, "j"), "j"); TEST_S((s = su_strlst_join(l, home, "")), "abcdefghijabcdefghij"); su_home_get_stats(su_strlst_home(l), 0, kids + 1, (sizeof kids[1])); su_home_stat_add(kids, kids + 1); su_strlst_destroy(l); su_home_get_stats(home, 1, parent, (sizeof parent)); su_home_check(home); su_home_deinit(home); su_home_init(home); { char s[] = "foo\nfaa\n"; TEST_1((l = su_strlst_split(home, s, "\n"))); TEST_SIZE(su_strlst_len(l), 3); TEST_1(su_strlst_append(l, "bar")); TEST_S(su_strlst_join(l, home, "\n"), "foo\nfaa\n\nbar"); } { char s[] = "foo"; TEST_1((l = su_strlst_split(home, s, "\n"))); TEST_SIZE(su_strlst_len(l), 1); } { char s[] = "\n\n"; TEST_1((l = su_strlst_split(home, s, "\n"))); TEST_SIZE(su_strlst_len(l), 3); } { char s[] = ""; TEST_1((l = su_strlst_split(home, s, "\n"))); TEST_SIZE(su_strlst_len(l), 1); } { int i; #define S \ "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\n" \ "n\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz\n" \ "A\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\n" \ "N\nO\nP\nQ\nR\nS\nT\nU\nV\nW\nX\nY\nZ\n" char s[] = S; TEST_1((l = su_strlst_split(home, s, "\n"))); TEST_SIZE(su_strlst_len(l), 53); TEST_1(su_strlst_append(l, "bar")); TEST_S(su_strlst_join(l, home, "\n"), S "\nbar"); TEST_1(!su_strlst_remove(l, 54)); for (i = 0; i < 54; i++) { TEST_1(su_strlst_remove(l, 0)); TEST_1(!su_strlst_remove(l, 53 - i)); TEST_SIZE(su_strlst_len(l), 53 - i); } TEST_1(!su_strlst_remove(l, 0)); TEST_SIZE(su_strlst_len(l), 0); } { char const *s0; TEST_1(l = su_strlst_create_with(NULL, s0 = "a", "b", NULL)); TEST_1(su_strlst_item(l, 0) == s0); TEST_S(su_strlst_item(l, 0), "a"); TEST_S(su_strlst_item(l, 1), "b"); TEST_1(su_strlst_item(l, 2) == NULL); TEST_S(su_slprintf(l, "1: %u", 1), "1: 1"); TEST_S(su_slprintf(l, "1.0: %g", 1.0), "1.0: 1"); TEST_1(su_strlst_append(l, "")); TEST_S(su_strlst_join(l, home, "\n"), "a\n" "b\n" "1: 1\n" "1.0: 1\n"); TEST_VOID(su_strlst_destroy(l)); TEST_1(l2 = su_strlst_create_with_dup(NULL, s0 = "0", "1", "2", "3", "4", "5", "6", "7", NULL)); TEST_1(su_strlst_item(l2, 0) != s0); TEST_S(su_strlst_item(l2, 0), "0"); TEST_S(su_strlst_item(l2, 1), "1"); TEST_S(su_strlst_item(l2, 2), "2"); TEST_S(su_strlst_item(l2, 3), "3"); TEST_S(su_strlst_item(l2, 4), "4"); TEST_S(su_strlst_item(l2, 5), "5"); TEST_S(su_strlst_item(l2, 6), "6"); TEST_S(su_strlst_item(l2, 7), "7"); TEST_1(su_strlst_item(l2, 8) == NULL); TEST_S(su_strlst_join(l2, home, ""), "01234567"); TEST_VOID(su_strlst_destroy(l2)); } su_home_check(home); su_home_deinit(home); END(); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ char read_buffer[BUFSIZ]; /* buffer used to read data from file*/ /* Parse standard options given to run the test. */ msg = parse_opts(ac, av, (option_t *) NULL, NULL); if (msg != (char *) NULL) { tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); /*NOTREACHED*/ } /* Perform global setup for test */ setup(); /* Check looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* Reset Tst_count in case we are looping. */ Tst_count=0; /* * Call sync(2) to commit buffer data to disk. */ TEST_VOID(sync()); if (TEST_RETURN == -1) { tst_resm(TFAIL, "%s, Failed, errno=%d : %s", TCID, TEST_ERRNO, strerror(TEST_ERRNO)); } else { /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { /* Set the file ptr to b'nning of file */ if (lseek(fildes, 0, SEEK_SET) < 0) { tst_brkm(TFAIL, cleanup, "lseek() " "failed on %s, error=%d", TEMP_FILE, errno); /*NOTREACHED*/ } /* Read the contents of file */ if (read(fildes, read_buffer, \ sizeof(read_buffer)) > 0) { if (strcmp(read_buffer, write_buffer)) { tst_resm(TFAIL, "Data read " "from %s doesn't match " "with witten data", TEMP_FILE); } else { tst_resm(TPASS, "Functionality " "of sync() successful"); } } else { tst_brkm(TFAIL, cleanup, "read() Fails on %s, error=%d", TEMP_FILE, errno); /*NOTREACHED*/ } } else { tst_resm(TPASS, "call succeeded"); } } Tst_count++; /* incr. TEST_LOOP counter */ } /* End for TEST_LOOPING */ /* Call cleanup() to undo setup done for the test. */ cleanup(); /*NOTREACHED*/ return(0); } /* End main */
static bool test_key2(Omega::Registry::IKey* pKey, const Omega::string_t& strKey) { if (!test_values(pKey)) return false; Omega::string_t strTestKey("TestKey_{0}"); strTestKey %= GetCurrentProcessId(); while (pKey->IsKey(strTestKey)) { strTestKey = "_" + strTestKey; } Omega::Registry::IKey* pSubKey; try { pSubKey = pKey->OpenKey(strTestKey,Omega::Registry::IKey::OpenCreate); } catch (Omega::IAccessDeniedException* pE) { // We have insufficient permissions to write here pE->Release(); return true; } TEST(pSubKey); TEST(pKey->IsKey(strTestKey)); if (!test_values(pSubKey)) return false; pSubKey->Release(); pSubKey = pKey->OpenKey(strTestKey,Omega::Registry::IKey::OpenExisting); TEST(pSubKey); pSubKey->Release(); Omega::Registry::IKey::string_set_t keys = pKey->EnumSubKeys(); TEST(!keys.empty()); TEST(keys.find(strTestKey) != keys.end()); try { pKey->OpenKey(strTestKey,Omega::Registry::IKey::CreateNew); TEST_FAIL("No exception thrown!"); } catch (Omega::IAlreadyExistsException* pE) { pE->Release(); } TEST_VOID(pKey->DeleteSubKey(strTestKey)); TEST(!pKey->IsKey(strTestKey)); try { pKey->OpenKey(strTestKey,Omega::Registry::IKey::OpenExisting); TEST_FAIL("No exception thrown!"); } catch (Omega::INotFoundException* pE) { pE->Release(); } keys = pKey->EnumSubKeys(); TEST(keys.find(strTestKey) == keys.end()); pKey->OpenKey(strTestKey + "/Subkey",Omega::Registry::IKey::CreateNew); TEST_VOID(pKey->DeleteSubKey(strTestKey)); TEST(!pKey->IsKey(strTestKey + "/Subkey")); TEST(!pKey->IsKey(strTestKey)); return true; }
static bool test_values(Omega::Registry::IKey* pKey) { // Generate a unique value name Omega::string_t strTestValue("TestValue_{0}"); strTestValue %= GetCurrentProcessId(); while (pKey->IsValue(strTestValue)) { strTestValue = "_" + strTestValue; } try { pKey->SetValue(strTestValue,"Yes"); } catch (Omega::IAccessDeniedException* pE) { // We have insufficient permissions to write here pE->Release(); return true; } TEST_VOID(pKey->SetValue(strTestValue,"Yes")); TEST(pKey->IsValue(strTestValue)); TEST(pKey->GetValue(strTestValue) == "Yes"); TEST_VOID(pKey->SetValue(strTestValue,"No")); TEST(pKey->GetValue(strTestValue) == "No"); TEST_VOID(pKey->DeleteValue(strTestValue)); TEST(!pKey->IsValue(strTestValue)); TEST_VOID(pKey->SetValue(strTestValue,"Yes")); TEST_VOID(pKey->DeleteValue(strTestValue)); TEST(!pKey->IsValue(strTestValue)); try { pKey->GetValue(strTestValue); TEST_FAIL("No exception thrown!"); } catch (Omega::INotFoundException* pE) { pE->Release(); } TEST_VOID(pKey->DeleteValue(strTestValue)); try { pKey->SetValue("","Invalid name"); TEST_FAIL("No exception thrown!"); } catch (Omega::IAccessDeniedException* pE) { pE->Release(); } TEST_VOID(pKey->SetValue(strTestValue,"Yes")); Omega::Registry::IKey::string_set_t values = pKey->EnumValues(); TEST(!values.empty()); TEST(values.find(strTestValue) != values.end()); TEST_VOID(pKey->DeleteValue(strTestValue)); values = pKey->EnumValues(); TEST(values.find(strTestValue) == values.end()); return true; }