[libpeas] Merge python2 and python3 extension tests



commit 6fbfff562cc26809366643d1b96430220c77631c
Author: Garrett Regier <garrettregier gmail com>
Date:   Tue Nov 12 22:42:10 2013 -0800

    Merge python2 and python3 extension tests
    
    This will avoid further duplication when adding new tests.

 tests/libpeas/Makefile.am                          |    2 +
 .../libpeas/{extension-python.c => extension-py.c} |   47 ++++++--
 tests/libpeas/extension-python3.c                  |  123 --------------------
 tests/libpeas/testing/testing-extension.c          |    3 +-
 tests/libpeas/testing/testing-extension.h          |   11 ++-
 5 files changed, 47 insertions(+), 139 deletions(-)
---
diff --git a/tests/libpeas/Makefile.am b/tests/libpeas/Makefile.am
index 6107fd7..1917bde 100644
--- a/tests/libpeas/Makefile.am
+++ b/tests/libpeas/Makefile.am
@@ -33,12 +33,14 @@ endif
 
 if ENABLE_PYTHON2
 TEST_PROGS               += extension-python
+extension_python_SOURCES  = extension-py.c
 extension_python_CFLAGS   = $(PYGOBJECT_CFLAGS) $(PYTHON2_CFLAGS)
 extension_python_LDADD    = $(LDADD) $(PYGOBJECT_LIBS) $(PYTHON2_LIBS)
 endif
 
 if ENABLE_PYTHON3
 TEST_PROGS                += extension-python3
+extension_python3_SOURCES  = extension-py.c
 extension_python3_CFLAGS   = $(PYGOBJECT_CFLAGS) $(PYTHON3_CFLAGS)
 extension_python3_LDADD    = $(LDADD) $(PYGOBJECT_LIBS) $(PYTHON3_LIBS)
 endif
