d5ee344596fb5a9cece742f52f80f7853a3a3afc
[ira/wip.git] / source4 / lib / torture / subunit.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Samba utility functions
4    Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "includes.h"
21 #include "lib/torture/torture.h"
22
23 static void subunit_init(struct torture_results *results) 
24 {
25         /* FIXME: register segv and bus handler */
26 }
27
28 static void subunit_suite_start(struct torture_context *ctx,
29                                 struct torture_suite *suite)
30 {
31 }
32
33 static void subunit_print_testname(struct torture_context *ctx, 
34                                    struct torture_tcase *tcase,
35                                    struct torture_test *test)
36 {
37         if (!strcmp(tcase->name, test->name)) {
38                 printf("%s", test->name);
39         } else {
40                 printf("%s.%s", tcase->name, test->name);
41         }
42 }
43
44 static void subunit_test_start(struct torture_context *ctx, 
45                                struct torture_tcase *tcase,
46                                struct torture_test *test)
47 {
48         printf("test: ");
49         subunit_print_testname(ctx, tcase, test);       
50         printf("\n");
51 }
52
53 static void subunit_test_result(struct torture_context *context, 
54                                 enum torture_result res, const char *reason)
55 {
56         switch (res) {
57         case TORTURE_OK:
58                 printf("success: ");
59                 break;
60         case TORTURE_FAIL:
61                 printf("failure: ");
62                 break;
63         case TORTURE_ERROR:
64                 printf("error: ");
65                 break;
66         case TORTURE_SKIP:
67                 printf("skip: ");
68                 break;
69         }
70         subunit_print_testname(context, context->active_tcase, context->active_test);   
71
72         if (reason)
73                 printf(" [\n%s\n]", reason);
74         printf("\n");
75 }
76
77 static void subunit_comment(struct torture_context *test,
78                             const char *comment)
79 {
80         fprintf(stderr, "%s", comment);
81 }
82
83 static void subunit_warning(struct torture_context *test,
84                             const char *comment)
85 {
86         fprintf(stderr, "WARNING!: %s\n", comment);
87 }
88
89 const struct torture_ui_ops torture_subunit_ui_ops = {
90         .init = subunit_init,
91         .comment = subunit_comment,
92         .warning = subunit_warning,
93         .test_start = subunit_test_start,
94         .test_result = subunit_test_result,
95         .suite_start = subunit_suite_start
96 };