File: TestOverloads.py

package info (click to toggle)
vtk6 6.3.0%2Bdfsg2-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 118,880 kB
  • sloc: cpp: 1,442,792; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,119; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 154; makefile: 103; objc: 17
file content (68 lines) | stat: -rw-r--r-- 2,359 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""Test overloaded method resolution in VTK-Python

The wrappers should call overloaded C++ methods using similar
overload resolution rules as C++.  Python itself does not have
method overloading.

Created on Feb 15, 2015 by David Gobbi

"""

import sys
import exceptions
import vtk
from vtk.test import Testing

class TestOverloads(Testing.vtkTest):

    def testMethods(self):
        """Test overloaded methods"""
        # single-argument method vtkTransform::SetMatrix()
        t = vtk.vtkTransform()
        m = vtk.vtkMatrix4x4()
        m.SetElement(0, 0, 2)
        t.SetMatrix(m)
        self.assertEqual(t.GetMatrix().GetElement(0, 0), 2)
        t.SetMatrix([0,1,0,0, 1,0,0,0, 0,0,-1,0, 0,0,0,1])
        self.assertEqual(t.GetMatrix().GetElement(0, 0), 0)
        # mixed number of arguments
        w = vtk.vtkRenderWindow()
        w.SetTileScale(2)
        self.assertEqual(w.GetTileScale(), (2,2))
        w.SetTileScale(3,4)
        self.assertEqual(w.GetTileScale(), (3,4))

    def testConstructors(self):
        """Test overloaded constructors"""
        # resolve by number of arguments
        v = vtk.vtkVector3d(3, 4, 5)
        self.assertEqual((v[0], v[1], v[2]), (3, 4, 5))
        v = vtk.vtkVector3d(6)
        self.assertEqual((v[0], v[1], v[2]), (6, 6, 6))
        # resolve by argument type
        v = vtk.vtkVariant(3.0)
        self.assertEqual(v.GetType(), vtk.VTK_DOUBLE)
        v = vtk.vtkVariant(1)
        self.assertEqual(v.GetType(), vtk.VTK_INT)
        v = vtk.vtkVariant("hello")
        self.assertEqual(v.GetType(), vtk.VTK_STRING)
        v = vtk.vtkVariant(vtk.vtkObject())
        self.assertEqual(v.GetType(), vtk.VTK_OBJECT)

    def testArgumentConversion(self):
        """Test argument conversion via implicit constructors"""
        # automatic conversion to vtkVariant
        a = vtk.vtkVariantArray()
        a.InsertNextValue(2.5)
        a.InsertNextValue(vtk.vtkObject())
        self.assertEqual(a.GetValue(0), vtk.vtkVariant(2.5))
        self.assertEqual(a.GetValue(1).GetType(), vtk.VTK_OBJECT)
        # same, but this one is via "const vtkVariant&" argument
        a = vtk.vtkDenseArray[float]()
        a.Resize(1)
        a.SetVariantValue(0, 2.5)
        self.assertEqual(a.GetVariantValue(0).ToDouble(), 2.5)


if __name__ == "__main__":
    Testing.main([(TestOverloads, 'test')])