From f3d7d1f96fba76c275df990b97d4c0995a70ee4b Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 26 Mar 2023 10:03:05 -0700 Subject: test: Convert test code to use glib test helpers Signed-off-by: Alan Coopersmith --- .gitlab-ci.yml | 9 +++++++-- configure.ac | 8 +++++++- test/EditResStream.c | 48 ++++++++++++++++++++++++++++++------------------ test/Makefile.am | 25 +++++++++++++++++++++++-- test/tap-test | 2 ++ 5 files changed, 69 insertions(+), 23 deletions(-) create mode 100755 test/tap-test diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ef25a82..4d2f615 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -32,8 +32,8 @@ variables: # The tag should be updated each time the list of packages is updated. # Changing a tag forces the associated image to be rebuilt. # Note: the tag has no meaning, we use a date format purely for readability - FDO_DISTRIBUTION_TAG: '2023-02-16.0' - FDO_DISTRIBUTION_PACKAGES: 'git gcc pkgconf autoconf automake libtool make xutils-dev x11proto-dev libx11-dev libxext-dev libxt-dev xmlto xorg-sgml-doctools w3m xsltproc fop xz-utils' + FDO_DISTRIBUTION_TAG: '2023-03-27.0' + FDO_DISTRIBUTION_PACKAGES: 'git gcc pkgconf autoconf automake libtool make xutils-dev x11proto-dev libx11-dev libxext-dev libxt-dev xmlto xorg-sgml-doctools w3m xsltproc fop xz-utils libglib2.0-dev' # @@ -98,3 +98,8 @@ build: - make check - make distcheck - popd > /dev/null + artifacts: + when: always + reports: + paths: + - _builddir/test/*.log diff --git a/configure.ac b/configure.ac index f02fade..48c761a 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Initialize Autoconf AC_PREREQ([2.70]) AC_INIT([libXmu], [1.1.4], - [https://gitlab.freedesktop.org/xorg/lib/libxmu/-/issues], [libXmu]) + [https://gitlab.freedesktop.org/xorg/lib/libxmu/-/issues/], [libXmu]) AC_CONFIG_SRCDIR([Makefile.am]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIRS([m4]) @@ -43,6 +43,12 @@ XORG_LINT_LIBRARY([Xmu]) LINTLIBUU=`echo $LINTLIB | sed s/Xmu/Xmuu/` AC_SUBST(LINTLIBUU) +# --enable-unit-tests +AC_REQUIRE_AUX_FILE([tap-driver.sh]) +XORG_ENABLE_UNIT_TESTS +XORG_WITH_GLIB([2.46]) +XORG_MEMORY_CHECK_FLAGS + AC_CONFIG_FILES([Makefile doc/Makefile include/Makefile diff --git a/test/EditResStream.c b/test/EditResStream.c index 4f35a37..b8a3ff3 100644 --- a/test/EditResStream.c +++ b/test/EditResStream.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. + * Copyright (c) 2022, 2023, Oracle and/or its affiliates. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -22,14 +22,16 @@ */ /* Test code for ProtocolStream Get/Put functions in src/EditResCom.c */ +#include "config.h" #include -#include +#include static const char *test_string = "\tIt was a dark and stormy night...\n"; #define FillBuffer(d, v) memset(d, v, sizeof(d)) -int main(void) +static void +test_EditResStream(void) { ProtocolStream ps = { 0, 0, NULL, NULL, NULL }; unsigned char c; @@ -60,40 +62,50 @@ int main(void) ps.current = ps.top; res = _XEditResGet8(&ps, &c); - assert(res == True); - assert(c == 8); + g_assert_cmpint(res, ==, True); + g_assert_cmpint(c, ==, 8); res = _XEditResGet16(&ps, &s); - assert(res == True); - assert(s == 16); + g_assert_cmpint(res, ==, True); + g_assert_cmpint(s, ==, 16); res = _XEditResGet16(&ps, &s); - assert(res == True); - assert(s == 0xface); + g_assert_cmpint(res, ==, True); + g_assert_cmpint(s, ==, 0xface); /* set the full value so we can make sure that in 64-bit mode we write to the full long value, not just 32-bits of it. */ memset(&l, 0x0f, sizeof(l)); res = _XEditResGet32(&ps, &l); - assert(res == True); - assert(l == 32); + g_assert_cmpint(res, ==, True); + g_assert_cmpint(l, ==, 32); memset(&l, 0x0f, sizeof(l)); res = _XEditResGet32(&ps, &l); - assert(res == True); - assert(l == 0xbabeface); + g_assert_cmpint(res, ==, True); + g_assert_cmpint(l, ==, 0xbabeface); res = _XEditResGetString8(&ps, &str); - assert(res == True); - assert(strcmp(str, test_string) == 0); + g_assert_cmpint(res, ==, True); + g_assert_cmpstr(str, ==, test_string); XtFree(str); str = NULL; res = _XEditResGetWidgetInfo(&ps, &out); - assert(res == True); - assert(memcmp(ids, out.ids, sizeof(ids)) == 0); + g_assert_cmpint(res, ==, True); + g_assert_cmpmem(ids, sizeof(ids), out.ids, out.num_widgets * sizeof(long)); XtFree((char *) out.ids); out.ids = NULL; +} + +int +main(int argc, char** argv) +{ + g_test_init(&argc, &argv, NULL); + g_test_bug_base(PACKAGE_BUGREPORT); + + g_test_add_func("/EditResCom/ProtocolStream", + test_EditResStream); - return 0; + return g_test_run(); } diff --git a/test/Makefile.am b/test/Makefile.am index 955c0a6..6a1dbbf 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright (c) 2022, Oracle and/or its affiliates. +# Copyright (c) 2022, 2023, Oracle and/or its affiliates. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -21,10 +21,31 @@ # DEALINGS IN THE SOFTWARE. # +if ENABLE_UNIT_TESTS +if HAVE_GLIB + AM_CPPFLAGS = -D_CONST_X_STRING -I${top_srcdir}/include +AM_CFLAGS = $(CWARNFLAGS) $(XMU_CFLAGS) $(GLIB_CFLAGS) + +XMU_TEST_LIBS = ${top_builddir}/src/libXmu.la $(XMU_LIBS) $(GLIB_LIBS) +XMUU_TEST_LIBS = ${top_builddir}/src/libXmuu.la $(XMUU_LIBS) $(GLIB_LIBS) check_PROGRAMS = EditResStream TESTS = $(check_PROGRAMS) +TESTS_ENVIRONMENT = $(MALLOC_DEBUG_ENV) +TESTS_ENVIRONMENT += G_TEST_SRCDIR="$(abs_srcdir)" +TESTS_ENVIRONMENT += G_TEST_BUILDDIR="$(abs_builddir)" + +LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \ + $(top_srcdir)/tap-driver.sh +LOG_COMPILER = $(srcdir)/tap-test + EditResStream_SOURCES = EditResStream.c -EditResStream_LDADD = ${top_builddir}/src/libXmu.la $(XMU_LIBS) +EditResStream_LDADD = $(XMU_TEST_LIBS) + +endif HAVE_GLIB +endif ENABLE_UNIT_TESTS + +EXTRA_DIST = \ + tap-test diff --git a/test/tap-test b/test/tap-test new file mode 100755 index 0000000..99a6d97 --- /dev/null +++ b/test/tap-test @@ -0,0 +1,2 @@ +#! /bin/sh +"$1" -k --tap -- cgit v1.2.1