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 | #ifndef GST_DISABLE_GST_DEBUG |
---|
30 | static const gchar *lines[] = { |
---|
31 | "--gst-debug-disable", |
---|
32 | "--gst-debug-no-color", |
---|
33 | "--gst-debug-level=4", |
---|
34 | "--gst-debug=cat:4,cat_*:3", |
---|
35 | "--gst-debug-level=4 --gst-debug=cat_*:5" |
---|
36 | }; |
---|
37 | |
---|
38 | static void |
---|
39 | debug_not_reached (GstDebugCategory * category, GstDebugLevel level, |
---|
40 | const gchar * file, const gchar * function, gint line, GObject * object, |
---|
41 | GstDebugMessage * message, gpointer thread) |
---|
42 | { |
---|
43 | g_assert_not_reached (); |
---|
44 | } |
---|
45 | #endif |
---|
46 | |
---|
47 | gint |
---|
48 | main (gint argc, gchar * argv[]) |
---|
49 | { |
---|
50 | if (argc == 1) { |
---|
51 | /* this is the main run that calls the others */ |
---|
52 | |
---|
53 | unsetenv ("GST_DEBUG"); |
---|
54 | gst_init (&argc, &argv); |
---|
55 | #ifndef GST_DISABLE_GST_DEBUG |
---|
56 | { |
---|
57 | gint i, runs, exit; |
---|
58 | gchar *command; |
---|
59 | |
---|
60 | runs = G_N_ELEMENTS (lines); |
---|
61 | for (i = 0; i < runs; i++) { |
---|
62 | int ret; |
---|
63 | |
---|
64 | command = g_strdup_printf ("./commandline %s %d", lines[i], i); |
---|
65 | g_print ("running \"%s\"\n", command); |
---|
66 | ret = g_spawn_command_line_sync (command, NULL, NULL, &exit, NULL); |
---|
67 | g_assert (ret == TRUE); |
---|
68 | g_assert (exit == 0); |
---|
69 | g_print ("\"%s\" worked as expected.\n", command); |
---|
70 | g_free (command); |
---|
71 | } |
---|
72 | } |
---|
73 | #endif |
---|
74 | |
---|
75 | return 0; |
---|
76 | } else { |
---|
77 | gst_init (&argc, &argv); |
---|
78 | if (argc != 2) { |
---|
79 | g_print |
---|
80 | ("something funny happened to the command line arguments, aborting.\n"); |
---|
81 | return 1; |
---|
82 | } |
---|
83 | #ifndef GST_DISABLE_GST_DEBUG |
---|
84 | g_assert (gst_debug_remove_log_function (gst_debug_log_default) == 1); |
---|
85 | #endif |
---|
86 | GST_DEBUG_CATEGORY_INIT (cat, "cat", 0, "non-static category"); |
---|
87 | GST_DEBUG_CATEGORY_INIT (cat_static, "cat_static", 0, "static category"); |
---|
88 | switch (argv[1][0]) { |
---|
89 | case '0': |
---|
90 | g_assert (gst_debug_is_active () == FALSE); |
---|
91 | #ifndef GST_DISABLE_GST_DEBUG |
---|
92 | gst_debug_add_log_function (debug_not_reached, NULL); |
---|
93 | #endif |
---|
94 | GST_ERROR ("This will not be seen"); |
---|
95 | return 0; |
---|
96 | case '1': |
---|
97 | return gst_debug_is_colored ()? 1 : 0; |
---|
98 | case '2': |
---|
99 | g_assert (gst_debug_get_default_threshold () == 4); |
---|
100 | g_assert (gst_debug_category_get_threshold (cat) == 4); |
---|
101 | return 0; |
---|
102 | case '3': |
---|
103 | g_assert (gst_debug_get_default_threshold () == GST_LEVEL_DEFAULT); |
---|
104 | g_assert (gst_debug_category_get_threshold (cat) == 4); |
---|
105 | g_assert (gst_debug_category_get_threshold (cat_static) == 3); |
---|
106 | return 0; |
---|
107 | case '4': |
---|
108 | g_assert (gst_debug_get_default_threshold () == 4); |
---|
109 | g_assert (gst_debug_category_get_threshold (cat) == 4); |
---|
110 | g_assert (gst_debug_category_get_threshold (cat_static) == 5); |
---|
111 | return 0; |
---|
112 | default: |
---|
113 | g_print ("usupported command, aborting...\n"); |
---|
114 | return -1; |
---|
115 | } |
---|
116 | } |
---|
117 | g_assert_not_reached (); |
---|
118 | } |
---|