7c9c443f9bf773bb6a6a7bbe1a5db529856d255e
[ira/wip.git] / testprogs / win32 / spoolss / torture.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 3 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, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef __TORTURE_UI_H__
22 #define __TORTURE_UI_H__
23
24 /****************************************************************************
25 ****************************************************************************/
26
27 enum torture_result {
28         TORTURE_OK=0,
29         TORTURE_FAIL=1,
30         TORTURE_ERROR=2,
31         TORTURE_SKIP=3
32 };
33
34 struct torture_context {
35         enum torture_result last_result;
36         char *last_reason;
37         BOOL print;
38         BOOL samba3;
39 };
40
41 /****************************************************************************
42 ****************************************************************************/
43
44 #define torture_assert(torture_ctx,expr,cmt) do {\
45         if (!(expr)) {\
46                 torture_result(torture_ctx, TORTURE_FAIL, __location__": Expression `%s' failed: %s", __STRING(expr), cmt); \
47                 return false;\
48         }\
49 } while(0)
50
51 #define torture_assert_str_equal(torture_ctx,got,expected,cmt)\
52         do { const char *__got = (got), *__expected = (expected); \
53         if (strcmp(__got, __expected) != 0) { \
54                 torture_result(torture_ctx, TORTURE_FAIL, \
55                         __location__": "#got" was %s, expected %s: %s", \
56                         __got, __expected, cmt); \
57                 return false; \
58         } \
59         } while(0)
60
61 #define torture_assert_int_equal(torture_ctx,got,expected,cmt)\
62         do { int __got = (got), __expected = (expected); \
63         if (__got != __expected) { \
64                 torture_result(torture_ctx, TORTURE_FAIL, \
65                         __location__": "#got" was %d, expected %d: %s", \
66                         __got, __expected, cmt); \
67                 return false; \
68         } \
69         } while(0)
70
71 #define torture_assert_mem_equal(torture_ctx,got,expected,len,cmt)\
72         do { const void *__got = (got), *__expected = (expected); \
73         if (memcmp(__got, __expected, len) != 0) { \
74                 torture_result(torture_ctx, TORTURE_FAIL, \
75                         __location__": "#got" of len %d did not match "#expected": %s", (int)len, cmt); \
76                 return false; \
77         } \
78         } while(0)
79
80 #define torture_skip(torture_ctx,cmt) do {\
81                 torture_result(torture_ctx, TORTURE_SKIP, __location__": %s", cmt);\
82                 return true; \
83         } while(0)
84
85 #define torture_fail(torture_ctx,cmt) do {\
86                 torture_result(torture_ctx, TORTURE_FAIL, __location__": %s", cmt);\
87                 return false; \
88         } while (0)
89
90 #include "torture_proto.h"
91
92 #endif