summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2022-10-10 18:29:50 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2022-10-10 18:29:50 +0000
commite701578c6f4e621c7c3c688b5a04bcbf0a67d930 (patch)
treedfb8e202d4fb756c895b6abd535f7c78674908ed
parent2290411e93b7c1ed224935a00f22cce3614dab28 (diff)
parenta91959e0d45cd624846d2f83edf0d10bae9fc2d0 (diff)
downloadlibglnx-e701578c6f4e621c7c3c688b5a04bcbf0a67d930.tar.gz
Merge branch 'wip/smcv/assert-true-false' into 'master'
backport-testutils: Add g_assert_true(), g_assert_false() See merge request GNOME/libglnx!44
-rw-r--r--glnx-backport-testutils.h8
-rw-r--r--tests/test-libglnx-testing.c4
-rw-r--r--tests/testing-helper.c14
3 files changed, 26 insertions, 0 deletions
diff --git a/glnx-backport-testutils.h b/glnx-backport-testutils.h
index 2febcc0..9c17f06 100644
--- a/glnx-backport-testutils.h
+++ b/glnx-backport-testutils.h
@@ -34,6 +34,14 @@
G_BEGIN_DECLS
+#ifndef g_assert_true /* added in 2.38 */
+#define g_assert_true(x) g_assert ((x))
+#endif
+
+#ifndef g_assert_false /* added in 2.38 */
+#define g_assert_false(x) g_assert (!(x))
+#endif
+
#ifndef g_assert_nonnull /* added in 2.40 */
#define g_assert_nonnull(x) g_assert (x != NULL)
#endif
diff --git a/tests/test-libglnx-testing.c b/tests/test-libglnx-testing.c
index 8435113..449481d 100644
--- a/tests/test-libglnx-testing.c
+++ b/tests/test-libglnx-testing.c
@@ -47,6 +47,8 @@ test_assertions (void)
const char * const strv2[] = {"one", "two", NULL};
GStatBuf statbuf;
+ g_assert_true (null == NULL);
+ g_assert_false (null != NULL);
g_assert_null (null);
g_assert_nonnull (nonnull);
g_assert_cmpmem (null, 0, null, 0);
@@ -64,6 +66,8 @@ test_assertion_failures (void)
{
static const char * const assertion_failures[] =
{
+ "true",
+ "false",
"nonnull",
"null",
"mem_null_nonnull",
diff --git a/tests/testing-helper.c b/tests/testing-helper.c
index 4e00fbe..7c2192c 100644
--- a/tests/testing-helper.c
+++ b/tests/testing-helper.c
@@ -49,6 +49,18 @@ test_messages (void)
}
static void
+test_assertion_failure_true (void)
+{
+ g_assert_true (null != NULL);
+}
+
+static void
+test_assertion_failure_false (void)
+{
+ g_assert_false (null == NULL);
+}
+
+static void
test_assertion_failure_nonnull (void)
{
g_assert_nonnull (null);
@@ -303,6 +315,8 @@ main (int argc,
{
/* Use -p to select a specific one of these */
#define T(x) g_test_add_func ("/assertion-failure/" #x, test_assertion_failure_ ## x)
+ T (true);
+ T (false);
T (nonnull);
T (null);
T (mem_null_nonnull);