r14720: Add torture_context argument to all torture tests
[kai/samba.git] / source4 / torture / ui.c
1 /* 
2    Unix SMB/CIFS implementation.
3    SMB torture UI functions
4
5    Copyright (C) Jelmer Vernooij 2006
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "torture/ui.h"
24
25 struct torture_test *torture_test(struct torture_context *ctx, const char *name, const char *description)
26 {
27         struct torture_test *test = talloc(ctx, struct torture_test);
28
29         test->name = talloc_strdup(test, name);
30         test->description = talloc_strdup(test, description);
31         test->context = ctx;
32
33         ctx->ui_ops->test_start(test);
34
35         return test;
36 }
37
38 struct torture_test *torture_subtest(struct torture_test *parent, const char *name, const char *description)
39 {
40         struct torture_test *test = talloc(parent, struct torture_test);
41
42         test->name = talloc_strdup(test, name);
43         test->description = talloc_strdup(test, description);
44         test->context = parent->context;
45
46         test->context->ui_ops->test_start(test);
47         
48         return NULL;
49 }
50
51 void torture_comment(struct torture_test *test, const char *comment, ...) _PRINTF_ATTRIBUTE(2,3)
52 {
53         va_list ap;
54         char *tmp;
55         va_start(ap, comment);
56         tmp = talloc_vasprintf(test, comment, ap);
57                 
58         test->context->ui_ops->comment(test, tmp);
59         
60         talloc_free(tmp);
61 }
62
63 void torture_ok(struct torture_test *test)
64 {
65         test->context->ui_ops->test_result(test, TORTURE_OK);
66 }
67
68 void torture_fail(struct torture_test *test)
69 {
70         test->context->ui_ops->test_result(test, TORTURE_FAIL);
71 }
72
73 void torture_skip(struct torture_test *test)
74 {
75         test->context->ui_ops->test_result(test, TORTURE_SKIP);
76 }