mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-24 08:08:22 +00:00
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
This commit is contained in:
parent
b92de88031
commit
9cc64e4bec
8 changed files with 125 additions and 7 deletions
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
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:
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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; \
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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; \
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue