[glom] Added a regression test for the loading of the python modules.



commit cceb65731c3c1f4cc3255c64adcd500ce7332ae6
Author: Johannes Schmid <jhs jsschmid de>
Date:   Thu Sep 17 17:52:04 2009 +0200

     Added a regression test for the loading of the python modules.
    
    Unfortunately this test doesn't trigger the crash bug that happens on exit() on the maemo platform.

 ChangeLog                              |    8 ++++
 Makefile_tests.am                      |    7 +++-
 regression_tests/test_python_module.cc |   57 ++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a9fcd6a..a9c339b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2009-09-17  Johannes Schmid  <jschmid openismus com>
 
+	* regression_tests/test_python_module.cc:
+	* Makefile_tests.am:
+	Added a regression test for the loading of the python modules.
+	Unfortunately this test doesn't trigger the crash bug that
+	happens on exit() on the maemo platform.
+
+2009-09-17  Johannes Schmid  <jschmid openismus com>
+
 	* glom/main.cc:
 	Really check if pygda module is available. A typo caused
 	the check for the glom module twice while the gda module
diff --git a/Makefile_tests.am b/Makefile_tests.am
index 6e95bd0..fdf2424 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -24,11 +24,13 @@ check_PROGRAMS =						\
 	glom/test_pyembed					\
 	regression_tests/test_parsing_time			\
 	regression_tests/test_signal_reemit			\
-	regression_tests/test_load_python_library
+	regression_tests/test_load_python_library \
+	regression_tests/test_python_module
 
 TESTS =	regression_tests/test_parsing_time	\
 	regression_tests/test_signal_reemit	\
-	regression_tests/test_load_python_library
+	regression_tests/test_load_python_library \
+	regression_tests/test_python_module
 
 tests_ldadd = glom/libglom/libglom-$(GLOM_ABI_VERSION).la $(LIBGLOM_LIBS)
 
@@ -63,3 +65,4 @@ glom_test_pyembed_LDADD = $(LIBGLOM_LIBS) $(PYTHON_LIBS)
 regression_tests_test_parsing_time_LDADD = $(tests_ldadd)
 regression_tests_test_signal_reemit_LDADD = $(LIBGLOM_LIBS)
 regression_tests_test_load_python_library_LDADD = $(LIBGLOM_LIBS)
+regression_tests_test_python_module_LDADD = $(LIBGLOM_LIBS) $(PYTHON_LIBS) glom/libglom/libglom-$(GLOM_ABI_VERSION).la
diff --git a/regression_tests/test_python_module.cc b/regression_tests/test_python_module.cc
new file mode 100644
index 0000000..0240097
--- /dev/null
+++ b/regression_tests/test_python_module.cc
@@ -0,0 +1,57 @@
+#include <Python.h>
+#include <cstdio>
+#include <libglom/init.h>
+
+#include "config.h"
+#include "glom/python_embed/glom_python.h"
+
+#ifndef G_OS_WIN32
+extern "C" void __libc_freeres(void);
+#endif
+
+namespace Glom
+{
+bool glom_python_module_is_available()
+{
+  const gchar* name = "glom_" GLOM_ABI_VERSION_UNDERLINED;
+  PyObject* module_glom = PyImport_ImportModule((char*)name); //TODO: unref this?
+
+  if(!module_glom)
+  {
+    g_warning("Glom: A python import of %s failed.\n", name);
+  }
+
+  return module_glom != 0;
+}
+
+bool gda_python_module_is_available()
+{
+  const gchar* name = "gda";
+  PyObject* module_glom = PyImport_ImportModule((char*)name); //TODO: unref this?
+
+  if(!module_glom)
+  {
+    g_warning("Glom: A python import of %s failed.\n", name);
+  }
+
+  return module_glom != 0;
+}
+
+}
+
+int main ()
+{
+#ifndef G_OS_WIN32
+  atexit(__libc_freeres);
+#endif
+  Glom::libglom_init();  // Calls PyInitialize()
+  
+  if (!Glom::gda_python_module_is_available())
+    return EXIT_FAILURE;
+  if (!Glom::glom_python_module_is_available())
+    return EXIT_FAILURE;
+  
+  Glom::libglom_deinit(); // Calls Py_Finalize();
+  
+  return EXIT_SUCCESS;
+}



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