3 * Unit tests for GstTracerRecord
5 * Copyright (C) 2016 Stefan Sauer <ensonic@users.sf.net>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
23 #include <gst/check/gstcheck.h>
24 #include <gst/gsttracerrecord.h>
26 static GList *messages; /* NULL */
27 static gboolean save_messages; /* FALSE */
30 tracer_log_func (GstDebugCategory * category,
31 GstDebugLevel level, const gchar * file, const gchar * function,
32 gint line, GObject * object, GstDebugMessage * message, gpointer unused)
36 if (!save_messages || level != GST_LEVEL_TRACE ||
37 !g_str_equal (category->name, "GST_TRACER")) {
41 dbg_msg = gst_debug_message_get (message);
42 fail_unless (dbg_msg != NULL);
44 messages = g_list_append (messages, g_strdup (dbg_msg));
50 gst_debug_remove_log_function (gst_debug_log_default);
51 gst_debug_add_log_function (tracer_log_func, NULL, NULL);
52 gst_debug_set_threshold_for_name ("GST_TRACER", GST_LEVEL_TRACE);
54 save_messages = FALSE;
60 save_messages = FALSE;
61 gst_debug_set_threshold_for_name ("GST_TRACER", GST_LEVEL_NONE);
62 gst_debug_add_log_function (gst_debug_log_default, NULL, NULL);
63 gst_debug_remove_log_function (tracer_log_func);
64 g_list_foreach (messages, (GFunc) g_free, NULL);
69 GST_START_TEST (serialize_message_logging)
75 tr = gst_tracer_record_new (gst_structure_new ("test.class",
76 "string", GST_TYPE_STRUCTURE, gst_structure_new ("value",
77 "type", G_TYPE_GTYPE, G_TYPE_STRING,
83 gst_tracer_record_log (tr, "test");
84 save_messages = FALSE;
86 fail_unless_equals_int (g_list_length (messages), 1);
87 str = (gchar *) messages->data;
88 fail_unless (str != NULL);
94 GST_START_TEST (serialize_static_record)
102 GstPadDirection enum_val;
105 tr = gst_tracer_record_new (gst_structure_new ("test.class",
106 "string", GST_TYPE_STRUCTURE, gst_structure_new ("value",
107 "type", G_TYPE_GTYPE, G_TYPE_STRING,
109 "int", GST_TYPE_STRUCTURE, gst_structure_new ("value",
110 "type", G_TYPE_GTYPE, G_TYPE_INT,
112 "bool", GST_TYPE_STRUCTURE, gst_structure_new ("value",
113 "type", G_TYPE_GTYPE, G_TYPE_BOOLEAN,
115 "enum", GST_TYPE_STRUCTURE, gst_structure_new ("value",
116 "type", G_TYPE_GTYPE, GST_TYPE_PAD_DIRECTION,
121 save_messages = TRUE;
122 gst_tracer_record_log (tr, "test", 1, TRUE, GST_PAD_SRC);
123 save_messages = FALSE;
125 str = (gchar *) messages->data;
126 GST_INFO ("serialized to '%s'", str);
128 s = gst_structure_from_string (str, NULL);
129 fail_unless (s != NULL);
131 fail_unless_equals_string (gst_structure_get_name (s), "test");
133 fail_unless (gst_structure_get (s,
134 "string", G_TYPE_STRING, &str_val,
135 "int", G_TYPE_INT, &int_val,
136 "bool", G_TYPE_BOOLEAN, &bool_val,
137 "enum", GST_TYPE_PAD_DIRECTION, &enum_val, NULL));
138 fail_unless_equals_int (int_val, 1);
139 fail_unless_equals_string (str_val, "test");
140 fail_unless_equals_int (bool_val, TRUE);
141 fail_unless_equals_int (enum_val, GST_PAD_SRC);
143 gst_structure_free (s);
150 gst_tracer_record_suite (void)
152 Suite *s = suite_create ("GstTracerRecord");
153 TCase *tc_chain = tcase_create ("record");
155 suite_add_tcase (s, tc_chain);
156 tcase_add_checked_fixture (tc_chain, setup, cleanup);
157 tcase_add_test (tc_chain, serialize_message_logging);
158 tcase_add_test (tc_chain, serialize_static_record);
160 /* FIXME: add more tests, e.g. enums, pointer types and optional fields */
165 GST_CHECK_MAIN (gst_tracer_record);