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 32'''Test cases for method arguments modifications performed as described on typesystem.''' 33 34import os 35import sys 36import unittest 37 38sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 39from shiboken_paths import init_paths 40init_paths() 41 42from sample import Modifications, Point 43 44class ArgumentModificationsTest(unittest.TestCase): 45 '''Test cases for method arguments modifications performed as described on typesystem.''' 46 47 def setUp(self): 48 self.mods = Modifications() 49 50 def tearDown(self): 51 del self.mods 52 53 def testArgRemoval0(self): 54 '''Tests argument removal modifications on Modifications.argRemoval0.''' 55 # void [-> PyObject*] argRemoval0(int, bool, int = 123 [removed, new val = 321], int = 456) 56 # code-injection: returns tuple with received parameters plus removed ones 57 a0, a1, a2 = 1, True, 2 58 self.assertEqual(self.mods.argRemoval0(a0, a1), (a0, a1, 321, 456)) 59 self.assertEqual(self.mods.argRemoval0(a0, a1, a2), (a0, a1, 321, a2)) 60 # the other wasn't modified 61 # void argRemoval0(int, bool, int, bool) 62 self.assertEqual(self.mods.argRemoval0(0, False, 0, False), None) 63 64 def testArgRemoval1(self): 65 '''Tests argument removal modifications on Modifications.argRemoval1.''' 66 # void [-> PyObject*] argRemoval1(int, bool, Point = Point(1, 2) [removed], Point = Point(3, 4) [removed], int = 333) 67 # code-injection: returns tuple with received parameters plus removed ones 68 a0, a1, a2 = 1, True, 2 69 self.assertEqual(self.mods.argRemoval1(a0, a1), (a0, a1, Point(1, 2), Point(3, 4), 333)) 70 self.assertEqual(self.mods.argRemoval1(a0, a1, a2), (a0, a1, Point(1, 2), Point(3, 4), a2)) 71 # the other wasn't modified 72 # void argRemoval1(int, bool, int, bool) 73 self.assertEqual(self.mods.argRemoval1(0, False, 0, False), None) 74 75 def testArgRemoval2(self): 76 '''Tests argument removal modifications on Modifications.argRemoval2.''' 77 # void [-> PyObject*] argRemoval2(int, bool, Point = Point(1, 2) [removed], Point = Point(3, 4) [removed], int = 333) 78 # code-injection: returns tuple with received parameters plus removed ones 79 a0, a1, a2 = 1, True, 2 80 self.assertEqual(self.mods.argRemoval2(a0, a1), (a0, a1, Point(1, 2), Point(3, 4), 333)) 81 self.assertEqual(self.mods.argRemoval2(a0, a1, a2), (a0, a1, Point(1, 2), Point(3, 4), a2)) 82 83 def testArgRemoval3(self): 84 '''Tests argument removal modifications on Modifications.argRemoval3.''' 85 # void [-> PyObject*] argRemoval3(int, Point = Point(1, 2) [removed], bool = true, Point = Point(3, 4) [removed], int = 333) 86 # code-injection: returns tuple with received parameters plus removed ones 87 a0, a1, a2 = 1, True, 2 88 self.assertEqual(self.mods.argRemoval3(a0), (a0, Point(1, 2), True, Point(3, 4), 333)) 89 self.assertEqual(self.mods.argRemoval3(a0, a1), (a0, Point(1, 2), a1, Point(3, 4), 333)) 90 self.assertEqual(self.mods.argRemoval3(a0, a1, a2), (a0, Point(1, 2), a1, Point(3, 4), a2)) 91 92 def testArgRemoval4(self): 93 '''Tests argument removal modifications on Modifications.argRemoval4.''' 94 # void [-> PyObject*] argRemoval4(int, Point [removed, new val = Point(6, 9)], bool, Point = Point(3, 4) [removed], int = 333) 95 # code-injection: returns tuple with received parameters plus removed ones 96 a0, a1, a2 = 1, True, 2 97 self.assertRaises(TypeError, self.mods.argRemoval4, a0) 98 self.assertEqual(self.mods.argRemoval4(a0, a1), (a0, Point(6, 9), a1, Point(3, 4), 333)) 99 self.assertEqual(self.mods.argRemoval4(a0, a1, a2), (a0, Point(6, 9), a1, Point(3, 4), a2)) 100 101 def testArgRemoval5(self): 102 '''Tests argument removal modifications on Modifications.argRemoval5.''' 103 # void [-> PyObject*] argRemoval5(int [removed, new val = 100], bool, 104 # Point = Point(1, 2) [removed], 105 # Point = Point(3, 4) [removed], int = 333) 106 # code-injection: returns tuple with received parameters plus removed ones 107 a0, a1, a2 = True, 2, True 108 self.assertEqual(self.mods.argRemoval5(a0), (100, a0, Point(1, 2), Point(3, 4), 333)) 109 self.assertEqual(self.mods.argRemoval5(a0, a1), (100, a0, Point(1, 2), Point(3, 4), a1)) 110 # void [-> PyObject*] argRemoval5(int [removed, new val = 200], bool, int, bool) 111 # code-injection: returns tuple with received parameters plus removed ones 112 self.assertEqual(self.mods.argRemoval5(a0, a1, a2), (200, a0, a1, a2)) 113 114if __name__ == '__main__': 115 unittest.main() 116 117