r15818: Improve UI utilities: allow format strings and add some convenience macros.
[sfrench/samba-autobuild/.git] / source4 / torture / ui.h
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 struct torture_test;
23
24 enum torture_result { 
25         TORTURE_OK=0, 
26         TORTURE_FAIL=1, 
27         TORTURE_TODO=2, 
28         TORTURE_SKIP=3
29 };
30
31 struct torture_ui_ops
32 {
33         void (*comment) (struct torture_test *, const char *);
34         void (*test_start) (struct torture_test *);
35         void (*test_result) (struct torture_test *, enum torture_result, 
36                                                  const char *reason);
37 };
38
39 struct torture_test
40 {
41         char *name;
42         char *description;
43
44         void *ui_data;
45
46         struct torture_context *context;
47 };
48
49 struct torture_context
50 {
51         const struct torture_ui_ops *ui_ops;
52         void *ui_data;
53
54         int skipped;
55         int todo;
56         int success;
57         int failed;
58 };
59
60 #define torture_assert(ctx,expr,string) \
61         if (!(expr)) { \
62                 torture_fail(ctx, "%s:%d (%s): %s", __FILE__, __LINE__, string, \
63                                          __STRING(expr)); \
64                 return False; \
65         }
66
67 #define torture_assert_werr_equal(ctx,got,expected,string) \
68         if (!W_ERROR_EQUAL(got, expected)) { \
69                 torture_fail(ctx, "%s:%d (%s): got %s, expected %s", __FILE__, \
70                                          __LINE__, string, win_errstr(got), win_errstr(expected)); \
71                 return False; \
72         }
73
74 #define torture_assert_ntstatus_equal(ctx,got,expected,string) \
75         if (!NT_STATUS_EQUAL(got, expected)) { \
76                 torture_fail(ctx, "%s:%d (%s): got %s, expected %s", __FILE__, \
77                                          __LINE__, string, nt_errstr(got), nt_errstr(expected)); \
78                 return False; \
79         }
80
81 /* Convenience macros */
82
83 #define torture_assert_ntstatus_ok(ctx,expr,string) \
84                 torture_assert_ntstatus_equal(ctx,expr,NT_STATUS_OK,string)
85
86 #define torture_assert_werr_ok(ctx,expr,string) \
87                 torture_assert_werr_equal(ctx,expr,WERR_OK,string)
88
89 struct torture_test *torture_test(struct torture_context *ctx, const char *name, const char *description);
90 struct torture_test *torture_subtest(struct torture_test *parent, const char *name, const char *description);
91 void torture_comment(struct torture_test *test, const char *comment, ...) _PRINTF_ATTRIBUTE(2,3);
92 void torture_ok(struct torture_test *test);
93 void torture_fail(struct torture_test *test, const char *reason, ...) _PRINTF_ATTRIBUTE(2,3);;
94 void torture_skip(struct torture_test *test, const char *reason, ...) _PRINTF_ATTRIBUTE(2,3);