Exemplo n.º 1
0
    def test_implicit_reference_conversions(self):
        import System
        from Merlin.Testing import Flag
        from Merlin.Testing.Call import AnyStruct, AnyReference, ClassBase, ClassDerived, Consumer, \
            First, Int32WrapperClass, Int32WrapperStruct, Second, Source1, StructBase, StructDerived, Third
        from Merlin.Testing.TypeSample import VoidVoidDelegate, Int32Int32Delegate

        for x in [AnyStruct(), AnyReference(), None]:  # boxing conversion for AnyStruct
            Consumer.EatObject(x); Flag.Check(801)
        
        for x in [First(), Second(), Third(), ClassDerived(), None]: 
            Consumer.EatFirst(x); Flag.Check(808)
        
        for x in [ StructBase(), ClassBase(), StructDerived(), ClassDerived() ]:  # boxing conversion for StructXXX
            Consumer.EatIBase(x); Flag.Check(802)
        
        a = System.Array[Source1]([Source1(), Source1()])
        self.assertRaises(TypeError, Consumer.EatTarget1Array, a)
        self.assertRaises(TypeError, Consumer.EatTarget2Array, a)

        c = System.Array[int]([1, 2, 3])
        d = System.Array[Int32WrapperClass]([Int32WrapperClass(1),])
        e = System.Array[Int32WrapperStruct]([Int32WrapperStruct(2),])
        self.assertRaisesMessage(TypeError, "expected Array[Int32WrapperClass], got Array[int]", 
                            Consumer.EatInt32WrapperClassArray, c)
        self.assertRaisesMessage(TypeError, "expected Array[Int32WrapperStruct], got Array[int]", 
                            Consumer.EatInt32WrapperStructArray, c)
        for x in [d, e]:
            self.assertRaises(TypeError, Consumer.EatInt32Array, x)
        
        f = System.Array[Second]([Second(), Second()])
        g = System.Array[Third]([Third(), ])
        for x in [f, g]:
            Consumer.EatFirstArray(f); Flag.Check(815)
            
        for x in [None, a, c, d, e, f, g]:
            Consumer.EatArray(x); Flag.Check(806)
        
        for x in [VoidVoidDelegate(Consumer.MVoidVoid), Int32Int32Delegate(Consumer.MInt32Int32)]:
            Consumer.EatDelegate(x); Flag.Check(807)
        
        a = AnyStruct()
        Consumer.EatAnyStruct(a); Flag.Check(850)
        self.assertRaisesMessage(TypeError, 'expected AnyStruct, got NoneType', Consumer.EatAnyStruct, None)
        
        for x in [a, None]:
            Consumer.EatNullableAnyStruct(a); Flag.Check(851)
Exemplo n.º 2
0
    def test_boxing_conversion(self):
        from Merlin.Testing import Flag
        from Merlin.Testing.Call import AnyStruct, Consumer, StructBase
        from Merlin.Testing.TypeSample import EnumInt16, EnumUInt32
        for x in [AnyStruct(), EnumInt16.B, None, StructBase()]:
            Consumer.EatValueType(x)
            Flag.Check(809)

        for x in [EnumInt16.A, EnumUInt32.C, None]:
            Consumer.EatEnumType(x)
            Flag.Check(810)