• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
27 static void
test_pass(void)28 test_pass (void)
29 {
30 }
31 
32 static void
test_skip(void)33 test_skip (void)
34 {
35   g_test_skip ("not enough tea");
36 }
37 
38 static void
test_fail(void)39 test_fail (void)
40 {
41   g_test_fail ();
42 }
43 
44 static void
test_incomplete(void)45 test_incomplete (void)
46 {
47   g_test_incomplete ("mind reading not implemented yet");
48 }
49 
50 static void
test_summary(void)51 test_summary (void)
52 {
53   g_test_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 
58 int
main(int argc,char * argv[])59 main (int   argc,
60       char *argv[])
61 {
62   char *argv1;
63 
64   setlocale (LC_ALL, "");
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 (&argv[1], &argv[2], (argc - 2) * sizeof (char *));
79 
80   argc -= 1;
81   argv[argc] = NULL;
82 
83   g_test_init (&argc, &argv, NULL);
84   g_test_set_nonfatal_assertions ();
85 
86   if (g_strcmp0 (argv1, "pass") == 0)
87     {
88       g_test_add_func ("/pass", test_pass);
89     }
90   else if (g_strcmp0 (argv1, "skip") == 0)
91     {
92       g_test_add_func ("/skip", test_skip);
93     }
94   else if (g_strcmp0 (argv1, "incomplete") == 0)
95     {
96       g_test_add_func ("/incomplete", test_incomplete);
97     }
98   else if (g_strcmp0 (argv1, "fail") == 0)
99     {
100       g_test_add_func ("/fail", test_fail);
101     }
102   else if (g_strcmp0 (argv1, "all-non-failures") == 0)
103     {
104       g_test_add_func ("/pass", test_pass);
105       g_test_add_func ("/skip", test_skip);
106       g_test_add_func ("/incomplete", test_incomplete);
107     }
108   else if (g_strcmp0 (argv1, "all") == 0)
109     {
110       g_test_add_func ("/pass", test_pass);
111       g_test_add_func ("/skip", test_skip);
112       g_test_add_func ("/incomplete", test_incomplete);
113       g_test_add_func ("/fail", test_fail);
114     }
115   else if (g_strcmp0 (argv1, "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 ("/a", test_pass);
120       g_test_add_func ("/b", test_pass);
121       g_test_add_func ("/b/a", test_pass);
122       g_test_add_func ("/b/b", test_pass);
123       g_test_add_func ("/b/b/a", test_pass);
124       g_test_add_func ("/prefix/a", test_pass);
125       g_test_add_func ("/prefix/b/b", test_pass);
126       g_test_add_func ("/prefix-long/a", test_pass);
127       g_test_add_func ("/c/a", test_pass);
128       g_test_add_func ("/d/a", test_pass);
129     }
130   else if (g_strcmp0 (argv1, "summary") == 0)
131     {
132       g_test_add_func ("/summary", test_summary);
133     }
134   else
135     {
136       g_assert_not_reached ();
137     }
138 
139   return g_test_run ();
140 }
141