gst-indent run on core
[platform/upstream/gstreamer.git] / testsuite / debug / commandline.c
1 /*
2  * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
3  *
4  * commandline.c: Test if the command line arguments work
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library 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 GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 #include <gst/gst.h>
25
26 GST_DEBUG_CATEGORY (cat);
27 GST_DEBUG_CATEGORY_STATIC (cat_static);
28
29 static const gchar *lines[] = {
30   "--gst-debug-disable",
31   "--gst-debug-no-color",
32   "--gst-debug-level=4",
33   "--gst-debug=cat:4,cat_*:3",
34   "--gst-debug-level=4 --gst-debug=cat_*:5"
35 };
36
37 static void
38 debug_not_reached (GstDebugCategory * category, GstDebugLevel level,
39     const gchar * file, const gchar * function, gint line, GObject * object,
40     GstDebugMessage * message, gpointer thread)
41 {
42   g_assert_not_reached ();
43 }
44
45 gint
46 main (gint argc, gchar * argv[])
47 {
48   if (argc == 1) {
49     /* this is the main run that calls the others */
50     gint i, runs, exit;
51     gchar *command;
52
53     unsetenv ("GST_DEBUG");
54     gst_init (&argc, &argv);
55     runs = G_N_ELEMENTS (lines);
56     for (i = 0; i < runs; i++) {
57       command = g_strdup_printf ("%s %s %d", argv[0], lines[i], i);
58       g_print ("running \"%s\"\n", command);
59       g_assert (g_spawn_command_line_sync (command, NULL, NULL, &exit,
60               NULL) == TRUE);
61       g_assert (exit == 0);
62       g_print ("\"%s\" worked as expected.\n", command);
63       g_free (command);
64     }
65
66     return 0;
67   } else {
68     gst_init (&argc, &argv);
69     if (argc != 2) {
70       g_print
71           ("something funny happened to the command line arguments, aborting.\n");
72       return 1;
73     }
74     gst_debug_remove_log_function (gst_debug_log_default);
75     GST_DEBUG_CATEGORY_INIT (cat, "cat", 0, "non-static category");
76     GST_DEBUG_CATEGORY_INIT (cat_static, "cat_static", 0, "static category");
77     switch (argv[1][0]) {
78       case '0':
79         g_assert (gst_debug_is_active () == FALSE);
80         gst_debug_add_log_function (debug_not_reached, NULL);
81         GST_ERROR ("This will not be seen");
82         return 0;
83       case '1':
84         return gst_debug_is_colored ()? 1 : 0;
85       case '2':
86         g_assert (gst_debug_get_default_threshold () == 4);
87         g_assert (gst_debug_category_get_threshold (cat) == 4);
88         return 0;
89       case '3':
90         g_assert (gst_debug_get_default_threshold () == GST_LEVEL_DEFAULT);
91         g_assert (gst_debug_category_get_threshold (cat) == 4);
92         g_assert (gst_debug_category_get_threshold (cat_static) == 3);
93         return 0;
94       case '4':
95         g_assert (gst_debug_get_default_threshold () == 4);
96         g_assert (gst_debug_category_get_threshold (cat) == 4);
97         g_assert (gst_debug_category_get_threshold (cat_static) == 5);
98         return 0;
99       default:
100         g_print ("usupported command, aborting...\n");
101         return -1;
102     }
103   }
104   g_assert_not_reached ();
105 }