2 Unix SMB/CIFS implementation.
3 SMB torture UI functions
5 Copyright (C) Jelmer Vernooij 2006
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.
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.
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.
22 #ifndef __TORTURE_UI_H__
23 #define __TORTURE_UI_H__
26 struct torture_context;
39 void (*comment) (struct torture_context *, const char *);
40 void (*suite_start) (struct torture_context *, struct torture_suite *);
41 void (*suite_finish) (struct torture_context *, struct torture_suite *);
42 void (*tcase_start) (struct torture_context *, struct torture_tcase *);
43 void (*tcase_finish) (struct torture_context *, struct torture_tcase *);
44 void (*test_start) (struct torture_context *,
45 struct torture_tcase *,
46 struct torture_test *);
47 void (*test_result) (struct torture_context *, enum torture_result,
51 struct torture_context
53 const struct torture_ui_ops *ui_ops;
56 struct torture_test *active_test;
57 struct torture_tcase *active_tcase;
64 enum torture_result last_result;
73 const char *description;
74 struct torture_tcase {
76 const char *description;
77 BOOL (*setup) (struct torture_context *tcase, void **data);
78 BOOL (*teardown) (struct torture_context *tcase, void *data);
79 BOOL fixture_persistent;
83 const char *description;
86 BOOL (*run) (struct torture_context *test,
87 const void *tcase_data,
88 const void *test_data);
89 struct torture_test *prev, *next;
91 struct torture_tcase *prev, *next;
95 struct torture_suite *torture_suite_create(TALLOC_CTX *ctx, const char *name);
96 void torture_tcase_set_fixture(struct torture_tcase *tcase,
97 BOOL (*setup) (struct torture_context *, void **),
98 BOOL (*teardown) (struct torture_context *, void *));
99 struct torture_test *torture_tcase_add_test(struct torture_tcase *tcase,
101 BOOL (*run) (struct torture_context *test, const void *tcase_data,
102 const void *test_data),
103 const void *test_data);
104 struct torture_tcase *torture_suite_add_tcase(struct torture_suite *suite,
106 struct torture_tcase *torture_suite_add_simple_tcase(
107 struct torture_suite *suite,
109 BOOL (*run) (struct torture_context *test, const void *test_data),
112 BOOL torture_run_suite(struct torture_context *context,
113 struct torture_suite *suite);
115 BOOL torture_run_tcase(struct torture_context *context,
116 struct torture_tcase *tcase);
118 BOOL torture_run_test(struct torture_context *context,
119 struct torture_tcase *tcase,
120 struct torture_test *test);
122 #define torture_assert(ctx,expr,string) \
124 torture_fail(ctx, "%s:%d (%s): %s", __FILE__, __LINE__, string, \
129 #define torture_assert_werr_equal(ctx,got,expected,string) \
130 do { WERROR __got = got, __expected = expected; \
131 if (!W_ERROR_EQUAL(__got, __expected)) { \
132 torture_fail(ctx, "%s:%d (%s): got %s, expected %s", __FILE__, \
133 __LINE__, string, win_errstr(__got), win_errstr(__expected)); \
138 #define torture_assert_ntstatus_equal(ctx,got,expected,string) \
139 do { NTSTATUS __got = got, __expected = expected; \
140 if (!NT_STATUS_EQUAL(__got, __expected)) { \
141 torture_fail(ctx, "%s:%d (%s): got %s, expected %s", __FILE__, \
142 __LINE__, string, nt_errstr(__got), nt_errstr(__expected)); \
148 #define torture_assert_casestr_equal(ctx,got,expected,string) \
149 do { const char *__got = got, __expected = expected; \
150 if (strcasecmp(__got, __expected) != 0) { \
151 torture_fail(ctx, "%s:%d (%s): got %s, expected %s", __FILE__, \
152 __LINE__, string, got, expected); \
157 #define torture_assert_str_equal(ctx,got,expected,string) \
158 do { const char *__got = got, __expected = expected; \
159 if (strcmp(__got, __expected) != 0) { \
160 torture_fail(ctx, "%s:%d (%s): got %s, expected %s", __FILE__, \
161 __LINE__, string, __got, __expected); \
167 /* Convenience macros */
169 #define torture_assert_ntstatus_ok(ctx,expr,string) \
170 torture_assert_ntstatus_equal(ctx,expr,NT_STATUS_OK,string)
172 #define torture_assert_werr_ok(ctx,expr,string) \
173 torture_assert_werr_equal(ctx,expr,WERR_OK,string)
175 void torture_comment(struct torture_context *test, const char *comment, ...) PRINTF_ATTRIBUTE(2,3);
176 void torture_fail(struct torture_context *test, const char *reason, ...) PRINTF_ATTRIBUTE(2,3);
177 void torture_skip(struct torture_context *test, const char *reason, ...) PRINTF_ATTRIBUTE(2,3);
178 const char *torture_setting(struct torture_context *test, const char *name,
179 const char *default_value);
181 /* Helper function commonly used */
182 BOOL torture_teardown_free(struct torture_context *torture, void *data);
184 #endif /* __TORTURE_UI_H__ */