2 * Unix SMB/CIFS implementation.
3 * libsmbconf - Samba configuration library: testsuite
4 * Copyright (C) Michael Adam 2008
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 static void print_strings(const char *prefix
,
23 uint32_t num_strings
, const char **strings
)
31 for (count
= 0; count
< num_strings
; count
++) {
32 printf("%s%s\n", prefix
, strings
[count
]);
36 static bool test_get_includes(struct smbconf_ctx
*ctx
)
40 uint32_t num_includes
= 0;
41 char **includes
= NULL
;
42 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
44 printf("test: get_includes\n");
45 werr
= smbconf_get_global_includes(ctx
, mem_ctx
,
46 &num_includes
, &includes
);
47 if (!W_ERROR_IS_OK(werr
)) {
48 printf("failure: get_includes - %s\n", dos_errstr(werr
));
52 printf("got %u includes%s\n", num_includes
,
53 (num_includes
> 0) ? ":" : ".");
54 print_strings("", num_includes
, (const char **)includes
);
56 printf("success: get_includes\n");
64 static bool torture_smbconf_txt(void)
68 struct smbconf_ctx
*conf_ctx
= NULL
;
69 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
71 printf("test: text backend\n");
73 printf("test: init\n");
74 werr
= smbconf_init_txt_simple(mem_ctx
, &conf_ctx
, NULL
, true);
75 if (!W_ERROR_IS_OK(werr
)) {
76 printf("failure: init failed: %s\n", dos_errstr(werr
));
80 printf("success: init\n");
82 ret
&= test_get_includes(conf_ctx
);
84 smbconf_shutdown(conf_ctx
);
88 printf("success: text backend\n");
95 static bool torture_smbconf_reg(void)
99 struct smbconf_ctx
*conf_ctx
= NULL
;
100 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
102 printf("test: registry backend\n");
104 printf("test: init\n");
105 werr
= smbconf_init_reg(mem_ctx
, &conf_ctx
, NULL
);
106 if (!W_ERROR_IS_OK(werr
)) {
107 printf("failure: init failed: %s\n", dos_errstr(werr
));
111 printf("success: init\n");
113 ret
&= test_get_includes(conf_ctx
);
115 smbconf_shutdown(conf_ctx
);
119 printf("success: registry backend\n");
122 TALLOC_FREE(mem_ctx
);
126 static bool torture_smbconf(void)
129 ret
&= torture_smbconf_txt();
131 ret
&= torture_smbconf_reg();
135 int main(int argc
, const char **argv
)
139 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
141 struct poptOption long_options
[] = {
150 pc
= poptGetContext("smbconftort", argc
, (const char **)argv
,
153 while(poptGetNextOpt(pc
) != -1) { }
157 ret
= lp_load(get_dyn_CONFIGFILE(),
158 true, /* globals_only */
159 false, /* save_defaults */
161 true /* initialize globals */);
164 printf("failure: error loading the configuration\n");
168 ret
= torture_smbconf();
171 TALLOC_FREE(mem_ctx
);