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.
23 #include "torture/ui.h"
25 static int test_destructor(void *_test)
27 struct torture_test *test = _test;
29 if (test->result == TORTURE_OK)
36 struct torture_test *torture_test(struct torture_context *ctx, const char *name, const char *description)
38 struct torture_test *test = talloc(ctx, struct torture_test);
40 test->name = talloc_strdup(test, name);
41 test->description = talloc_strdup(test, description);
44 ctx->ui_ops->test_start(test);
46 talloc_set_destructor(test, test_destructor);
51 struct torture_test *torture_subtest(struct torture_test *parent, const char *name, const char *description)
53 struct torture_test *test = talloc(parent, struct torture_test);
55 test->name = talloc_strdup(test, name);
56 test->description = talloc_strdup(test, description);
57 test->context = parent->context;
59 test->context->ui_ops->test_start(test);
61 talloc_set_destructor(test, test_destructor);
66 void torture_comment(struct torture_test *test, const char *comment, ...) _PRINTF_ATTRIBUTE(2,3)
70 va_start(ap, comment);
71 tmp = talloc_vasprintf(test, comment, ap);
73 test->context->ui_ops->comment(test, tmp);
79 void torture_ok(struct torture_test *test)
81 test->context->ui_ops->test_result(test, TORTURE_OK, NULL);
82 test->context->success++;
85 void torture_fail(struct torture_test *test, const char *fmt, ...) _PRINTF_ATTRIBUTE(2,3)
90 reason = talloc_vasprintf(test, fmt, ap);
92 test->context->ui_ops->test_result(test, TORTURE_FAIL, reason);
95 test->context->failed++;
98 BOOL torture_result(struct torture_context *torture)
100 return (torture->failed == 0);
103 void torture_skip(struct torture_test *test, const char *fmt, ...) _PRINTF_ATTRIBUTE(2,3)
108 reason = talloc_vasprintf(test, fmt, ap);
110 test->context->ui_ops->test_result(test, TORTURE_SKIP, reason);
112 test->context->skipped++;