Simplify subprocesses in tests
[platform/upstream/glib.git] / glib / tests / option-argv0.c
1 /* 
2  * Copyright (C) 2011 Red Hat, Inc.
3  *
4  * This work is provided "as is"; redistribution and modification
5  * in whole or in part, in any medium, physical or electronic is
6  * permitted without restriction.
7  *
8  * This work is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  *
12  * In no event shall the authors or contributors be liable for any
13  * direct, indirect, incidental, special, exemplary, or consequential
14  * damages (including, but not limited to, procurement of substitute
15  * goods or services; loss of use, data, or profits; or business
16  * interruption) however caused and on any theory of liability, whether
17  * in contract, strict liability, or tort (including negligence or
18  * otherwise) arising in any way out of the use of this software, even
19  * if advised of the possibility of such damage.
20  *
21  * Authors: Colin Walters <walters@verbum.org>
22  */
23
24 #include <glib.h>
25
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <string.h>
29
30 #if defined __linux || defined __OpenBSD__
31 static void
32 test_platform_argv0 (void)
33 {
34   GOptionContext *context;
35   gboolean arg;
36   GOptionEntry entries [] =
37     { { "test", 't', 0, G_OPTION_ARG_STRING, &arg, NULL, NULL },
38       { NULL } };
39   gboolean retval;
40
41   context = g_option_context_new (NULL);
42   g_option_context_add_main_entries (context, entries, NULL);
43   
44   retval = g_option_context_parse (context, NULL, NULL, NULL);
45   g_assert (retval == TRUE);
46   g_assert (strcmp (g_get_prgname(), "option-argv0") == 0
47             || strcmp (g_get_prgname (), "lt-option-argv0") == 0);
48
49   g_option_context_free (context);
50 }
51 #endif
52
53 int
54 main (int   argc,
55       char *argv[])
56 {
57   g_test_init (&argc, &argv, "no_g_set_prgname", NULL);
58
59 #if defined __linux || defined __OpenBSD__
60   g_test_add_func ("/option/argv0", test_platform_argv0);
61 #endif
62
63   return g_test_run ();
64 }