Add basic std::pair Python testing

Based on Ruby's li_std_pair_runme.rb
This commit is contained in:
William S Fulton 2020-08-13 13:41:09 +01:00
parent 46e17f1458
commit a38f30a194
1 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,47 @@
from li_std_pair import *
def check(flag):
if not flag:
raise RuntimeError("Check failed")
intPair = makeIntPair(7, 6)
check(isinstance(intPair, tuple))
check(len(intPair) == 2)
check(intPair[0] == 7)
check(intPair[1] == 6)
intPairConstRef = makeIntPairConstRef(7, 6)
check(isinstance(intPairConstRef, tuple))
check(intPairConstRef[0] == 7)
check(intPairConstRef[1] == 6)
#
# Each of these should return a reference to a wrapped
# std::pair<int, int> object (i.e. an IntPair instance).
#
intPairPtr = makeIntPairPtr(7, 6)
check(isinstance(intPairPtr, IntPair))
check(intPairPtr[0] == 7)
check(intPairPtr[1] == 6)
intPairRef = makeIntPairRef(7, 6)
check(isinstance(intPairRef, IntPair))
check(intPairRef[0] == 7)
check(intPairRef[1] == 6)
#
# Now test various input typemaps. Each of the wrapped C++ functions
# (product1, product2 and product3) is expecting an argument of a
# different type (see li_std_pair.i). Typemaps should be in place to
# convert this tuple into the expected argument type.
#
check(product1(intPair) == 42)
check(product2(intPair) == 42)
# check(product3(intPair) == 42) # TODO, if desirable to match Ruby wrappers behaviour. Requires equivalent to typemap(in) std::pair* in Lib/ruby/std_pair.i and further fixes to stop recursive calls to swig::asptr which this testcase shows. Plus further changes for any type of sequence type (including other STL containers) to be accepted by all methods taking an STL container to match Ruby behaviour.
#
# Similarly, each of the input typemaps should know what to do
# with an IntPair instance.
#
check(product1(intPairPtr) == 42)
check(product2(intPairPtr) == 42)
check(product3(intPairPtr) == 42)