1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# 4############################################################################# 5## 6## Copyright (C) 2016 The Qt Company Ltd. 7## Contact: https://www.qt.io/licensing/ 8## 9## This file is part of the test suite of Qt for Python. 10## 11## $QT_BEGIN_LICENSE:GPL-EXCEPT$ 12## Commercial License Usage 13## Licensees holding valid commercial Qt licenses may use this file in 14## accordance with the commercial license agreement provided with the 15## Software or, alternatively, in accordance with the terms contained in 16## a written agreement between you and The Qt Company. For licensing terms 17## and conditions see https://www.qt.io/terms-conditions. For further 18## information use the contact form at https://www.qt.io/contact-us. 19## 20## GNU General Public License Usage 21## Alternatively, this file may be used under the terms of the GNU 22## General Public License version 3 as published by the Free Software 23## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 24## included in the packaging of this file. Please review the following 25## information to ensure the GNU General Public License requirements will 26## be met: https://www.gnu.org/licenses/gpl-3.0.html. 27## 28## $QT_END_LICENSE$ 29## 30############################################################################# 31 32import os 33import sys 34import unittest 35 36sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 37from shiboken_paths import init_paths 38init_paths() 39 40from sample import Photon 41 42'''This tests classes that inherit from template classes, 43simulating a situation found in Qt's phonon module.''' 44 45class TemplateInheritingClassTest(unittest.TestCase): 46 def testClassBasics(self): 47 self.assertEqual(Photon.ValueIdentity.classType(), Photon.IdentityType) 48 self.assertEqual(Photon.ValueDuplicator.classType(), Photon.DuplicatorType) 49 50 def testInstanceBasics(self): 51 value = 123 52 samer = Photon.ValueIdentity(value) 53 self.assertEqual(samer.multiplicator(), 1) 54 doubler = Photon.ValueDuplicator(value) 55 self.assertEqual(doubler.multiplicator(), 2) 56 self.assertEqual(samer.value(), doubler.value()) 57 self.assertEqual(samer.calculate() * 2, doubler.calculate()) 58 59 def testPassToFunctionAsPointer(self): 60 obj = Photon.ValueDuplicator(123) 61 self.assertEqual(Photon.callCalculateForValueDuplicatorPointer(obj), obj.calculate()) 62 63 def testPassToFunctionAsReference(self): 64 obj = Photon.ValueDuplicator(321) 65 self.assertEqual(Photon.callCalculateForValueDuplicatorReference(obj), obj.calculate()) 66 67 def testPassToMethodAsValue(self): 68 value1, value2 = 123, 321 69 one = Photon.ValueIdentity(value1) 70 other = Photon.ValueIdentity(value2) 71 self.assertEqual(one.sumValueUsingPointer(other), value1 + value2) 72 73 def testPassToMethodAsReference(self): 74 value1, value2 = 123, 321 75 one = Photon.ValueDuplicator(value1) 76 other = Photon.ValueDuplicator(value2) 77 self.assertEqual(one.sumValueUsingReference(other), value1 + value2) 78 79 def testPassPointerThrough(self): 80 obj1 = Photon.ValueIdentity(123) 81 self.assertEqual(obj1, obj1.passPointerThrough(obj1)) 82 obj2 = Photon.ValueDuplicator(321) 83 self.assertEqual(obj2, obj2.passPointerThrough(obj2)) 84 self.assertRaises(TypeError, obj1.passPointerThrough, obj2) 85 86if __name__ == '__main__': 87 unittest.main() 88