From 133511040930ba119ee23cea936dd6a7210f08bb Mon Sep 17 00:00:00 2001 From: Havard Graff Date: Tue, 6 Nov 2018 10:20:17 +0100 Subject: [PATCH] tests: fix tests when compiling with glib_checks=disabled We won't be able to do ASSERT_CRITICAL, but the main body of the tests are still valid, and given we ship GStreamer with this configuration, it is important to be able to run some tests against it. --- configure.ac | 10 ++++++++++ gst/gstconfig.h.in | 22 ++++++++++++++++++++++ gst/meson.build | 4 ++++ libs/gst/check/gstcheck.h | 5 +++++ tests/check/gst/gstcaps.c | 4 +--- tests/check/gst/gstghostpad.c | 1 + tests/check/gst/gstobject.c | 1 + tests/check/gst/gststructure.c | 4 +++- tests/check/gst/gsturi.c | 2 +- tests/check/gst/gstvalue.c | 23 ++++++++++++++++------- tests/check/libs/adapter.c | 2 +- 11 files changed, 65 insertions(+), 13 deletions(-) diff --git a/configure.ac b/configure.ac index 2bb7430..4f6aaac 100644 --- a/configure.ac +++ b/configure.ac @@ -118,6 +118,16 @@ AC_SUBST(GST_REGISTRY_DOC_TYPES) AG_GST_CHECK_SUBSYSTEM_DISABLE(PLUGIN,[plugin]) AM_CONDITIONAL(GST_DISABLE_PLUGIN, test "x$GST_DISABLE_PLUGIN" = "xyes") +GST_DISABLE_CAST_CHECKS_DEFINE=0 +AC_SUBST(GST_DISABLE_CAST_CHECKS_DEFINE) + +GST_DISABLE_GLIB_ASSERTS_DEFINE=0 +AC_SUBST(GST_DISABLE_GLIB_ASSERTS_DEFINE) + +GST_DISABLE_GLIB_CHECKS_DEFINE=0 +AC_SUBST(GST_DISABLE_GLIB_CHECKS_DEFINE) + + AG_GST_ARG_DEBUG AG_GST_ARG_PROFILING AG_GST_ARG_VALGRIND diff --git a/gst/gstconfig.h.in b/gst/gstconfig.h.in index 41bbdde..7be1b19 100644 --- a/gst/gstconfig.h.in +++ b/gst/gstconfig.h.in @@ -91,6 +91,28 @@ */ @GST_DISABLE_REGISTRY_DEFINE@ +/** + * GST_DISABLE_CAST_CHECKS: + * + * Disable run-time GObject cast checks + */ +#define GST_DISABLE_CAST_CHECKS @GST_DISABLE_CAST_CHECKS_DEFINE@ + +/** + * GST_DISABLE_GLIB_ASSERTS: + * + * Disable GLib assertion + */ +#define GST_DISABLE_GLIB_ASSERTS @GST_DISABLE_GLIB_ASSERTS_DEFINE@ + +/** + * GST_DISABLE_GLIB_CHECKS: + * + * Disable GLib checks such as API guards + */ +#define GST_DISABLE_GLIB_CHECKS @GST_DISABLE_GLIB_CHECKS_DEFINE@ + + /* FIXME: test and document these! */ /* Configures the use of external plugins */ @GST_DISABLE_PLUGIN_DEFINE@ diff --git a/gst/meson.build b/gst/meson.build index 4ad2170..145e97a 100644 --- a/gst/meson.build +++ b/gst/meson.build @@ -180,6 +180,10 @@ else gst_cdata.set('GST_DISABLE_PARSE_DEFINE', '#define GST_DISABLE_PARSE 1') endif +gst_cdata.set10('GST_DISABLE_CAST_CHECKS_DEFINE', cast_checks.disabled()) +gst_cdata.set10('GST_DISABLE_GLIB_ASSERTS_DEFINE', glib_asserts.disabled()) +gst_cdata.set10('GST_DISABLE_GLIB_CHECKS_DEFINE', glib_checks.disabled()) + # FIXME: add --disable-plugin option? gst_cdata.set('GST_DISABLE_PLUGIN_DEFINE', '#undef GST_DISABLE_PLUGIN') diff --git a/libs/gst/check/gstcheck.h b/libs/gst/check/gstcheck.h index cc6d5f3..f59f400 100644 --- a/libs/gst/check/gstcheck.h +++ b/libs/gst/check/gstcheck.h @@ -617,6 +617,10 @@ G_STMT_START { \ #define THREAD_TEST_RUNNING() (!!_gst_check_threads_running) /* additional assertions */ + +#if GST_DISABLE_GLIB_CHECKS +#define ASSERT_CRITICAL(code) +#else #define ASSERT_CRITICAL(code) \ G_STMT_START { \ _gst_check_expecting_log = TRUE; \ @@ -627,6 +631,7 @@ G_STMT_START { \ "Expected g_critical, got nothing", NULL); \ _gst_check_expecting_log = FALSE; \ } G_STMT_END +#endif /* GST_DISABLE_GLIB_CHECKS */ #define ASSERT_WARNING(code) \ G_STMT_START { \ diff --git a/tests/check/gst/gstcaps.c b/tests/check/gst/gstcaps.c index a85a033..acceb6f 100644 --- a/tests/check/gst/gstcaps.c +++ b/tests/check/gst/gstcaps.c @@ -1102,19 +1102,17 @@ GST_END_TEST; GST_START_TEST (test_broken) { - GstCaps *c1; + GstCaps *c1 = NULL; /* NULL is not valid for media_type */ ASSERT_CRITICAL (c1 = gst_caps_new_simple (NULL, "field", G_TYPE_INT, 1, NULL)); fail_if (c1); -#ifndef G_DISABLE_CHECKS /* such a name is not valid, see gst_structure_validate_name() */ ASSERT_CRITICAL (c1 = gst_caps_new_simple ("1#@abc", "field", G_TYPE_INT, 1, NULL)); fail_if (c1); -#endif } GST_END_TEST; diff --git a/tests/check/gst/gstghostpad.c b/tests/check/gst/gstghostpad.c index 087d034..cefd183 100644 --- a/tests/check/gst/gstghostpad.c +++ b/tests/check/gst/gstghostpad.c @@ -949,6 +949,7 @@ GST_START_TEST (test_ghost_pads_src_link_unlink) fail_unless (unlinked_count2 == 0); /* this should fail with a critial */ + dummy = NULL; ASSERT_CRITICAL (dummy = gst_ghost_pad_new ("ghostpad", srcpad)); fail_unless (dummy == NULL); fail_unless (linked_count1 == 1); diff --git a/tests/check/gst/gstobject.c b/tests/check/gst/gstobject.c index 96ad284..4acb0d3 100644 --- a/tests/check/gst/gstobject.c +++ b/tests/check/gst/gstobject.c @@ -427,6 +427,7 @@ GST_START_TEST (test_fake_object_parentage) parent = gst_object_get_parent (object1); fail_if (parent != NULL, "GstFakeObject has parent"); /* try to set a NULL parent, this should give a warning */ + result = FALSE; ASSERT_CRITICAL (result = gst_object_set_parent (object1, NULL)); fail_if (result, "GstFakeObject accepted NULL parent"); /* try to set itself as parent, we expect a warning here */ diff --git a/tests/check/gst/gststructure.c b/tests/check/gst/gststructure.c index 07fea67..15815ef 100644 --- a/tests/check/gst/gststructure.c +++ b/tests/check/gst/gststructure.c @@ -188,6 +188,7 @@ GST_START_TEST (test_from_string) gst_structure_free (structure); s = "0.10:decoder-video/mpeg, abc=(boolean)false"; + structure = NULL; ASSERT_CRITICAL (structure = gst_structure_from_string (s, NULL)); fail_unless (structure == NULL, "Could not get structure from string %s", s); @@ -223,7 +224,7 @@ GST_END_TEST; GST_START_TEST (test_to_string) { - GstStructure *st1; + GstStructure *st1 = NULL; ASSERT_CRITICAL (st1 = gst_structure_new_empty ("Foo\nwith-newline")); fail_unless (st1 == NULL); @@ -426,6 +427,7 @@ GST_START_TEST (test_structure_new) ("0.10:decoder-video/mpeg"))); /* make sure we bail out correctly in case of an error or if parsing fails */ + s = NULL; ASSERT_CRITICAL (s = gst_structure_new ("^joo\nba\ndoo^", "abc", G_TYPE_BOOLEAN, FALSE, NULL)); fail_unless (s == NULL); diff --git a/tests/check/gst/gsturi.c b/tests/check/gst/gsturi.c index fa87c7c..d5ffe44 100644 --- a/tests/check/gst/gsturi.c +++ b/tests/check/gst/gsturi.c @@ -85,7 +85,7 @@ GST_END_TEST; #ifndef GST_REMOVE_DEPRECATED GST_START_TEST (test_gst_uri_construct) { - gchar *l; + gchar *l = NULL; /* URI with no protocol or empty protocol should return empty string */ ASSERT_CRITICAL (l = gst_uri_construct (NULL, "/path/to/file")); diff --git a/tests/check/gst/gstvalue.c b/tests/check/gst/gstvalue.c index 35bd23c..841a4c8 100644 --- a/tests/check/gst/gstvalue.c +++ b/tests/check/gst/gstvalue.c @@ -2954,16 +2954,19 @@ GST_START_TEST (test_deserialize_int_range) str = g_strdup_printf ("foo/bar, range=[ 1, %" G_GINT64_FORMAT " ];", (gint64) G_MAXINT + 1); + s = NULL; ASSERT_CRITICAL (s = gst_structure_from_string (str, &end)); g_free (str); - gst_structure_free (s); + if (s) + gst_structure_free (s); str = g_strdup_printf ("foo/bar, range=[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT " ];", (gint64) G_MAXINT, (gint64) G_MAXINT + 1); ASSERT_CRITICAL (s = gst_structure_from_string (str, NULL)); end = NULL; g_free (str); - gst_structure_free (s); + if (s) + gst_structure_free (s); /* check a valid int64_range deserialization. Those ranges need to * be explicit about their storage type. */ @@ -2985,10 +2988,13 @@ GST_START_TEST (test_deserialize_int_range) str = g_strdup_printf ("foo/bar, range=(gint64)[ 1, %" G_GUINT64_FORMAT " ];", (guint64) G_MAXINT64 + 1); + s = NULL; ASSERT_CRITICAL (s = gst_structure_from_string (str, &end)); - fail_unless (*end == '\0'); - gst_structure_free (s); - end = NULL; + if (s) { + fail_unless (*end == '\0'); + gst_structure_free (s); + end = NULL; + } g_free (str); /* check invalid int64_range deserialization into a int64_range */ @@ -2997,7 +3003,8 @@ GST_START_TEST (test_deserialize_int_range) G_GUINT64_FORMAT " ];", (gint64) G_MAXINT, (guint64) G_MAXINT64 + 1); ASSERT_CRITICAL (s = gst_structure_from_string (str, NULL)); g_free (str); - gst_structure_free (s); + if (s) + gst_structure_free (s); /* check invalid int64_range deserialization into a int_range */ str = @@ -3065,6 +3072,7 @@ GST_START_TEST (test_stepped_int_range_parsing) fail_unless (s != NULL); fail_unless (*end == '\0'); gst_structure_free (s); + s = NULL; g_free (str); } @@ -3072,7 +3080,8 @@ GST_START_TEST (test_stepped_int_range_parsing) for (n = 0; n < G_N_ELEMENTS (bad_ranges); ++n) { str = g_strdup_printf ("foo/bar, range=%s", bad_ranges[n]); ASSERT_CRITICAL (s = gst_structure_from_string (str, &end)); - gst_structure_free (s); + if (s) + gst_structure_free (s); g_free (str); } } diff --git a/tests/check/libs/adapter.c b/tests/check/libs/adapter.c index cedb966..3b38f9c 100644 --- a/tests/check/libs/adapter.c +++ b/tests/check/libs/adapter.c @@ -40,7 +40,7 @@ GST_START_TEST (test_peek1) GstBuffer *buffer; guint avail; GstMapInfo info; - const guint8 *data1, *data2, *idata; + const guint8 *data1 = NULL, *data2 = NULL, *idata = NULL; adapter = gst_adapter_new (); fail_if (adapter == NULL); -- 2.7.4