Commit 3db2e076e7f3e06a11a35ec701da637f08dd3fda

Authored by Jürgen Knödlseder
1 parent 2e2d3d18

Remove Python code and make abstract again.

The Python code was removed as this required a linking of GammaLib with the Python library, which we want to avoid. Linking to Python should only be required by the Python wrappers.

As we created a specific Python test suite GPythonTestSuite for Python unit tests, we can make GTestSuite abstract again, which is cleaner.
include/GTestSuite.hpp
... ... @@ -20,7 +20,7 @@
20 20 ***************************************************************************/
21 21 /**
22 22 * @file GTestSuite.hpp
23   - * @brief Test suite class definition
  23 + * @brief Abstract test suite class definition
24 24 * @author Jean-Baptiste Cayrou
25 25 */
26 26  
... ... @@ -45,7 +45,7 @@ typedef void (GTestSuite::*pfunction)(void);
45 45 /***********************************************************************//**
46 46 * @class GTestSuite
47 47 *
48   - * @brief Test suite base class for unit testing on GammaLib fixtures
  48 + * @brief Abstract test suite class for unit testing on GammaLib fixtures
49 49 *
50 50 * @todo Detailed explanation.
51 51 ***************************************************************************/
... ... @@ -63,11 +63,13 @@ public:
63 63 GTestCase& operator[](const int& index);
64 64 const GTestCase& operator[](const int& index) const;
65 65  
  66 + // Pure virtual methods
  67 + virtual void set(void) = 0;
  68 +
66 69 // Other methods
67 70 void clear(void);
68 71 int size(void) const;
69 72 void append(pfunction function, const std::string& name);
70   - virtual void set(void);
71 73 virtual bool run(void);
72 74 std::string name(void) const;
73 75 void name(const std::string& name);
... ... @@ -106,6 +108,8 @@ protected:
106 108  
107 109 // Protected members
108 110 std::string m_name; //!< Name of the test suite
  111 + std::vector<std::string> m_names; //!< Names of test functions
  112 + std::vector<pfunction> m_functions; //!< Test functions of this suite
109 113 std::vector<GTestCase*> m_tests; //!< List of test results
110 114 std::vector<GTestCase*> m_stack_try; //!< Stack for nested try blocks
111 115 int m_index; //!< Index of actual test function
... ... @@ -113,12 +117,6 @@ protected:
113 117 int m_errors; //!< Number of errors
114 118 GLog m_log; //!< Log
115 119 time_t m_timestamp; //!< Timestamp
116   -
117   - // Public members so that the the swig extension can access them
118   -public:
119   - std::vector<std::string> m_names; //!< Names of test functions
120   - std::vector<pfunction> m_functions; //!< Test functions of this suite
121   - std::vector<void*> m_py_object; //!< Test Python functions of this suite
122 120 };
123 121  
124 122 #endif /* GTESTSUITE_HPP */
... ...
src/test/GTestSuite.cpp
... ... @@ -20,7 +20,7 @@
20 20 ***************************************************************************/
21 21 /**
22 22 * @file GTestSuite.cpp
23   - * @brief Test Suite class implementation
  23 + * @brief Abstract test Suite class implementation
24 24 * @author Jean-Baptiste Cayrou
25 25 */
26 26  
... ... @@ -44,11 +44,6 @@ pthread_attr_t gomp_thread_attr;
44 44 #endif
45 45 #endif
46 46  
47   -/* __ Python section ____________________________________________________ */
48   -#ifdef HAVE_PYTHON
49   -#include "Python.h"
50   -#endif
51   -
52 47 /* __ Method name definitions ____________________________________________ */
53 48 #define G_OP_ACCESS "GTestSuite::operator[](int&)"
54 49 #define G_TRY_SUCCESS "GTestSuite::test_try_success()"
... ... @@ -246,7 +241,6 @@ void GTestSuite::append(const pfunction function, const std::string&amp; name)
246 241 {
247 242 // Add test function pointer and name to suite
248 243 m_functions.push_back(function);
249   - m_py_object.push_back(NULL);
250 244 m_names.push_back(name);
251 245  
252 246 // Return
... ... @@ -255,21 +249,6 @@ void GTestSuite::append(const pfunction function, const std::string&amp; name)
255 249  
256 250  
257 251 /***********************************************************************//**
258   - * @brief Set test functions
259   - *
260   - * Dummy set method that does not set any test function. This method does
261   - * only exist since Python version < 3 does not know abstract classes, but
262   - * we want to use GTestSuite to derive Python test classes. Thus, GTestSuite
263   - * is not abstract.
264   - ***************************************************************************/
265   -void GTestSuite::set(void)
266   -{
267   - // Return
268   - return;
269   -}
270   -
271   -
272   -/***********************************************************************//**
273 252 * @brief Run all tests in test suite
274 253 *
275 254 * Executes all test functions that have been appended to the test suite.
... ... @@ -297,11 +276,7 @@ bool GTestSuite::run(void)
297 276 for (m_index = 0; m_index < m_functions.size(); ++m_index) {
298 277  
299 278 // Continue only if function is valid
300   - #ifdef HAVE_PYTHON
301   - if (m_functions[m_index] != NULL || m_py_object[m_index] != NULL) {
302   - #else
303 279 if (m_functions[m_index] != NULL) {
304   - #endif
305 280  
306 281 // Save the number of errors and failures before test
307 282 // execution. We use this after the test to see if
... ... @@ -328,22 +303,9 @@ bool GTestSuite::run(void)
328 303 clock_t t_start = clock();
329 304 #endif
330 305  
331   - // Execute test function. If Python bindings are enabled we check
332   - // if we have a C++ function or a Python object.
  306 + // Execute test function
333 307 try {
334   - #ifdef HAVE_PYTHON
335   - if (m_functions[m_index] != NULL) {
336   - (this->*(m_functions[m_index]))();
337   - }
338   - else if (m_py_object[m_index] != NULL) {
339   - PyObject* args = Py_BuildValue("()");
340   - PyObject* func = static_cast<PyObject*>(m_py_object[m_index]);
341   - PyEval_CallObject(func, args);
342   - Py_DECREF(args);
343   - }
344   - #else
345 308 (this->*(m_functions[m_index]))();
346   - #endif
347 309 }
348 310 catch(std::exception& e) {
349 311  
... ... @@ -890,7 +852,6 @@ void GTestSuite::init_members(void)
890 852 // Initialise members
891 853 m_name = "Unnamed Test Suite";
892 854 m_functions.clear();
893   - m_py_object.clear();
894 855 m_names.clear();
895 856 m_tests.clear();
896 857 m_stack_try.clear();
... ... @@ -920,7 +881,6 @@ void GTestSuite::copy_members(const GTestSuite&amp; suite)
920 881 // Copy members
921 882 m_name = suite.m_name;
922 883 m_functions = suite.m_functions;
923   - m_py_object = suite.m_py_object;
924 884 m_names = suite.m_names;
925 885 m_tests = suite.m_tests;
926 886 m_stack_try = suite.m_stack_try;
... ...