[Spice-commits] 3 commits - server/tests

Frediano Ziglio fziglio at kemper.freedesktop.org
Fri Mar 3 16:50:06 UTC 2017


 server/tests/Makefile.am           |    3 
 server/tests/test-codecs-parsing.c |   13 ----
 server/tests/test-glib-compat.c    |  112 +++++++++++++++++++++++++++++++++++++
 server/tests/test-glib-compat.h    |   42 +++++++++++++
 server/tests/test-leaks.c          |    7 --
 server/tests/test-options.c        |    7 --
 server/tests/test-stat-file.c      |   10 ---
 server/tests/test-vdagent.c        |   92 ------------------------------
 8 files changed, 162 insertions(+), 124 deletions(-)

New commits:
commit a22a76371e2fbd4bfdada91ec35c4705c6386fa8
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Mar 2 13:46:05 2017 +0000

    tests: Reuse GLib compatibility code
    
    Instead of disabling the code use the compatibility functions.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/tests/Makefile.am b/server/tests/Makefile.am
index 6983f6c..db23177 100644
--- a/server/tests/Makefile.am
+++ b/server/tests/Makefile.am
@@ -122,6 +122,7 @@ test_vdagent_CPPFLAGS =			\
 	-UGLIB_VERSION_MIN_REQUIRED	\
 	-UGLIB_VERSION_MAX_ALLOWED	\
 	$(NULL)
+test_codecs_parsing_CPPFLAGS = $(test_vdagent_CPPFLAGS)
 
 if HAVE_GSTREAMER
 test_gst_SOURCES = test-gst.c \
diff --git a/server/tests/test-codecs-parsing.c b/server/tests/test-codecs-parsing.c
index a2e1b9a..0390a49 100644
--- a/server/tests/test-codecs-parsing.c
+++ b/server/tests/test-codecs-parsing.c
@@ -45,9 +45,6 @@ static void codecs_good(void)
     spice_server_destroy(server);
 }
 
-/* g_test_expect_message is available since Glib 2.34 */
-#if GLIB_CHECK_VERSION(2, 34, 0)
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 static void codecs_bad(void)
 {
     guint i;
@@ -137,17 +134,13 @@ static void codecs_bad(void)
 
     spice_server_destroy(server);
 }
-G_GNUC_END_IGNORE_DEPRECATIONS
-#endif
 
 int main(int argc, char *argv[])
 {
     g_test_init(&argc, &argv, NULL);
 
     g_test_add_func("/server/codecs-good", codecs_good);
-#if GLIB_CHECK_VERSION(2, 34, 0)
     g_test_add_func("/server/codecs-bad", codecs_bad);
-#endif
 
     return g_test_run();
 }
commit 73f8a65d060e49db2958200edbff5456a637f4f5
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Mar 2 13:45:14 2017 +0000

    tests: Move some specific GLib compatibility to compatibility file
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/tests/test-codecs-parsing.c b/server/tests/test-codecs-parsing.c
index 5af2e5d..a2e1b9a 100644
--- a/server/tests/test-codecs-parsing.c
+++ b/server/tests/test-codecs-parsing.c
@@ -16,13 +16,9 @@
    License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 #include <config.h>
-#include <glib.h>
 #include <spice.h>
 
