예제 #1
0
 def throwUndeclaredC(self, a, b, c, current=None):
     ex = Test.C()
     ex.aMem = a
     ex.bMem = b
     ex.cMem = c
     f = Ice.Future()
     f.set_exception(ex)
     return f
예제 #2
0
파일: AllTests.py 프로젝트: zj771484545/ice
def allTests(helper, communicator):
    ref = "test:{0}".format(helper.getTestEndpoint())
    base = communicator.stringToProxy(ref)
    test(base)

    custom = Test.CustomPrx.checkedCast(base)
    test(custom)

    byteList = [1, 2, 3, 4, 5]
    if sys.version_info[0] == 2:
        byteString = ''.join(map(chr, byteList))
    else:
        byteString = bytes(byteList)
    stringList = ['s1', 's2', 's3']

    sys.stdout.write("testing custom sequences... ")
    sys.stdout.flush()

    (r, b2) = custom.opByteString1(byteString)
    if sys.version_info[0] == 2:
        test(isinstance(r, str))
        test(isinstance(b2, str))
    else:
        test(isinstance(r, bytes))
        test(isinstance(b2, bytes))
    test(r == byteString)
    test(b2 == byteString)

    (r, b2) = custom.opByteString2(byteString)
    test(isinstance(r, tuple))
    test(isinstance(b2, list))
    for i in range(0, len(byteList)):
        test(r[i] == byteList[i])
        test(b2[i] == byteList[i])

    (r, b2) = custom.opByteList1(byteList)
    test(isinstance(r, list))
    test(isinstance(b2, list))
    for i in range(0, len(byteList)):
        test(r[i] == byteList[i])
        test(b2[i] == byteList[i])

    (r, b2) = custom.opByteList2(byteList)
    if sys.version_info[0] == 2:
        test(isinstance(r, str))
    else:
        test(isinstance(r, bytes))
    test(isinstance(b2, tuple))
    test(r == byteString)
    for i in range(0, len(byteList)):
        test(b2[i] == byteList[i])

    (r, b2) = custom.opStringList1(stringList)
    test(isinstance(r, list))
    test(isinstance(b2, list))
    test(r == stringList)
    test(b2 == stringList)

    (r, b2) = custom.opStringList2(stringList)
    test(isinstance(r, tuple))
    test(isinstance(b2, tuple))
    for i in range(0, len(stringList)):
        test(r[i] == stringList[i])
        test(b2[i] == stringList[i])

    (r, b2) = custom.opStringTuple1(stringList)
    test(isinstance(r, tuple))
    test(isinstance(b2, tuple))
    for i in range(0, len(stringList)):
        test(r[i] == stringList[i])
        test(b2[i] == stringList[i])

    (r, b2) = custom.opStringTuple2(stringList)
    test(isinstance(r, list))
    test(isinstance(b2, list))
    test(r == stringList)
    test(b2 == stringList)

    s = Test.S()
    s.b1 = byteList
    s.b2 = byteList
    s.b3 = byteList
    s.b4 = byteList
    s.s1 = stringList
    s.s2 = stringList
    s.s3 = stringList
    s.s4 = stringList
    custom.sendS(s)

    c = Test.C()
    c.b1 = byteList
    c.b2 = byteList
    c.b3 = byteList
    c.b4 = byteList
    c.s1 = stringList
    c.s2 = stringList
    c.s3 = stringList
    c.s4 = stringList
    custom.sendC(c)

    print("ok")

    sys.stdout.write("testing python:array.array... ")
    sys.stdout.flush()

    v = [True, False, True, False, True]
    v1, v2 = custom.opBoolSeq(array.array("b", v))
    test(isinstance(v1, array.array))
    test(isinstance(v2, array.array))
    test(len(v1) == len(v))
    test(len(v2) == len(v))
    for i in range(len(v)):
        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))
    test(isinstance(v2, array.array))
    test(len(v1) == len(v))
    test(len(v2) == len(v))
    for i in range(len(v)):
        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))
    test(isinstance(v2, array.array))
    test(len(v1) == len(v))
    test(len(v2) == len(v))
    for i in range(len(v)):
        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))
    test(isinstance(v2, array.array))
    test(len(v1) == len(v))
    test(len(v2) == len(v))
    for i in range(len(v)):
        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
    #
    if sys.version_info[:2] >= (3, 3):
        v = [0, 2, 4, 8, 16, 32, 64, 128, 256]
        v1, v2 = custom.opLongSeq(array.array("q", v))
        test(isinstance(v1, array.array))
        test(isinstance(v2, array.array))
        test(len(v1) == len(v))
        test(len(v2) == len(v))
        for i in range(len(v)):
            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))
    test(isinstance(v2, array.array))
    test(len(v1) == len(v))
    test(len(v2) == len(v))
    for i in range(len(v)):
        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))
    test(isinstance(v2, array.array))
    test(len(v1) == len(v))
    test(len(v2) == len(v))
    for i in range(len(v)):
        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
    # allow Ice to check that the container item size and endianness
    #
    if sys.version_info[0] >= 3:
        try:
            custom.opBoolSeq(array.array("h", [1, 2, 3, 4]))
            test(False)
        except ValueError:
            pass

        try:
            custom.opShortSeq(array.array("i", [1, 2, 3, 4]))
            test(False)
        except ValueError:
            pass

        try:
            custom.opIntSeq(array.array("h", [1, 2, 3, 4]))
            test(False)
        except ValueError:
            pass

        try:
            custom.opLongSeq(array.array("h", [1, 2, 3, 4]))
            test(False)
        except ValueError:
            pass

        try:
            custom.opFloatSeq(array.array("h", [1, 2, 3, 4]))
            test(False)
        except ValueError:
            pass

        try:
            custom.opDoubleSeq(array.array("h", [1, 2, 3, 4]))
            test(False)
        except ValueError:
            pass

    try:
        custom.opBogusArrayNotExistsFactory()
        test(False)
    except ImportError:
        pass

    try:
        custom.opBogusArrayThrowFactory()
        test(False)
    except ValueError:
        pass

    try:
        custom.opBogusArrayType()
        test(False)
    except ValueError:
        pass

    try:
        custom.opBogusArrayNoneFactory()
        test(False)
    except ValueError:
        pass

    try:
        custom.opBogusArraySignatureFactory()
        test(False)
    except TypeError:
        pass

    try:
        custom.opBogusArrayNoCallableFactory()
        test(False)
    except RuntimeError:
        pass

    print("ok")

    try:
        import numpy
        ref = "test.numpy:{0}".format(helper.getTestEndpoint())
        base = communicator.stringToProxy(ref)
        test(base)

        custom = Test.NumPy.CustomPrx.checkedCast(base)
        test(custom)
        sys.stdout.write("testing python:numpy.ndarray... ")
        sys.stdout.flush()

        v = [True, False, True, False, True]
        v1, v2 = custom.opBoolSeq(numpy.array(v, numpy.bool_))
        test(isinstance(v1, numpy.ndarray))
        test(isinstance(v2, numpy.ndarray))
        test(len(v1) == len(v))
        test(len(v2) == len(v))
        for i in range(len(v)):
            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))
        test(isinstance(v2, numpy.ndarray))
        test(len(v1) == len(v))
        test(len(v2) == len(v))
        for i in range(len(v)):
            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))
        test(isinstance(v2, numpy.ndarray))
        test(len(v1) == len(v))
        test(len(v2) == len(v))
        for i in range(len(v)):
            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))
        test(isinstance(v2, numpy.ndarray))
        test(len(v1) == len(v))
        test(len(v2) == len(v))
        for i in range(len(v)):
            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))
        test(isinstance(v2, numpy.ndarray))
        test(len(v1) == len(v))
        test(len(v2) == len(v))
        for i in range(len(v)):
            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))
        test(isinstance(v2, numpy.ndarray))
        test(len(v1) == len(v))
        test(len(v2) == len(v))
        for i in range(len(v)):
            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))
        test(isinstance(v2, numpy.ndarray))
        test(len(v1) == len(v))
        test(len(v2) == len(v))
        for i in range(len(v)):
            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),
            numpy.complex128(4 + 4j)
        ], numpy.complex128)
        v2 = custom.opComplex128Seq(v1)
        test(isinstance(v2, numpy.ndarray))
        test(len(v1) == len(v2))
        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],
                             [True, False, True]], numpy.bool_)))

        v1 = custom.opByteMatrix()
        test(
            numpy.array_equal(
                v1, numpy.array([[1, 0, 1], [1, 0, 1], [1, 0, 1]],
                                numpy.int8)))

        v1 = custom.opShortMatrix()
        test(
            numpy.array_equal(
                v1, numpy.array([[1, 0, 1], [1, 0, 1], [1, 0, 1]],
                                numpy.int16)))

        v1 = custom.opIntMatrix()
        test(
            numpy.array_equal(
                v1, numpy.array([[1, 0, 1], [1, 0, 1], [1, 0, 1]],
                                numpy.int32)))

        v1 = custom.opLongMatrix()
        test(
            numpy.array_equal(
                v1, numpy.array([[1, 0, 1], [1, 0, 1], [1, 0, 1]],
                                numpy.int64)))

        v1 = custom.opFloatMatrix()
        test(
            numpy.array_equal(
                v1,
                numpy.array(
                    [[1.1, 0.1, 1.1], [1.1, 0.1, 1.1], [1.1, 0.1, 1.1]],
                    numpy.float32)))

        v1 = custom.opDoubleMatrix()
        test(
            numpy.array_equal(
                v1,
                numpy.array(
                    [[1.1, 0.1, 1.1], [1.1, 0.1, 1.1], [1.1, 0.1, 1.1]],
                    numpy.float64)))

        try:
            custom.opBogusNumpyArrayType()
            test(False)
        except ValueError:
            pass

        print("ok")
    except ImportError:
        print("numpy not installed skiping python:numpy.ndarray testing")
        pass

    return custom
예제 #3
0
파일: ServerAMD.py 프로젝트: zhoushiyi/ice
 def throwCasC_async(self, cb, a, b, c, current=None):
     ex = Test.C()
     ex.aMem = a
     ex.bMem = b
     ex.cMem = c
     cb.ice_exception(ex)
예제 #4
0
def allTests(communicator):
    sys.stdout.write("testing equals() for Slice structures... ")
    sys.stdout.flush()

    #
    # Define some default values.
    #
    def_s2 = Test.S2(True, 98, 99, 100, 101, "string", (1, 2, 3), Test.S1("name"))

    #
    # Compare default-constructed structures.
    #
    test(Test.S2() == Test.S2())

    #
    # Change one member at a time.
    #
    v = copy.copy(def_s2)
    test(v == def_s2)

    v = copy.copy(def_s2)
    v.bo = False
    test(v != def_s2)

    v = copy.copy(def_s2)
    v.by = v.by - 1
    test(v != def_s2)

    v = copy.copy(def_s2)
    v.sh = v.sh - 1
    test(v != def_s2)

    v = copy.copy(def_s2)
    v.i = v.i - 1
    test(v != def_s2)

    v = copy.copy(def_s2)
    v.l = v.l - 1
    test(v != def_s2)

    v = copy.copy(def_s2)
    v.str = ""
    test(v != def_s2)

    #
    # String member
    #
    v1 = copy.copy(def_s2)
    v1.str = "string"
    test(v1 == def_s2)

    v1 = copy.copy(def_s2)
    v2 = copy.copy(def_s2)
    v1.str = None
    test(v1 != v2)

    v1 = copy.copy(def_s2)
    v2 = copy.copy(def_s2)
    v2.str = None
    test(v1 != v2)

    v1 = copy.copy(def_s2)
    v2 = copy.copy(def_s2)
    v1.str = None
    v2.str = None
    test(v1 == v2)

    #
    # Sequence member
    #
    v1 = copy.copy(def_s2)
    v1.seq = copy.copy(def_s2.seq)
    test(v1 == def_s2)

    v1 = copy.copy(def_s2)
    v1.seq = ()
    test(v1 != def_s2)

    v1 = copy.copy(def_s2)
    v1.seq = (1, 2, 3)
    test(v1 == def_s2)

    v1 = copy.copy(def_s2)
    v2 = copy.copy(def_s2)
    v1.seq = None
    test(v1 != v2)

    v1 = copy.copy(def_s2)
    v2 = copy.copy(def_s2)
    v2.seq = None
    test(v1 != v2)

    #
    # Struct member
    #
    v1 = copy.copy(def_s2)
    v1.s = copy.copy(def_s2.s)
    test(v1 == def_s2)

    v1 = copy.copy(def_s2)
    v1.s = Test.S1("name")
    test(v1 == def_s2)

    v1 = copy.copy(def_s2)
    v1.s = Test.S1("noname")
    test(v1 != def_s2)

    v1 = copy.copy(def_s2)
    v2 = copy.copy(def_s2)
    v1.s = None
    test(v1 != v2)

    v1 = copy.copy(def_s2)
    v2 = copy.copy(def_s2)
    v2.s = None
    test(v1 != v2)

    #
    # Define some default values.
    #
    def_s3 = Test.S3(Test.C("name"), {"1":"2"}, communicator.stringToProxy("test"))

    #
    # Compare default-constructed structures.
    #
    test(Test.S3() == Test.S3())

    #
    # Change one member at a time.
    #
    v1 = copy.copy(def_s3)
    test(v1 == def_s3)

    v1.obj = None
    test(v1 != def_s3)

    v1.obj = Test.C("name")
    test(v1 != def_s3)

    v1 = copy.copy(def_s3)
    v1.sd = copy.copy(def_s3.sd)
    test(v1 == def_s3)

    v1.sd = None
    test(v1 != def_s3)

    v1.sd = {"1":"3"}
    test(v1 != def_s3)

    v1 = copy.copy(def_s3)
    v1.prx = None
    test(v1 != def_s3)

    v1.prx = communicator.stringToProxy("test")
    test(v1 == def_s3)

    v1.prx = communicator.stringToProxy("test2")
    test(v1 != def_s3)

    print("ok")
