diff options
author | Renato Filho <renato.filho@openbossa.org> | 2011-06-06 11:42:46 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:15:25 -0300 |
commit | 7b731d702c64d172e192aa1876e4a6fade6c38d7 (patch) | |
tree | a87bdca4d3a89a3ea86c321837b9939015fdf8c9 /tests | |
parent | c2890587871dd425da146d0c60510119a809b869 (diff) |
Created unit test for add function rich-compare function.
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>
Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/samplebinding/time_test.py | 11 | ||||
-rw-r--r-- | tests/samplebinding/typesystem_sample.xml | 38 |
2 files changed, 49 insertions, 0 deletions
diff --git a/tests/samplebinding/time_test.py b/tests/samplebinding/time_test.py index b08b65ffb..5c0270d7a 100644 --- a/tests/samplebinding/time_test.py +++ b/tests/samplebinding/time_test.py @@ -28,6 +28,7 @@ import sys import unittest +import datetime from sample import Time, ImplicitConv, ObjectType, Str @@ -118,6 +119,16 @@ class TimeTest(unittest.TestCase): result = time.somethingCompletelyDifferent(1, 2, ImplicitConv.CtorOne) self.assertEqual(result, Time.ThreeArgs) + def testCompareWithPythonTime(self): + time = Time(12, 32, 05) + py = datetime.time(12, 32, 05) + self.assertEqual(time, py) + + def testNotEqual(self): + time = Time(12, 32, 06) + py = datetime.time(12, 32, 05) + self.assertNotEqual(time, py) + if __name__ == '__main__': unittest.main() diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index 359da0656..6cbd77af4 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -1171,7 +1171,45 @@ </value-type> <value-type name="Time"> + <extra-includes> + <include file-name="datetime.h" location="global"/> + </extra-includes> <enum-type name="NumArgs"/> + <add-function signature="operator!=(const PyObject*)" return-type="PyObject"> + <inject-code> + if (!PyDateTimeAPI) + PyDateTime_IMPORT; + if (PyTime_Check(%1)) { + int pyH = PyDateTime_TIME_GET_HOUR(%1); + int pyM = PyDateTime_TIME_GET_MINUTE(%1); + int pyS = PyDateTime_TIME_GET_SECOND(%1); + if ((pyH == %CPPSELF.hour()) &&l; + (pyM == %CPPSELF.minute()) && + (pyS == %CPPSELF.second())) + %PYARG_0 = Py_False; + else + %PYARG_0 = Py_True; + } + </inject-code> + </add-function> + <add-function signature="operator==(const PyObject*)" return-type="PyObject"> + <inject-code> + if (!PyDateTimeAPI) + PyDateTime_IMPORT; + if (PyTime_Check(%1)) { + int pyH = PyDateTime_TIME_GET_HOUR(%1); + int pyM = PyDateTime_TIME_GET_MINUTE(%1); + int pyS = PyDateTime_TIME_GET_SECOND(%1); + if ((pyH == %CPPSELF.hour()) &&l; + (pyM == %CPPSELF.minute()) && + (pyS == %CPPSELF.second())) + %PYARG_0 = Py_True; + else + %PYARG_0 = Py_False; + } + </inject-code> + </add-function> + </value-type> <value-type name="Size"> <add-function signature="Size(const char*)"> |