2 * Check: a unit test framework for C
3 * Copyright (C) 2001, 2002 Arien Malec
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #include "../lib/libcompat.h"
28 #include "check_list.h"
29 #include "check_impl.h"
30 #include "check_str.h"
31 #include "check_print.h"
33 static void srunner_fprint_summary (FILE * file, SRunner * sr,
34 enum print_output print_mode);
35 static void srunner_fprint_results (FILE * file, SRunner * sr,
36 enum print_output print_mode);
40 srunner_print (SRunner * sr, enum print_output print_mode)
42 srunner_fprint (stdout, sr, print_mode);
46 srunner_fprint (FILE * file, SRunner * sr, enum print_output print_mode)
48 if (print_mode == CK_ENV) {
49 print_mode = get_env_printmode ();
52 srunner_fprint_summary (file, sr, print_mode);
53 srunner_fprint_results (file, sr, print_mode);
57 srunner_fprint_summary (FILE * file, SRunner * sr, enum print_output print_mode)
60 if (print_mode == CK_SUBUNIT)
64 if (print_mode >= CK_MINIMAL) {
67 str = sr_stat_str (sr);
68 fprintf (file, "%s\n", str);
75 srunner_fprint_results (FILE * file, SRunner * sr, enum print_output print_mode)
80 if (print_mode == CK_SUBUNIT)
84 resultlst = sr->resultlst;
86 for (check_list_front (resultlst); !check_list_at_end (resultlst);
87 check_list_advance (resultlst)) {
88 TestResult *tr = (TestResult *) check_list_val (resultlst);
90 tr_fprint (file, tr, print_mode);
96 fprint_xml_esc (FILE * file, const char *str)
98 for (; *str != '\0'; str++) {
102 /* handle special characters that must be escaped */
104 fputs (""", file);
107 fputs ("'", file);
110 fputs ("<", file);
113 fputs (">", file);
116 fputs ("&", file);
119 /* regular characters, print as is */
128 tr_fprint (FILE * file, TestResult * tr, enum print_output print_mode)
130 if (print_mode == CK_ENV) {
131 print_mode = get_env_printmode ();
134 if ((print_mode >= CK_VERBOSE && tr->rtype == CK_PASS) ||
135 (tr->rtype != CK_PASS && print_mode >= CK_NORMAL)) {
136 char *trstr = tr_str (tr);
138 fprintf (file, "%s\n", trstr);
144 tr_xmlprint (FILE * file, TestResult * tr,
145 enum print_output print_mode CK_ATTRIBUTE_UNUSED)
148 char *path_name = NULL;
149 char *file_name = NULL;
154 snprintf (result, sizeof (result), "%s", "success");
157 snprintf (result, sizeof (result), "%s", "failure");
160 snprintf (result, sizeof (result), "%s", "error");
162 case CK_TEST_RESULT_INVALID:
169 slash = strrchr (tr->file, '/');
171 slash = strrchr (tr->file, '\\');
175 path_name = strdup (".");
176 file_name = tr->file;
178 path_name = strdup (tr->file);
179 path_name[slash - tr->file] = 0; /* Terminate the temporary string. */
180 file_name = slash + 1;
185 fprintf (file, " <test result=\"%s\">\n", result);
186 fprintf (file, " <path>%s</path>\n",
187 (path_name == NULL ? "" : path_name));
188 fprintf (file, " <fn>%s:%d</fn>\n",
189 (file_name == NULL ? "" : file_name), tr->line);
190 fprintf (file, " <id>%s</id>\n", tr->tname);
191 fprintf (file, " <iteration>%d</iteration>\n", tr->iter);
192 fprintf (file, " <duration>%d.%06d</duration>\n",
193 tr->duration < 0 ? -1 : tr->duration / US_PER_SEC,
194 tr->duration < 0 ? 0 : tr->duration % US_PER_SEC);
195 fprintf (file, " <description>");
196 fprint_xml_esc (file, tr->tcname);
197 fprintf (file, "</description>\n");
198 fprintf (file, " <message>");
199 fprint_xml_esc (file, tr->msg);
200 fprintf (file, "</message>\n");
201 fprintf (file, " </test>\n");
207 get_env_printmode (void)
209 char *env = getenv ("CK_VERBOSITY");
213 if (strcmp (env, "silent") == 0)
215 if (strcmp (env, "minimal") == 0)
217 if (strcmp (env, "verbose") == 0)