aboutsummaryrefslogtreecommitdiffstats
path: root/tests/samplebinding/date_conversions.h
diff options
context:
space:
mode:
authorrenatofilho <renato.filho@openbossa.org>2010-10-01 16:49:35 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:07:20 -0300
commit6d660aee32805af4af23d17381398c3f3503c7cf (patch)
tree43c630d08bc8c906ecac1d0968633f7eb8a982f8 /tests/samplebinding/date_conversions.h
parent871a08552d72b49f39761a6b99cce12a0765f3cd (diff)
Unit test to target conversion.
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Marcelo Lira <marcelo.lira@openbossa.org>
Diffstat (limited to 'tests/samplebinding/date_conversions.h')
-rw-r--r--tests/samplebinding/date_conversions.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/samplebinding/date_conversions.h b/tests/samplebinding/date_conversions.h
new file mode 100644
index 000000000..ef459114a
--- /dev/null
+++ b/tests/samplebinding/date_conversions.h
@@ -0,0 +1,35 @@
+namespace Shiboken {
+template <>
+struct PythonConverter<SbkDate>
+{
+ static bool isPythonConvertible(PyObject* pyObj)
+ {
+ if (!PyDateTimeAPI)
+ PyDateTime_IMPORT;
+
+ return PyDate_Check(pyObj);
+ }
+
+ static SbkDate* transformFromPython(PyObject* obj)
+ {
+ if (isPythonConvertible(obj)) {
+ int day = PyDateTime_GET_DAY(obj);
+ int month = PyDateTime_GET_MONTH(obj);
+ int year = PyDateTime_GET_YEAR(obj);
+ return new SbkDate(day, month, year);
+ }
+ return 0;
+ }
+
+ static PyObject* transformToPython(SbkDate* d)
+ {
+ if (d) {
+ if (!PyDateTimeAPI)
+ PyDateTime_IMPORT;
+
+ return PyDate_FromDate(d->day(), d->month(), d->year());
+ }
+ return 0;
+ }
+};
+}