summaryrefslogtreecommitdiff
path: root/source4/torture/ui.h
blob: 006e2b99efa31219046ac2f1851bcb8f16955fe4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/* 
   Unix SMB/CIFS implementation.
   SMB torture UI functions

   Copyright (C) Jelmer Vernooij 2006
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef __TORTURE_UI_H__
#define __TORTURE_UI_H__

struct torture_test;
struct torture_context;
struct torture_suite;
struct torture_tcase;

enum torture_result { 
	TORTURE_OK=0, 
	TORTURE_FAIL=1, 
	TORTURE_TODO=2, 
	TORTURE_SKIP=3
};

struct torture_ui_ops
{
	void (*comment) (struct torture_context *, const char *);
	void (*suite_start) (struct torture_context *, struct torture_suite *);
	void (*suite_finish) (struct torture_context *, struct torture_suite *);
	void (*tcase_start) (struct torture_context *, struct torture_tcase *); 
	void (*tcase_finish) (struct torture_context *, struct torture_tcase *);
	void (*test_start) (struct torture_context *, 
						struct torture_tcase *,
						struct torture_test *);
	void (*test_result) (struct torture_context *, enum torture_result, 
						 const char *reason);
};

struct torture_context
{
	const struct torture_ui_ops *ui_ops;
	void *ui_data;

	struct torture_test *active_test;
	struct torture_tcase *active_tcase;

	int skipped;
	int todo;
	int success;
	int failed;

	enum torture_result last_result;
	char *last_reason;

	char *outputdir;
};

struct torture_suite
{
	const char *name;
	const char *description;
	struct torture_tcase {
	    const char *name;
		const char *description;
		BOOL (*setup) (struct torture_context *tcase, void **data);
		BOOL (*teardown) (struct torture_context *tcase, void *data); 
		BOOL fixture_persistent;
		const void *data;
		struct torture_test {
			const char *name;
			const char *description;
			const void *data;
			BOOL dangerous;
			BOOL (*run) (struct torture_context *test, 
						 const void *tcase_data,
						 const void *test_data);
			struct torture_test *prev, *next;
		} *tests;
		struct torture_tcase *prev, *next;
	} *testcases;
};

struct torture_suite *torture_suite_create(TALLOC_CTX *ctx, const char *name);
void torture_tcase_set_fixture(struct torture_tcase *tcase, 
		BOOL (*setup) (struct torture_context *, void **),
		BOOL (*teardown) (struct torture_context *, void *));
struct torture_test *torture_tcase_add_test(struct torture_tcase *tcase, 
		const char *name, 
		BOOL (*run) (struct torture_context *test, const void *tcase_data,
					 const void *test_data),
		const void *test_data);
struct torture_tcase *torture_suite_add_tcase(struct torture_suite *suite, 
							 const char *name);
struct torture_tcase *torture_suite_add_simple_tcase(
		struct torture_suite *suite, 
		const char *name,
		BOOL (*run) (struct torture_context *test, const void *test_data),
		const void *data);

BOOL torture_run_suite(struct torture_context *context, 
					   struct torture_suite *suite);

BOOL torture_run_tcase(struct torture_context *context, 
					   struct torture_tcase *tcase);

BOOL torture_run_test(struct torture_context *context, 
					  struct torture_tcase *tcase,
					  struct torture_test *test);

#define torture_assert(ctx,expr,string) \
	if (!(expr)) { \
		torture_fail(ctx, "%s:%d (%s): %s", __FILE__, __LINE__, string, \
					 __STRING(expr)); \
		return False; \
	}

#define torture_assert_werr_equal(ctx,got,expected,string) \
	do { WERROR __got = got, __expected = expected; \
	if (!W_ERROR_EQUAL(__got, __expected)) { \
		torture_fail(ctx, "%s:%d (%s): got %s, expected %s", __FILE__, \
					 __LINE__, string, win_errstr(__got), win_errstr(__expected)); \
		return False; \
	} \
	} while (0)

#define torture_assert_ntstatus_equal(ctx,got,expected,string) \
	do { NTSTATUS __got = got, __expected = expected; \
	if (!NT_STATUS_EQUAL(__got, __expected)) { \
		torture_fail(ctx, "%s:%d (%s): got %s, expected %s", __FILE__, \
					 __LINE__, string, nt_errstr(__got), nt_errstr(__expected)); \
		return False; \
	}\
	} while(0)


#define torture_assert_casestr_equal(ctx,got,expected,string) \
	do { const char *__got = got, *__expected = expected; \
	if (strcasecmp(__got, __expected) != 0) { \
		torture_fail(ctx, "%s:%d (%s): got %s, expected %s", __FILE__, \
					 __LINE__, string, got, expected); \
		return False; \
	} \
	} while(0)

#define torture_assert_str_equal(ctx,got,expected,string) \
	do { const char *__got = got, *__expected = expected; \
	if (strcmp(__got, __expected) != 0) { \
		torture_fail(ctx, "%s:%d (%s): got %s, expected %s", __FILE__, \
					 __LINE__, string, __got, __expected); \
		return False; \
	} \
	} while(0)


/* Convenience macros */

#define torture_assert_ntstatus_ok(ctx,expr,string) \
		torture_assert_ntstatus_equal(ctx,expr,NT_STATUS_OK,string)

#define torture_assert_werr_ok(ctx,expr,string) \
		torture_assert_werr_equal(ctx,expr,WERR_OK,string)

void torture_comment(struct torture_context *test, const char *comment, ...) PRINTF_ATTRIBUTE(2,3);
void torture_fail(struct torture_context *test, const char *reason, ...) PRINTF_ATTRIBUTE(2,3);
void torture_skip(struct torture_context *test, const char *reason, ...) PRINTF_ATTRIBUTE(2,3);
const char *torture_setting(struct torture_context *test, const char *name, 
							const char *default_value);

/* Helper function commonly used */
BOOL torture_teardown_free(struct torture_context *torture, void *data);

#endif /* __TORTURE_UI_H__ */