diff options
author | Luciano Wolf <luciano.wolf@openbossa.org> | 2010-04-14 19:14:21 -0300 |
---|---|---|
committer | Luciano Wolf <luciano.wolf@openbossa.org> | 2010-04-21 12:26:52 -0300 |
commit | da4915fd1ddfd1e04a6ef21b0117d83fc7fe2d5d (patch) | |
tree | f3e5320f87887ddd64d4760afb020d2b995205a6 /tests/samplebinding | |
parent | f0f1aa01139a073430eb2c5feb767dedc45d3b4f (diff) |
Support to "only private constructor available" case.
Diffstat (limited to 'tests/samplebinding')
-rw-r--r-- | tests/samplebinding/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/samplebinding/global.h | 1 | ||||
-rwxr-xr-x | tests/samplebinding/privatector_test.py | 79 | ||||
-rw-r--r-- | tests/samplebinding/typesystem_sample.xml | 1 |
4 files changed, 82 insertions, 0 deletions
diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt index 7510b5b3f..06e35ecb8 100644 --- a/tests/samplebinding/CMakeLists.txt +++ b/tests/samplebinding/CMakeLists.txt @@ -45,6 +45,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/pairuser_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/point_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/pointerholder_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/polygon_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/privatector_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/privatedtor_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/protectednonpolymorphic_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/protectedpolymorphic_wrapper.cpp diff --git a/tests/samplebinding/global.h b/tests/samplebinding/global.h index f54fb5166..c037a5b66 100644 --- a/tests/samplebinding/global.h +++ b/tests/samplebinding/global.h @@ -24,6 +24,7 @@ #include "point.h" #include "pointerholder.h" #include "polygon.h" +#include "privatector.h" #include "privatedtor.h" #include "protected.h" #include "reference.h" diff --git a/tests/samplebinding/privatector_test.py b/tests/samplebinding/privatector_test.py new file mode 100755 index 000000000..ea713670f --- /dev/null +++ b/tests/samplebinding/privatector_test.py @@ -0,0 +1,79 @@ +#!/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 a class with only a private constructor.''' + +import gc +import sys +import unittest + +from sample import PrivateCtor + + +class PrivateCtorTest(unittest.TestCase): + '''Test case for PrivateCtor class''' + + def testPrivateCtorInstanciation(self): + '''Test if instanciation of class with a private constructor raises an exception.''' + self.assertRaises(TypeError, PrivateCtor) + + def testPrivateCtorInheritance(self): + '''Test if inheriting from PrivateCtor raises an exception.''' + def inherit(): + class Foo(PrivateCtor): + pass + self.assertRaises(TypeError, inherit) + + def testPrivateCtorInstanceMethod(self): + '''Test if PrivateCtor.instance() method return the proper singleton.''' + pd1 = PrivateCtor.instance() + calls = pd1.instanceCalls() + self.assertEqual(type(pd1), PrivateCtor) + pd2 = PrivateCtor.instance() + self.assertEqual(pd2, pd1) + self.assertEqual(pd2.instanceCalls(), calls + 1) + + def testPrivateCtorRefCounting(self): + '''Test refcounting of the singleton returned by PrivateCtor.instance().''' + pd1 = PrivateCtor.instance() + calls = pd1.instanceCalls() + refcnt = sys.getrefcount(pd1) + pd2 = PrivateCtor.instance() + self.assertEqual(pd2.instanceCalls(), calls + 1) + self.assertEqual(sys.getrefcount(pd2), sys.getrefcount(pd1)) + self.assertEqual(sys.getrefcount(pd2), refcnt + 1) + del pd1 + self.assertEqual(sys.getrefcount(pd2), refcnt) + del pd2 + gc.collect() + pd3 = PrivateCtor.instance() + self.assertEqual(type(pd3), PrivateCtor) + self.assertEqual(pd3.instanceCalls(), calls + 2) + self.assertEqual(sys.getrefcount(pd3), refcnt) + +if __name__ == '__main__': + unittest.main() + diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index cfe709a61..6a56a1958 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -988,6 +988,7 @@ <value-type name="VoidHolder"/> + <object-type name="PrivateCtor" /> <object-type name="PrivateDtor" /> <object-type name="Base1"/> |