diff --git a/tests/libpeas/extension-python.c b/tests/libpeas/extension-py.c
similarity index 70%
rename from tests/libpeas/extension-python.c
rename to tests/libpeas/extension-py.c
index 30f2be0..2c45072 100644
--- a/tests/libpeas/extension-python.c
+++ b/tests/libpeas/extension-py.c
@@ -1,8 +1,9 @@
 /*
- * extension-python.c
+ * extension-py.c
  * This file is part of libpeas
  *
- * Copyright (C) 2011 - Steve Frécinaux, Garrett Regier
+ * Copyright (C) 2011 - Steve Frécinaux
+ * Copyright (C) 2011-2013 - Garrett Regier
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU Library General Public License as published by
@@ -26,14 +27,25 @@
 #include <pygobject.h>
 
 #include <libpeas/peas-activatable.h>
+#include "libpeas/peas-engine-priv.h"
 #include "loaders/python/peas-extension-python.h"
 
 #include "testing/testing-extension.h"
 #include "introspection/introspection-base.h"
 
+
+#if PY_VERSION_HEX < 0x03000000
+#define PY_LOADER       python
+#else
+#define PY_LOADER       python3
+#endif
+
+#define PY_LOADER_STR       G_STRINGIFY (PY_LOADER)
+
+
 static void
-test_extension_python_instance_refcount (PeasEngine     *engine,
-                                         PeasPluginInfo *info)
+test_extension_py_instance_refcount (PeasEngine     *engine,
+                                     PeasPluginInfo *info)
 {
   PeasExtension *extension;
   PyObject *instance;
@@ -55,8 +67,8 @@ test_extension_python_instance_refcount (PeasEngine     *engine,
 }
 
 static void
-test_extension_python_activatable_subject_refcount (PeasEngine     *engine,
-                                                    PeasPluginInfo *info)
+test_extension_py_activatable_subject_refcount (PeasEngine     *engine,
+                                                PeasPluginInfo *info)
 {
   PeasExtension *extension;
   GObject *object;
@@ -96,13 +108,15 @@ test_extension_python_activatable_subject_refcount (PeasEngine     *engine,
 }
 
 static void
-test_extension_python_nonexistent (PeasEngine *engine)
+test_extension_py_nonexistent (PeasEngine *engine)
 {
   PeasPluginInfo *info;
 
-  testing_util_push_log_hook ("Error loading plugin 'extension-python-nonexistent'");
+  testing_util_push_log_hook ("Error loading plugin 'extension-"
+                              PY_LOADER_STR "-nonexistent'");
 
-  info = peas_engine_get_plugin_info (engine, "extension-python-nonexistent");
+  info = peas_engine_get_plugin_info (engine,
+                                      "extension-" PY_LOADER_STR "-nonexistent");
 
   g_assert (!peas_engine_load_plugin (engine, info));
 }
@@ -113,11 +127,18 @@ main (int   argc,
 {
   testing_init (&argc, &argv);
 
-  testing_extension_all ("python");
+  testing_extension_all (PY_LOADER_STR);
+
+#undef EXTENSION_TEST
+  
+#define EXTENSION_TEST(loader, path, func) \
+  testing_extension_add (EXTENSION_TEST_NAME (loader, path), \
+                         (gpointer) test_extension_py_##func)
 
-  EXTENSION_TEST (python, "instance-refcount", instance_refcount);
-  EXTENSION_TEST (python, "activatable-subject-refcount", activatable_subject_refcount);
-  EXTENSION_TEST (python, "nonexistent", nonexistent);
+  EXTENSION_TEST (PY_LOADER, "instance-refcount", instance_refcount);
+  EXTENSION_TEST (PY_LOADER, "activatable-subject-refcount",
+                  activatable_subject_refcount);
+  EXTENSION_TEST (PY_LOADER, "nonexistent", nonexistent);
 
   return testing_extension_run_tests ();
 }
diff --git a/tests/libpeas/testing/testing-extension.c b/tests/libpeas/testing/testing-extension.c
index 7fde1d4..278e07f 100644
--- a/tests/libpeas/testing/testing-extension.c
+++ b/tests/libpeas/testing/testing-extension.c
@@ -471,7 +471,8 @@ test_extension_properties_prerequisite (PeasEngine     *engine,
 
 #define _EXTENSION_TEST(loader, path, ftest) \
   G_STMT_START { \
-    gchar *full_path = g_strdup_printf ("/extension/%s/" path, loader); \
+    gchar *full_path = g_strdup_printf (EXTENSION_TEST_NAME (%s, "%s"), \
+                                        loader, path); \
 \
     g_test_add (full_path, TestFixture, \
                 (gpointer) test_extension_##ftest, \
diff --git a/tests/libpeas/testing/testing-extension.h b/tests/libpeas/testing/testing-extension.h
index 84097ea..f2e05b7 100644
--- a/tests/libpeas/testing/testing-extension.h
+++ b/tests/libpeas/testing/testing-extension.h
@@ -41,11 +41,18 @@ int testing_extension_run_tests   (void);
   testing_extension_callable (loader); \
   testing_extension_properties (loader)
 
-/* This macro is there to add loader-specific tests. */
+/* These macros are here to add loader-specific tests. */
+#define EXTENSION_TEST_NAME(loader, path) \
+  ("/extension/" G_STRINGIFY (loader) "/" path)
+
 #define EXTENSION_TEST(loader, path, func) \
-  testing_extension_add ("/extension/" #loader "/" path, \
+  testing_extension_add (EXTENSION_TEST_NAME (loader, path), \
                          (gpointer) test_extension_##loader##_##func)
 
+#define EXTENSION_TEST_FUNC(loader, path, func) \
+  g_test_add_func (EXTENSION_TEST_NAME (loader, path), \
+                   (gpointer) test_extension_##loader##_##func)
+
 G_END_DECLS
 
 #endif /* __TESTING__EXTENSION_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]