From 9cc64e4bec6d73c38bdfbba2a4c68e3aaa8bdccd Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Fri, 9 Sep 2005 14:34:43 +0000 Subject: [PATCH] check/gst/gstpad.c: add tests for valid pad naming Original commit message from CVS: * 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 --- ChangeLog | 14 ++++++++++++++ check/gst/gstpad.c | 36 ++++++++++++++++++++++++++++++++++++ gst/check/gstcheck.c | 5 ++++- gst/check/gstcheck.h | 14 +++++++++++++- gst/gstpad.c | 8 +++++--- libs/gst/check/gstcheck.c | 5 ++++- libs/gst/check/gstcheck.h | 14 +++++++++++++- tests/check/gst/gstpad.c | 36 ++++++++++++++++++++++++++++++++++++ 8 files changed, 125 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index e839fb3433..468937bfa6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2005-09-09 Thomas Vander Stichele + + * 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 * configure.ac: diff --git a/check/gst/gstpad.c b/check/gst/gstpad.c index 8a467210d1..4c172a0b66 100644 --- a/check/gst/gstpad.c +++ b/check/gst/gstpad.c @@ -193,6 +193,41 @@ GST_START_TEST (test_get_allowed_caps) 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) { @@ -207,6 +242,7 @@ 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; } diff --git a/gst/check/gstcheck.c b/gst/check/gstcheck.c index 6d66a1b0fd..f1c05a0570 100644 --- a/gst/check/gstcheck.c +++ b/gst/check/gstcheck.c @@ -45,6 +45,7 @@ GCond *sync_cond; /* used to synchronize all threads and main thre 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 @@ -52,7 +53,7 @@ void gst_check_log_message_func const gchar * message, gpointer user_data) { if (_gst_check_debug) { - g_print (message); + g_print ("%s", message); } } @@ -71,6 +72,8 @@ void gst_check_log_critical_func 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 */ diff --git a/gst/check/gstcheck.h b/gst/check/gstcheck.h index d5ea1c18a9..2626dc3a79 100644 --- a/gst/check/gstcheck.h +++ b/gst/check/gstcheck.h @@ -41,6 +41,7 @@ GST_DEBUG_CATEGORY_EXTERN (check_debug); */ 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 */ @@ -203,10 +204,21 @@ G_STMT_START { \ _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; \ diff --git a/gst/gstpad.c b/gst/gstpad.c index cc542cca45..4315431b13 100644 --- a/gst/gstpad.c +++ b/gst/gstpad.c @@ -3541,8 +3541,8 @@ gst_pad_template_dispose (GObject * object) 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 @@ -3636,8 +3636,10 @@ gst_pad_template_new (const gchar * name_template, 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); diff --git a/libs/gst/check/gstcheck.c b/libs/gst/check/gstcheck.c index 6d66a1b0fd..f1c05a0570 100644 --- a/libs/gst/check/gstcheck.c +++ b/libs/gst/check/gstcheck.c @@ -45,6 +45,7 @@ GCond *sync_cond; /* used to synchronize all threads and main thre 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 @@ -52,7 +53,7 @@ void gst_check_log_message_func const gchar * message, gpointer user_data) { if (_gst_check_debug) { - g_print (message); + g_print ("%s", message); } } @@ -71,6 +72,8 @@ void gst_check_log_critical_func 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 */ diff --git a/libs/gst/check/gstcheck.h b/libs/gst/check/gstcheck.h index d5ea1c18a9..2626dc3a79 100644 --- a/libs/gst/check/gstcheck.h +++ b/libs/gst/check/gstcheck.h @@ -41,6 +41,7 @@ GST_DEBUG_CATEGORY_EXTERN (check_debug); */ 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 */ @@ -203,10 +204,21 @@ G_STMT_START { \ _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; \ diff --git a/tests/check/gst/gstpad.c b/tests/check/gst/gstpad.c index 8a467210d1..4c172a0b66 100644 --- a/tests/check/gst/gstpad.c +++ b/tests/check/gst/gstpad.c @@ -193,6 +193,41 @@ GST_START_TEST (test_get_allowed_caps) 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) { @@ -207,6 +242,7 @@ 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; }