1 | /* |
---|
2 | * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de> |
---|
3 | * |
---|
4 | * output.c: Test if the debugging output macros 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 | #include <gst/gst.h> |
---|
22 | |
---|
23 | GST_DEBUG_CATEGORY_STATIC (cat_default); |
---|
24 | #define GST_CAT_DEFAULT cat_default |
---|
25 | GST_DEBUG_CATEGORY_STATIC (cat2); |
---|
26 | |
---|
27 | static gint count = -1; |
---|
28 | static GstElement *pipeline; |
---|
29 | |
---|
30 | #ifndef GST_DISABLE_GST_DEBUG |
---|
31 | static void |
---|
32 | check_message (GstDebugCategory * category, GstDebugLevel level, |
---|
33 | const gchar * file, const gchar * function, gint line, GObject * object, |
---|
34 | GstDebugMessage * message, gpointer unused) |
---|
35 | { |
---|
36 | gint temp; |
---|
37 | |
---|
38 | /* these checks require count to be set right. So the order in the main |
---|
39 | funtion is actually important. */ |
---|
40 | /* <0 means no checks */ |
---|
41 | if (count < 0) |
---|
42 | return; |
---|
43 | |
---|
44 | g_print ("expecting \"%s\"...", (gchar *) message); |
---|
45 | /* level */ |
---|
46 | temp = (count % 5) + 1; |
---|
47 | g_assert (level == temp); |
---|
48 | /* category */ |
---|
49 | temp = (count % 10) / 5; |
---|
50 | g_assert (category == (temp ? cat2 : cat_default)); |
---|
51 | /* object */ |
---|
52 | temp = (count % 20) / 10; |
---|
53 | g_assert (object == (GObject *) (temp ? pipeline : NULL)); |
---|
54 | g_print ("[OK]\n"); |
---|
55 | } |
---|
56 | #endif |
---|
57 | |
---|
58 | gint |
---|
59 | main (gint argc, gchar * argv[]) |
---|
60 | { |
---|
61 | |
---|
62 | gst_init (&argc, &argv); |
---|
63 | |
---|
64 | GST_DEBUG_CATEGORY_INIT (cat_default, "GST_Check_default", 0, |
---|
65 | "default category for this test"); |
---|
66 | GST_DEBUG_CATEGORY_INIT (cat2, "GST_Check_2", 0, |
---|
67 | "second category for this test"); |
---|
68 | #ifndef GST_DISABLE_GST_DEBUG |
---|
69 | g_assert (gst_debug_remove_log_function (gst_debug_log_default) == 1); |
---|
70 | #endif |
---|
71 | gst_debug_add_log_function (check_message, NULL); |
---|
72 | |
---|
73 | count = 0; |
---|
74 | GST_ERROR ("This is an error."); |
---|
75 | ++count; |
---|
76 | GST_WARNING ("This is a warning."); |
---|
77 | ++count; |
---|
78 | GST_INFO ("This is an info message."); |
---|
79 | ++count; |
---|
80 | GST_DEBUG ("This is a debug message."); |
---|
81 | ++count; |
---|
82 | GST_LOG ("This is a log message."); |
---|
83 | ++count; |
---|
84 | GST_CAT_ERROR (cat2, "This is an error with category."); |
---|
85 | ++count; |
---|
86 | GST_CAT_WARNING (cat2, "This is a warning with category."); |
---|
87 | ++count; |
---|
88 | GST_CAT_INFO (cat2, "This is an info message with category."); |
---|
89 | ++count; |
---|
90 | GST_CAT_DEBUG (cat2, "This is a debug message with category."); |
---|
91 | ++count; |
---|
92 | GST_CAT_LOG (cat2, "This is a log message with category."); |
---|
93 | count = -1; |
---|
94 | pipeline = gst_element_factory_make ("pipeline", "testelement"); |
---|
95 | count = 10; |
---|
96 | GST_ERROR_OBJECT (pipeline, "This is an error with object."); |
---|
97 | ++count; |
---|
98 | GST_WARNING_OBJECT (pipeline, "This is a warning with object."); |
---|
99 | ++count; |
---|
100 | GST_INFO_OBJECT (pipeline, "This is an info message with object."); |
---|
101 | ++count; |
---|
102 | GST_DEBUG_OBJECT (pipeline, "This is a debug message with object."); |
---|
103 | ++count; |
---|
104 | GST_LOG_OBJECT (pipeline, "This is a log message with object."); |
---|
105 | ++count; |
---|
106 | GST_CAT_ERROR_OBJECT (cat2, pipeline, |
---|
107 | "This is an error with category and object."); |
---|
108 | ++count; |
---|
109 | GST_CAT_WARNING_OBJECT (cat2, pipeline, |
---|
110 | "This is a warning with category and object."); |
---|
111 | ++count; |
---|
112 | GST_CAT_INFO_OBJECT (cat2, pipeline, |
---|
113 | "This is an info message with category and object."); |
---|
114 | ++count; |
---|
115 | GST_CAT_DEBUG_OBJECT (cat2, pipeline, |
---|
116 | "This is a debug message with category and object."); |
---|
117 | ++count; |
---|
118 | GST_CAT_LOG_OBJECT (cat2, pipeline, |
---|
119 | "This is a log message with category and object."); |
---|
120 | count = -1; |
---|
121 | |
---|
122 | #ifndef GST_DISABLE_GST_DEBUG |
---|
123 | g_assert (gst_debug_remove_log_function (check_message) == 1); |
---|
124 | #endif |
---|
125 | |
---|
126 | return 0; |
---|
127 | } |
---|