diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-11-06 13:34:56 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-11-06 13:34:56 -0300 |
commit | f69bf045ad195efe9725c2c6a483a1473cd9ce43 (patch) | |
tree | 6e1edcc8a42a48ce63a8581a771417088d92882b /tests | |
parent | 858e19f8ace26fd1b38d516dc5023530d8e53544 (diff) |
added a new test called Time with a set of constructor and method
signatures to test the overload decisor on more situations;
also a clarifying comment was added to the Point class
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libsample/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/libsample/point.h | 3 | ||||
-rw-r--r-- | tests/libsample/sometime.cpp | 99 | ||||
-rw-r--r-- | tests/libsample/sometime.h | 94 | ||||
-rw-r--r-- | tests/samplebinding/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/samplebinding/global.h | 1 | ||||
-rwxr-xr-x | tests/samplebinding/time_test.py | 117 | ||||
-rw-r--r-- | tests/samplebinding/typesystem_sample.xml | 2 |
8 files changed, 318 insertions, 0 deletions
diff --git a/tests/libsample/CMakeLists.txt b/tests/libsample/CMakeLists.txt index 2e0be4dff..a9043d08b 100644 --- a/tests/libsample/CMakeLists.txt +++ b/tests/libsample/CMakeLists.txt @@ -20,6 +20,7 @@ reference.cpp samplenamespace.cpp simplefile.cpp size.cpp +sometime.cpp str.cpp virtualmethods.cpp ) diff --git a/tests/libsample/point.h b/tests/libsample/point.h index be73e4d43..01570cff0 100644 --- a/tests/libsample/point.h +++ b/tests/libsample/point.h @@ -56,7 +56,10 @@ public: const Point& getConstReferenceToSelf() const { return *this; } const Point* getSelf() const { return this; } + // The != operator is not implemented for the purpose of testing + // for the absense of the __ne__ method in the Python binding. bool operator==(const Point& other); + Point operator+(const Point& other); Point operator-(const Point& other); diff --git a/tests/libsample/sometime.cpp b/tests/libsample/sometime.cpp new file mode 100644 index 000000000..75b4260d3 --- /dev/null +++ b/tests/libsample/sometime.cpp @@ -0,0 +1,99 @@ +/* + * This file is part of the Shiboken Python Binding Generator project. + * + * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). + * + * Contact: PySide team <contact@pyside.org> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. Please + * review the following information to ensure the GNU Lesser General + * Public License version 2.1 requirements will be met: + * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. + * + * As a special exception to the GNU Lesser General Public License + * version 2.1, the object code form of a "work that uses the Library" + * may incorporate material from a header file that is part of the + * Library. You may distribute such object code under terms of your + * choice, provided that the incorporated material (i) does not exceed + * more than 5% of the total time of the Library; and (ii) is limited to + * numerical parameters, data structure layouts, accessors, macros, + * inline functions and templates. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "sometime.h" +#include "stdio.h" + +void +Time::setTime() +{ + m_hour = 0; + m_minute = 0; + m_second = 0; + m_msec = 0; + m_is_null = true; +} + +void +Time::setTime(int h, int m, int s, int ms) +{ + m_hour = h; + m_minute = m; + m_second = s; + m_msec = ms; + m_is_null = false; +} + + +Time::NumArgs +Time::somethingCompletelyDifferent() +{ + return ZeroArgs; +} + +Time::NumArgs +Time::somethingCompletelyDifferent(int h, int m, ImplicitConv ic, ObjectType* type) +{ + if (type) + return FourArgs; + if (ic.ctorEnum() == ImplicitConv::CtorThree && ic.objId() == -1) + return TwoArgs; + return ThreeArgs; +} + +Str +Time::toString() const +{ + if (m_is_null) + return Str(); + char buffer[13]; + sprintf(buffer, "%02d:%02d:%02d.%03d", m_hour, m_minute, m_second, m_msec); + return Str(buffer); +} + +bool +Time::operator==(const Time& other) const +{ + return m_hour == other.m_hour + && m_minute == other.m_minute + && m_second == other.m_second + && m_msec == other.m_msec + && m_is_null == m_is_null; +} + +bool +Time::operator!=(const Time& other) const +{ + return !operator==(other); +} diff --git a/tests/libsample/sometime.h b/tests/libsample/sometime.h new file mode 100644 index 000000000..12fd4e09c --- /dev/null +++ b/tests/libsample/sometime.h @@ -0,0 +1,94 @@ +/* + * This file is part of the Shiboken Python Binding Generator project. + * + * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). + * + * Contact: PySide team <contact@pyside.org> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. Please + * review the following information to ensure the GNU Lesser General + * Public License version 2.1 requirements will be met: + * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. + * + * As a special exception to the GNU Lesser General Public License + * version 2.1, the object code form of a "work that uses the Library" + * may incorporate material from a header file that is part of the + * Library. You may distribute such object code under terms of your + * choice, provided that the incorporated material (i) does not exceed + * more than 5% of the total time of the Library; and (ii) is limited to + * numerical parameters, data structure layouts, accessors, macros, + * inline functions and templates. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef SOMETIME_H +#define SOMETIME_H + +#include "str.h" +#include "implicitconv.h" +#include "objecttype.h" + +class Time +{ +public: + enum NumArgs { + ZeroArgs, + TwoArgs, + ThreeArgs, + FourArgs + }; + + Time() + : m_hour(0), m_minute(0), m_second(0), m_msec(0), m_is_null(true) + {} + Time(int h, int m, int s = 0, int ms = 0) + : m_hour(h), m_minute(m), m_second(s), m_msec(ms), m_is_null(false) + {} + + ~Time() {} + + bool isNull() const { return m_is_null; } + + int hour() const { return m_hour; } + int minute() const { return m_minute; } + int second() const { return m_second; } + int msec() const { return m_msec; } + + void setTime(); + void setTime(int h, int m, int s = 0, int ms = 0); + + // This one is completely different from the other methods in this class, + // it was added to give the overload decisor a really hard time with + // an value-type with implicit conversion and a default argument, and also + // an object-type, just because I feel like it. + NumArgs somethingCompletelyDifferent(); + NumArgs somethingCompletelyDifferent(int h, int m, + ImplicitConv ic = ImplicitConv::CtorThree, + ObjectType* type = 0); + + Str toString() const; + bool operator==(const Time& other) const; + bool operator!=(const Time& other) const; + +private: + int m_hour; + int m_minute; + int m_second; + int m_msec; + + bool m_is_null; +}; + +#endif // SOMETIME_H + diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt index f4e3ddb92..b8fed1966 100644 --- a/tests/samplebinding/CMakeLists.txt +++ b/tests/samplebinding/CMakeLists.txt @@ -29,6 +29,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/simplefile_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/size_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/str_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/time_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/virtualmethods_wrapper.cpp ) diff --git a/tests/samplebinding/global.h b/tests/samplebinding/global.h index d119e9939..5e240bca6 100644 --- a/tests/samplebinding/global.h +++ b/tests/samplebinding/global.h @@ -21,5 +21,6 @@ #include "simplefile.h" #include "size.h" #include "str.h" +#include "sometime.h" #include "virtualmethods.h" diff --git a/tests/samplebinding/time_test.py b/tests/samplebinding/time_test.py new file mode 100755 index 000000000..e85536957 --- /dev/null +++ b/tests/samplebinding/time_test.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# This file is part of the Shiboken Python Bindings Generator project. +# +# Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +# +# Contact: PySide team <contact@pyside.org> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# version 2.1 as published by the Free Software Foundation. Please +# review the following information to ensure the GNU Lesser General +# Public License version 2.1 requirements will be met: +# http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +# # +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +# 02110-1301 USA + +'''Test cases for constructor and method signature decisor on Time class.''' + +import sys +import unittest + +from sample import Time, ImplicitConv, ObjectType, Str + +class TimeTest(unittest.TestCase): + '''Test cases for constructor and method signature decisor on Time class. + The constructor and one method have these signatures: CTORMETHOD() and + CTORMETHOD(int h, int m, int s = 0, int ms = 0); there another method + with a more complex signature METH(int, int, ImplicitConv=DEFVALUE, ObjectType=0), + to produce an even worse scenario. + ''' + + def testConstructorWithoutParamers(self): + '''Constructor without parameters: Time()''' + time = Time() + self.assert_(time.isNull()) + + def testConstructorWithAllParamers(self): + '''Constructor with all parameters: Time(int h, int m, int s = 0, int ms = 0)''' + time = Time(1, 2, 3, 4) + self.assertTrue(time.toString(), '01:02:03.004') + + def testConstructorWithThreeParamers(self): + '''Constructor with 3 parameters: Time(int h, int m, int s = 0, int ms = 0)''' + time = Time(1, 2, 3) + self.assertTrue(time.toString(), '01:02:03.000') + + def testConstructorWithTwoParamers(self): + '''Constructor with 2 parameters: Time(int h, int m, int s = 0, int ms = 0)''' + time = Time(1, 2) + self.assertTrue(time.toString(), '01:02:00.000') + + def testSimpleMethodWithoutParamers(self): + '''Constructor without parameters: Time.setTime()''' + time = Time(1, 2, 3, 4) + time.setTime() + self.assert_(time.isNull()) + + def testSimpleMethodWithAllParamers(self): + '''Simple method with all parameters: Time.setTime(int h, int m, int s = 0, int ms = 0)''' + time = Time() + time.setTime(1, 2, 3, 4) + self.assertTrue(time.toString(), '01:02:03.004') + + def testSimpleMethodWithThreeParamers(self): + '''Simple method with 3 parameters: Time.setTime(int h, int m, int s = 0, int ms = 0)''' + time = Time() + time.setTime(1, 2, 3) + self.assertTrue(time.toString(), '01:02:03.000') + + def testSimpleMethodWithTwoParamers(self): + '''Simple method with 2 parameters: Time.setTime(int h, int m, int s = 0, int ms = 0)''' + time = Time() + time.setTime(1, 2) + self.assertTrue(time.toString(), '01:02:00.000') + + def testMethodWithoutParamers(self): + '''Method without parameters: Time.somethingCompletelyDifferent()''' + time = Time() + result = time.somethingCompletelyDifferent() + self.assertEqual(result, Time.ZeroArgs) + + def testMethodWithAllParamers(self): + '''Method with all parameters: + Time.somethingCompletelyDifferent( + int h, int m, ImplicitConv ic = ImplicitConv::CtorThree, ObjectType* type = 0 + ); + ''' + time = Time() + obj = ObjectType() + result = time.somethingCompletelyDifferent(1, 2, ImplicitConv(2), obj) + self.assertEqual(result, Time.FourArgs) + + def testMethodWithThreeParamers(self): + '''Method with 3 parameters: Time.somethingCompletelyDifferent(...)''' + time = Time() + result = time.somethingCompletelyDifferent(1, 2, ImplicitConv(ImplicitConv.CtorOne)) + self.assertEqual(result, Time.ThreeArgs) + + def testMethodWithTwoParamers(self): + '''Method with 2 parameters: Time.somethingCompletelyDifferent(...)''' + time = Time() + result = time.somethingCompletelyDifferent(1, 2) + self.assertEqual(result, Time.TwoArgs) + +if __name__ == '__main__': + unittest.main() + diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index 162f4cffa..2232eb6e1 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -34,6 +34,7 @@ <enum-type name="Derived::OtherOverloadedFuncEnum"/> <enum-type name="Modifications::OverloadedModFunc"/> <enum-type name="ImplicitConv::CtorEnum"/> + <enum-type name="Time::NumArgs"/> <!-- BUG: renaming the ICOverloadedFuncEnum to the same name of a global enum causes the generator to confuse the @@ -236,6 +237,7 @@ </inject-code> </add-function> </value-type> + <value-type name="Time"/> <value-type name="Size"/> <value-type name="MapUser"/> <value-type name="PairUser"/> |