r12608: Remove some unused #include lines.
[kai/samba-autobuild/.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
26 static BOOL test_hive(TALLOC_CTX *mem_ctx, const char *backend, const char *location)
27 {
28         WERROR error;
29         struct registry_key *root, *subkey;
30         uint32_t count;
31         
32         if (!reg_has_backend(backend)) {
33                 printf("Backend '%s' support not compiled in, ignoring\n", backend);
34                 return True;
35         }
36
37         error = reg_open_hive(mem_ctx, backend, location, NULL, &root);
38         if (!W_ERROR_IS_OK(error)) {
39                 printf("reg_open_hive() failed\n"); 
40                 return False;
41         }
42
43         /* This is a new backend. There should be no subkeys and no 
44          * values */
45         error = reg_key_num_subkeys(root, &count);
46         if (!W_ERROR_IS_OK(error)) {
47                 printf("reg_key_num_subkeys failed\n");
48                 return False;
49         }
50
51         if (count != 0) {
52                 printf("New key has non-zero subkey count\n");
53                 return False;
54         }
55
56         error = reg_key_num_values(root, &count);
57         if (!W_ERROR_IS_OK(error)) {
58                 printf("reg_key_num_values failed\n");
59                 return False;
60         }
61
62         if (count != 0) {
63                 printf("New key has non-zero value count\n");
64                 return False;
65         }
66
67         error = reg_key_add_name(mem_ctx, root, "Nested\\Key", SEC_MASK_GENERIC, NULL, &subkey);
68         if (!W_ERROR_IS_OK(error)) {
69                 return False;
70         }
71
72         error = reg_key_del(root, "Nested\\Key");
73         if (!W_ERROR_IS_OK(error)) {
74                 return False;
75         }
76
77         talloc_free(root);
78
79         return True;
80 }
81
82 BOOL torture_registry(void) 
83 {
84         BOOL ret = True;
85         TALLOC_CTX *mem_ctx = talloc_init("torture_registry");
86
87         registry_init();
88
89         ret &= test_hive(mem_ctx, "nt4", "TEST.DAT");
90         ret &= test_hive(mem_ctx, "ldb", "test.ldb");
91         ret &= test_hive(mem_ctx, "gconf", ".");
92         ret &= test_hive(mem_ctx, "dir", ".");
93
94         talloc_free(mem_ctx);
95
96         return ret;
97 }