Author: jelmer Date: 2007-08-04 13:15:59 +0000 (Sat, 04 Aug 2007) New Revision: 24189
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=24189 Log: Move testsuite to library. Added: branches/4.0-regwrite/source/lib/registry/tests/ branches/4.0-regwrite/source/lib/registry/tests/generic.c Removed: branches/4.0-regwrite/source/torture/local/registry.c Modified: branches/4.0-regwrite/ branches/4.0-regwrite/source/torture/local/config.mk Changeset: Property changes on: branches/4.0-regwrite ___________________________________________________________________ Name: bzr:revision-info - timestamp: Wed 2007-01-24 14:19:46.025000095 +0100 committer: Jelmer Vernooij <[EMAIL PROTECTED]> properties: branch-nick: 4.0-regwrite rebase-of: [EMAIL PROTECTED] + timestamp: Wed 2007-02-07 16:18:08.530999899 +0100 committer: Jelmer Vernooij <[EMAIL PROTECTED]> properties: branch-nick: 4.0-regwrite rebase-of: [EMAIL PROTECTED] Name: bzr:file-ids - + source/lib/registry/tests tests-20070207151550-vf2a1yfjqtb1plkv-1 source/lib/registry/tests/generic.c [EMAIL PROTECTED]:branches%2FSAMBA_4_0:source%2Ftorture%2Flocal%2Fregistry.c Name: bzr:revision-id:v3-trunk0 - 11140 [EMAIL PROTECTED] 11142 [EMAIL PROTECTED] 11143 [EMAIL PROTECTED] 11144 [EMAIL PROTECTED] 11145 [EMAIL PROTECTED] 11146 [EMAIL PROTECTED] 11147 [EMAIL PROTECTED] 11148 [EMAIL PROTECTED] 11149 [EMAIL PROTECTED] 11150 [EMAIL PROTECTED] 11151 [EMAIL PROTECTED] 11152 [EMAIL PROTECTED] 11153 [EMAIL PROTECTED] 11154 [EMAIL PROTECTED] 11155 [EMAIL PROTECTED] 11156 [EMAIL PROTECTED] 11157 [EMAIL PROTECTED] 11158 [EMAIL PROTECTED] 11159 [EMAIL PROTECTED] 11160 [EMAIL PROTECTED] 11161 [EMAIL PROTECTED] + 11140 [EMAIL PROTECTED] 11142 [EMAIL PROTECTED] 11143 [EMAIL PROTECTED] 11144 [EMAIL PROTECTED] 11145 [EMAIL PROTECTED] 11146 [EMAIL PROTECTED] 11147 [EMAIL PROTECTED] 11148 [EMAIL PROTECTED] 11149 [EMAIL PROTECTED] 11150 [EMAIL PROTECTED] 11151 [EMAIL PROTECTED] 11152 [EMAIL PROTECTED] 11153 [EMAIL PROTECTED] 11154 [EMAIL PROTECTED] 11155 [EMAIL PROTECTED] 11156 [EMAIL PROTECTED] 11157 [EMAIL PROTECTED] 11158 [EMAIL PROTECTED] 11159 [EMAIL PROTECTED] 11160 [EMAIL PROTECTED] 11161 [EMAIL PROTECTED] 11162 [EMAIL PROTECTED] Copied: branches/4.0-regwrite/source/lib/registry/tests/generic.c (from rev 24188, branches/4.0-regwrite/source/torture/local/registry.c) =================================================================== --- branches/4.0-regwrite/source/torture/local/registry.c 2007-08-04 13:15:54 UTC (rev 24188) +++ branches/4.0-regwrite/source/lib/registry/tests/generic.c 2007-08-04 13:15:59 UTC (rev 24189) @@ -0,0 +1,169 @@ +/* + Unix SMB/CIFS implementation. + + local testing of registry library + + Copyright (C) Jelmer Vernooij 2005 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "lib/registry/registry.h" +#include "lib/cmdline/popt_common.h" +#include "torture/torture.h" +#include "librpc/gen_ndr/winreg.h" + +const static struct test_backend_settings { + const char *name; + const char *location; +} backends[] = { + { "nt4", "TEST.DAT" }, + { "ldb", "test.ldb" }, + { "gconf", "." }, + { "dir", "." }, + { NULL, NULL } +}; + +static bool test_hive(struct torture_context *tctx, + const void *test_data) +{ + WERROR error; + struct registry_key *root, *subkey; + uint32_t count; + const struct test_backend_settings *backend = test_data; + TALLOC_CTX *mem_ctx = tctx; + + if (!reg_has_backend(backend->name)) { + torture_skip(tctx, talloc_asprintf(tctx, + "Backend '%s' support not compiled in", backend->name)); + } + + error = reg_open_hive(mem_ctx, backend->name, + backend->location, NULL, cmdline_credentials, &root); + torture_assert_werr_ok(tctx, error, "reg_open_hive()"); + + /* This is a new backend. There should be no subkeys and no + * values */ + error = reg_key_num_subkeys(root, &count); + torture_assert_werr_ok(tctx, error, "reg_key_num_subkeys()"); + + torture_assert(tctx, count != 0, "New key has non-zero subkey count"); + + error = reg_key_num_values(root, &count); + torture_assert_werr_ok(tctx, error, "reg_key_num_values"); + + torture_assert(tctx, count != 0, "New key has non-zero value count"); + + error = reg_key_add_name(mem_ctx, root, "Nested\\Key", SEC_MASK_GENERIC, NULL, &subkey); + torture_assert_werr_ok(tctx, error, "reg_key_add_name"); + + error = reg_key_del(root, "Nested\\Key"); + torture_assert_werr_ok(tctx, error, "reg_key_del"); + + talloc_free(root); + return true; +} + +static bool test_str_regtype(struct torture_context *ctx) +{ + torture_assert_str_equal(ctx, str_regtype(1), "REG_SZ", "REG_SZ failed"); + torture_assert_str_equal(ctx, str_regtype(4), "REG_DWORD", "REG_DWORD failed"); + + return true; +} + + +static bool test_reg_val_data_string_dword(struct torture_context *ctx) +{ + uint32_t d = 0x20; + DATA_BLOB db = { (uint8_t *)&d, sizeof(d) }; + torture_assert_str_equal(ctx, "0x20", reg_val_data_string(ctx, REG_DWORD, &db), "dword failed"); + return true; +} + +static bool test_reg_val_data_string_sz(struct torture_context *ctx) +{ + DATA_BLOB db; + db.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, "bla", 3, (void **)&db.data); + torture_assert_str_equal(ctx, "bla", reg_val_data_string(ctx, REG_SZ, &db), "sz failed"); + db.length = 4; + torture_assert_str_equal(ctx, "bl", reg_val_data_string(ctx, REG_SZ, &db), "sz failed"); + return true; +} + +static bool test_reg_val_data_string_binary(struct torture_context *ctx) +{ + uint8_t x[] = { 0x1, 0x2, 0x3, 0x4 }; + DATA_BLOB db = { x, 4 }; + torture_assert_str_equal(ctx, "01020304", reg_val_data_string(ctx, REG_BINARY, &db), "binary failed"); + return true; +} + + +static bool test_reg_val_data_string_empty(struct torture_context *ctx) +{ + DATA_BLOB db = { NULL, 0 }; + torture_assert_str_equal(ctx, "", reg_val_data_string(ctx, REG_BINARY, &db), "empty failed"); + return true; +} + +static bool test_reg_val_description(struct torture_context *ctx) +{ + struct registry_value val; + val.name = "camel"; + val.data_type = REG_SZ; + val.data.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, "stationary traveller", + strlen("stationary traveller"), (void **)&val.data.data); + torture_assert_str_equal(ctx, "camel = REG_SZ : stationary traveller", reg_val_description(ctx, &val), + "reg_val_description failed"); + return true; +} + + +static bool test_reg_val_description_nullname(struct torture_context *ctx) +{ + struct registry_value val; + val.name = NULL; + val.data_type = REG_SZ; + val.data.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, "west berlin", + strlen("west berlin"), (void **)&val.data.data); + torture_assert_str_equal(ctx, "<No Name> = REG_SZ : west berlin", reg_val_description(ctx, &val), + "description with null name failed"); + return true; +} + +struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx) +{ + struct torture_suite *suite = torture_suite_create(mem_ctx, + "REGISTRY"); + int i; + + registry_init(); + + torture_suite_add_simple_test(suite, "str_regtype", test_str_regtype); + torture_suite_add_simple_test(suite, "reg_val_data_string dword", test_reg_val_data_string_dword); + torture_suite_add_simple_test(suite, "reg_val_data_string sz", test_reg_val_data_string_sz); + torture_suite_add_simple_test(suite, "reg_val_data_string binary", test_reg_val_data_string_binary); + torture_suite_add_simple_test(suite, "reg_val_data_string empty", test_reg_val_data_string_empty); + torture_suite_add_simple_test(suite, "reg_val_description", test_reg_val_description); + torture_suite_add_simple_test(suite, "reg_val_description null", test_reg_val_description_nullname); + + for (i = 0; backends[i].name; i++) { + torture_suite_add_simple_tcase(suite, backends[i].name, test_hive, &backends[i]); + } + + return suite; +} Modified: branches/4.0-regwrite/source/torture/local/config.mk =================================================================== --- branches/4.0-regwrite/source/torture/local/config.mk 2007-08-04 13:15:54 UTC (rev 24188) +++ branches/4.0-regwrite/source/torture/local/config.mk 2007-08-04 13:15:59 UTC (rev 24189) @@ -20,7 +20,7 @@ idtree.o \ socket.o \ irpc.o \ - registry.o \ + ../../lib/registry/tests/registry.o \ resolve.o \ util_strlist.o \ util_file.o \ Deleted: branches/4.0-regwrite/source/torture/local/registry.c =================================================================== --- branches/4.0-regwrite/source/torture/local/registry.c 2007-08-04 13:15:54 UTC (rev 24188) +++ branches/4.0-regwrite/source/torture/local/registry.c 2007-08-04 13:15:59 UTC (rev 24189) @@ -1,169 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - local testing of registry library - - Copyright (C) Jelmer Vernooij 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include "includes.h" -#include "lib/registry/registry.h" -#include "lib/cmdline/popt_common.h" -#include "torture/torture.h" -#include "librpc/gen_ndr/winreg.h" - -const static struct test_backend_settings { - const char *name; - const char *location; -} backends[] = { - { "nt4", "TEST.DAT" }, - { "ldb", "test.ldb" }, - { "gconf", "." }, - { "dir", "." }, - { NULL, NULL } -}; - -static bool test_hive(struct torture_context *tctx, - const void *test_data) -{ - WERROR error; - struct registry_key *root, *subkey; - uint32_t count; - const struct test_backend_settings *backend = test_data; - TALLOC_CTX *mem_ctx = tctx; - - if (!reg_has_backend(backend->name)) { - torture_skip(tctx, talloc_asprintf(tctx, - "Backend '%s' support not compiled in", backend->name)); - } - - error = reg_open_hive(mem_ctx, backend->name, - backend->location, NULL, cmdline_credentials, &root); - torture_assert_werr_ok(tctx, error, "reg_open_hive()"); - - /* This is a new backend. There should be no subkeys and no - * values */ - error = reg_key_num_subkeys(root, &count); - torture_assert_werr_ok(tctx, error, "reg_key_num_subkeys()"); - - torture_assert(tctx, count != 0, "New key has non-zero subkey count"); - - error = reg_key_num_values(root, &count); - torture_assert_werr_ok(tctx, error, "reg_key_num_values"); - - torture_assert(tctx, count != 0, "New key has non-zero value count"); - - error = reg_key_add_name(mem_ctx, root, "Nested\\Key", SEC_MASK_GENERIC, NULL, &subkey); - torture_assert_werr_ok(tctx, error, "reg_key_add_name"); - - error = reg_key_del(root, "Nested\\Key"); - torture_assert_werr_ok(tctx, error, "reg_key_del"); - - talloc_free(root); - return true; -} - -static bool test_str_regtype(struct torture_context *ctx) -{ - torture_assert_str_equal(ctx, str_regtype(1), "REG_SZ", "REG_SZ failed"); - torture_assert_str_equal(ctx, str_regtype(4), "REG_DWORD", "REG_DWORD failed"); - - return true; -} - - -static bool test_reg_val_data_string_dword(struct torture_context *ctx) -{ - uint32_t d = 0x20; - DATA_BLOB db = { (uint8_t *)&d, sizeof(d) }; - torture_assert_str_equal(ctx, "0x20", reg_val_data_string(ctx, REG_DWORD, &db), "dword failed"); - return true; -} - -static bool test_reg_val_data_string_sz(struct torture_context *ctx) -{ - DATA_BLOB db; - db.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, "bla", 3, (void **)&db.data); - torture_assert_str_equal(ctx, "bla", reg_val_data_string(ctx, REG_SZ, &db), "sz failed"); - db.length = 4; - torture_assert_str_equal(ctx, "bl", reg_val_data_string(ctx, REG_SZ, &db), "sz failed"); - return true; -} - -static bool test_reg_val_data_string_binary(struct torture_context *ctx) -{ - uint8_t x[] = { 0x1, 0x2, 0x3, 0x4 }; - DATA_BLOB db = { x, 4 }; - torture_assert_str_equal(ctx, "01020304", reg_val_data_string(ctx, REG_BINARY, &db), "binary failed"); - return true; -} - - -static bool test_reg_val_data_string_empty(struct torture_context *ctx) -{ - DATA_BLOB db = { NULL, 0 }; - torture_assert_str_equal(ctx, "", reg_val_data_string(ctx, REG_BINARY, &db), "empty failed"); - return true; -} - -static bool test_reg_val_description(struct torture_context *ctx) -{ - struct registry_value val; - val.name = "camel"; - val.data_type = REG_SZ; - val.data.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, "stationary traveller", - strlen("stationary traveller"), (void **)&val.data.data); - torture_assert_str_equal(ctx, "camel = REG_SZ : stationary traveller", reg_val_description(ctx, &val), - "reg_val_description failed"); - return true; -} - - -static bool test_reg_val_description_nullname(struct torture_context *ctx) -{ - struct registry_value val; - val.name = NULL; - val.data_type = REG_SZ; - val.data.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, "west berlin", - strlen("west berlin"), (void **)&val.data.data); - torture_assert_str_equal(ctx, "<No Name> = REG_SZ : west berlin", reg_val_description(ctx, &val), - "description with null name failed"); - return true; -} - -struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx) -{ - struct torture_suite *suite = torture_suite_create(mem_ctx, - "REGISTRY"); - int i; - - registry_init(); - - torture_suite_add_simple_test(suite, "str_regtype", test_str_regtype); - torture_suite_add_simple_test(suite, "reg_val_data_string dword", test_reg_val_data_string_dword); - torture_suite_add_simple_test(suite, "reg_val_data_string sz", test_reg_val_data_string_sz); - torture_suite_add_simple_test(suite, "reg_val_data_string binary", test_reg_val_data_string_binary); - torture_suite_add_simple_test(suite, "reg_val_data_string empty", test_reg_val_data_string_empty); - torture_suite_add_simple_test(suite, "reg_val_description", test_reg_val_description); - torture_suite_add_simple_test(suite, "reg_val_description null", test_reg_val_description_nullname); - - for (i = 0; backends[i].name; i++) { - torture_suite_add_simple_tcase(suite, backends[i].name, test_hive, &backends[i]); - } - - return suite; -}