-/* GLIB_CHECK_VERSION(2, 40, 0) */
-#ifndef g_assert_nonnull
-#define g_assert_nonnull g_assert
-#endif
+#include "test-glib-compat.h"
 
 static void codecs_good(void)
 {
diff --git a/server/tests/test-glib-compat.h b/server/tests/test-glib-compat.h
index 23e094d..e50d093 100644
--- a/server/tests/test-glib-compat.h
+++ b/server/tests/test-glib-compat.h
@@ -31,4 +31,12 @@ void g_test_expect_message(const gchar *log_domain, GLogLevelFlags log_level,
                            const gchar *pattern);
 #endif
 
+/* GLIB_CHECK_VERSION(2, 40, 0) */
+#ifndef g_assert_nonnull
+#define g_assert_nonnull g_assert
+#endif
+#ifndef g_assert_null
+#define g_assert_null(ptr) g_assert((ptr) == NULL)
+#endif
+
 #endif // TEST_GLIB_COMPAT_H_
diff --git a/server/tests/test-leaks.c b/server/tests/test-leaks.c
index b8521f4..e07e3c6 100644
--- a/server/tests/test-leaks.c
+++ b/server/tests/test-leaks.c
@@ -16,16 +16,11 @@
    License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 #include <config.h>
-#include <glib.h>
 #include <spice.h>
 
+#include "test-glib-compat.h"
 #include "basic-event-loop.h"
 
-/* GLIB_CHECK_VERSION(2, 40, 0) */
-#ifndef g_assert_nonnull
-#define g_assert_nonnull g_assert
-#endif
-
 static void leaks(void)
 {
     int result;
diff --git a/server/tests/test-options.c b/server/tests/test-options.c
index 0cfd4b3..4d77bff 100644
--- a/server/tests/test-options.c
+++ b/server/tests/test-options.c
@@ -16,16 +16,11 @@
    License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 #include <config.h>
-#include <glib.h>
 #include <spice.h>
 
+#include "test-glib-compat.h"
 #include "basic-event-loop.h"
 
-/* GLIB_CHECK_VERSION(2, 40, 0) */
-#ifndef g_assert_nonnull
-#define g_assert_nonnull g_assert
-#endif
-
 static void agent_options(void)
 {
     SpiceCoreInterface *core ;
diff --git a/server/tests/test-stat-file.c b/server/tests/test-stat-file.c
index 40cf37d..63a2a2b 100644
--- a/server/tests/test-stat-file.c
+++ b/server/tests/test-stat-file.c
@@ -19,19 +19,11 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
-#include <glib.h>
 #include <spice.h>
 
+#include "test-glib-compat.h"
 #include "stat-file.h"
 
-/* GLIB_CHECK_VERSION(2, 40, 0) */
-#ifndef g_assert_nonnull
-#define g_assert_nonnull g_assert
-#endif
-#ifndef g_assert_null
-#define g_assert_null(ptr) g_assert((ptr) == NULL)
-#endif
-
 static void stat_file(void)
 {
     RedStatFile *stat_file;
commit b7a7ed3900948d8143931a51bbf024c99b7e03ac
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Fri Mar 3 14:02:16 2017 +0000

    tests: Move some glib compatibility code to a separate file
    
    Allow to reuse this code in other tests.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/tests/Makefile.am b/server/tests/Makefile.am
index dd04834..6983f6c 100644
--- a/server/tests/Makefile.am
+++ b/server/tests/Makefile.am
@@ -25,6 +25,8 @@ libtest_a_SOURCES =				\
 	basic-event-loop.h			\
 	test-display-base.c			\
 	test-display-base.h			\
+	test-glib-compat.c			\
+	test-glib-compat.h			\
 	$(NULL)
 
 LDADD =								\
diff --git a/server/tests/test-glib-compat.c b/server/tests/test-glib-compat.c
new file mode 100644
index 0000000..9b47dc6
--- /dev/null
+++ b/server/tests/test-glib-compat.c
@@ -0,0 +1,112 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+   Copyright (C) 2017 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/>.
+*/
+
+#include <config.h>
+
+#include "glib-compat.h"
+
+#if !GLIB_CHECK_VERSION(2, 34, 0)
+
+/* The code in this #ifdef block is taken from glib and is licensed under the
+ * GNU Lesser General Public License version 2 or later.
+ *
+ * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
+ * Modified by the GLib Team and others 1997-2000.  See GLib AUTHORS
+ * file for a list of people on the GLib Team.
+ */
+
+typedef struct {
+    gchar *log_domain;
+    GLogLevelFlags log_level;
+    gchar *pattern;
+} GTestExpectedMessage;
+
+static GSList *expected_messages = NULL;
+
+static gboolean fatal_log_filter(const gchar *log_domain,
+                                 GLogLevelFlags log_level,
+                                 const gchar *msg,
+                                 gpointer user_data)
+{
+    GTestExpectedMessage *expected = expected_messages->data;
+
+    if ((g_strcmp0(expected->log_domain, log_domain) == 0)
+            && ((log_level & expected->log_level) == expected->log_level)
+            && (g_pattern_match_simple(expected->pattern, msg))) {
+        expected_messages = g_slist_delete_link(expected_messages,
+                                                expected_messages);
+        g_free (expected->log_domain);
+        g_free (expected->pattern);
+        g_free (expected);
+
+        return FALSE;
+    }
+    return TRUE;
+}
+
+void
+g_test_assert_expected_messages_internal (const char     *domain,
+                                          const char     *file,
+                                          int             line,
+                                          const char     *func)
+{
+  if (expected_messages)
+    {
+      GTestExpectedMessage *expected;
+      gchar *message;
+
+      expected = expected_messages->data;
+
+      message = g_strdup_printf ("Did not see expected message %s: %s",
+                                 expected->log_domain ? expected->log_domain : "**",
+                                 expected->pattern);
+      g_error ("%s", message);
+      g_free (message);
+    }
+}
+
+#define g_test_assert_expected_messages() g_test_assert_expected_messages_internal (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC)
+
+void
+g_test_expect_message (const gchar    *log_domain,
+                       GLogLevelFlags  log_level,
+                       const gchar    *pattern)
+{
+  GTestExpectedMessage *expected;
+
+  g_return_if_fail (log_level != 0);
+  g_return_if_fail (pattern != NULL);
+  g_return_if_fail (~log_level & G_LOG_LEVEL_ERROR);
+
+  if (expected_messages == NULL)
+    {
+      g_test_log_set_fatal_handler(fatal_log_filter, NULL);
+    }
+
+  expected = g_new (GTestExpectedMessage, 1);
+  expected->log_domain = g_strdup (log_domain);
+  expected->log_level = log_level;
+  expected->pattern = g_strdup (pattern);
+
+  if ((log_level & G_LOG_LEVEL_MASK) <= G_LOG_LEVEL_WARNING)
+    {
+      expected_messages = g_slist_append (expected_messages, expected);
+    }
+}
+
+#endif /* GLIB_CHECK_VERSION(2, 34, 0) */
diff --git a/server/tests/test-glib-compat.h b/server/tests/test-glib-compat.h
new file mode 100644
index 0000000..23e094d
--- /dev/null
+++ b/server/tests/test-glib-compat.h
@@ -0,0 +1,34 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+   Copyright (C) 2017 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/>.
+*/
+#ifndef TEST_GLIB_COMPAT_H_
+#define TEST_GLIB_COMPAT_H_
+
+#include <glib.h>
+
+#include "glib-compat.h"
+
+#if !GLIB_CHECK_VERSION(2, 34, 0)
+void g_test_assert_expected_messages_internal(const char *domain,
+                                              const char *file, int line, const char *func);
+#define g_test_assert_expected_messages() \
+    g_test_assert_expected_messages_internal (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC)
+void g_test_expect_message(const gchar *log_domain, GLogLevelFlags log_level,
+                           const gchar *pattern);
+#endif
+
+#endif // TEST_GLIB_COMPAT_H_
diff --git a/server/tests/test-vdagent.c b/server/tests/test-vdagent.c
index a4d48ee..e1d8b82 100644
--- a/server/tests/test-vdagent.c
+++ b/server/tests/test-vdagent.c
@@ -27,6 +27,7 @@
 #include <spice/vd_agent.h>
 
 #include "test-display-base.h"
+#include "test-glib-compat.h"
 
 SpiceCoreInterface *core;
 SpiceTimer *ping_timer;
@@ -37,97 +38,6 @@ int ping_ms = 100;
 #define MIN(a, b) ((a) > (b) ? (b) : (a))
 #endif
 
-#if !GLIB_CHECK_VERSION(2, 34, 0)
-
-/* The code in this #ifdef block is taken from glib and is licensed under the
- * GNU Lesser General Public License version 2 or later.
- *
- * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
- * Modified by the GLib Team and others 1997-2000.  See GLib AUTHORS
- * file for a list of people on the GLib Team.
- */
-
-typedef struct {
-    gchar *log_domain;
-    GLogLevelFlags log_level;
-    gchar *pattern;
-} GTestExpectedMessage;
-
-static GSList *expected_messages = NULL;
-
-static gboolean fatal_log_filter(const gchar *log_domain,
-                                 GLogLevelFlags log_level,
-                                 const gchar *msg,
-                                 gpointer user_data)
-{
-    GTestExpectedMessage *expected = expected_messages->data;
-
-    if ((g_strcmp0(expected->log_domain, log_domain) == 0)
-            && ((log_level & expected->log_level) == expected->log_level)
-            && (g_pattern_match_simple(expected->pattern, msg))) {
-        expected_messages = g_slist_delete_link(expected_messages,
-                                                expected_messages);
-        g_free (expected->log_domain);
-        g_free (expected->pattern);
-        g_free (expected);
-
-        return FALSE;
-    }
-    return TRUE;
-}
-
-static void
-g_test_assert_expected_messages_internal (const char     *domain,
-                                          const char     *file,
-                                          int             line,
-                                          const char     *func)
-{
-  if (expected_messages)
-    {
-      GTestExpectedMessage *expected;
-      gchar *message;
-
-      expected = expected_messages->data;
-
-      message = g_strdup_printf ("Did not see expected message %s: %s",
-                                 expected->log_domain ? expected->log_domain : "**",
-                                 expected->pattern);
-      g_error ("%s", message);
-      g_free (message);
-    }
-}
-
-#define g_test_assert_expected_messages() g_test_assert_expected_messages_internal (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC)
-
-static void
-g_test_expect_message (const gchar    *log_domain,
-                       GLogLevelFlags  log_level,
-                       const gchar    *pattern)
-{
-  GTestExpectedMessage *expected;
-
-  g_return_if_fail (log_level != 0);
-  g_return_if_fail (pattern != NULL);
-  g_return_if_fail (~log_level & G_LOG_LEVEL_ERROR);
-
-  if (expected_messages == NULL)
-    {
-      g_test_log_set_fatal_handler(fatal_log_filter, NULL);
-    }
-
-  expected = g_new (GTestExpectedMessage, 1);
-  expected->log_domain = g_strdup (log_domain);
-  expected->log_level = log_level;
-  expected->pattern = g_strdup (pattern);
-
-  if ((log_level & G_LOG_LEVEL_MASK) <= G_LOG_LEVEL_WARNING)
-    {
-      expected_messages = g_slist_append (expected_messages, expected);
-    }
-}
-
-#endif /* GLIB_CHECK_VERSION(2, 34, 0) */
-
 
 static int vmc_write(SPICE_GNUC_UNUSED SpiceCharDeviceInstance *sin,
                      SPICE_GNUC_UNUSED const uint8_t *buf,


More information about the Spice-commits mailing list