1/*
2 * Copyright 2018 Collabora Ltd.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, see
16 * <http://www.gnu.org/licenses/>.
17 */
18
19#include <glib.h>
20#include <locale.h>
21#ifdef G_OS_WIN32
22#include <fcntl.h>
23#include <io.h>
24#include <stdio.h>
25#endif
26
27static void
28test_pass (void)
29{
30}
31
32static void
33test_skip (void)
34{
35 g_test_skip (msg: "not enough tea");
36}
37
38static void
39test_fail (void)
40{
41 g_test_fail ();
42}
43
44static void
45test_incomplete (void)
46{
47 g_test_incomplete (msg: "mind reading not implemented yet");
48}
49
50static void
51test_summary (void)
52{
53 g_test_summary (summary: "Tests that g_test_summary() works with TAP, by outputting a "
54 "known summary message in testing-helper, and checking for "
55 "it in the TAP output later.");
56}
57
58int
59main (int argc,
60 char *argv[])
61{
62 char *argv1;
63
64 setlocale (LC_ALL, locale: "");
65
66#ifdef G_OS_WIN32
67 /* Windows opens std streams in text mode, with \r\n EOLs.
68 * Sometimes it's easier to force a switch to binary mode than
69 * to account for extra \r in testcases.
70 */
71 setmode (fileno (stdout), O_BINARY);
72#endif
73
74 g_return_val_if_fail (argc > 1, 1);
75 argv1 = argv[1];
76
77 if (argc > 2)
78 memmove (dest: &argv[1], src: &argv[2], n: (argc - 2) * sizeof (char *));
79
80 argc -= 1;
81 argv[argc] = NULL;
82
83 g_test_init (argc: &argc, argv: &argv, NULL);
84 g_test_set_nonfatal_assertions ();
85
86 if (g_strcmp0 (str1: argv1, str2: "pass") == 0)
87 {
88 g_test_add_func (testpath: "/pass", test_func: test_pass);
89 }
90 else if (g_strcmp0 (str1: argv1, str2: "skip") == 0)
91 {
92 g_test_add_func (testpath: "/skip", test_func: test_skip);
93 }
94 else if (g_strcmp0 (str1: argv1, str2: "incomplete") == 0)
95 {
96 g_test_add_func (testpath: "/incomplete", test_func: test_incomplete);
97 }
98 else if (g_strcmp0 (str1: argv1, str2: "fail") == 0)
99 {
100 g_test_add_func (testpath: "/fail", test_func: test_fail);
101 }
102 else if (g_strcmp0 (str1: argv1, str2: "all-non-failures") == 0)
103 {
104 g_test_add_func (testpath: "/pass", test_func: test_pass);
105 g_test_add_func (testpath: "/skip", test_func: test_skip);
106 g_test_add_func (testpath: "/incomplete", test_func: test_incomplete);
107 }
108 else if (g_strcmp0 (str1: argv1, str2: "all") == 0)
109 {
110 g_test_add_func (testpath: "/pass", test_func: test_pass);
111 g_test_add_func (testpath: "/skip", test_func: test_skip);
112 g_test_add_func (testpath: "/incomplete", test_func: test_incomplete);
113 g_test_add_func (testpath: "/fail", test_func: test_fail);
114 }
115 else if (g_strcmp0 (str1: argv1, str2: "skip-options") == 0)
116 {
117 /* The caller is expected to skip some of these with
118 * -p/-r, -s/-x and/or --GTestSkipCount */
119 g_test_add_func (testpath: "/a", test_func: test_pass);
120 g_test_add_func (testpath: "/b", test_func: test_pass);
121 g_test_add_func (testpath: "/b/a", test_func: test_pass);
122 g_test_add_func (testpath: "/b/b", test_func: test_pass);
123 g_test_add_func (testpath: "/b/b/a", test_func: test_pass);
124 g_test_add_func (testpath: "/prefix/a", test_func: test_pass);
125 g_test_add_func (testpath: "/prefix/b/b", test_func: test_pass);
126 g_test_add_func (testpath: "/prefix-long/a", test_func: test_pass);
127 g_test_add_func (testpath: "/c/a", test_func: test_pass);
128 g_test_add_func (testpath: "/d/a", test_func: test_pass);
129 }
130 else if (g_strcmp0 (str1: argv1, str2: "summary") == 0)
131 {
132 g_test_add_func (testpath: "/summary", test_func: test_summary);
133 }
134 else
135 {
136 g_assert_not_reached ();
137 }
138
139 return g_test_run ();
140}
141

source code of gtk/subprojects/glib/glib/tests/testing-helper.c