r15819: Use updated API in smbtorture, use UI tools in registry tests.
[Samba.git] / source / torture / local / registry.c
blob49f019ba7a437eacc91866c9a6f87dd1556a230d
1 /*
2 Unix SMB/CIFS implementation.
4 local testing of registry library
6 Copyright (C) Jelmer Vernooij 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "includes.h"
24 #include "lib/registry/registry.h"
25 #include "lib/cmdline/popt_common.h"
26 #include "torture/torture.h"
27 #include "torture/ui.h"
29 static bool test_hive(struct torture_context *parent_ctx, const char *backend, const char *location)
31 WERROR error;
32 struct registry_key *root, *subkey;
33 uint32_t count;
34 struct torture_test *ctx = torture_test(parent_ctx, "test_hive", backend);
36 if (!reg_has_backend(backend)) {
37 torture_skip(ctx, "Backend '%s' support not compiled in", backend);
38 return True;
41 error = reg_open_hive(ctx, backend, location, NULL, cmdline_credentials, &root);
42 torture_assert_werr_ok(ctx, error, "reg_open_hive()");
44 /* This is a new backend. There should be no subkeys and no
45 * values */
46 error = reg_key_num_subkeys(root, &count);
47 torture_assert_werr_ok(ctx, error, "reg_key_num_subkeys()");
49 torture_assert(ctx, count != 0, "New key has non-zero subkey count");
51 error = reg_key_num_values(root, &count);
52 torture_assert_werr_ok(ctx, error, "reg_key_num_values");
54 torture_assert(ctx, count != 0, "New key has non-zero value count");
56 error = reg_key_add_name(ctx, root, "Nested\\Key", SEC_MASK_GENERIC, NULL, &subkey);
57 torture_assert_werr_ok(ctx, error, "reg_key_add_name");
59 error = reg_key_del(root, "Nested\\Key");
60 torture_assert_werr_ok(ctx, error, "reg_key_del");
62 talloc_free(root);
64 torture_ok(ctx);
66 return True;
69 BOOL torture_registry(struct torture_context *torture)
71 BOOL ret = True;
73 registry_init();
75 ret &= test_hive(torture, "nt4", "TEST.DAT");
76 ret &= test_hive(torture, "ldb", "test.ldb");
77 ret &= test_hive(torture, "gconf", ".");
78 ret &= test_hive(torture, "dir", ".");
80 return ret;