2005-09-09 Thomas Vander Stichele <thomas at apestaart dot org>
+ * check/gst/gstpad.c: (GST_START_TEST), (name_is_valid),
+ (gst_pad_suite):
+ add tests for valid pad naming
+ * gst/check/gstcheck.c: (gst_check_log_message_func),
+ (gst_check_log_critical_func):
+ add ASSERT_WARNING
+ remove printing of code, it is fragile when the code contains
+ % and the line number is enough info
+ * gst/check/gstcheck.h:
+ * gst/gstpad.c: (gst_pad_template_new):
+ fix memleaks
+
+2005-09-09 Thomas Vander Stichele <thomas at apestaart dot org>
+
* configure.ac:
say what CHECK flags we use
* docs/libs/gstreamer-libs.types:
GST_END_TEST;
+static gboolean
+name_is_valid (const gchar * name, GstPadPresence presence)
+{
+ GstPadTemplate *new;
+
+ new = gst_pad_template_new (name, GST_PAD_SRC, presence, GST_CAPS_ANY);
+ if (new) {
+ gst_object_unref (GST_OBJECT (new));
+ return TRUE;
+ }
+ return FALSE;
+}
+
+GST_START_TEST (test_name_is_valid)
+{
+ gboolean result = FALSE;
+
+ fail_unless (name_is_valid ("src", GST_PAD_ALWAYS));
+ ASSERT_WARNING (name_is_valid ("src%", GST_PAD_ALWAYS));
+ ASSERT_WARNING (result = name_is_valid ("src%d", GST_PAD_ALWAYS));
+ fail_if (result);
+
+ fail_unless (name_is_valid ("src", GST_PAD_REQUEST));
+ ASSERT_WARNING (name_is_valid ("src%s%s", GST_PAD_REQUEST));
+ ASSERT_WARNING (name_is_valid ("src%c", GST_PAD_REQUEST));
+ ASSERT_WARNING (name_is_valid ("src%", GST_PAD_REQUEST));
+ ASSERT_WARNING (name_is_valid ("src%dsrc", GST_PAD_REQUEST));
+
+ fail_unless (name_is_valid ("src", GST_PAD_SOMETIMES));
+ fail_unless (name_is_valid ("src%c", GST_PAD_SOMETIMES));
+}
+
+GST_END_TEST;
+
+
Suite *
gst_pad_suite (void)
{
tcase_add_test (tc_chain, test_refcount);
tcase_add_test (tc_chain, test_get_allowed_caps);
tcase_add_test (tc_chain, test_link_unlink_threaded);
+ tcase_add_test (tc_chain, test_name_is_valid);
return s;
}
gboolean _gst_check_debug = FALSE;
gboolean _gst_check_raised_critical = FALSE;
+gboolean _gst_check_raised_warning = FALSE;
gboolean _gst_check_expecting_log = FALSE;
void gst_check_log_message_func
const gchar * message, gpointer user_data)
{
if (_gst_check_debug) {
- g_print (message);
+ g_print ("%s", message);
}
}
if (log_level & G_LOG_LEVEL_CRITICAL)
_gst_check_raised_critical = TRUE;
+ if (log_level & G_LOG_LEVEL_WARNING)
+ _gst_check_raised_warning = TRUE;
}
/* initialize GStreamer testing */
*/
extern gboolean _gst_check_threads_running;
extern gboolean _gst_check_raised_critical;
+extern gboolean _gst_check_raised_warning;
extern gboolean _gst_check_expecting_log;
/* global variables used in test methods */
_gst_check_raised_critical = FALSE; \
code; \
_fail_unless (_gst_check_raised_critical, __FILE__, __LINE__, \
- "Expected g_critical, got nothing: '"#code"'"); \
+ "Expected g_critical, got nothing"); \
_gst_check_expecting_log = FALSE; \
} G_STMT_END
+#define ASSERT_WARNING(code) \
+G_STMT_START { \
+ _gst_check_expecting_log = TRUE; \
+ _gst_check_raised_warning = FALSE; \
+ code; \
+ _fail_unless (_gst_check_raised_warning, __FILE__, __LINE__, \
+ "Expected g_warning, got nothing"); \
+ _gst_check_expecting_log = FALSE; \
+} G_STMT_END
+
+
#define ASSERT_OBJECT_REFCOUNT(object, name, value) \
G_STMT_START { \
int rc; \
G_OBJECT_CLASS (padtemplate_parent_class)->dispose (object);
}
-/* ALWAYS padtemplates cannot have conversion specifications, it doesn't make
- * sense.
+/* ALWAYS padtemplates cannot have conversion specifications (like src_%d),
+ * since it doesn't make sense.
* SOMETIMES padtemplates can do whatever they want, they are provided by the
* element.
* REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the
g_return_val_if_fail (presence == GST_PAD_ALWAYS
|| presence == GST_PAD_SOMETIMES || presence == GST_PAD_REQUEST, NULL);
- if (!name_is_valid (name_template, presence))
+ if (!name_is_valid (name_template, presence)) {
+ gst_caps_unref (caps);
return NULL;
+ }
new = g_object_new (gst_pad_template_get_type (),
"name", name_template, NULL);
gboolean _gst_check_debug = FALSE;
gboolean _gst_check_raised_critical = FALSE;
+gboolean _gst_check_raised_warning = FALSE;
gboolean _gst_check_expecting_log = FALSE;
void gst_check_log_message_func
const gchar * message, gpointer user_data)
{
if (_gst_check_debug) {
- g_print (message);
+ g_print ("%s", message);
}
}
if (log_level & G_LOG_LEVEL_CRITICAL)
_gst_check_raised_critical = TRUE;
+ if (log_level & G_LOG_LEVEL_WARNING)
+ _gst_check_raised_warning = TRUE;
}
/* initialize GStreamer testing */
*/
extern gboolean _gst_check_threads_running;
extern gboolean _gst_check_raised_critical;
+extern gboolean _gst_check_raised_warning;
extern gboolean _gst_check_expecting_log;
/* global variables used in test methods */
_gst_check_raised_critical = FALSE; \
code; \
_fail_unless (_gst_check_raised_critical, __FILE__, __LINE__, \
- "Expected g_critical, got nothing: '"#code"'"); \
+ "Expected g_critical, got nothing"); \
_gst_check_expecting_log = FALSE; \
} G_STMT_END
+#define ASSERT_WARNING(code) \
+G_STMT_START { \
+ _gst_check_expecting_log = TRUE; \
+ _gst_check_raised_warning = FALSE; \
+ code; \
+ _fail_unless (_gst_check_raised_warning, __FILE__, __LINE__, \
+ "Expected g_warning, got nothing"); \
+ _gst_check_expecting_log = FALSE; \
+} G_STMT_END
+
+
#define ASSERT_OBJECT_REFCOUNT(object, name, value) \
G_STMT_START { \
int rc; \
GST_END_TEST;
+static gboolean
+name_is_valid (const gchar * name, GstPadPresence presence)
+{
+ GstPadTemplate *new;
+
+ new = gst_pad_template_new (name, GST_PAD_SRC, presence, GST_CAPS_ANY);
+ if (new) {
+ gst_object_unref (GST_OBJECT (new));
+ return TRUE;
+ }
+ return FALSE;
+}
+
+GST_START_TEST (test_name_is_valid)
+{
+ gboolean result = FALSE;
+
+ fail_unless (name_is_valid ("src", GST_PAD_ALWAYS));
+ ASSERT_WARNING (name_is_valid ("src%", GST_PAD_ALWAYS));
+ ASSERT_WARNING (result = name_is_valid ("src%d", GST_PAD_ALWAYS));
+ fail_if (result);
+
+ fail_unless (name_is_valid ("src", GST_PAD_REQUEST));
+ ASSERT_WARNING (name_is_valid ("src%s%s", GST_PAD_REQUEST));
+ ASSERT_WARNING (name_is_valid ("src%c", GST_PAD_REQUEST));
+ ASSERT_WARNING (name_is_valid ("src%", GST_PAD_REQUEST));
+ ASSERT_WARNING (name_is_valid ("src%dsrc", GST_PAD_REQUEST));
+
+ fail_unless (name_is_valid ("src", GST_PAD_SOMETIMES));
+ fail_unless (name_is_valid ("src%c", GST_PAD_SOMETIMES));
+}
+
+GST_END_TEST;
+
+
Suite *
gst_pad_suite (void)
{
tcase_add_test (tc_chain, test_refcount);
tcase_add_test (tc_chain, test_get_allowed_caps);
tcase_add_test (tc_chain, test_link_unlink_threaded);
+ tcase_add_test (tc_chain, test_name_is_valid);
return s;
}