r26589: torture: Add non-const version of torture_tcase_add_simple_test
authorKai Blin <kai@samba.org>
Mon, 24 Dec 2007 19:06:57 +0000 (13:06 -0600)
committerStefan Metzmacher <metze@samba.org>
Wed, 26 Dec 2007 17:57:05 +0000 (11:57 -0600)
(This used to be commit 1ae9cde5105cc4349a44e6098e9393e06acaf95d)

source4/lib/registry/tests/hive.c
source4/lib/registry/tests/registry.c
source4/torture/ui.c

index dc59d0f9cafb6cd164390dc2932a676f1988ad19..bc3c82552efc9529f8473b4bcdc73f965a32ce82 100644 (file)
@@ -61,11 +61,10 @@ static bool test_keyinfo_root(struct torture_context *tctx,
        return true;
 }
 
-static bool test_keyinfo_nums(struct torture_context *tctx,
-                             const void *test_data)
+static bool test_keyinfo_nums(struct torture_context *tctx, void *test_data)
 {
        uint32_t num_subkeys, num_values;
-       const struct hive_key *root = (const struct hive_key *)test_data;
+       struct hive_key *root = (struct hive_key *)test_data;
        WERROR error;
        struct hive_key *subkey;
        uint32_t data = 42;
@@ -111,10 +110,9 @@ static bool test_add_subkey(struct torture_context *tctx,
        return true;
 }
 
-static bool test_flush_key(struct torture_context *tctx,
-                          const void *test_data)
+static bool test_flush_key(struct torture_context *tctx, void *test_data)
 {
-       const struct hive_key *root = (const struct hive_key *)test_data;
+       struct hive_key *root = (struct hive_key *)test_data;
 
        torture_assert_werr_ok(tctx, hive_key_flush(root), "flush key");
 
@@ -268,11 +266,11 @@ static void tcase_add_tests(struct torture_tcase *tcase)
                                                test_del_nonexistant_key);
        torture_tcase_add_simple_test_const(tcase, "add_subkey",
                                                test_add_subkey);
-       torture_tcase_add_simple_test_const(tcase, "flush_key",
+       torture_tcase_add_simple_test(tcase, "flush_key",
                                                test_flush_key);
        torture_tcase_add_simple_test_const(tcase, "get_info",
                                                test_keyinfo_root);
-       torture_tcase_add_simple_test_const(tcase, "get_info_nums",
+       torture_tcase_add_simple_test(tcase, "get_info_nums",
                                                test_keyinfo_nums);
        torture_tcase_add_simple_test_const(tcase, "set_value",
                                                test_set_value);
index 789790986580d032c18f2f9ebddc2c8ff42a4135..2133e72310b81a485054386ceec25caea410c096 100644 (file)
 /**
  * Test obtaining a predefined key.
  */
-static bool test_get_predefined(struct torture_context *tctx,
-                               const void *_data)
+static bool test_get_predefined(struct torture_context *tctx, void *_data)
 {
-       const struct registry_context *rctx =
-               (const struct registry_context *)_data;
+       struct registry_context *rctx = (struct registry_context *)_data;
        struct registry_key *root;
        WERROR error;
 
@@ -48,9 +46,9 @@ static bool test_get_predefined(struct torture_context *tctx,
  * Test obtaining a predefined key.
  */
 static bool test_get_predefined_unknown(struct torture_context *tctx,
-                                       const void *_data)
+               void *_data)
 {
-       const struct registry_context *rctx = _data;
+       struct registry_context *rctx = _data;
        struct registry_key *root;
        WERROR error;
 
@@ -60,11 +58,9 @@ static bool test_get_predefined_unknown(struct torture_context *tctx,
        return true;
 }
 
-static bool test_predef_key_by_name(struct torture_context *tctx,
-                                   const void *_data)
+static bool test_predef_key_by_name(struct torture_context *tctx, void *_data)
 {
-       const struct registry_context *rctx =
-               (const struct registry_context *)_data;
+       struct registry_context *rctx = (struct registry_context *)_data;
        struct registry_key *root;
        WERROR error;
 
@@ -82,10 +78,9 @@ static bool test_predef_key_by_name(struct torture_context *tctx,
 }
 
 static bool test_predef_key_by_name_invalid(struct torture_context *tctx,
-                                           const void *_data)
+               void *_data)
 {
-       const struct registry_context *rctx =
-               (const struct registry_context *)_data;
+       struct registry_context *rctx = (struct registry_context *)_data;
        struct registry_key *root;
        WERROR error;
 
@@ -98,11 +93,9 @@ static bool test_predef_key_by_name_invalid(struct torture_context *tctx,
 /**
  * Test creating a new subkey
  */
-static bool test_create_subkey(struct torture_context *tctx,
-                              const void *_data)
+static bool test_create_subkey(struct torture_context *tctx, void *_data)
 {
-       const struct registry_context *rctx =
-               (const struct registry_context *)_data;
+       struct registry_context *rctx = (struct registry_context *)_data;
        struct registry_key *root, *newkey;
        WERROR error;
 
@@ -121,11 +114,9 @@ static bool test_create_subkey(struct torture_context *tctx,
 /**
  * Test creating a new nested subkey
  */
-static bool test_create_nested_subkey(struct torture_context *tctx,
-                                     const void *_data)
+static bool test_create_nested_subkey(struct torture_context *tctx, void *_data)
 {
-       const struct registry_context *rctx =
-               (const struct registry_context *)_data;
+       struct registry_context *rctx = (struct registry_context *)_data;
        struct registry_key *root, *newkey1, *newkey2;
        WERROR error;
 
@@ -149,11 +140,9 @@ static bool test_create_nested_subkey(struct torture_context *tctx,
 /**
  * Test creating a new subkey
  */
-static bool test_key_add_abs_top(struct torture_context *tctx,
-                                const void *_data)
+static bool test_key_add_abs_top(struct torture_context *tctx, void *_data)
 {
-       const struct registry_context *rctx =
-               (const struct registry_context *)_data;
+       struct registry_context *rctx = (struct registry_context *)_data;
        struct registry_key *root;
        WERROR error;
 
@@ -168,12 +157,10 @@ static bool test_key_add_abs_top(struct torture_context *tctx,
 /**
  * Test creating a new subkey
  */
-static bool test_key_add_abs(struct torture_context *tctx,
-                            const void *_data)
+static bool test_key_add_abs(struct torture_context *tctx, void *_data)
 {
        WERROR error;
-       const struct registry_context *rctx =
-               (const struct registry_context *)_data;
+       struct registry_context *rctx = (struct registry_context *)_data;
        struct registry_key *root, *result1, *result2;
 
        error = reg_key_add_abs(tctx, rctx,  "HKEY_CLASSES_ROOT\\bloe", 0, NULL,
@@ -198,10 +185,9 @@ static bool test_key_add_abs(struct torture_context *tctx,
 }
 
 
-static bool test_del_key(struct torture_context *tctx, const void *_data)
+static bool test_del_key(struct torture_context *tctx, void *_data)
 {
-       const struct registry_context *rctx =
-               (const struct registry_context *)_data;
+       struct registry_context *rctx = (struct registry_context *)_data;
        struct registry_key *root, *newkey;
        WERROR error;
 
@@ -229,7 +215,7 @@ static bool test_del_key(struct torture_context *tctx, const void *_data)
  * creating a single key for testing purposes.
  */
 static bool create_test_key(struct torture_context *tctx,
-                           const struct registry_context *rctx,
+                           struct registry_context *rctx,
                            const char *name,
                            struct registry_key **root,
                            struct registry_key **subkey)
@@ -247,10 +233,9 @@ static bool create_test_key(struct torture_context *tctx,
 }
 
 
-static bool test_flush_key(struct torture_context *tctx, const void *_data)
+static bool test_flush_key(struct torture_context *tctx, void *_data)
 {
-       const struct registry_context *rctx =
-               (const struct registry_context *)_data;
+       struct registry_context *rctx = (struct registry_context *)_data;
        struct registry_key *root, *subkey;
        WERROR error;
 
@@ -266,10 +251,9 @@ static bool test_flush_key(struct torture_context *tctx, const void *_data)
        return true;
 }
 
-static bool test_query_key(struct torture_context *tctx, const void *_data)
+static bool test_query_key(struct torture_context *tctx, void *_data)
 {
-       const struct registry_context *rctx =
-               (const struct registry_context *)_data;
+       struct registry_context *rctx = (struct registry_context *)_data;
        struct registry_key *root, *subkey;
        WERROR error;
        NTTIME last_changed_time;
@@ -291,10 +275,9 @@ static bool test_query_key(struct torture_context *tctx, const void *_data)
        return true;
 }
 
-static bool test_query_key_nums(struct torture_context *tctx, const void *_data)
+static bool test_query_key_nums(struct torture_context *tctx, void *_data)
 {
-       const struct registry_context *rctx =
-               (const struct registry_context *)_data;
+       struct registry_context *rctx = (struct registry_context *)_data;
        struct registry_key *root, *subkey1, *subkey2;
        WERROR error;
        uint32_t num_subkeys, num_values;
@@ -326,10 +309,9 @@ static bool test_query_key_nums(struct torture_context *tctx, const void *_data)
  * the returned parameters for get_subkey_by_index are optional and
  * that enumerating the parents of a non-top-level node works.
  */
-static bool test_list_subkeys(struct torture_context *tctx, const void *_data)
+static bool test_list_subkeys(struct torture_context *tctx, void *_data)
 {
-       const struct registry_context *rctx =
-               (const struct registry_context *)_data;
+       struct registry_context *rctx = (struct registry_context *)_data;
        struct registry_key *subkey = NULL, *root;
        WERROR error;
        NTTIME last_mod_time;
@@ -366,10 +348,9 @@ static bool test_list_subkeys(struct torture_context *tctx, const void *_data)
 /**
  * Test setting a value
  */
-static bool test_set_value(struct torture_context *tctx, const void *_data)
+static bool test_set_value(struct torture_context *tctx, void *_data)
 {
-       const struct registry_context *rctx =
-               (const struct registry_context *)_data;
+       struct registry_context *rctx = (struct registry_context *)_data;
        struct registry_key *subkey = NULL, *root;
        WERROR error;
        uint32_t data = 42;
@@ -387,10 +368,9 @@ static bool test_set_value(struct torture_context *tctx, const void *_data)
 /**
  * Test getting/setting security descriptors
  */
-static bool test_security(struct torture_context *tctx, const void *_data)
+static bool test_security(struct torture_context *tctx, void *_data)
 {
-       const struct registry_context *rctx =
-               (const struct registry_context *)_data;
+       struct registry_context *rctx = (struct registry_context *)_data;
        struct registry_key *subkey = NULL, *root;
        WERROR error;
        struct security_descriptor *osd, *nsd;
@@ -422,10 +402,9 @@ static bool test_security(struct torture_context *tctx, const void *_data)
 /**
  * Test getting a value
  */
-static bool test_get_value(struct torture_context *tctx, const void *_data)
+static bool test_get_value(struct torture_context *tctx, void *_data)
 {
-       const struct registry_context *rctx =
-               (const struct registry_context *)_data;
+       struct registry_context *rctx = (struct registry_context *)_data;
        struct registry_key *subkey = NULL, *root;
        WERROR error;
        DATA_BLOB data;
@@ -459,10 +438,9 @@ static bool test_get_value(struct torture_context *tctx, const void *_data)
 /**
  * Test unsetting a value
  */
-static bool test_del_value(struct torture_context *tctx, const void *_data)
+static bool test_del_value(struct torture_context *tctx, void *_data)
 {
-       const struct registry_context *rctx =
-               (const struct registry_context *)_data;
+       struct registry_context *rctx =(struct registry_context *)_data;
        struct registry_key *subkey = NULL, *root;
        WERROR error;
        DATA_BLOB data;
@@ -495,10 +473,9 @@ static bool test_del_value(struct torture_context *tctx, const void *_data)
 /**
  * Test listing values
  */
-static bool test_list_values(struct torture_context *tctx, const void *_data)
+static bool test_list_values(struct torture_context *tctx, void *_data)
 {
-       const struct registry_context *rctx =
-               (const struct registry_context *)_data;
+       struct registry_context *rctx = (struct registry_context *)_data;
        struct registry_key *subkey = NULL, *root;
        WERROR error;
        DATA_BLOB data;
@@ -560,43 +537,42 @@ static bool setup_local_registry(struct torture_context *tctx, void **data)
 
 static void tcase_add_tests(struct torture_tcase *tcase)
 {
-       torture_tcase_add_simple_test_const(tcase, "list_subkeys",
-                                               test_list_subkeys);
-       torture_tcase_add_simple_test_const(tcase, "get_predefined_key",
-                                               test_get_predefined);
-       torture_tcase_add_simple_test_const(tcase, "get_predefined_key",
-                                               test_get_predefined_unknown);
-       torture_tcase_add_simple_test_const(tcase, "create_key",
-                                               test_create_subkey);
-       torture_tcase_add_simple_test_const(tcase, "create_key",
-                                               test_create_nested_subkey);
-       torture_tcase_add_simple_test_const(tcase, "key_add_abs",
-                                               test_key_add_abs);
-       torture_tcase_add_simple_test_const(tcase, "key_add_abs_top",
-                                               test_key_add_abs_top);
-       torture_tcase_add_simple_test_const(tcase, "set_value",
-                                               test_set_value);
-       torture_tcase_add_simple_test_const(tcase, "get_value",
-                                               test_get_value);
-       torture_tcase_add_simple_test_const(tcase, "list_values",
-                                               test_list_values);
-       torture_tcase_add_simple_test_const(tcase, "del_key",
-                                               test_del_key);
-       torture_tcase_add_simple_test_const(tcase, "del_value",
-                                               test_del_value);
-       torture_tcase_add_simple_test_const(tcase, "flush_key",
-                                               test_flush_key);
-       torture_tcase_add_simple_test_const(tcase, "query_key",
-                                               test_query_key);
-       torture_tcase_add_simple_test_const(tcase, "query_key_nums",
-                                               test_query_key_nums);
-       torture_tcase_add_simple_test_const(tcase, "test_predef_key_by_name",
-                                               test_predef_key_by_name);
-       torture_tcase_add_simple_test_const(tcase, "security",
-                                               test_security);
-       torture_tcase_add_simple_test_const(tcase,
-                       "test_predef_key_by_name_invalid",
-                       test_predef_key_by_name_invalid);
+       torture_tcase_add_simple_test(tcase, "list_subkeys",
+                                       test_list_subkeys);
+       torture_tcase_add_simple_test(tcase, "get_predefined_key",
+                                       test_get_predefined);
+       torture_tcase_add_simple_test(tcase, "get_predefined_key",
+                                       test_get_predefined_unknown);
+       torture_tcase_add_simple_test(tcase, "create_key",
+                                       test_create_subkey);
+       torture_tcase_add_simple_test(tcase, "create_key",
+                                       test_create_nested_subkey);
+       torture_tcase_add_simple_test(tcase, "key_add_abs",
+                                       test_key_add_abs);
+       torture_tcase_add_simple_test(tcase, "key_add_abs_top",
+                                       test_key_add_abs_top);
+       torture_tcase_add_simple_test(tcase, "set_value",
+                                       test_set_value);
+       torture_tcase_add_simple_test(tcase, "get_value",
+                                       test_get_value);
+       torture_tcase_add_simple_test(tcase, "list_values",
+                                       test_list_values);
+       torture_tcase_add_simple_test(tcase, "del_key",
+                                       test_del_key);
+       torture_tcase_add_simple_test(tcase, "del_value",
+                                       test_del_value);
+       torture_tcase_add_simple_test(tcase, "flush_key",
+                                       test_flush_key);
+       torture_tcase_add_simple_test(tcase, "query_key",
+                                       test_query_key);
+       torture_tcase_add_simple_test(tcase, "query_key_nums",
+                                       test_query_key_nums);
+       torture_tcase_add_simple_test(tcase, "test_predef_key_by_name",
+                                       test_predef_key_by_name);
+       torture_tcase_add_simple_test(tcase, "security",
+                                       test_security);
+       torture_tcase_add_simple_test(tcase,"test_predef_key_by_name_invalid",
+                                       test_predef_key_by_name_invalid);
 }
 
 struct torture_suite *torture_registry_registry(TALLOC_CTX *mem_ctx)
index ce72dd5b088d8ce0d3498f09feda5c3c914ec77a..66722a4cae0f23edf63f03f3f7947cd796fec752 100644 (file)
@@ -531,4 +531,36 @@ struct torture_test *torture_tcase_add_simple_test_const(
        return test;
 }
 
+static bool wrap_test_with_simple_test(struct torture_context *torture_ctx,
+                                      struct torture_tcase *tcase,
+                                      struct torture_test *test)
+{
+       bool (*fn) (struct torture_context *, void *tcase_data);
+
+       fn = test->fn;
+
+       return fn(torture_ctx, tcase->data);
+}
+
+struct torture_test *torture_tcase_add_simple_test(struct torture_tcase *tcase,
+               const char *name,
+               bool (*run) (struct torture_context *test, void *tcase_data))
+{
+       struct torture_test *test;
+
+       test = talloc(tcase, struct torture_test);
+
+       test->name = talloc_strdup(test, name);
+       test->description = NULL;
+       test->run = wrap_test_with_simple_test;
+       test->fn = run;
+       test->data = NULL;
+       test->dangerous = false;
+
+       DLIST_ADD_END(tcase->tests, test, struct torture_test *);
+
+       return test;
+}
+
+