diff options
Diffstat (limited to 'python/test/Ice/custom/AllTests.py')
-rw-r--r-- | python/test/Ice/custom/AllTests.py | 207 |
1 files changed, 207 insertions, 0 deletions
diff --git a/python/test/Ice/custom/AllTests.py b/python/test/Ice/custom/AllTests.py index d0d7c73d220..7b0a634176c 100644 --- a/python/test/Ice/custom/AllTests.py +++ b/python/test/Ice/custom/AllTests.py @@ -125,6 +125,13 @@ def allTests(helper, communicator): test(v1[i] == v[i]) test(v2[i] == v[i]) + v = [] + v1, v2 = custom.opBoolSeq(array.array("b", v)) + test(isinstance(v1, array.array)) + test(isinstance(v2, array.array)) + test(len(v1) == 0) + test(len(v2) == 0) + v = [0, 2, 4, 8, 16, 32, 64, 127] v1, v2 = custom.opByteSeq(array.array("b", v)) test(isinstance(v1, array.array)) @@ -135,6 +142,13 @@ def allTests(helper, communicator): test(v1[i] == v[i]) test(v2[i] == v[i]) + v = [] + v1, v2 = custom.opByteSeq(array.array("b", v)) + test(isinstance(v1, array.array)) + test(isinstance(v2, array.array)) + test(len(v1) == 0) + test(len(v2) == 0) + v = [0, 2, 4, 8, 16, 32, 64, 128, 256] v1, v2 = custom.opShortSeq(array.array("h", v)) test(isinstance(v1, array.array)) @@ -145,6 +159,13 @@ def allTests(helper, communicator): test(v1[i] == v[i]) test(v2[i] == v[i]) + v = [] + v1, v2 = custom.opShortSeq(array.array("h", v)) + test(isinstance(v1, array.array)) + test(isinstance(v2, array.array)) + test(len(v1) == 0) + test(len(v2) == 0) + v = [0, 2, 4, 8, 16, 32, 64, 128, 256] v1, v2 = custom.opIntSeq(array.array("i", v)) test(isinstance(v1, array.array)) @@ -155,6 +176,13 @@ def allTests(helper, communicator): test(v1[i] == v[i]) test(v2[i] == v[i]) + v = [] + v1, v2 = custom.opIntSeq(array.array("i", v)) + test(isinstance(v1, array.array)) + test(isinstance(v2, array.array)) + test(len(v1) == 0) + test(len(v2) == 0) + # # The array "q" type specifier is new in Python 3.3 # @@ -169,6 +197,13 @@ def allTests(helper, communicator): test(v1[i] == v[i]) test(v2[i] == v[i]) + v = [] + v1, v2 = custom.opLongSeq(array.array("q", v)) + test(isinstance(v1, array.array)) + test(isinstance(v2, array.array)) + test(len(v1) == 0) + test(len(v2) == 0) + v = [0.1, 0.2, 0.4, 0.8, 0.16, 0.32, 0.64, 0.128, 0.256] v1, v2 = custom.opFloatSeq(array.array("f", v)) test(isinstance(v1, array.array)) @@ -179,6 +214,13 @@ def allTests(helper, communicator): test(round(v1[i], 1) == round(v[i], 1)) test(round(v2[i], 1) == round(v[i], 1)) + v = [] + v1, v2 = custom.opFloatSeq(array.array("f", v)) + test(isinstance(v1, array.array)) + test(isinstance(v2, array.array)) + test(len(v1) == 0) + test(len(v2) == 0) + v = [0.1, 0.2, 0.4, 0.8, 0.16, 0.32, 0.64, 0.128, 0.256] v1, v2 = custom.opDoubleSeq(array.array("d", v)) test(isinstance(v1, array.array)) @@ -189,6 +231,69 @@ def allTests(helper, communicator): test(round(v1[i], 1) == round(v[i], 1)) test(round(v2[i], 1) == round(v[i], 1)) + v = [] + v1, v2 = custom.opDoubleSeq(array.array("d", v)) + test(isinstance(v1, array.array)) + test(isinstance(v2, array.array)) + test(len(v1) == 0) + test(len(v2) == 0) + + + d = Test.D() + d.boolSeq = array.array("b", [True, False, True, False, True]) + d.byteSeq = array.array("b", [0, 2, 4, 8, 16, 32, 64, 127]) + d.shortSeq = array.array("h", [0, 2, 4, 8, 16, 32, 64, 128, 256]) + d.intSeq = array.array("i", [0, 2, 4, 8, 16, 32, 64, 128, 256]) + # + # The array "q" type specifier is new in Python 3.3 + # + if sys.version_info[:2] >= (3, 3): + d.longSeq = array.array("q", [0, 2, 4, 8, 16, 32, 64, 128, 256]) + d.floatSeq = array.array("f", [0.1, 0.2, 0.4, 0.8, 0.16, 0.32, 0.64, 0.128, 0.256]) + d.doubleSeq = array.array("d", [0.1, 0.2, 0.4, 0.8, 0.16, 0.32, 0.64, 0.128, 0.256]) + + d1 = custom.opD(d) + test(isinstance(d1.boolSeq, array.array)) + test(len(d1.boolSeq) == len(d.boolSeq)) + for i in range(len(d.boolSeq)): + test(d.boolSeq[i] == d1.boolSeq[i]) + + test(isinstance(d1.byteSeq, array.array)) + test(len(d1.byteSeq) == len(d.byteSeq)) + for i in range(len(d.byteSeq)): + test(d.byteSeq[i] == d1.byteSeq[i]) + + test(isinstance(d1.intSeq, array.array)) + test(len(d1.intSeq) == len(d.intSeq)) + for i in range(len(d.intSeq)): + test(d.intSeq[i] == d1.intSeq[i]) + + # + # The array "q" type specifier is new in Python 3.3 + # + if sys.version_info[:2] >= (3, 3): + test(isinstance(d1.longSeq, array.array)) + test(len(d1.longSeq) == len(d.longSeq)) + for i in range(len(d.longSeq)): + test(d.longSeq[i] == d1.longSeq[i]) + + test(isinstance(d1.floatSeq, array.array)) + test(len(d1.floatSeq) == len(d.floatSeq)) + for i in range(len(d.floatSeq)): + test(round(d.floatSeq[i], 1) == round(d1.floatSeq[i], 1)) + + test(isinstance(d1.doubleSeq, array.array)) + test(len(d1.doubleSeq) == len(d.doubleSeq)) + for i in range(len(d.doubleSeq)): + test(round(d.doubleSeq[i], 1) == round(d1.doubleSeq[i], 1)) + + d1 = custom.opD(Test.D()) + test(d1.boolSeq == Ice.Unset) + test(d1.byteSeq == Ice.Unset) + test(d1.intSeq == Ice.Unset) + test(d1.longSeq == Ice.Unset) + test(d1.floatSeq == Ice.Unset) + test(d1.doubleSeq == Ice.Unset) # # With python 3.3 we use the new buffer interface for marshaling # sequences of types that implement the buffer protocol and this @@ -290,6 +395,13 @@ def allTests(helper, communicator): test(v1[i] == v[i]) test(v2[i] == v[i]) + v = [] + v1, v2 = custom.opBoolSeq(numpy.array(v, numpy.bool_)) + test(isinstance(v1, numpy.ndarray)) + test(isinstance(v2, numpy.ndarray)) + test(len(v1) == 0) + test(len(v2) == 0) + v = [0, 2, 4, 8, 16, 32, 64, 127] v1, v2 = custom.opByteSeq(numpy.array(v, numpy.int8)) test(isinstance(v1, numpy.ndarray)) @@ -300,6 +412,13 @@ def allTests(helper, communicator): test(v1[i] == v[i]) test(v2[i] == v[i]) + v = [] + v1, v2 = custom.opByteSeq(numpy.array(v, numpy.int8)) + test(isinstance(v1, numpy.ndarray)) + test(isinstance(v2, numpy.ndarray)) + test(len(v1) == 0) + test(len(v2) == 0) + v = [0, 2, 4, 8, 16, 32, 64, 128, 256] v1, v2 = custom.opShortSeq(numpy.array(v, numpy.int16)) test(isinstance(v1, numpy.ndarray)) @@ -310,6 +429,13 @@ def allTests(helper, communicator): test(v1[i] == v[i]) test(v2[i] == v[i]) + v = [] + v1, v2 = custom.opShortSeq(numpy.array(v, numpy.int16)) + test(isinstance(v1, numpy.ndarray)) + test(isinstance(v2, numpy.ndarray)) + test(len(v1) == 0) + test(len(v2) == 0) + v = [0, 2, 4, 8, 16, 32, 64, 128, 256] v1, v2 = custom.opIntSeq(numpy.array(v, numpy.int32)) test(isinstance(v1, numpy.ndarray)) @@ -320,6 +446,13 @@ def allTests(helper, communicator): test(v1[i] == v[i]) test(v2[i] == v[i]) + v = [] + v1, v2 = custom.opIntSeq(numpy.array(v, numpy.int32)) + test(isinstance(v1, numpy.ndarray)) + test(isinstance(v2, numpy.ndarray)) + test(len(v1) == 0) + test(len(v2) == 0) + v = [0, 2, 4, 8, 16, 32, 64, 128, 256] v1, v2 = custom.opLongSeq(numpy.array(v, numpy.int64)) test(isinstance(v1, numpy.ndarray)) @@ -330,6 +463,13 @@ def allTests(helper, communicator): test(v1[i] == v[i]) test(v2[i] == v[i]) + v = [] + v1, v2 = custom.opLongSeq(numpy.array(v, numpy.int64)) + test(isinstance(v1, numpy.ndarray)) + test(isinstance(v2, numpy.ndarray)) + test(len(v1) == 0) + test(len(v2) == 0) + v = [0.1, 0.2, 0.4, 0.8, 0.16, 0.32, 0.64, 0.128, 0.256] v1, v2 = custom.opFloatSeq(numpy.array(v, numpy.float32)) test(isinstance(v1, numpy.ndarray)) @@ -340,6 +480,13 @@ def allTests(helper, communicator): test(round(float(v1[i]), 1) == round(v[i], 1)) test(round(float(v2[i]), 1) == round(v[i], 1)) + v = [] + v1, v2 = custom.opFloatSeq(numpy.array(v, numpy.float32)) + test(isinstance(v1, numpy.ndarray)) + test(isinstance(v2, numpy.ndarray)) + test(len(v1) == 0) + test(len(v2) == 0) + v = [0.1, 0.2, 0.4, 0.8, 0.16, 0.32, 0.64, 0.128, 0.256] v1, v2 = custom.opDoubleSeq(numpy.array(v, numpy.float64)) test(isinstance(v1, numpy.ndarray)) @@ -350,6 +497,61 @@ def allTests(helper, communicator): test(round(float(v1[i]), 1) == round(v[i], 1)) test(round(float(v2[i]), 1) == round(v[i], 1)) + v = [] + v1, v2 = custom.opDoubleSeq(numpy.array(v, numpy.float64)) + test(isinstance(v1, numpy.ndarray)) + test(isinstance(v2, numpy.ndarray)) + test(len(v1) == 0) + test(len(v2) == 0) + + d = Test.NumPy.D() + d.boolSeq = numpy.array([True, False, True, False, True], numpy.bool_) + d.byteSeq = numpy.array([0, 2, 4, 8, 16, 32, 64, 127], numpy.int8) + d.shortSeq = numpy.array([0, 2, 4, 8, 16, 32, 64, 128, 256], numpy.int16) + d.intSeq = numpy.array([0, 2, 4, 8, 16, 32, 64, 128, 256], numpy.int32) + d.longSeq = numpy.array([0, 2, 4, 8, 16, 32, 64, 128, 256], numpy.int64) + d.floatSeq = numpy.array([0.1, 0.2, 0.4, 0.8, 0.16, 0.32, 0.64, 0.128, 0.256], numpy.float32) + d.doubleSeq = numpy.array([0.1, 0.2, 0.4, 0.8, 0.16, 0.32, 0.64, 0.128, 0.256], numpy.float64) + + d1 = custom.opD(d) + test(isinstance(d1.boolSeq, numpy.ndarray)) + test(len(d1.boolSeq) == len(d.boolSeq)) + for i in range(len(d.boolSeq)): + test(d.boolSeq[i] == d1.boolSeq[i]) + + test(isinstance(d1.byteSeq, numpy.ndarray)) + test(len(d1.byteSeq) == len(d.byteSeq)) + for i in range(len(d.byteSeq)): + test(d.byteSeq[i] == d1.byteSeq[i]) + + test(isinstance(d1.intSeq, numpy.ndarray)) + test(len(d1.intSeq) == len(d.intSeq)) + for i in range(len(d.intSeq)): + test(d.intSeq[i] == d1.intSeq[i]) + + test(isinstance(d1.longSeq, numpy.ndarray)) + test(len(d1.longSeq) == len(d.longSeq)) + for i in range(len(d.longSeq)): + test(d.longSeq[i] == d1.longSeq[i]) + + test(isinstance(d1.floatSeq, numpy.ndarray)) + test(len(d1.floatSeq) == len(d.floatSeq)) + for i in range(len(d.floatSeq)): + test(round(d.floatSeq[i], 1) == round(d1.floatSeq[i], 1)) + + test(isinstance(d1.doubleSeq, numpy.ndarray)) + test(len(d1.doubleSeq) == len(d.doubleSeq)) + for i in range(len(d.doubleSeq)): + test(round(d.doubleSeq[i], 1) == round(d1.doubleSeq[i], 1)) + + d1 = custom.opD(Test.NumPy.D()) + test(d1.boolSeq == Ice.Unset) + test(d1.byteSeq == Ice.Unset) + test(d1.intSeq == Ice.Unset) + test(d1.longSeq == Ice.Unset) + test(d1.floatSeq == Ice.Unset) + test(d1.doubleSeq == Ice.Unset) + v1 = numpy.array([numpy.complex128(1 + 1j), numpy.complex128(2 + 2j), numpy.complex128(3 + 3j), @@ -360,6 +562,11 @@ def allTests(helper, communicator): for i in range(len(v1)): test(v1[i] == v2[i]) + v1 = numpy.array([], numpy.complex128) + v2 = custom.opComplex128Seq(v1) + test(isinstance(v2, numpy.ndarray)) + test(len(v1) == len(v2)) + v1 = custom.opBoolMatrix() test(numpy.array_equal(v1, numpy.array([[True, False, True], [True, False, True], |