예제 #5
0
def allTests(helper, communicator):
    sys.stdout.write("test same Slice type name in different scopes... ")
    sys.stdout.flush()
    i1 = Test.IPrx.checkedCast(
        communicator.stringToProxy("i1:{0}".format(helper.getTestEndpoint())))

    s1 = Test.S(0)

    s2, s3 = i1.opS(s1)

    test(s2 == s1)
    test(s3 == s1)

    sseq1 = [s1]

    sseq2, sseq3 = i1.opSSeq(sseq1)

    test(sseq2[0] == s1)
    test(sseq3[0] == s1)

    smap1 = {"a": s1}
    smap2, smap3 = i1.opSMap(smap1)
    test(smap2["a"] == s1)
    test(smap3["a"] == s1)

    c1 = Test.C(s1)

    c2, c3 = i1.opC(c1)

    test(c2.s == s1)
    test(c3.s == s1)

    cseq1 = [c1]
    cseq2, cseq3 = i1.opCSeq(cseq1)

    test(cseq2[0].s == s1)
    test(cseq3[0].s == s1)

    cmap1 = {"a": c1}
    cmap2, cmap3 = i1.opCMap(cmap1)
    test(cmap2["a"].s == s1)
    test(cmap3["a"].s == s1)

    i2 = Test.Inner.Inner2.IPrx.checkedCast(
        communicator.stringToProxy("i2:{0}".format(helper.getTestEndpoint())))

    s1 = Test.Inner.Inner2.S(0)

    s2, s3 = i2.opS(s1)

    test(s2 == s1)
    test(s3 == s1)

    sseq1 = [s1]

    sseq2, sseq3 = i2.opSSeq(sseq1)

    test(sseq2[0] == s1)
    test(sseq3[0] == s1)

    smap1 = {"a": s1}
    smap2, smap3 = i2.opSMap(smap1)
    test(smap2["a"] == s1)
    test(smap3["a"] == s1)

    c1 = Test.Inner.Inner2.C(s1)

    c2, c3 = i2.opC(c1)

    test(c2.s == s1)
    test(c3.s == s1)

    cseq1 = [c1]
    cseq2, cseq3 = i2.opCSeq(cseq1)

    test(cseq2[0].s == s1)
    test(cseq3[0].s == s1)

    cmap1 = {"a": c1}
    cmap2, cmap3 = i2.opCMap(cmap1)
    test(cmap2["a"].s == s1)
    test(cmap3["a"].s == s1)

    i3 = Test.Inner.IPrx.checkedCast(
        communicator.stringToProxy("i3:{0}".format(helper.getTestEndpoint())))

    s1 = Test.Inner.Inner2.S(0)

    s2, s3 = i3.opS(s1)

    test(s2 == s1)
    test(s3 == s1)

    sseq1 = [s1]

    sseq2, sseq3 = i3.opSSeq(sseq1)

    test(sseq2[0] == s1)
    test(sseq3[0] == s1)

    smap1 = {"a": s1}
    smap2, smap3 = i3.opSMap(smap1)
    test(smap2["a"] == s1)
    test(smap3["a"] == s1)

    c1 = Test.Inner.Inner2.C(s1)

    c2, c3 = i3.opC(c1)

    test(c2.s == s1)
    test(c3.s == s1)

    cseq1 = [c1]
    cseq2, cseq3 = i3.opCSeq(cseq1)

    test(cseq2[0].s == s1)
    test(cseq3[0].s == s1)

    cmap1 = {"a": c1}
    cmap2, cmap3 = i3.opCMap(cmap1)
    test(cmap2["a"].s == s1)
    test(cmap3["a"].s == s1)

    i4 = Inner.Test.Inner2.IPrx.checkedCast(
        communicator.stringToProxy("i4:{0}".format(helper.getTestEndpoint())))

    s1 = Test.S(0)

    s2, s3 = i4.opS(s1)

    test(s2 == s1)
    test(s3 == s1)

    sseq1 = [s1]

    sseq2, sseq3 = i4.opSSeq(sseq1)

    test(sseq2[0] == s1)
    test(sseq3[0] == s1)

    smap1 = {"a": s1}
    smap2, smap3 = i4.opSMap(smap1)
    test(smap2["a"] == s1)
    test(smap3["a"] == s1)

    c1 = Test.C(s1)

    c2, c3 = i4.opC(c1)

    test(c2.s == s1)
    test(c3.s == s1)

    cseq1 = [c1]
    cseq2, cseq3 = i4.opCSeq(cseq1)

    test(cseq2[0].s == s1)
    test(cseq3[0].s == s1)

    cmap1 = {"a": c1}
    cmap2, cmap3 = i4.opCMap(cmap1)
    test(cmap2["a"].s == s1)
    test(cmap3["a"].s == s1)

    i1.shutdown()
    print("ok")
예제 #6
0
파일: TestI.py 프로젝트: chuanqingli/ice
 def throwUndeclaredC(self, a, b, c, current=None):
     ex = Test.C()
     ex.aMem = a
     ex.bMem = b
     ex.cMem = c
     raise ex
