[Spice-commits] tests/Makefile.am tests/meson.build tests/test-utils.c

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Mar 5 18:38:27 UTC 2020


 tests/Makefile.am  |   14 +++++++++++
 tests/meson.build  |    7 ++++-
 tests/test-utils.c |   64 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+), 1 deletion(-)

New commits:
commit a3ec7c173d304f4960e6e21f822528dd26b6ec9a
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Wed Mar 4 16:42:43 2020 +0000

    test-utils: Add a test for some utils.h functions
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Kevin Pouget <kpouget at redhat.com>

diff --git a/tests/Makefile.am b/tests/Makefile.am
index e8766d8..d3eba84 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -79,6 +79,20 @@ test_dummy_recorder_LDADD =				\
 	$(top_builddir)/common/libspice-common.la	\
 	$(NULL)
 
+
+TESTS += test_utils
+test_utils_SOURCES =			\
+	test-utils.c			\
+	$(NULL)
+test_utils_CFLAGS =			\
+	-I$(top_srcdir)			\
+	$(GLIB2_CFLAGS)			\
+	$(NULL)
+test_utils_LDADD =					\
+	$(top_builddir)/common/libspice-common.la	\
+	$(NULL)
+
+
 # Avoid need for python(pyparsing) by end users
 TEST_MARSHALLERS =				\
 	generated_test_marshallers.c		\
diff --git a/tests/meson.build b/tests/meson.build
index f1a9334..d315056 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,7 +1,12 @@
 #
 # Build tests
 #
-tests = ['test-logging', 'test-region', 'test-ssl-verify']
+tests = [
+  'test-logging',
+  'test-region',
+  'test-ssl-verify',
+  'test-utils',
+]
 tests_deps = [spice_common_dep]
 
 foreach t : tests
diff --git a/tests/test-utils.c b/tests/test-utils.c
new file mode 100644
index 0000000..a1b1815
--- /dev/null
+++ b/tests/test-utils.c
@@ -0,0 +1,64 @@
+/*
+   Copyright (C) 2020 Red Hat, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+/* Test that tests some utils.h functions */
+#undef NDEBUG
+#include <config.h>
+#include <assert.h>
+
+#include <common/utils.h>
+
+int main(void)
+{
+    unsigned int i;
+    uint8_t bytes[64];
+
+    memset(bytes, 0, sizeof(bytes));
+
+    // some early bytes
+    set_bitmap(10, bytes);
+    assert(bytes[1] == 0x4);
+
+    assert(test_bitmap(10, bytes));
+    assert(!test_bitmap(12, bytes));
+
+    set_bitmap(12, bytes);
+    assert(bytes[1] == 0x14);
+
+    assert(test_bitmap(10, bytes));
+    assert(test_bitmap(12, bytes));
+
+    // some higher bytes, to check truncation
+    assert(!test_bitmap(363, bytes));
+    assert(!test_bitmap(367, bytes));
+
+    set_bitmap(367, bytes);
+    assert(!test_bitmap(363, bytes));
+    assert(test_bitmap(367, bytes));
+
+    set_bitmap(363, bytes);
+    assert(test_bitmap(363, bytes));
+    assert(test_bitmap(367, bytes));
+
+    // check all bytes are zeroes except one set above
+    bytes[1] = 0;
+    bytes[45] = 0;
+    for (i = 0; i < sizeof(bytes); ++i) {
+        assert(bytes[i] == 0);
+    }
+
+    return 0;
+}


More information about the Spice-commits mailing list