r14720: Add torture_context argument to all torture tests
[samba.git] / source4 / torture / local / registry.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    local testing of registry library
5
6    Copyright (C) Jelmer Vernooij 2005
7    
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.
12    
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.
17    
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.
21 */
22
23 #include "includes.h"
24 #include "lib/registry/registry.h"
25 #include "lib/cmdline/popt_common.h"
26 #include "torture/torture.h"
27
28 static BOOL test_hive(TALLOC_CTX *mem_ctx, const char *backend, const char *location)
29 {
30         WERROR error;
31         struct registry_key *root, *subkey;
32         uint32_t count;
33         
34         if (!reg_has_backend(backend)) {
35                 printf("Backend '%s' support not compiled in, ignoring\n", backend);
36                 return True;
37         }
38
39         error = reg_open_hive(mem_ctx, backend, location, NULL, cmdline_credentials, &root);
40         if (!W_ERROR_IS_OK(error)) {
41                 printf("reg_open_hive() failed\n"); 
42                 return False;
43         }
44
45         /* This is a new backend. There should be no subkeys and no 
46          * values */
47         error = reg_key_num_subkeys(root, &count);
48         if (!W_ERROR_IS_OK(error)) {
49                 printf("reg_key_num_subkeys failed\n");
50                 return False;
51         }
52
53         if (count != 0) {
54                 printf("New key has non-zero subkey count\n");
55                 return False;
56         }
57
58         error = reg_key_num_values(root, &count);
59         if (!W_ERROR_IS_OK(error)) {
60                 printf("reg_key_num_values failed\n");
61                 return False;
62         }
63
64         if (count != 0) {
65                 printf("New key has non-zero value count\n");
66                 return False;
67         }
68
69         error = reg_key_add_name(mem_ctx, root, "Nested\\Key", SEC_MASK_GENERIC, NULL, &subkey);
70         if (!W_ERROR_IS_OK(error)) {
71                 return False;
72         }
73
74         error = reg_key_del(root, "Nested\\Key");
75         if (!W_ERROR_IS_OK(error)) {
76                 return False;
77         }
78
79         talloc_free(root);
80
81         return True;
82 }
83
84 BOOL torture_registry(struct torture_context *torture) 
85 {
86         BOOL ret = True;
87         TALLOC_CTX *mem_ctx = talloc_init("torture_registry");
88
89         registry_init();
90
91         ret &= test_hive(mem_ctx, "nt4", "TEST.DAT");
92         ret &= test_hive(mem_ctx, "ldb", "test.ldb");
93         ret &= test_hive(mem_ctx, "gconf", ".");
94         ret &= test_hive(mem_ctx, "dir", ".");
95
96         talloc_free(mem_ctx);
97
98         return ret;
99 }