check/gst/gstpad.c: add tests for valid pad naming
authorThomas Vander Stichele <thomas@apestaart.org>
Fri, 9 Sep 2005 14:34:43 +0000 (14:34 +0000)
committerThomas Vander Stichele <thomas@apestaart.org>
Fri, 9 Sep 2005 14:34:43 +0000 (14:34 +0000)
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
check/gst/gstpad.c
gst/check/gstcheck.c
gst/check/gstcheck.h
gst/gstpad.c
libs/gst/check/gstcheck.c
libs/gst/check/gstcheck.h
tests/check/gst/gstpad.c

index e839fb3..468937b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 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:
index 8a46721..4c172a0 100644 (file)
@@ -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;
 }
 
index 6d66a1b..f1c05a0 100644 (file)
@@ -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 */
index d5ea1c1..2626dc3 100644 (file)
@@ -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;                                                      \
index cc542cc..4315431 100644 (file)
@@ -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);
index 6d66a1b..f1c05a0 100644 (file)
@@ -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 */
index d5ea1c1..2626dc3 100644 (file)
@@ -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;                                                      \
index 8a46721..4c172a0 100644 (file)
@@ -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;
 }