|
| 1 | +#include <Python.h> |
| 2 | + |
| 3 | +#include "base.h" |
| 4 | +#include "test_common.h" |
| 5 | + |
| 6 | +static PyObject *base_module; |
| 7 | + |
| 8 | +/* setUp and tearDown must be nonstatic void(void) */ |
| 9 | +void setUp(void) {} |
| 10 | + |
| 11 | +void tearDown(void) {} |
| 12 | + |
| 13 | +/** |
| 14 | + * @brief Tests _pg_is_int_tuple when passed a tuple of ints |
| 15 | + */ |
| 16 | +static PyObject* |
| 17 | +test__pg_is_int_tuple_nominal(PyObject *self, PyObject *_null) |
| 18 | +{ |
| 19 | + PyObject *arg1 = Py_BuildValue("(iii)", 1, 2, 3); |
| 20 | + PyObject *arg2 = Py_BuildValue("(iii)", -1, -2, -3); |
| 21 | + PyObject *arg3 = Py_BuildValue("(iii)", 1, -2, -3); |
| 22 | + |
| 23 | + TEST_ASSERT_EQUAL(1, _pg_is_int_tuple(arg1)); |
| 24 | + TEST_ASSERT_EQUAL(1, _pg_is_int_tuple(arg2)); |
| 25 | + TEST_ASSERT_EQUAL(1, _pg_is_int_tuple(arg3)); |
| 26 | + |
| 27 | + Py_RETURN_NONE; |
| 28 | +} |
| 29 | + |
| 30 | +/** |
| 31 | + * @brief Tests _pg_is_int_tuple when passed a tuple of non-numeric values |
| 32 | + */ |
| 33 | +static PyObject* |
| 34 | +test__pg_is_int_tuple_failureModes(PyObject *self, PyObject *_null) |
| 35 | +{ |
| 36 | + PyObject *arg1 = |
| 37 | + Py_BuildValue("(sss)", (char *)"Larry", (char *)"Moe", (char *)"Curly"); |
| 38 | + PyObject *arg2 = Py_BuildValue("(sss)", (char *)NULL, (char *)NULL, |
| 39 | + (char *)NULL); // tuple of None's |
| 40 | + PyObject *arg3 = Py_BuildValue("(OOO)", arg1, arg2, arg1); |
| 41 | + |
| 42 | + TEST_ASSERT_EQUAL(0, _pg_is_int_tuple(arg1)); |
| 43 | + TEST_ASSERT_EQUAL(0, _pg_is_int_tuple(arg2)); |
| 44 | + TEST_ASSERT_EQUAL(0, _pg_is_int_tuple(arg3)); |
| 45 | + |
| 46 | + Py_RETURN_NONE; |
| 47 | +} |
| 48 | + |
| 49 | +/** |
| 50 | + * @brief Tests _pg_is_int_tuple when passed a tuple of floats |
| 51 | + */ |
| 52 | +static PyObject* |
| 53 | +test__pg_is_int_tuple_floats(PyObject *self, PyObject *_null) |
| 54 | +{ |
| 55 | + PyObject *arg1 = Py_BuildValue("(ddd)", 1.0, 2.0, 3.0); |
| 56 | + PyObject *arg2 = Py_BuildValue("(ddd)", -1.1, -2.2, -3.3); |
| 57 | + PyObject *arg3 = Py_BuildValue("(ddd)", 1.0, -2.0, -3.1); |
| 58 | + |
| 59 | + TEST_ASSERT_EQUAL(1, _pg_is_int_tuple(arg1)); |
| 60 | + TEST_ASSERT_EQUAL(0, _pg_is_int_tuple(arg2)); |
| 61 | + TEST_ASSERT_EQUAL(0, _pg_is_int_tuple(arg3)); |
| 62 | + |
| 63 | + Py_RETURN_NONE; |
| 64 | +} |
| 65 | + |
| 66 | +/*=======Test Reset Option=====*/ |
| 67 | +/* This must be void(void) */ |
| 68 | +void resetTest(void) |
| 69 | +{ |
| 70 | + tearDown(); |
| 71 | + setUp(); |
| 72 | +} |
| 73 | + |
| 74 | +/*=======Exposed Test Reset Option=====*/ |
| 75 | +static PyObject* |
| 76 | +reset_test(PyObject *self, PyObject *_null) |
| 77 | +{ |
| 78 | + resetTest(); |
| 79 | + |
| 80 | + Py_RETURN_NONE; |
| 81 | +} |
| 82 | + |
| 83 | +/*=======Run The Tests=======*/ |
| 84 | +static PyObject* |
| 85 | +run_tests(PyObject *self, PyObject *_null) |
| 86 | +{ |
| 87 | + UnityBegin("base_ctest.c"); |
| 88 | + RUN_TEST_PG_INTERNAL(test__pg_is_int_tuple_nominal, 15, self, _null); |
| 89 | + RUN_TEST_PG_INTERNAL(test__pg_is_int_tuple_failureModes, 29, self, _null); |
| 90 | + RUN_TEST_PG_INTERNAL(test__pg_is_int_tuple_floats, 46, self, _null); |
| 91 | + |
| 92 | + return PyLong_FromLong(UnityEnd()); |
| 93 | +} |
| 94 | + |
| 95 | +static PyMethodDef base_test_methods[] = { |
| 96 | + {"test__pg_is_int_tuple_nominal", (PyCFunction)test__pg_is_int_tuple_nominal, METH_NOARGS, "Tests _pg_is_int_tuple when passed a tuple of ints"}, |
| 97 | + {"test__pg_is_int_tuple_failureModes", (PyCFunction)test__pg_is_int_tuple_failureModes, METH_NOARGS, "Tests _pg_is_int_tuple when passed a tuple of non-numeric values"}, |
| 98 | + {"test__pg_is_int_tuple_floats", (PyCFunction)test__pg_is_int_tuple_floats, METH_NOARGS, "Tests _pg_is_int_tuple when passed a tuple of floats"}, |
| 99 | + {"reset_test", (PyCFunction)reset_test, METH_NOARGS, "Resets the test suite between tests, run_tests automatically calls this after each test case it calls"}, |
| 100 | + {"run_tests", (PyCFunction)run_tests, METH_NOARGS, "Runs all the tests in this test wuite"}, |
| 101 | + {NULL, NULL, 0, NULL}}; |
| 102 | + |
| 103 | +MODINIT_DEFINE(base_ctest) |
| 104 | +{ |
| 105 | + PyObject* module; |
| 106 | + |
| 107 | + static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT, |
| 108 | + "base_ctest", |
| 109 | + "C unit tests for the pygame.base internal implementation", |
| 110 | + -1, |
| 111 | + base_test_methods, |
| 112 | + NULL, |
| 113 | + NULL, |
| 114 | + NULL, |
| 115 | + NULL}; |
| 116 | + |
| 117 | + /* create the module */ |
| 118 | + module = PyModule_Create(&_module); |
| 119 | + if (!module) { |
| 120 | + return NULL; |
| 121 | + } |
| 122 | + |
| 123 | + return module; |
| 124 | +} |
| 125 | + |
| 126 | +// #undef main |
| 127 | +// /*=======MAIN=====*/ |
| 128 | +// int main(void) { |
| 129 | +// Py_Initialize(); |
| 130 | +// UnityBegin("test_base.c"); |
| 131 | +// RUN_TEST(test__pg_is_int_tuple_nominal, 17); |
| 132 | +// RUN_TEST(test__pg_is_int_tuple_failureModes, 31); |
| 133 | +// RUN_TEST(test__pg_is_int_tuple_floats, 45); |
| 134 | + |
| 135 | +// return (UnityEnd()); |
| 136 | +// } |
0 commit comments