From 24627630badd13162c028ed1d1ca1e2b40fb1685 Mon Sep 17 00:00:00 2001
From: Manuel Gunther <siebenkopf@googlemail.com>
Date: Tue, 13 Sep 2016 13:12:06 -0600
Subject: [PATCH] Implemented basic framework for C++-API tests

---
 bob/io/base/test.cpp    | 66 +++++++++++++++++++++++++++++++++++++++++
 bob/io/base/test_cpp.py |  4 +++
 setup.py                | 14 +++++++++
 3 files changed, 84 insertions(+)
 create mode 100644 bob/io/base/test.cpp
 create mode 100644 bob/io/base/test_cpp.py

diff --git a/bob/io/base/test.cpp b/bob/io/base/test.cpp
new file mode 100644
index 0000000..607a383
--- /dev/null
+++ b/bob/io/base/test.cpp
@@ -0,0 +1,66 @@
+/**
+ * @author Manuel Gunther
+ * @date Tue Sep 13 13:01:31 MDT 2016
+ *
+ * @brief Tests for bob::io::base
+ */
+
+#include <bob.io.base/api.h>
+#include <bob.extension/documentation.h>
+
+static auto s_test_api = bob::extension::FunctionDoc(
+  "_test_api",
+  "Some tests for API functions"
+)
+.add_prototype("");
+
+static PyObject* _test_api(PyObject*){
+BOB_TRY
+  Py_RETURN_NONE;
+BOB_CATCH_FUNCTION("_test_api", 0)
+}
+
+static PyMethodDef module_methods[] = {
+    {
+      s_test_api.name(),
+      (PyCFunction)_test_api,
+      METH_NOARGS,
+      s_test_api.doc(),
+    },
+    {0}  /* Sentinel */
+};
+
+PyDoc_STRVAR(module_docstr, "Tests for bob::io::base");
+
+#if PY_VERSION_HEX >= 0x03000000
+static PyModuleDef module_definition = {
+  PyModuleDef_HEAD_INIT,
+  BOB_EXT_MODULE_NAME,
+  module_docstr,
+  -1,
+  module_methods,
+  0, 0, 0, 0
+};
+#endif
+
+static PyObject* create_module (void) {
+
+# if PY_VERSION_HEX >= 0x03000000
+  PyObject* m = PyModule_Create(&module_definition);
+  auto m_ = make_xsafe(m);
+  const char* ret = "O";
+# else
+  PyObject* m = Py_InitModule3(BOB_EXT_MODULE_NAME, module_methods, module_docstr);
+  const char* ret = "N";
+# endif
+  if (!m) return 0;
+
+  return Py_BuildValue(ret, m);
+}
+
+PyMODINIT_FUNC BOB_EXT_ENTRY_NAME (void) {
+# if PY_VERSION_HEX >= 0x03000000
+  return
+# endif
+    create_module();
+}
diff --git a/bob/io/base/test_cpp.py b/bob/io/base/test_cpp.py
new file mode 100644
index 0000000..987a75e
--- /dev/null
+++ b/bob/io/base/test_cpp.py
@@ -0,0 +1,4 @@
+from ._test import _test_api
+
+def test_cpp():
+  _test_api()
diff --git a/setup.py b/setup.py
index 610485d..08ab4e5 100644
--- a/setup.py
+++ b/setup.py
@@ -227,6 +227,20 @@ setup(
         packages = packages,
         boost_modules = boost_modules,
       ),
+
+      Extension("bob.io.base._test",
+        [
+          "bob/io/base/test.cpp",
+        ],
+        library_dirs = library_dirs,
+        libraries = libraries,
+        define_macros = define_macros,
+        system_include_dirs = system_include_dirs,
+        version = version,
+        bob_packages = bob_packages,
+        packages = packages,
+        boost_modules = boost_modules,
+      ),
     ],
 
     cmdclass = {
-- 
GitLab