예제 #7
0
파일: AllTests.py 프로젝트: stick/zeroc-ice
def allTests(communicator):
    sys.stdout.write("testing stringToProxy... ")
    sys.stdout.flush()
    ref = "initial:default -p 12010"
    base = communicator.stringToProxy(ref)
    test(base)
    print("ok")

    sys.stdout.write("testing checked cast... ")
    sys.stdout.flush()
    initial = Test.InitialPrx.checkedCast(base)
    test(initial)
    test(initial == base)
    print("ok")

    sys.stdout.write("testing optional data members... ")
    sys.stdout.flush()

    oo1 = Test.OneOptional()
    test(oo1.a == Ice.Unset)
    oo1.a = 15

    oo2 = Test.OneOptional(16)
    test(oo2.a == 16)

    mo1 = Test.MultiOptional()
    test(mo1.a == Ice.Unset)
    test(mo1.b == Ice.Unset)
    test(mo1.c == Ice.Unset)
    test(mo1.d == Ice.Unset)
    test(mo1.e == Ice.Unset)
    test(mo1.f == Ice.Unset)
    test(mo1.g == Ice.Unset)
    test(mo1.h == Ice.Unset)
    test(mo1.i == Ice.Unset)
    test(mo1.j == Ice.Unset)
    test(mo1.k == Ice.Unset)
    test(mo1.bs == Ice.Unset)
    test(mo1.ss == Ice.Unset)
    test(mo1.iid == Ice.Unset)
    test(mo1.sid == Ice.Unset)
    test(mo1.fs == Ice.Unset)
    test(mo1.vs == Ice.Unset)

    test(mo1.shs == Ice.Unset)
    test(mo1.es == Ice.Unset)
    test(mo1.fss == Ice.Unset)
    test(mo1.vss == Ice.Unset)
    test(mo1.oos == Ice.Unset)
    test(mo1.oops == Ice.Unset)

    test(mo1.ied == Ice.Unset)
    test(mo1.ifsd == Ice.Unset)
    test(mo1.ivsd == Ice.Unset)
    test(mo1.iood == Ice.Unset)
    test(mo1.ioopd == Ice.Unset)

    test(mo1.bos == Ice.Unset)

    fs = Test.FixedStruct(78)
    vs = Test.VarStruct("hello")
    mo1 = Test.MultiOptional(15, True, 19, 78, 99, 5.5, 1.0, "test", Test.MyEnum.MyEnumMember, \
                             Test.MultiOptionalPrx.uncheckedCast(communicator.stringToProxy("test")), \
                             None, [5], ["test", "test2"], {4:3}, {"test":10}, fs, vs, [1], \
                             [Test.MyEnum.MyEnumMember, Test.MyEnum.MyEnumMember], \
                             [ fs ], [ vs ], [ oo1 ], \
                             [ Test.OneOptionalPrx.uncheckedCast(communicator.stringToProxy("test")) ], \
                             {4:Test.MyEnum.MyEnumMember}, {4:fs}, {5:vs}, {5:Test.OneOptional(15)}, \
                             {5:Test.OneOptionalPrx.uncheckedCast(communicator.stringToProxy("test"))}, \
                             [False, True, False])

    test(mo1.a == 15)
    test(mo1.b == True)
    test(mo1.c == 19)
    test(mo1.d == 78)
    test(mo1.e == 99)
    test(mo1.f == 5.5)
    test(mo1.g == 1.0)
    test(mo1.h == "test")
    test(mo1.i == Test.MyEnum.MyEnumMember)
    test(mo1.j == Test.MultiOptionalPrx.uncheckedCast(communicator.stringToProxy("test")))
    test(mo1.k == None)
    test(mo1.bs == [5])
    test(mo1.ss == ["test", "test2"])
    test(mo1.iid[4] == 3)
    test(mo1.sid["test"] == 10)
    test(mo1.fs == Test.FixedStruct(78))
    test(mo1.vs == Test.VarStruct("hello"))

    test(mo1.shs[0] == 1)
    test(mo1.es[0] == Test.MyEnum.MyEnumMember and mo1.es[1] == Test.MyEnum.MyEnumMember)
    test(mo1.fss[0] == Test.FixedStruct(78))
    test(mo1.vss[0] == Test.VarStruct("hello"))
    test(mo1.oos[0] == oo1)
    test(mo1.oops[0] == Test.OneOptionalPrx.uncheckedCast(communicator.stringToProxy("test")))

    test(mo1.ied[4] == Test.MyEnum.MyEnumMember)
    test(mo1.ifsd[4] == Test.FixedStruct(78))
    test(mo1.ivsd[5] == Test.VarStruct("hello"))
    test(mo1.iood[5].a == 15)
    test(mo1.ioopd[5] == Test.OneOptionalPrx.uncheckedCast(communicator.stringToProxy("test")))

    test(mo1.bos == [False, True, False])

    print("ok")

    sys.stdout.write("testing marshaling... ")
    sys.stdout.flush()

    oo4 = initial.pingPong(Test.OneOptional())
    test(oo4.a == Ice.Unset)

    oo5 = initial.pingPong(oo1)
    test(oo1.a == oo5.a)

    mo4 = initial.pingPong(Test.MultiOptional())
    test(mo4.a == Ice.Unset)
    test(mo4.b == Ice.Unset)
    test(mo4.c == Ice.Unset)
    test(mo4.d == Ice.Unset)
    test(mo4.e == Ice.Unset)
    test(mo4.f == Ice.Unset)
    test(mo4.g == Ice.Unset)
    test(mo4.h == Ice.Unset)
    test(mo4.i == Ice.Unset)
    test(mo4.j == Ice.Unset)
    test(mo4.k == Ice.Unset)
    test(mo4.bs == Ice.Unset)
    test(mo4.ss == Ice.Unset)
    test(mo4.iid == Ice.Unset)
    test(mo4.sid == Ice.Unset)
    test(mo4.fs == Ice.Unset)
    test(mo4.vs == Ice.Unset)

    test(mo4.shs == Ice.Unset)
    test(mo4.es == Ice.Unset)
    test(mo4.fss == Ice.Unset)
    test(mo4.vss == Ice.Unset)
    test(mo4.oos == Ice.Unset)
    test(mo4.oops == Ice.Unset)

    test(mo4.ied == Ice.Unset)
    test(mo4.ifsd == Ice.Unset)
    test(mo4.ivsd == Ice.Unset)
    test(mo4.iood == Ice.Unset)
    test(mo4.ioopd == Ice.Unset)

    test(mo4.bos == Ice.Unset)

    mo5 = initial.pingPong(mo1)
    test(mo5.a == mo1.a)
    test(mo5.b == mo1.b)
    test(mo5.c == mo1.c)
    test(mo5.d == mo1.d)
    test(mo5.e == mo1.e)
    test(mo5.f == mo1.f)
    test(mo5.g == mo1.g)
    test(mo5.h == mo1.h)
    test(mo5.i == mo1.i)
    test(mo5.j == mo1.j)
    test(mo5.k == None)
    if sys.version_info[0] == 2:
        test(mo5.bs == "\x05")
    else:
        test(mo5.bs[0] == 5)
    test(mo5.ss == mo1.ss)
    test(mo5.iid[4] == 3)
    test(mo5.sid["test"] == 10)
    test(mo5.fs == mo1.fs)
    test(mo5.vs == mo1.vs)
    test(mo5.shs == mo1.shs)
    test(mo5.es[0] == Test.MyEnum.MyEnumMember and mo1.es[1] == Test.MyEnum.MyEnumMember)
    test(mo5.fss[0] == Test.FixedStruct(78))
    test(mo5.vss[0] == Test.VarStruct("hello"))
    test(mo5.oos[0].a == 15)
    test(mo5.oops[0] == Test.OneOptionalPrx.uncheckedCast(communicator.stringToProxy("test")))

    test(mo5.ied[4] == Test.MyEnum.MyEnumMember)
    test(mo5.ifsd[4] == Test.FixedStruct(78))
    test(mo5.ivsd[5] == Test.VarStruct("hello"))
    test(mo5.iood[5].a == 15)
    test(mo5.ioopd[5] == Test.OneOptionalPrx.uncheckedCast(communicator.stringToProxy("test")))

    test(mo5.bos == mo1.bos)

    # Clear the first half of the optional members
    mo6 = Test.MultiOptional()
    mo6.b = mo5.b
    mo6.d = mo5.d
    mo6.f = mo5.f
    mo6.h = mo5.h
    mo6.j = mo5.j
    mo6.bs = mo5.bs
    mo6.iid = mo5.iid
    mo6.fs = mo5.fs
    mo6.shs = mo5.shs
    mo6.fss = mo5.fss
    mo6.oos = mo5.oos
    mo6.ifsd = mo5.ifsd
    mo6.iood = mo5.iood
    mo6.bos = mo5.bos

    mo7 = initial.pingPong(mo6)
    test(mo7.a == Ice.Unset)
    test(mo7.b == mo1.b)
    test(mo7.c == Ice.Unset)
    test(mo7.d == mo1.d)
    test(mo7.e == Ice.Unset)
    test(mo7.f == mo1.f)
    test(mo7.g == Ice.Unset)
    test(mo7.h == mo1.h)
    test(mo7.i == Ice.Unset)
    test(mo7.j == mo1.j)
    test(mo7.k == Ice.Unset)
    if sys.version_info[0] == 2:
        test(mo7.bs == "\x05")
    else:
        test(mo7.bs[0] == 5)
    test(mo7.ss == Ice.Unset)
    test(mo7.iid[4] == 3)
    test(mo7.sid == Ice.Unset)
    test(mo7.fs == mo1.fs)
    test(mo7.vs == Ice.Unset)

    test(mo7.shs == mo1.shs)
    test(mo7.es == Ice.Unset)
    test(mo7.fss[0] == Test.FixedStruct(78))
    test(mo7.vss == Ice.Unset)
    test(mo7.oos[0].a == 15)
    test(mo7.oops == Ice.Unset)

    test(mo7.ied == Ice.Unset)
    test(mo7.ifsd[4] == Test.FixedStruct(78))
    test(mo7.ivsd == Ice.Unset)
    test(mo7.iood[5].a == 15)
    test(mo7.ioopd == Ice.Unset)

    test(mo7.bos == [False, True, False])

    # Clear the second half of the optional members
    mo8 = Test.MultiOptional()
    mo8.a = mo5.a
    mo8.c = mo5.c
    mo8.e = mo5.e
    mo8.g = mo5.g
    mo8.i = mo5.i
    mo8.k = mo8
    mo8.ss = mo5.ss
    mo8.sid = mo5.sid
    mo8.vs = mo5.vs

    mo8.es = mo5.es
    mo8.vss = mo5.vss
    mo8.oops = mo5.oops

    mo8.ied = mo5.ied
    mo8.ivsd = mo5.ivsd
    mo8.ioopd = mo5.ioopd

    mo9 = initial.pingPong(mo8)
    test(mo9.a == mo1.a)
    test(mo9.b == Ice.Unset)
    test(mo9.c == mo1.c)
    test(mo9.d == Ice.Unset)
    test(mo9.e == mo1.e)
    test(mo9.f == Ice.Unset)
    test(mo9.g == mo1.g)
    test(mo9.h == Ice.Unset)
    test(mo9.i == mo1.i)
    test(mo9.j == Ice.Unset)
    test(mo9.k == mo9)
    test(mo9.bs == Ice.Unset)
    test(mo9.ss == mo1.ss)
    test(mo9.iid == Ice.Unset)
    test(mo9.sid["test"] == 10)
    test(mo9.fs == Ice.Unset)
    test(mo9.vs == mo1.vs)

    test(mo9.shs == Ice.Unset)
    test(mo9.es[0] == Test.MyEnum.MyEnumMember and mo1.es[1] == Test.MyEnum.MyEnumMember)
    test(mo9.fss == Ice.Unset)
    test(mo9.vss[0] == Test.VarStruct("hello"))
    test(mo9.oos == Ice.Unset)
    test(mo9.oops[0] == Test.OneOptionalPrx.uncheckedCast(communicator.stringToProxy("test")))

    test(mo9.ied[4] == Test.MyEnum.MyEnumMember)
    test(mo9.ifsd == Ice.Unset)
    test(mo9.ivsd[5] == Test.VarStruct("hello"))
    test(mo9.iood == Ice.Unset)
    test(mo9.ioopd[5] == Test.OneOptionalPrx.uncheckedCast(communicator.stringToProxy("test")))

    test(mo9.bos == Ice.Unset)

    #
    # Use the 1.0 encoding with operations whose only class parameters are optional.
    #
    initial.sendOptionalClass(True, Test.OneOptional(53))
    initial.ice_encodingVersion(Ice.Encoding_1_0).sendOptionalClass(True, Test.OneOptional(53))

    r = initial.returnOptionalClass(True)
    test(r != Ice.Unset)
    r = initial.ice_encodingVersion(Ice.Encoding_1_0).returnOptionalClass(True)
    test(r == Ice.Unset)

    print("ok")

    sys.stdout.write("testing marshaling of large containers with fixed size elements... ")
    sys.stdout.flush()

    mc = Test.MultiOptional()

    mc.bs = []
    for i in range(1000):
        mc.bs.append(0)
    mc.shs = []
    for i in range(300):
        mc.shs.append(0)

    mc.fss = []
    for i in range(300):
        mc.fss.append(Test.FixedStruct())

    mc.ifsd = {}
    for i in range(300):
        mc.ifsd[i] = Test.FixedStruct()

    mc = initial.pingPong(mc)
    test(len(mc.bs) == 1000)
    test(len(mc.shs) == 300)
    test(len(mc.fss) == 300)
    test(len(mc.ifsd) == 300)

    print("ok")

    sys.stdout.write("testing tag marshaling... ")
    sys.stdout.flush()

    b = Test.B()
    b2 = initial.pingPong(b)
    test(b2.ma == Ice.Unset)
    test(b2.mb == Ice.Unset)
    test(b2.mc == Ice.Unset)

    b.ma = 10
    b.mb = 11
    b.mc = 12
    b.md = 13

    b2 = initial.pingPong(b)
    test(b2.ma == 10)
    test(b2.mb == 11)
    test(b2.mc == 12)
    test(b2.md == 13)

    print("ok")

    sys.stdout.write("testing marshalling of objects with optional objects...")
    sys.stdout.flush()

    f = Test.F()
    
    f.af = Test.A()
    f.ae = f.af
    
    rf = initial.pingPong(f)
    test(rf.ae == rf.af)
    
    print("ok")

    sys.stdout.write("testing optional with default values... ")
    sys.stdout.flush()

    wd = initial.pingPong(Test.WD())
    test(wd.a == 5)
    test(wd.s == "test")
    wd.a = Ice.Unset
    wd.s = Ice.Unset
    wd = initial.pingPong(wd)
    test(wd.a == Ice.Unset)
    test(wd.s == Ice.Unset)

    print("ok")

    if communicator.getProperties().getPropertyAsInt("Ice.Default.SlicedFormat") > 0:
        sys.stdout.write("testing marshaling with unknown class slices... ")
        sys.stdout.flush()

        c = Test.C()
        c.ss = "test"
        c.ms = "testms"
        c = initial.pingPong(c)
        test(c.ma == Ice.Unset)
        test(c.mb == Ice.Unset)
        test(c.mc == Ice.Unset)
        test(c.md == Ice.Unset)
        test(c.ss == "test")
        test(c.ms == "testms")

        print("ok")

        sys.stdout.write("testing optionals with unknown classes... ")
        sys.stdout.flush()

        initial2 = Test.Initial2Prx.uncheckedCast(base)
        d = Test.D()
        d.ds = "test"
        d.seq = ["test1", "test2", "test3", "test4"]
        d.ao = Test.A(18)
        d.requiredB = 14;
        d.requiredA = 14;
        initial2.opClassAndUnknownOptional(Test.A(), d)

        print("ok")

    sys.stdout.write("testing optional parameters... ")
    sys.stdout.flush()

    (p2, p3) = initial.opByte(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    (p2, p3) = initial.opByte(56)
    test(p2 == 56 and p3 == 56)
    r = initial.begin_opByte(56)
    (p2, p3) = initial.end_opByte(r)
    test(p2 == 56 and p3 == 56)

    (p2, p3) = initial.opBool(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    (p2, p3) = initial.opBool(True)
    test(p2 == True and p3 == True)
    r = initial.begin_opBool(True)
    (p2, p3) = initial.end_opBool(r)
    test(p2 == True and p3 == True)

    (p2, p3) = initial.opShort(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    (p2, p3) = initial.opShort(56)
    test(p2 == 56 and p3 == 56)
    r = initial.begin_opShort(56)
    (p2, p3) = initial.end_opShort(r)
    test(p2 == 56 and p3 == 56)

    (p2, p3) = initial.opInt(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    (p2, p3) = initial.opInt(56)
    test(p2 == 56 and p3 == 56)
    r = initial.begin_opInt(56)
    (p2, p3) = initial.end_opInt(r)
    test(p2 == 56 and p3 == 56)

    (p2, p3) = initial.opLong(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    (p2, p3) = initial.opLong(56)
    test(p2 == 56 and p3 == 56)
    r = initial.begin_opLong(56)
    (p2, p3) = initial.end_opLong(r)
    test(p2 == 56 and p3 == 56)

    (p2, p3) = initial.opFloat(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    (p2, p3) = initial.opFloat(1.0)
    test(p2 == 1.0 and p3 == 1.0)
    r = initial.begin_opFloat(1.0)
    (p2, p3) = initial.end_opFloat(r)
    test(p2 == 1.0 and p3 == 1.0)

    (p2, p3) = initial.opDouble(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    (p2, p3) = initial.opDouble(1.0)
    test(p2 == 1.0 and p3 == 1.0)
    r = initial.begin_opDouble(1.0)
    (p2, p3) = initial.end_opDouble(r)
    test(p2 == 1.0 and p3 == 1.0)

    (p2, p3) = initial.opString(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    (p2, p3) = initial.opString("test")
    test(p2 == "test" and p3 == "test")
    r = initial.begin_opString("test")
    (p2, p3) = initial.end_opString(r)
    test(p2 == "test" and p3 == "test")

    (p2, p3) = initial.opMyEnum(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    (p2, p3) = initial.opMyEnum(Test.MyEnum.MyEnumMember)
    test(p2 == Test.MyEnum.MyEnumMember and p3 == Test.MyEnum.MyEnumMember)
    r = initial.begin_opMyEnum(Test.MyEnum.MyEnumMember)
    (p2, p3) = initial.end_opMyEnum(r)
    test(p2 == Test.MyEnum.MyEnumMember and p3 == Test.MyEnum.MyEnumMember)

    (p2, p3) = initial.opSmallStruct(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    p1 = Test.SmallStruct(56)
    (p2, p3) = initial.opSmallStruct(p1)
    test(p2 == p1 and p3 == p1)
    r = initial.begin_opSmallStruct(p1)
    (p2, p3) = initial.end_opSmallStruct(r)
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opFixedStruct(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    p1 = Test.FixedStruct(56)
    (p2, p3) = initial.opFixedStruct(p1)
    test(p2 == p1 and p3 == p1)
    r = initial.begin_opFixedStruct(p1)
    (p2, p3) = initial.end_opFixedStruct(r)
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opVarStruct(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    p1 = Test.VarStruct("test")
    (p2, p3) = initial.opVarStruct(p1)
    test(p2 == p1 and p3 == p1)
    r = initial.begin_opVarStruct(p1)
    (p2, p3) = initial.end_opVarStruct(r)
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opOneOptional(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    p1 = Test.OneOptional(58)
    (p2, p3) = initial.opOneOptional(p1)
    test(p2.a == p1.a and p3.a == p1.a)
    r = initial.begin_opOneOptional(p1)
    (p2, p3) = initial.end_opOneOptional(r)
    test(p2.a == p1.a and p3.a == p1.a)

    (p2, p3) = initial.opOneOptionalProxy(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    p1 = Test.OneOptionalPrx.uncheckedCast(communicator.stringToProxy("test"))
    (p2, p3) = initial.opOneOptionalProxy(p1)
    test(p2 == p1 and p3 == p1)
    r = initial.begin_opOneOptionalProxy(p1)
    (p2, p3) = initial.end_opOneOptionalProxy(r)
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opByteSeq(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    p1 = [56 for x in range(100)]
    (p2, p3) = initial.opByteSeq(p1)
    test(len(p2) == len(p1) and len(p3) == len(p1))
    if sys.version_info[0] == 2:
        test(p2[0] == '\x38')
        test(p3[0] == '\x38')
    else:
        test(p2[0] == 0x38)
        test(p3[0] == 0x38)
    r = initial.begin_opByteSeq(p1)
    (p2, p3) = initial.end_opByteSeq(r)
    test(len(p2) == len(p1) and len(p3) == len(p1))
    if sys.version_info[0] == 2:
        test(p2[0] == '\x38')
        test(p3[0] == '\x38')
    else:
        test(p2[0] == 0x38)
        test(p3[0] == 0x38)

    (p2, p3) = initial.opBoolSeq(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    p1 = [True for x in range(100)]
    (p2, p3) = initial.opBoolSeq(p1)
    test(p2 == p1 and p3 == p1)
    r = initial.begin_opBoolSeq(p1)
    (p2, p3) = initial.end_opBoolSeq(r)
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opShortSeq(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    p1 = [56 for x in range(100)]
    (p2, p3) = initial.opShortSeq(p1)
    test(p2 == p1 and p3 == p1)
    r = initial.begin_opShortSeq(p1)
    (p2, p3) = initial.end_opShortSeq(r)
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opIntSeq(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    p1 = [56 for x in range(100)]
    (p2, p3) = initial.opIntSeq(p1)
    test(p2 == p1 and p3 == p1)
    r = initial.begin_opIntSeq(p1)
    (p2, p3) = initial.end_opIntSeq(r)
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opLongSeq(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    p1 = [56 for x in range(100)]
    (p2, p3) = initial.opLongSeq(p1)
    test(p2 == p1 and p3 == p1)
    r = initial.begin_opLongSeq(p1)
    (p2, p3) = initial.end_opLongSeq(r)
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opFloatSeq(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    p1 = [1.0 for x in range(100)]
    (p2, p3) = initial.opFloatSeq(p1)
    test(p2 == p1 and p3 == p1)
    r = initial.begin_opFloatSeq(p1)
    (p2, p3) = initial.end_opFloatSeq(r)
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opDoubleSeq(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    p1 = [1.0 for x in range(100)]
    (p2, p3) = initial.opDoubleSeq(p1)
    test(p2 == p1 and p3 == p1)
    r = initial.begin_opDoubleSeq(p1)
    (p2, p3) = initial.end_opDoubleSeq(r)
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opStringSeq(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    p1 = ["test1" for x in range(100)]
    (p2, p3) = initial.opStringSeq(p1)
    test(p2 == p1 and p3 == p1)
    r = initial.begin_opStringSeq(p1)
    (p2, p3) = initial.end_opStringSeq(r)
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opSmallStructSeq(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    p1 = [Test.SmallStruct(1) for x in range(10)]
    (p2, p3) = initial.opSmallStructSeq(p1)
    test(p2 == p1 and p3 == p1)
    r = initial.begin_opSmallStructSeq(p1)
    (p2, p3) = initial.end_opSmallStructSeq(r)
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opSmallStructList(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    p1 = tuple([Test.SmallStruct(1) for x in range(10)])
    (p2, p3) = initial.opSmallStructList(p1)
    test(p2 == p1 and p3 == p1)
    r = initial.begin_opSmallStructList(p1)
    (p2, p3) = initial.end_opSmallStructList(r)
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opFixedStructSeq(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    p1 = [Test.FixedStruct(1) for x in range(10)]
    (p2, p3) = initial.opFixedStructSeq(p1)
    test(p2 == p1 and p3 == p1)
    r = initial.begin_opFixedStructSeq(p1)
    (p2, p3) = initial.end_opFixedStructSeq(r)
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opFixedStructList(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    p1 = tuple([Test.FixedStruct(1) for x in range(10)])
    (p2, p3) = initial.opFixedStructList(p1)
    test(p2 == p1 and p3 == p1)
    r = initial.begin_opFixedStructList(p1)
    (p2, p3) = initial.end_opFixedStructList(r)
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opVarStructSeq(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    p1 = [Test.VarStruct("test") for x in range(10)]
    (p2, p3) = initial.opVarStructSeq(p1)
    test(p2 == p1 and p3 == p1)
    r = initial.begin_opVarStructSeq(p1)
    (p2, p3) = initial.end_opVarStructSeq(r)
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opIntIntDict(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    p1 = {1:2, 2:3}
    (p2, p3) = initial.opIntIntDict(p1)
    test(p2 == p1 and p3 == p1)
    r = initial.begin_opIntIntDict(p1)
    (p2, p3) = initial.end_opIntIntDict(r)
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opStringIntDict(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)
    p1 = {"1":2, "2":3}
    (p2, p3) = initial.opStringIntDict(p1)
    test(p2 == p1 and p3 == p1)
    r = initial.begin_opStringIntDict(p1)
    (p2, p3) = initial.end_opStringIntDict(r)
    test(p2 == p1 and p3 == p1)

    print("ok")

    sys.stdout.write("testing exception optionals... ")
    sys.stdout.flush()

    try:
        initial.opOptionalException(Ice.Unset, Ice.Unset, Ice.Unset)
    except Test.OptionalException as ex:
        test(ex.a == Ice.Unset)
        test(ex.b == Ice.Unset)
        test(ex.o == Ice.Unset)

    try:
        initial.opOptionalException(30, "test", Test.OneOptional(53))
    except Test.OptionalException as ex:
        test(ex.a == 30)
        test(ex.b == "test")
        test(ex.o.a == 53)

    try:
        #
        # Use the 1.0 encoding with an exception whose only class members are optional.
        #
        initial.ice_encodingVersion(Ice.Encoding_1_0).opOptionalException(30, "test", Test.OneOptional(53))
    except Test.OptionalException as ex:
        test(ex.a == Ice.Unset)
        test(ex.b == Ice.Unset)
        test(ex.o == Ice.Unset)

    try:
        initial.opDerivedException(Ice.Unset, Ice.Unset, Ice.Unset)
    except Test.DerivedException as ex:
        test(ex.a == Ice.Unset)
        test(ex.b == Ice.Unset)
        test(ex.o == Ice.Unset)
        test(ex.ss == Ice.Unset)
        test(ex.o2 == Ice.Unset)

    try:
        initial.opDerivedException(30, "test2", Test.OneOptional(53))
    except Test.DerivedException as ex:
        test(ex.a == 30)
        test(ex.b == "test2")
        test(ex.o.a == 53)
        test(ex.ss == "test2")
        test(ex.o2 == ex.o)

    try:
        initial.opRequiredException(Ice.Unset, Ice.Unset, Ice.Unset)
    except Test.RequiredException as ex:
        test(ex.a == Ice.Unset)
        test(ex.b == Ice.Unset)
        test(ex.o == Ice.Unset)
        test(ex.ss == "test")
        test(ex.o2 == None)

    try:
        initial.opRequiredException(30, "test2", Test.OneOptional(53))
    except Test.RequiredException as ex:
        test(ex.a == 30)
        test(ex.b == "test2")
        test(ex.o.a == 53)
        test(ex.ss == "test2")
        test(ex.o2 == ex.o)

    print("ok")

    return initial
예제 #8
0
def allTests(communicator):
    ref = "test:default -p 12010"
    base = communicator.stringToProxy(ref)
    test(base)

    custom = Test.CustomPrx.checkedCast(base)
    test(custom)

    byteList = [1, 2, 3, 4, 5]
    if sys.version_info[0] == 2:
        byteString = ''.join(map(chr, byteList))
    else:
        byteString = bytes(byteList)
    stringList = ['s1', 's2', 's3']

    sys.stdout.write("testing custom sequences... ")
    sys.stdout.flush()

    (r, b2) = custom.opByteString1(byteString)
    if sys.version_info[0] == 2:
        test(isinstance(r, str))
        test(isinstance(b2, str))
    else:
        test(isinstance(r, bytes))
        test(isinstance(b2, bytes))
    test(r == byteString)
    test(b2 == byteString)

    (r, b2) = custom.opByteString2(byteString)
    test(isinstance(r, tuple))
    test(isinstance(b2, list))
    for i in range(0, len(byteList)):
        test(r[i] == byteList[i])
        test(b2[i] == byteList[i])

    (r, b2) = custom.opByteList1(byteList)
    test(isinstance(r, list))
    test(isinstance(b2, list))
    for i in range(0, len(byteList)):
        test(r[i] == byteList[i])
        test(b2[i] == byteList[i])

    (r, b2) = custom.opByteList2(byteList)
    if sys.version_info[0] == 2:
        test(isinstance(r, str))
    else:
        test(isinstance(r, bytes))
    test(isinstance(b2, tuple))
    test(r == byteString)
    for i in range(0, len(byteList)):
        test(b2[i] == byteList[i])

    (r, b2) = custom.opStringList1(stringList)
    test(isinstance(r, list))
    test(isinstance(b2, list))
    test(r == stringList)
    test(b2 == stringList)

    (r, b2) = custom.opStringList2(stringList)
    test(isinstance(r, tuple))
    test(isinstance(b2, tuple))
    for i in range(0, len(stringList)):
        test(r[i] == stringList[i])
        test(b2[i] == stringList[i])

    (r, b2) = custom.opStringTuple1(stringList)
    test(isinstance(r, tuple))
    test(isinstance(b2, tuple))
    for i in range(0, len(stringList)):
        test(r[i] == stringList[i])
        test(b2[i] == stringList[i])

    (r, b2) = custom.opStringTuple2(stringList)
    test(isinstance(r, list))
    test(isinstance(b2, list))
    test(r == stringList)
    test(b2 == stringList)

    s = Test.S()
    s.b1 = byteList;
    s.b2 = byteList;
    s.b3 = byteList;
    s.b4 = byteList;
    s.s1 = stringList;
    s.s2 = stringList;
    s.s3 = stringList;
    s.s4 = stringList;
    custom.sendS(s)

    c = Test.C()
    c.b1 = byteList;
    c.b2 = byteList;
    c.b3 = byteList;
    c.b4 = byteList;
    c.s1 = stringList;
    c.s2 = stringList;
    c.s3 = stringList;
    c.s4 = stringList;
    custom.sendC(c)

    print("ok")

    return custom
예제 #9
0
파일: AllTests.py 프로젝트: yzun/ice
def allTests(helper, communicator):
    sys.stdout.write("testing stringToProxy... ")
    sys.stdout.flush()
    ref = "initial:{0}".format(helper.getTestEndpoint())
    base = communicator.stringToProxy(ref)
    test(base)
    print("ok")

    sys.stdout.write("testing checked cast... ")
    sys.stdout.flush()
    initial = Test.InitialPrx.checkedCast(base)
    test(initial)
    test(initial == base)
    print("ok")

    sys.stdout.write("testing optional data members... ")
    sys.stdout.flush()

    oo1 = Test.OneOptional()
    test(oo1.a is Ice.Unset)
    oo1.a = 15

    oo2 = Test.OneOptional(16)
    test(oo2.a == 16)

    mo1 = Test.MultiOptional()
    test(mo1.a is Ice.Unset)
    test(mo1.b is Ice.Unset)
    test(mo1.c is Ice.Unset)
    test(mo1.d is Ice.Unset)
    test(mo1.e is Ice.Unset)
    test(mo1.f is Ice.Unset)
    test(mo1.g is Ice.Unset)
    test(mo1.h is Ice.Unset)
    test(mo1.i is Ice.Unset)
    test(mo1.j is Ice.Unset)
    test(mo1.k is Ice.Unset)
    test(mo1.bs is Ice.Unset)
    test(mo1.ss is Ice.Unset)
    test(mo1.iid is Ice.Unset)
    test(mo1.sid is Ice.Unset)
    test(mo1.fs is Ice.Unset)
    test(mo1.vs is Ice.Unset)

    test(mo1.shs is Ice.Unset)
    test(mo1.es is Ice.Unset)
    test(mo1.fss is Ice.Unset)
    test(mo1.vss is Ice.Unset)
    test(mo1.oos is Ice.Unset)
    test(mo1.oops is Ice.Unset)

    test(mo1.ied is Ice.Unset)
    test(mo1.ifsd is Ice.Unset)
    test(mo1.ivsd is Ice.Unset)
    test(mo1.iood is Ice.Unset)
    test(mo1.ioopd is Ice.Unset)

    test(mo1.bos is Ice.Unset)

    ss = Test.SmallStruct()
    fs = Test.FixedStruct(78)
    vs = Test.VarStruct("hello")
    mo1 = Test.MultiOptional(15, True, 19, 78, 99, 5.5, 1.0, "test", Test.MyEnum.MyEnumMember, \
                             communicator.stringToProxy("test"), \
                             None, [5], ["test", "test2"], {4:3}, {"test":10}, fs, vs, [1], \
                             [Test.MyEnum.MyEnumMember, Test.MyEnum.MyEnumMember], \
                             [ fs ], [ vs ], [ oo1 ], \
                             [ communicator.stringToProxy("test") ], \
                             {4:Test.MyEnum.MyEnumMember}, {4:fs}, {5:vs}, {5:Test.OneOptional(15)}, \
                             {5:communicator.stringToProxy("test")}, \
                             [False, True, False])

    test(mo1.a == 15)
    test(mo1.b == True)
    test(mo1.c == 19)
    test(mo1.d == 78)
    test(mo1.e == 99)
    test(mo1.f == 5.5)
    test(mo1.g == 1.0)
    test(mo1.h == "test")
    test(mo1.i == Test.MyEnum.MyEnumMember)
    test(mo1.j == communicator.stringToProxy("test"))
    test(mo1.k == None)
    test(mo1.bs == [5])
    test(mo1.ss == ["test", "test2"])
    test(mo1.iid[4] == 3)
    test(mo1.sid["test"] == 10)
    test(mo1.fs == Test.FixedStruct(78))
    test(mo1.vs == Test.VarStruct("hello"))

    test(mo1.shs[0] == 1)
    test(mo1.es[0] == Test.MyEnum.MyEnumMember and mo1.es[1] == Test.MyEnum.MyEnumMember)
    test(mo1.fss[0] == Test.FixedStruct(78))
    test(mo1.vss[0] == Test.VarStruct("hello"))
    test(mo1.oos[0] == oo1)
    test(mo1.oops[0] == communicator.stringToProxy("test"))

    test(mo1.ied[4] == Test.MyEnum.MyEnumMember)
    test(mo1.ifsd[4] == Test.FixedStruct(78))
    test(mo1.ivsd[5] == Test.VarStruct("hello"))
    test(mo1.iood[5].a == 15)
    test(mo1.ioopd[5] == communicator.stringToProxy("test"))

    test(mo1.bos == [False, True, False])

    #
    # Test generated struct and classes compare with Ice.Unset
    #
    test(ss != Ice.Unset)
    test(fs != Ice.Unset)
    test(vs != Ice.Unset)
    test(mo1 != Ice.Unset)

    print("ok")

    sys.stdout.write("testing marshaling... ")
    sys.stdout.flush()

    oo4 = initial.pingPong(Test.OneOptional())
    test(oo4.a is Ice.Unset)

    oo5 = initial.pingPong(oo1)
    test(oo1.a == oo5.a)

    mo4 = initial.pingPong(Test.MultiOptional())
    test(mo4.a is Ice.Unset)
    test(mo4.b is Ice.Unset)
    test(mo4.c is Ice.Unset)
    test(mo4.d is Ice.Unset)
    test(mo4.e is Ice.Unset)
    test(mo4.f is Ice.Unset)
    test(mo4.g is Ice.Unset)
    test(mo4.h is Ice.Unset)
    test(mo4.i is Ice.Unset)
    test(mo4.j is Ice.Unset)
    test(mo4.k is Ice.Unset)
    test(mo4.bs is Ice.Unset)
    test(mo4.ss is Ice.Unset)
    test(mo4.iid is Ice.Unset)
    test(mo4.sid is Ice.Unset)
    test(mo4.fs is Ice.Unset)
    test(mo4.vs is Ice.Unset)

    test(mo4.shs is Ice.Unset)
    test(mo4.es is Ice.Unset)
    test(mo4.fss is Ice.Unset)
    test(mo4.vss is Ice.Unset)
    test(mo4.oos is Ice.Unset)
    test(mo4.oops is Ice.Unset)

    test(mo4.ied is Ice.Unset)
    test(mo4.ifsd is Ice.Unset)
    test(mo4.ivsd is Ice.Unset)
    test(mo4.iood is Ice.Unset)
    test(mo4.ioopd is Ice.Unset)

    test(mo4.bos is Ice.Unset)

    mo5 = initial.pingPong(mo1)
    test(mo5.a == mo1.a)
    test(mo5.b == mo1.b)
    test(mo5.c == mo1.c)
    test(mo5.d == mo1.d)
    test(mo5.e == mo1.e)
    test(mo5.f == mo1.f)
    test(mo5.g == mo1.g)
    test(mo5.h == mo1.h)
    test(mo5.i == mo1.i)
    test(mo5.j == mo1.j)
    #
    # With Swift mapping you cannot distinguish null from unset
    # so we test for both here to support cross testing.
    #
    test(mo5.k is None or mo5.k is Ice.Unset)
    if sys.version_info[0] == 2:
        test(mo5.bs == "\x05")
    else:
        test(mo5.bs[0] == 5)
    test(mo5.ss == mo1.ss)
    test(mo5.iid[4] == 3)
    test(mo5.sid["test"] == 10)
    test(mo5.fs == mo1.fs)
    test(mo5.vs == mo1.vs)
    test(mo5.shs == mo1.shs)
    test(mo5.es[0] == Test.MyEnum.MyEnumMember and mo1.es[1] == Test.MyEnum.MyEnumMember)
    test(mo5.fss[0] == Test.FixedStruct(78))
    test(mo5.vss[0] == Test.VarStruct("hello"))
    test(mo5.oos[0].a == 15)
    test(mo5.oops[0] == communicator.stringToProxy("test"))

    test(mo5.ied[4] == Test.MyEnum.MyEnumMember)
    test(mo5.ifsd[4] == Test.FixedStruct(78))
    test(mo5.ivsd[5] == Test.VarStruct("hello"))
    test(mo5.iood[5].a == 15)
    test(mo5.ioopd[5] == communicator.stringToProxy("test"))

    test(mo5.bos == mo1.bos)

    # Clear the first half of the optional members
    mo6 = Test.MultiOptional()
    mo6.b = mo5.b
    mo6.d = mo5.d
    mo6.f = mo5.f
    mo6.h = mo5.h
    mo6.j = mo5.j
    mo6.bs = mo5.bs
    mo6.iid = mo5.iid
    mo6.fs = mo5.fs
    mo6.shs = mo5.shs
    mo6.fss = mo5.fss
    mo6.oos = mo5.oos
    mo6.ifsd = mo5.ifsd
    mo6.iood = mo5.iood
    mo6.bos = mo5.bos

    mo7 = initial.pingPong(mo6)
    test(mo7.a is Ice.Unset)
    test(mo7.b == mo1.b)
    test(mo7.c is Ice.Unset)
    test(mo7.d == mo1.d)
    test(mo7.e is Ice.Unset)
    test(mo7.f == mo1.f)
    test(mo7.g is Ice.Unset)
    test(mo7.h == mo1.h)
    test(mo7.i is Ice.Unset)
    test(mo7.j == mo1.j)
    test(mo7.k is Ice.Unset)
    if sys.version_info[0] == 2:
        test(mo7.bs == "\x05")
    else:
        test(mo7.bs[0] == 5)
    test(mo7.ss is Ice.Unset)
    test(mo7.iid[4] == 3)
    test(mo7.sid is Ice.Unset)
    test(mo7.fs == mo1.fs)
    test(mo7.vs is Ice.Unset)

    test(mo7.shs == mo1.shs)
    test(mo7.es is Ice.Unset)
    test(mo7.fss[0] == Test.FixedStruct(78))
    test(mo7.vss is Ice.Unset)
    test(mo7.oos[0].a == 15)
    test(mo7.oops is Ice.Unset)

    test(mo7.ied is Ice.Unset)
    test(mo7.ifsd[4] == Test.FixedStruct(78))
    test(mo7.ivsd is Ice.Unset)
    test(mo7.iood[5].a == 15)
    test(mo7.ioopd is Ice.Unset)

    test(mo7.bos == [False, True, False])

    # Clear the second half of the optional members
    mo8 = Test.MultiOptional()
    mo8.a = mo5.a
    mo8.c = mo5.c
    mo8.e = mo5.e
    mo8.g = mo5.g
    mo8.i = mo5.i
    mo8.k = mo8
    mo8.ss = mo5.ss
    mo8.sid = mo5.sid
    mo8.vs = mo5.vs

    mo8.es = mo5.es
    mo8.vss = mo5.vss
    mo8.oops = mo5.oops

    mo8.ied = mo5.ied
    mo8.ivsd = mo5.ivsd
    mo8.ioopd = mo5.ioopd

    mo9 = initial.pingPong(mo8)
    test(mo9.a == mo1.a)
    test(mo9.b is Ice.Unset)
    test(mo9.c == mo1.c)
    test(mo9.d is Ice.Unset)
    test(mo9.e == mo1.e)
    test(mo9.f is Ice.Unset)
    test(mo9.g == mo1.g)
    test(mo9.h is Ice.Unset)
    test(mo9.i == mo1.i)
    test(mo9.j is Ice.Unset)
    test(mo9.k == mo9)
    test(mo9.bs is Ice.Unset)
    test(mo9.ss == mo1.ss)
    test(mo9.iid is Ice.Unset)
    test(mo9.sid["test"] == 10)
    test(mo9.fs is Ice.Unset)
    test(mo9.vs == mo1.vs)

    test(mo9.shs is Ice.Unset)
    test(mo9.es[0] == Test.MyEnum.MyEnumMember and mo1.es[1] == Test.MyEnum.MyEnumMember)
    test(mo9.fss is Ice.Unset)
    test(mo9.vss[0] == Test.VarStruct("hello"))
    test(mo9.oos is Ice.Unset)
    test(mo9.oops[0] == communicator.stringToProxy("test"))

    test(mo9.ied[4] == Test.MyEnum.MyEnumMember)
    test(mo9.ifsd is Ice.Unset)
    test(mo9.ivsd[5] == Test.VarStruct("hello"))
    test(mo9.iood is Ice.Unset)
    test(mo9.ioopd[5] == communicator.stringToProxy("test"))

    test(mo9.bos is Ice.Unset)

    #
    # Use the 1.0 encoding with operations whose only class parameters are optional.
    #
    initial.sendOptionalClass(True, Test.OneOptional(53))
    initial.ice_encodingVersion(Ice.Encoding_1_0).sendOptionalClass(True, Test.OneOptional(53))

    r = initial.returnOptionalClass(True)
    test(r != Ice.Unset)
    r = initial.ice_encodingVersion(Ice.Encoding_1_0).returnOptionalClass(True)
    test(r is Ice.Unset)

    recursive1 = [ Test.Recursive() ]
    recursive2 = [ Test.Recursive() ]
    recursive1[0].value = recursive2;

    outer = Test.Recursive()
    outer.value = recursive1
    initial.pingPong(outer)

    g = Test.G()
    g.gg1Opt = Test.G1("gg1Opt")
    g.gg2 = Test.G2(10)
    g.gg2Opt = Test.G2(20)
    g.gg1 = Test.G1("gg1")
    r = initial.opG(g)
    test(r.gg1Opt.a == "gg1Opt")
    test(r.gg2.a == 10)
    test(r.gg2Opt.a == 20)
    test(r.gg1.a == "gg1")

    initial2 = Test.Initial2Prx.uncheckedCast(base)
    initial2.opVoid(15, "test")

    print("ok")

    sys.stdout.write("testing marshaling of large containers with fixed size elements... ")
    sys.stdout.flush()

    mc = Test.MultiOptional()

    mc.bs = []
    for i in range(1000):
        mc.bs.append(0)
    mc.shs = []
    for i in range(300):
        mc.shs.append(0)

    mc.fss = []
    for i in range(300):
        mc.fss.append(Test.FixedStruct())

    mc.ifsd = {}
    for i in range(300):
        mc.ifsd[i] = Test.FixedStruct()

    mc = initial.pingPong(mc)
    test(len(mc.bs) == 1000)
    test(len(mc.shs) == 300)
    test(len(mc.fss) == 300)
    test(len(mc.ifsd) == 300)

    print("ok")

    sys.stdout.write("testing tag marshaling... ")
    sys.stdout.flush()

    b = Test.B()
    b2 = initial.pingPong(b)
    test(b2.ma is Ice.Unset)
    test(b2.mb is Ice.Unset)
    test(b2.mc is Ice.Unset)

    b.ma = 10
    b.mb = 11
    b.mc = 12
    b.md = 13

    b2 = initial.pingPong(b)
    test(b2.ma == 10)
    test(b2.mb == 11)
    test(b2.mc == 12)
    test(b2.md == 13)

    print("ok")

    sys.stdout.write("testing marshalling of objects with optional objects...")
    sys.stdout.flush()

    f = Test.F()

    f.af = Test.A()
    f.ae = f.af

    rf = initial.pingPong(f)
    test(rf.ae == rf.af)

    print("ok")

    sys.stdout.write("testing optional with default values... ")
    sys.stdout.flush()

    wd = initial.pingPong(Test.WD())
    test(wd.a == 5)
    test(wd.s == "test")
    wd.a = Ice.Unset
    wd.s = Ice.Unset
    wd = initial.pingPong(wd)
    test(wd.a is Ice.Unset)
    test(wd.s is Ice.Unset)

    print("ok")

    if communicator.getProperties().getPropertyAsInt("Ice.Default.SlicedFormat") > 0:
        sys.stdout.write("testing marshaling with unknown class slices... ")
        sys.stdout.flush()

        c = Test.C()
        c.ss = "test"
        c.ms = "testms"
        c = initial.pingPong(c)
        test(c.ma is Ice.Unset)
        test(c.mb is Ice.Unset)
        test(c.mc is Ice.Unset)
        test(c.md is Ice.Unset)
        test(c.ss == "test")
        test(c.ms == "testms")

        print("ok")

        sys.stdout.write("testing optionals with unknown classes... ")
        sys.stdout.flush()

        initial2 = Test.Initial2Prx.uncheckedCast(base)
        d = Test.D()
        d.ds = "test"
        d.seq = ["test1", "test2", "test3", "test4"]
        d.ao = Test.A(18)
        d.requiredB = 14;
        d.requiredA = 14;
        initial2.opClassAndUnknownOptional(Test.A(), d)

        print("ok")

    sys.stdout.write("testing optional parameters... ")
    sys.stdout.flush()

    (p2, p3) = initial.opByte(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    (p2, p3) = initial.opByte(56)
    test(p2 == 56 and p3 == 56)
    f = initial.opByteAsync(56)
    (p2, p3) = f.result()
    test(p2 == 56 and p3 == 56)

    (p2, p3) = initial.opBool(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    (p2, p3) = initial.opBool(True)
    test(p2 == True and p3 == True)
    f = initial.opBoolAsync(True)
    (p2, p3) = f.result()
    test(p2 == True and p3 == True)

    (p2, p3) = initial.opShort(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    (p2, p3) = initial.opShort(56)
    test(p2 == 56 and p3 == 56)
    f = initial.opShortAsync(56)
    (p2, p3) = f.result()
    test(p2 == 56 and p3 == 56)

    (p2, p3) = initial.opInt(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    (p2, p3) = initial.opInt(56)
    test(p2 == 56 and p3 == 56)
    f = initial.opIntAsync(56)
    (p2, p3) = f.result()
    test(p2 == 56 and p3 == 56)

    (p2, p3) = initial.opLong(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    (p2, p3) = initial.opLong(56)
    test(p2 == 56 and p3 == 56)
    f = initial.opLongAsync(56)
    (p2, p3) = f.result()
    test(p2 == 56 and p3 == 56)

    (p2, p3) = initial.opFloat(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    (p2, p3) = initial.opFloat(1.0)
    test(p2 == 1.0 and p3 == 1.0)
    f = initial.opFloatAsync(1.0)
    (p2, p3) = f.result()
    test(p2 == 1.0 and p3 == 1.0)

    (p2, p3) = initial.opDouble(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    (p2, p3) = initial.opDouble(1.0)
    test(p2 == 1.0 and p3 == 1.0)
    f = initial.opDoubleAsync(1.0)
    (p2, p3) = f.result()
    test(p2 == 1.0 and p3 == 1.0)

    (p2, p3) = initial.opString(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    (p2, p3) = initial.opString("test")
    test(p2 == "test" and p3 == "test")
    f = initial.opStringAsync("test")
    (p2, p3) = f.result()
    test(p2 == "test" and p3 == "test")

    (p2, p3) = initial.opMyEnum(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    (p2, p3) = initial.opMyEnum(Test.MyEnum.MyEnumMember)
    test(p2 == Test.MyEnum.MyEnumMember and p3 == Test.MyEnum.MyEnumMember)
    f = initial.opMyEnumAsync(Test.MyEnum.MyEnumMember)
    (p2, p3) = f.result()
    test(p2 == Test.MyEnum.MyEnumMember and p3 == Test.MyEnum.MyEnumMember)

    (p2, p3) = initial.opSmallStruct(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = Test.SmallStruct(56)
    (p2, p3) = initial.opSmallStruct(p1)
    test(p2 == p1 and p3 == p1)
    (p2, p3) = initial.opSmallStruct(None) # Test null struct
    test(p2.m == 0 and p3.m == 0)
    f = initial.opSmallStructAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opFixedStruct(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = Test.FixedStruct(56)
    (p2, p3) = initial.opFixedStruct(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opFixedStructAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opVarStruct(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = Test.VarStruct("test")
    (p2, p3) = initial.opVarStruct(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opVarStructAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opOneOptional(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    if initial.supportsNullOptional():
        (p2, p3) = initial.opOneOptional(None)
        test(p2 is None and p3 is None)
    p1 = Test.OneOptional(58)
    (p2, p3) = initial.opOneOptional(p1)
    test(p2.a == p1.a and p3.a == p1.a)
    f = initial.opOneOptionalAsync(p1)
    (p2, p3) = f.result()
    test(p2.a == p1.a and p3.a == p1.a)

    (p2, p3) = initial.opOneOptionalProxy(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = communicator.stringToProxy("test")
    (p2, p3) = initial.opOneOptionalProxy(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opOneOptionalProxyAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opByteSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = [56 for x in range(100)]
    (p2, p3) = initial.opByteSeq(p1)
    test(len(p2) == len(p1) and len(p3) == len(p1))
    if sys.version_info[0] == 2:
        test(p2[0] == '\x38')
        test(p3[0] == '\x38')
    else:
        test(p2[0] == 0x38)
        test(p3[0] == 0x38)
    f = initial.opByteSeqAsync(p1)
    (p2, p3) = f.result()
    test(len(p2) == len(p1) and len(p3) == len(p1))
    if sys.version_info[0] == 2:
        test(p2[0] == '\x38')
        test(p3[0] == '\x38')
    else:
        test(p2[0] == 0x38)
        test(p3[0] == 0x38)

    (p2, p3) = initial.opBoolSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = [True for x in range(100)]
    (p2, p3) = initial.opBoolSeq(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opBoolSeqAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opShortSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = [56 for x in range(100)]
    (p2, p3) = initial.opShortSeq(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opShortSeqAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opIntSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = [56 for x in range(100)]
    (p2, p3) = initial.opIntSeq(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opIntSeqAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opLongSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = [56 for x in range(100)]
    (p2, p3) = initial.opLongSeq(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opLongSeqAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opFloatSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = [1.0 for x in range(100)]
    (p2, p3) = initial.opFloatSeq(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opFloatSeqAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opDoubleSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = [1.0 for x in range(100)]
    (p2, p3) = initial.opDoubleSeq(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opDoubleSeqAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opStringSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = ["test1" for x in range(100)]
    (p2, p3) = initial.opStringSeq(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opStringSeqAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opSmallStructSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = [Test.SmallStruct(1) for x in range(10)]
    (p2, p3) = initial.opSmallStructSeq(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opSmallStructSeqAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opSmallStructList(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = tuple([Test.SmallStruct(1) for x in range(10)])
    (p2, p3) = initial.opSmallStructList(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opSmallStructListAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opFixedStructSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = [Test.FixedStruct(1) for x in range(10)]
    (p2, p3) = initial.opFixedStructSeq(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opFixedStructSeqAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opFixedStructList(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = tuple([Test.FixedStruct(1) for x in range(10)])
    (p2, p3) = initial.opFixedStructList(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opFixedStructListAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opVarStructSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = [Test.VarStruct("test") for x in range(10)]
    (p2, p3) = initial.opVarStructSeq(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opVarStructSeqAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opIntIntDict(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = {1:2, 2:3}
    (p2, p3) = initial.opIntIntDict(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opIntIntDictAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opStringIntDict(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = {"1":2, "2":3}
    (p2, p3) = initial.opStringIntDict(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opStringIntDictAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opIntOneOptionalDict(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = {1:Test.OneOptional(58), 2:Test.OneOptional(59)}
    (p2, p3) = initial.opIntOneOptionalDict(p1)
    test(p2[1].a == 58 and p3[1].a == 58);
    f = initial.opIntOneOptionalDictAsync(p1)
    (p2, p3) = f.result()
    test(p2[1].a == 58 and p3[1].a == 58);

    print("ok")

    sys.stdout.write("testing exception optionals... ")
    sys.stdout.flush()

    try:
        initial.opOptionalException(Ice.Unset, Ice.Unset, Ice.Unset)
    except Test.OptionalException as ex:
        test(ex.a is Ice.Unset)
        test(ex.b is Ice.Unset)
        test(ex.o is Ice.Unset)

    try:
        initial.opOptionalException(30, "test", Test.OneOptional(53))
    except Test.OptionalException as ex:
        test(ex.a == 30)
        test(ex.b == "test")
        test(ex.o.a == 53)

    try:
        #
        # Use the 1.0 encoding with an exception whose only class members are optional.
        #
        initial.ice_encodingVersion(Ice.Encoding_1_0).opOptionalException(30, "test", Test.OneOptional(53))
    except Test.OptionalException as ex:
        test(ex.a is Ice.Unset)
        test(ex.b is Ice.Unset)
        test(ex.o is Ice.Unset)

    try:
        initial.opDerivedException(Ice.Unset, Ice.Unset, Ice.Unset)
    except Test.DerivedException as ex:
        test(ex.a is Ice.Unset)
        test(ex.b is Ice.Unset)
        test(ex.o is Ice.Unset)
        test(ex.ss is Ice.Unset)
        test(ex.o2 is Ice.Unset)

    try:
        initial.opDerivedException(30, "test2", Test.OneOptional(53))
    except Test.DerivedException as ex:
        test(ex.a == 30)
        test(ex.b == "test2")
        test(ex.o.a == 53)
        test(ex.ss == "test2")
        test(ex.o2 == ex.o)

    try:
        initial.opRequiredException(Ice.Unset, Ice.Unset, Ice.Unset)
    except Test.RequiredException as ex:
        test(ex.a is Ice.Unset)
        test(ex.b is Ice.Unset)
        test(ex.o is Ice.Unset)
        test(ex.ss == "test")
        test(ex.o2 == None)

    try:
        initial.opRequiredException(30, "test2", Test.OneOptional(53))
    except Test.RequiredException as ex:
        test(ex.a == 30)
        test(ex.b == "test2")
        test(ex.o.a == 53)
        test(ex.ss == "test2")
        test(ex.o2 == ex.o)

    print("ok")

    sys.stdout.write("testing optionals with marshaled results... ")
    sys.stdout.flush()

    test(initial.opMStruct1() != Ice.Unset);
    test(initial.opMDict1() != Ice.Unset);
    test(initial.opMSeq1() != Ice.Unset);
    test(initial.opMG1() != Ice.Unset);

    (p3, p2) = initial.opMStruct2(Ice.Unset);
    test(p2 == Ice.Unset and p3 == Ice.Unset);

    p1 = Test.SmallStruct();
    (p3, p2) = initial.opMStruct2(p1)
    test(p2 == p1 and p3 == p1)

    (p3, p2) = initial.opMSeq2(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)

    p1 = ["hello"]
    (p3, p2) = initial.opMSeq2(p1);
    test(p2[0] == "hello" and p3[0] == "hello")

    (p3, p2) = initial.opMDict2(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)

    p1 = {"test" : 54}
    (p3, p2) = initial.opMDict2(p1)
    test(p2["test"] == 54 and p3["test"] == 54)

    (p3, p2) = initial.opMG2(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)

    p1 = Test.G();
    (p3, p2) = initial.opMG2(p1);
    test(p2 != Ice.Unset and p3 != Ice.Unset and p3 == p2);

    print("ok")

    return initial
예제 #10
0
def allTests(helper, communicator):
    sys.stdout.write("testing stringToProxy... ")
    sys.stdout.flush()
    ref = "initial:{0}".format(helper.getTestEndpoint())
    base = communicator.stringToProxy(ref)
    test(base)
    print("ok")

    sys.stdout.write("testing checked cast... ")
    sys.stdout.flush()
    initial = Test.InitialPrx.checkedCast(base)
    test(initial)
    test(initial == base)
    print("ok")

    sys.stdout.write("testing optional data members... ")
    sys.stdout.flush()

    oo1 = Test.OneOptional()
    test(oo1.a is Ice.Unset)
    oo1.a = 15

    oo2 = Test.OneOptional(16)
    test(oo2.a == 16)

    mo1 = Test.MultiOptional()
    test(mo1.a is Ice.Unset)
    test(mo1.b is Ice.Unset)
    test(mo1.c is Ice.Unset)
    test(mo1.d is Ice.Unset)
    test(mo1.e is Ice.Unset)
    test(mo1.f is Ice.Unset)
    test(mo1.g is Ice.Unset)
    test(mo1.h is Ice.Unset)
    test(mo1.i is Ice.Unset)
    test(mo1.bs is Ice.Unset)
    test(mo1.ss is Ice.Unset)
    test(mo1.iid is Ice.Unset)
    test(mo1.sid is Ice.Unset)
    test(mo1.fs is Ice.Unset)
    test(mo1.vs is Ice.Unset)

    test(mo1.shs is Ice.Unset)
    test(mo1.es is Ice.Unset)
    test(mo1.fss is Ice.Unset)
    test(mo1.vss is Ice.Unset)
    test(mo1.oops is Ice.Unset)

    test(mo1.ied is Ice.Unset)
    test(mo1.ifsd is Ice.Unset)
    test(mo1.ivsd is Ice.Unset)

    test(mo1.bos is Ice.Unset)

    ss = Test.SmallStruct()
    fs = Test.FixedStruct(78)
    vs = Test.VarStruct("hello")
    mo1 = Test.MultiOptional(15, True, 19, 78, 99, 5.5, 1.0, "test", Test.MyEnum.MyEnumMember, \
                             [5], ["test", "test2"], {4:3}, {"test":10}, fs, vs, [1], \
                             [Test.MyEnum.MyEnumMember, Test.MyEnum.MyEnumMember], \
                             [ fs ], [ vs ], \
                             {4:Test.MyEnum.MyEnumMember}, {4:fs}, {5:vs}, \
                             [False, True, False])

    test(mo1.a == 15)
    test(mo1.b == True)
    test(mo1.c == 19)
    test(mo1.d == 78)
    test(mo1.e == 99)
    test(mo1.f == 5.5)
    test(mo1.g == 1.0)
    test(mo1.h == "test")
    test(mo1.i == Test.MyEnum.MyEnumMember)
    test(mo1.bs == [5])
    test(mo1.ss == ["test", "test2"])
    test(mo1.iid[4] == 3)
    test(mo1.sid["test"] == 10)
    test(mo1.fs == Test.FixedStruct(78))
    test(mo1.vs == Test.VarStruct("hello"))

    test(mo1.shs[0] == 1)
    test(mo1.es[0] == Test.MyEnum.MyEnumMember
         and mo1.es[1] == Test.MyEnum.MyEnumMember)
    test(mo1.fss[0] == Test.FixedStruct(78))
    test(mo1.vss[0] == Test.VarStruct("hello"))

    test(mo1.ied[4] == Test.MyEnum.MyEnumMember)
    test(mo1.ifsd[4] == Test.FixedStruct(78))
    test(mo1.ivsd[5] == Test.VarStruct("hello"))

    test(mo1.bos == [False, True, False])

    #
    # Test generated struct and classes compare with Ice.Unset
    #
    test(ss != Ice.Unset)
    test(fs != Ice.Unset)
    test(vs != Ice.Unset)
    test(mo1 != Ice.Unset)

    print("ok")

    sys.stdout.write("testing marshaling... ")
    sys.stdout.flush()

    oo4 = initial.pingPong(Test.OneOptional())
    test(oo4.a is Ice.Unset)

    oo5 = initial.pingPong(oo1)
    test(oo1.a == oo5.a)

    mo4 = initial.pingPong(Test.MultiOptional())
    test(mo4.a is Ice.Unset)
    test(mo4.b is Ice.Unset)
    test(mo4.c is Ice.Unset)
    test(mo4.d is Ice.Unset)
    test(mo4.e is Ice.Unset)
    test(mo4.f is Ice.Unset)
    test(mo4.g is Ice.Unset)
    test(mo4.h is Ice.Unset)
    test(mo4.i is Ice.Unset)
    test(mo4.bs is Ice.Unset)
    test(mo4.ss is Ice.Unset)
    test(mo4.iid is Ice.Unset)
    test(mo4.sid is Ice.Unset)
    test(mo4.fs is Ice.Unset)
    test(mo4.vs is Ice.Unset)

    test(mo4.shs is Ice.Unset)
    test(mo4.es is Ice.Unset)
    test(mo4.fss is Ice.Unset)
    test(mo4.vss is Ice.Unset)

    test(mo4.ied is Ice.Unset)
    test(mo4.ifsd is Ice.Unset)
    test(mo4.ivsd is Ice.Unset)

    test(mo4.bos is Ice.Unset)

    mo5 = initial.pingPong(mo1)
    test(mo5.a == mo1.a)
    test(mo5.b == mo1.b)
    test(mo5.c == mo1.c)
    test(mo5.d == mo1.d)
    test(mo5.e == mo1.e)
    test(mo5.f == mo1.f)
    test(mo5.g == mo1.g)
    test(mo5.h == mo1.h)
    test(mo5.i == mo1.i)
    if sys.version_info[0] == 2:
        test(mo5.bs == "\x05")
    else:
        test(mo5.bs[0] == 5)
    test(mo5.ss == mo1.ss)
    test(mo5.iid[4] == 3)
    test(mo5.sid["test"] == 10)
    test(mo5.fs == mo1.fs)
    test(mo5.vs == mo1.vs)
    test(mo5.shs == mo1.shs)
    test(mo5.es[0] == Test.MyEnum.MyEnumMember
         and mo1.es[1] == Test.MyEnum.MyEnumMember)
    test(mo5.fss[0] == Test.FixedStruct(78))
    test(mo5.vss[0] == Test.VarStruct("hello"))

    test(mo5.ied[4] == Test.MyEnum.MyEnumMember)
    test(mo5.ifsd[4] == Test.FixedStruct(78))
    test(mo5.ivsd[5] == Test.VarStruct("hello"))

    test(mo5.bos == mo1.bos)

    # Clear the first half of the optional members
    mo6 = Test.MultiOptional()
    mo6.b = mo5.b
    mo6.d = mo5.d
    mo6.f = mo5.f
    mo6.h = mo5.h
    mo6.bs = mo5.bs
    mo6.iid = mo5.iid
    mo6.fs = mo5.fs
    mo6.shs = mo5.shs
    mo6.fss = mo5.fss
    mo6.ifsd = mo5.ifsd
    mo6.bos = mo5.bos

    mo7 = initial.pingPong(mo6)
    test(mo7.a is Ice.Unset)
    test(mo7.b == mo1.b)
    test(mo7.c is Ice.Unset)
    test(mo7.d == mo1.d)
    test(mo7.e is Ice.Unset)
    test(mo7.f == mo1.f)
    test(mo7.g is Ice.Unset)
    test(mo7.h == mo1.h)
    test(mo7.i is Ice.Unset)
    if sys.version_info[0] == 2:
        test(mo7.bs == "\x05")
    else:
        test(mo7.bs[0] == 5)
    test(mo7.ss is Ice.Unset)
    test(mo7.iid[4] == 3)
    test(mo7.sid is Ice.Unset)
    test(mo7.fs == mo1.fs)
    test(mo7.vs is Ice.Unset)

    test(mo7.shs == mo1.shs)
    test(mo7.es is Ice.Unset)
    test(mo7.fss[0] == Test.FixedStruct(78))
    test(mo7.vss is Ice.Unset)

    test(mo7.ied is Ice.Unset)
    test(mo7.ifsd[4] == Test.FixedStruct(78))
    test(mo7.ivsd is Ice.Unset)

    test(mo7.bos == [False, True, False])

    # Clear the second half of the optional members
    mo8 = Test.MultiOptional()
    mo8.a = mo5.a
    mo8.c = mo5.c
    mo8.e = mo5.e
    mo8.g = mo5.g
    mo8.i = mo5.i
    mo8.ss = mo5.ss
    mo8.sid = mo5.sid
    mo8.vs = mo5.vs

    mo8.es = mo5.es
    mo8.vss = mo5.vss

    mo8.ied = mo5.ied
    mo8.ivsd = mo5.ivsd

    mo9 = initial.pingPong(mo8)
    test(mo9.a == mo1.a)
    test(mo9.b is Ice.Unset)
    test(mo9.c == mo1.c)
    test(mo9.d is Ice.Unset)
    test(mo9.e == mo1.e)
    test(mo9.f is Ice.Unset)
    test(mo9.g == mo1.g)
    test(mo9.h is Ice.Unset)
    test(mo9.i == mo1.i)
    test(mo9.bs is Ice.Unset)
    test(mo9.ss == mo1.ss)
    test(mo9.iid is Ice.Unset)
    test(mo9.sid["test"] == 10)
    test(mo9.fs is Ice.Unset)
    test(mo9.vs == mo1.vs)

    test(mo9.shs is Ice.Unset)
    test(mo9.es[0] == Test.MyEnum.MyEnumMember
         and mo1.es[1] == Test.MyEnum.MyEnumMember)
    test(mo9.fss is Ice.Unset)
    test(mo9.vss[0] == Test.VarStruct("hello"))

    test(mo9.ied[4] == Test.MyEnum.MyEnumMember)
    test(mo9.ifsd is Ice.Unset)
    test(mo9.ivsd[5] == Test.VarStruct("hello"))

    test(mo9.bos is Ice.Unset)

    initial2 = Test.Initial2Prx.uncheckedCast(base)
    initial2.opVoid(15, "test")

    print("ok")

    sys.stdout.write(
        "testing marshaling of large containers with fixed size elements... ")
    sys.stdout.flush()

    mc = Test.MultiOptional()

    mc.bs = []
    for i in range(1000):
        mc.bs.append(0)
    mc.shs = []
    for i in range(300):
        mc.shs.append(0)

    mc.fss = []
    for i in range(300):
        mc.fss.append(Test.FixedStruct())

    mc.ifsd = {}
    for i in range(300):
        mc.ifsd[i] = Test.FixedStruct()

    mc = initial.pingPong(mc)
    test(len(mc.bs) == 1000)
    test(len(mc.shs) == 300)
    test(len(mc.fss) == 300)
    test(len(mc.ifsd) == 300)

    print("ok")

    sys.stdout.write("testing tag marshaling... ")
    sys.stdout.flush()

    b = Test.B()
    b2 = initial.pingPong(b)
    test(b2.ma is Ice.Unset)
    test(b2.mb is Ice.Unset)
    test(b2.mc is Ice.Unset)

    b.ma = 10
    b.mb = 11
    b.mc = 12
    b.md = 13

    b2 = initial.pingPong(b)
    test(b2.ma == 10)
    test(b2.mb == 11)
    test(b2.mc == 12)
    test(b2.md == 13)

    print("ok")

    sys.stdout.write("testing optional with default values... ")
    sys.stdout.flush()

    wd = initial.pingPong(Test.WD())
    test(wd.a == 5)
    test(wd.s == "test")
    wd.a = Ice.Unset
    wd.s = Ice.Unset
    wd = initial.pingPong(wd)
    test(wd.a is Ice.Unset)
    test(wd.s is Ice.Unset)

    print("ok")

    if communicator.getProperties().getPropertyAsInt(
            "Ice.Default.SlicedFormat") > 0:
        sys.stdout.write("testing marshaling with unknown class slices... ")
        sys.stdout.flush()

        c = Test.C()
        c.ss = "test"
        c.ms = "testms"
        c = initial.pingPong(c)
        test(c.ma is Ice.Unset)
        test(c.mb is Ice.Unset)
        test(c.mc is Ice.Unset)
        test(c.md is Ice.Unset)
        test(c.ss == "test")
        test(c.ms == "testms")

        print("ok")

        sys.stdout.write("testing optionals with unknown classes... ")
        sys.stdout.flush()

        initial2 = Test.Initial2Prx.uncheckedCast(base)
        initial2.opClassAndUnknownOptional(Test.A())

        print("ok")

    sys.stdout.write("testing optional parameters... ")
    sys.stdout.flush()

    (p2, p3) = initial.opByte(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    (p2, p3) = initial.opByte(56)
    test(p2 == 56 and p3 == 56)
    f = initial.opByteAsync(56)
    (p2, p3) = f.result()
    test(p2 == 56 and p3 == 56)

    (p2, p3) = initial.opBool(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    (p2, p3) = initial.opBool(True)
    test(p2 == True and p3 == True)
    f = initial.opBoolAsync(True)
    (p2, p3) = f.result()
    test(p2 == True and p3 == True)

    (p2, p3) = initial.opShort(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    (p2, p3) = initial.opShort(56)
    test(p2 == 56 and p3 == 56)
    f = initial.opShortAsync(56)
    (p2, p3) = f.result()
    test(p2 == 56 and p3 == 56)

    (p2, p3) = initial.opInt(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    (p2, p3) = initial.opInt(56)
    test(p2 == 56 and p3 == 56)
    f = initial.opIntAsync(56)
    (p2, p3) = f.result()
    test(p2 == 56 and p3 == 56)

    (p2, p3) = initial.opLong(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    (p2, p3) = initial.opLong(56)
    test(p2 == 56 and p3 == 56)
    f = initial.opLongAsync(56)
    (p2, p3) = f.result()
    test(p2 == 56 and p3 == 56)

    (p2, p3) = initial.opFloat(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    (p2, p3) = initial.opFloat(1.0)
    test(p2 == 1.0 and p3 == 1.0)
    f = initial.opFloatAsync(1.0)
    (p2, p3) = f.result()
    test(p2 == 1.0 and p3 == 1.0)

    (p2, p3) = initial.opDouble(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    (p2, p3) = initial.opDouble(1.0)
    test(p2 == 1.0 and p3 == 1.0)
    f = initial.opDoubleAsync(1.0)
    (p2, p3) = f.result()
    test(p2 == 1.0 and p3 == 1.0)

    (p2, p3) = initial.opString(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    (p2, p3) = initial.opString("test")
    test(p2 == "test" and p3 == "test")
    f = initial.opStringAsync("test")
    (p2, p3) = f.result()
    test(p2 == "test" and p3 == "test")

    (p2, p3) = initial.opMyEnum(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    (p2, p3) = initial.opMyEnum(Test.MyEnum.MyEnumMember)
    test(p2 == Test.MyEnum.MyEnumMember and p3 == Test.MyEnum.MyEnumMember)
    f = initial.opMyEnumAsync(Test.MyEnum.MyEnumMember)
    (p2, p3) = f.result()
    test(p2 == Test.MyEnum.MyEnumMember and p3 == Test.MyEnum.MyEnumMember)

    (p2, p3) = initial.opSmallStruct(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = Test.SmallStruct(56)
    (p2, p3) = initial.opSmallStruct(p1)
    test(p2 == p1 and p3 == p1)
    (p2, p3) = initial.opSmallStruct(None)  # Test null struct
    test(p2.m == 0 and p3.m == 0)
    f = initial.opSmallStructAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opFixedStruct(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = Test.FixedStruct(56)
    (p2, p3) = initial.opFixedStruct(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opFixedStructAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opVarStruct(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = Test.VarStruct("test")
    (p2, p3) = initial.opVarStruct(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opVarStructAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opByteSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = [56 for x in range(100)]
    (p2, p3) = initial.opByteSeq(p1)
    test(len(p2) == len(p1) and len(p3) == len(p1))
    if sys.version_info[0] == 2:
        test(p2[0] == '\x38')
        test(p3[0] == '\x38')
    else:
        test(p2[0] == 0x38)
        test(p3[0] == 0x38)
    f = initial.opByteSeqAsync(p1)
    (p2, p3) = f.result()
    test(len(p2) == len(p1) and len(p3) == len(p1))
    if sys.version_info[0] == 2:
        test(p2[0] == '\x38')
        test(p3[0] == '\x38')
    else:
        test(p2[0] == 0x38)
        test(p3[0] == 0x38)

    (p2, p3) = initial.opBoolSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = [True for x in range(100)]
    (p2, p3) = initial.opBoolSeq(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opBoolSeqAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opShortSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = [56 for x in range(100)]
    (p2, p3) = initial.opShortSeq(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opShortSeqAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opIntSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = [56 for x in range(100)]
    (p2, p3) = initial.opIntSeq(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opIntSeqAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opLongSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = [56 for x in range(100)]
    (p2, p3) = initial.opLongSeq(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opLongSeqAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opFloatSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = [1.0 for x in range(100)]
    (p2, p3) = initial.opFloatSeq(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opFloatSeqAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opDoubleSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = [1.0 for x in range(100)]
    (p2, p3) = initial.opDoubleSeq(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opDoubleSeqAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opStringSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = ["test1" for x in range(100)]
    (p2, p3) = initial.opStringSeq(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opStringSeqAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opSmallStructSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = [Test.SmallStruct(1) for x in range(10)]
    (p2, p3) = initial.opSmallStructSeq(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opSmallStructSeqAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opSmallStructList(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = tuple([Test.SmallStruct(1) for x in range(10)])
    (p2, p3) = initial.opSmallStructList(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opSmallStructListAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opFixedStructSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = [Test.FixedStruct(1) for x in range(10)]
    (p2, p3) = initial.opFixedStructSeq(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opFixedStructSeqAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opFixedStructList(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = tuple([Test.FixedStruct(1) for x in range(10)])
    (p2, p3) = initial.opFixedStructList(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opFixedStructListAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opVarStructSeq(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = [Test.VarStruct("test") for x in range(10)]
    (p2, p3) = initial.opVarStructSeq(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opVarStructSeqAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opIntIntDict(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = {1: 2, 2: 3}
    (p2, p3) = initial.opIntIntDict(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opIntIntDictAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    (p2, p3) = initial.opStringIntDict(Ice.Unset)
    test(p2 is Ice.Unset and p3 is Ice.Unset)
    p1 = {"1": 2, "2": 3}
    (p2, p3) = initial.opStringIntDict(p1)
    test(p2 == p1 and p3 == p1)
    f = initial.opStringIntDictAsync(p1)
    (p2, p3) = f.result()
    test(p2 == p1 and p3 == p1)

    print("ok")

    sys.stdout.write("testing exception optionals... ")
    sys.stdout.flush()

    try:
        initial.opOptionalException(Ice.Unset, Ice.Unset, Ice.Unset)
    except Test.OptionalException as ex:
        test(ex.a is Ice.Unset)
        test(ex.b is Ice.Unset)
        test(ex.vs is Ice.Unset)

    try:
        initial.opOptionalException(30, "test", Test.VarStruct("hello"))
    except Test.OptionalException as ex:
        test(ex.a == 30)
        test(ex.b == "test")
        test(ex.vs.m == "hello")

    try:
        #
        # Use the 1.0 encoding with an exception whose only class members are optional.
        #
        initial.ice_encodingVersion(Ice.Encoding_1_0).opOptionalException(
            30, "test", Test.VarStruct("hello"))
    except Test.OptionalException as ex:
        test(ex.a is Ice.Unset)
        test(ex.b is Ice.Unset)
        test(ex.vs is Ice.Unset)

    try:
        initial.opDerivedException(Ice.Unset, Ice.Unset, Ice.Unset)
    except Test.DerivedException as ex:
        test(ex.a is Ice.Unset)
        test(ex.b is Ice.Unset)
        test(ex.vs is Ice.Unset)
        test(ex.ss is Ice.Unset)
        test(ex.vs2 is Ice.Unset)

    try:
        initial.opDerivedException(30, "test2", Test.VarStruct("hello2"))
    except Test.DerivedException as ex:
        test(ex.a == 30)
        test(ex.b == "test2")
        test(ex.vs.m == "hello2")
        test(ex.ss == "test2")
        test(ex.vs2 == ex.vs)

    try:
        initial.opRequiredException(Ice.Unset, Ice.Unset, Ice.Unset)
    except Test.RequiredException as ex:
        test(ex.a is Ice.Unset)
        test(ex.b is Ice.Unset)
        test(ex.vs is Ice.Unset)
        test(ex.ss == "test")
        test(ex.vs2 == None)

    try:
        initial.opRequiredException(30, "test2", Test.VarStruct("hello2"))
    except Test.RequiredException as ex:
        test(ex.a == 30)
        test(ex.b == "test2")
        test(ex.vs.m == "hello2")
        test(ex.ss == "test2")
        test(ex.vs2 == ex.vs)

    print("ok")

    sys.stdout.write("testing optionals with marshaled results... ")
    sys.stdout.flush()

    test(initial.opMStruct1() != Ice.Unset)
    test(initial.opMDict1() != Ice.Unset)
    test(initial.opMSeq1() != Ice.Unset)

    (p3, p2) = initial.opMStruct2(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)

    p1 = Test.SmallStruct()
    (p3, p2) = initial.opMStruct2(p1)
    test(p2 == p1 and p3 == p1)

    (p3, p2) = initial.opMSeq2(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)

    p1 = ["hello"]
    (p3, p2) = initial.opMSeq2(p1)
    test(p2[0] == "hello" and p3[0] == "hello")

    (p3, p2) = initial.opMDict2(Ice.Unset)
    test(p2 == Ice.Unset and p3 == Ice.Unset)

    p1 = {"test": 54}
    (p3, p2) = initial.opMDict2(p1)
    test(p2["test"] == 54 and p3["test"] == 54)

    print("ok")

    return initial