コード例 #1
0
        public void GetData_DataIsString_ReturnsTestString()
        {
            const string data = "TestData";

            var weakData = new WeakBase <string>(null, data, KeepOwnerAliveMode.NotKeepAlive);

            Assert.Equal(data, weakData.GetData());
        }
コード例 #2
0
        public WeakBase <Action> CreateWeakBase()
        {
            var writer = new TestConsoleWriter();

            var weakAction = new WeakBase <Action>(this, () => writer.Write("Test"), KeepOwnerAliveMode.NotKeepAlive);

            return(weakAction);
        }
コード例 #3
0
ファイル: cli_cs_bridgetest.cs プロジェクト: sitedata/core-1
        bool performTest(XBridgeTest xLBT)
        {
            check(xLBT != null, "### no test interface!");
            bool bRet = true;

            if (xLBT == null)
            {
                return(false);
            }

            // this data is never ever granted access to by calls other than equals(), assign()!
            TestDataElements aData = new TestDataElements(); // test against this data

            Object xI = new WeakBase();

            Any aAny = new Any(typeof(Object), xI);

            assign((TestElement)aData,
                   true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
                   0x123456789abcdef0, 0xfedcba9876543210,
                   17.0815f, 3.1415926359, TestEnum.LOLA,
                   Constants.STRING_TEST_CONSTANT, xI,
                   aAny);

            bRet = check(aData.Any.Value == xI, "### unexpected any!") && bRet;
            bRet = check(!(aData.Any.Value != xI), "### unexpected any!") && bRet;

            aData.Sequence    = new TestElement[2];
            aData.Sequence[0] = new TestElement(
                aData.Bool, aData.Char, aData.Byte, aData.Short,
                aData.UShort, aData.Long, aData.ULong,
                aData.Hyper, aData.UHyper, aData.Float,
                aData.Double, aData.Enum, aData.String,
                aData.Interface, aData.Any);       //(TestElement) aData;
            aData.Sequence[1] = new TestElement(); //is empty

            // aData complete

            // this is a manually copy of aData for first setting...
            TestDataElements aSetData = new TestDataElements();
            Any aAnySet = new Any(typeof(Object), xI);

            assign((TestElement)aSetData,
                   aData.Bool, aData.Char, aData.Byte, aData.Short, aData.UShort,
                   aData.Long, aData.ULong, aData.Hyper, aData.UHyper, aData.Float, aData.Double,
                   aData.Enum, aData.String, xI,
                   aAnySet);

            aSetData.Sequence    = new TestElement[2];
            aSetData.Sequence[0] = new TestElement(
                aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short,
                aSetData.UShort, aSetData.Long, aSetData.ULong,
                aSetData.Hyper, aSetData.UHyper, aSetData.Float,
                aSetData.Double, aSetData.Enum, aSetData.String,
                aSetData.Interface, aSetData.Any);    //TestElement) aSetData;
            aSetData.Sequence[1] = new TestElement(); // empty struct

            xLBT.setValues(
                aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short, aSetData.UShort,
                aSetData.Long, aSetData.ULong, aSetData.Hyper, aSetData.UHyper, aSetData.Float, aSetData.Double,
                aSetData.Enum, aSetData.String, aSetData.Interface, aSetData.Any, aSetData.Sequence, aSetData);

            {
                TestDataElements aRet  = new TestDataElements();
                TestDataElements aRet2 = new TestDataElements();
                xLBT.getValues(
                    out aRet.Bool, out aRet.Char, out aRet.Byte, out aRet.Short, out aRet.UShort,
                    out aRet.Long, out aRet.ULong, out aRet.Hyper, out aRet.UHyper,
                    out aRet.Float, out aRet.Double, out aRet.Enum, out aRet.String,
                    out aRet.Interface, out aRet.Any, out aRet.Sequence, out aRet2);

                bRet = check(compareData(aData, aRet) && compareData(aData, aRet2), "getValues test") && bRet;

                // set last retrieved values
                TestDataElements aSV2ret = xLBT.setValues2(
                    ref aRet.Bool, ref aRet.Char, ref aRet.Byte, ref aRet.Short, ref aRet.UShort,
                    ref aRet.Long, ref aRet.ULong, ref aRet.Hyper, ref aRet.UHyper, ref aRet.Float,
                    ref aRet.Double, ref aRet.Enum, ref aRet.String, ref aRet.Interface, ref aRet.Any,
                    ref aRet.Sequence, ref aRet2);

                // check inout sequence order
                // => inout sequence parameter was switched by test objects
                TestElement temp = aRet.Sequence[0];
                aRet.Sequence[0] = aRet.Sequence[1];
                aRet.Sequence[1] = temp;

                bRet = check(
                    compareData(aData, aSV2ret) && compareData(aData, aRet2),
                    "getValues2 test") && bRet;
            }
            {
                TestDataElements aRet   = new TestDataElements();
                TestDataElements aRet2  = new TestDataElements();
                TestDataElements aGVret = xLBT.getValues(
                    out aRet.Bool, out aRet.Char, out aRet.Byte, out aRet.Short,
                    out aRet.UShort, out aRet.Long, out aRet.ULong, out aRet.Hyper,
                    out aRet.UHyper, out aRet.Float, out aRet.Double, out aRet.Enum,
                    out aRet.String, out aRet.Interface, out aRet.Any, out aRet.Sequence,
                    out aRet2);

                bRet = check(compareData(aData, aRet) && compareData(aData, aRet2) && compareData(aData, aGVret), "getValues test") && bRet;

                // set last retrieved values
                xLBT.Bool      = aRet.Bool;
                xLBT.Char      = aRet.Char;
                xLBT.Byte      = aRet.Byte;
                xLBT.Short     = aRet.Short;
                xLBT.UShort    = aRet.UShort;
                xLBT.Long      = aRet.Long;
                xLBT.ULong     = aRet.ULong;
                xLBT.Hyper     = aRet.Hyper;
                xLBT.UHyper    = aRet.UHyper;
                xLBT.Float     = aRet.Float;
                xLBT.Double    = aRet.Double;
                xLBT.Enum      = aRet.Enum;
                xLBT.String    = aRet.String;
                xLBT.Interface = aRet.Interface;
                xLBT.Any       = aRet.Any;
                xLBT.Sequence  = aRet.Sequence;
                xLBT.Struct    = aRet2;
            }
            {
                TestDataElements aRet  = new TestDataElements();
                TestDataElements aRet2 = new TestDataElements();
                aRet.Hyper     = xLBT.Hyper;
                aRet.UHyper    = xLBT.UHyper;
                aRet.Float     = xLBT.Float;
                aRet.Double    = xLBT.Double;
                aRet.Byte      = xLBT.Byte;
                aRet.Char      = xLBT.Char;
                aRet.Bool      = xLBT.Bool;
                aRet.Short     = xLBT.Short;
                aRet.UShort    = xLBT.UShort;
                aRet.Long      = xLBT.Long;
                aRet.ULong     = xLBT.ULong;
                aRet.Enum      = xLBT.Enum;
                aRet.String    = xLBT.String;
                aRet.Interface = xLBT.Interface;
                aRet.Any       = xLBT.Any;
                aRet.Sequence  = xLBT.Sequence;
                aRet2          = xLBT.Struct;

                bRet = check(compareData(aData, aRet) && compareData(aData, aRet2), "struct comparison test") && bRet;

                bRet = check(performSequenceTest(xLBT), "sequence test") && bRet;

                // any test
                bRet = check(performAnyTest(xLBT, aData), "any test") && bRet;

                // sequence of call test
                bRet = check(performSequenceOfCallTest(xLBT), "sequence of call test") && bRet;

                // recursive call test
                bRet = check(performRecursiveCallTest(xLBT), "recursive test") && bRet;

                bRet = (compareData(aData, aRet) && compareData(aData, aRet2)) && bRet;

                // check setting of null reference
                xLBT.Interface = null;
                aRet.Interface = xLBT.Interface;
                bRet           = (aRet.Interface == null) && bRet;
            }
            // Test extended attributes that raise exceptions:
            try {
                int i = xLBT.RaiseAttr1;
                bRet &= check(false, "getRaiseAttr1 did not throw");
            } catch (RuntimeException)
            {
            }
            catch (System.Exception) {
                bRet &= check(false, "getRaiseAttr1 threw wrong type");
            }
            try {
                xLBT.RaiseAttr1 = 0;
                bRet           &= check(false, "setRaiseAttr1 did not throw");
            } catch (IllegalArgumentException) {
            } catch (System.Exception) {
                bRet &= check(false, "setRaiseAttr1 threw wrong type");
            }
            try {
                int i = xLBT.RaiseAttr2;
                bRet &= check(false, "getRaiseAttr2 did not throw");
            } catch (IllegalArgumentException) {
            } catch (System.Exception) {
                bRet &= check(false, "getRaiseAttr2 threw wrong type");
            }

            // Test instantiated polymorphic struct types:
            {
                TestPolyStruct poly = new TestPolyStruct(true);
                bRet &= check(
                    (bool)xLBT.transportPolyBoolean(poly).member,
                    "transportPolyBoolean");
                poly = new TestPolyStruct(12345L);
                xLBT.transportPolyHyper(ref poly);
                bRet &= check((long)poly.member == 12345L, "transportPolyUnsignedHyper");

                Any[] seq = { new Any(33), new Any("ABC") };
                poly = new TestPolyStruct(seq);
                TestPolyStruct poly2;
                xLBT.transportPolySequence(poly, out poly2);
                try {
                    Any[] ar = (Any[])poly2.member;
                    bRet &= check(
                        ar.Length == 2, "transportPolySequence, length");

                    int v0;
                    v0    = (int)ar[0].Value;
                    bRet &= check(v0 == 33, "transportPolySequence, element 0");

                    string v1 = (string)ar[1].Value;
                    bRet &= check(
                        v1.Equals("ABC"),
                        "transportPolySequence, element 1");
                } catch (InvalidCastException)
                {
                    bRet &= check(false, "transportPolySequence");
                }

                try {
                    //When the test object is a cli object then them member is null
                    //otherwise the bridge has provided a default value.
                    TestPolyStruct s = xLBT.getNullPolyLong();
                    if (s.member != null)
                    {
                        bRet &= check(((int)s.member) == 0, "getNullPolyLong");
                    }

                    s = xLBT.getNullPolyString();
                    if (s.member != null)
                    {
                        bRet &= check(((string)s.member).Length == 0,
                                      "getNullPolyString");
                    }
                    s = xLBT.getNullPolyType();
                    if (s.member != null)
                    {
                        bRet &= check(((Type)s.member) == typeof(void),
                                      "getNullPolyType");
                    }
                    s = xLBT.getNullPolyAny();
                    if (s.member != null)
                    {
                        Any nullAny = (Any)s.member;
                        //???
                        bRet &= check(nullAny.Type == typeof(void),
                                      "getNullPolyAny");
                    }
                    s = xLBT.getNullPolySequence();
                    if (s.member != null)
                    {
                        bRet &= check(((bool[])s.member).Length == 0,
                                      "getNullPolySequence");
                    }
                    s = xLBT.getNullPolyEnum();
                    if (s.member != null)
                    {
                        bRet &= check(((TestEnum)s.member) == TestEnum.TEST,
                                      "getNullPolyEnum");
                    }
                    s = xLBT.getNullPolyStruct();
                    if (s.member != null)
                    {
                        bRet &= check(((TestStruct)s.member).member == 0,
                                      "getNullPolyStruct");
                    }
                    s     = xLBT.getNullPolyInterface();
                    bRet &= check(s.member == null, "getNullPolyInterface");

                    s     = xLBT.getNullPolyBadEnum();
                    bRet &= check(((TestBadEnum)s.member) == TestBadEnum.M, "getNullPolyBadEnum");
                } catch (InvalidCastException)
                {
                    bRet &= check(false, "getNullPolyXXX, InvalidCastException");
                }
            }

            XBridgeTest2 xBT2 = xLBT as XBridgeTest2;

            if (xBT2 != null)
            {
                try {
                    xBT2.testConstructorsService(m_xContext);
                } catch (BadConstructorArguments) {
                    bRet = false;
                }
            }

            return(bRet);
        }
コード例 #4
0
        bool performTest(XBridgeTest xLBT)
        {
            check( xLBT != null, "### no test interface!" );
            bool bRet = true;
            if (xLBT == null)
            return false;

            // this data is never ever granted access to by calls other than equals(), assign()!
            TestDataElements aData = new TestDataElements(); // test against this data

            Object xI= new WeakBase();

            Any aAny = new Any( typeof(Object), xI);
            assign( (TestElement)aData,
            true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
            0x123456789abcdef0, 0xfedcba9876543210,
            17.0815f, 3.1415926359, TestEnum.LOLA,
            Constants.STRING_TEST_CONSTANT, xI,
            aAny);

            bRet = check( aData.Any.Value == xI, "### unexpected any!" ) && bRet;
            bRet = check( !(aData.Any.Value != xI), "### unexpected any!" ) && bRet;

            aData.Sequence = new TestElement[2];
            aData.Sequence[0] = new TestElement(
            aData.Bool, aData.Char, aData.Byte, aData.Short,
            aData.UShort, aData.Long, aData.ULong,
            aData.Hyper, aData.UHyper, aData.Float,
            aData.Double, aData.Enum, aData.String,
            aData.Interface, aData.Any); //(TestElement) aData;
            aData.Sequence[1] = new TestElement(); //is empty

            // aData complete

            // this is a manually copy of aData for first setting...
            TestDataElements aSetData = new TestDataElements();
            Any aAnySet= new Any(typeof(Object), xI);
            assign( (TestElement)aSetData,
            aData.Bool, aData.Char, aData.Byte, aData.Short, aData.UShort,
            aData.Long, aData.ULong, aData.Hyper, aData.UHyper, aData.Float, aData.Double,
            aData.Enum, aData.String, xI,
            aAnySet);

            aSetData.Sequence = new TestElement[2];
            aSetData.Sequence[0] = new TestElement(
            aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short,
            aSetData.UShort, aSetData.Long, aSetData.ULong,
            aSetData.Hyper, aSetData.UHyper, aSetData.Float,
            aSetData.Double, aSetData.Enum, aSetData.String,
            aSetData.Interface, aSetData.Any); //TestElement) aSetData;
            aSetData.Sequence[1] = new TestElement(); // empty struct

            xLBT.setValues(
            aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short, aSetData.UShort,
            aSetData.Long, aSetData.ULong, aSetData.Hyper, aSetData.UHyper, aSetData.Float, aSetData.Double,
            aSetData.Enum, aSetData.String, aSetData.Interface, aSetData.Any, aSetData.Sequence, aSetData );

            {
            TestDataElements aRet = new TestDataElements();
            TestDataElements aRet2 = new TestDataElements();
            xLBT.getValues(
            out aRet.Bool, out aRet.Char, out aRet.Byte, out aRet.Short, out aRet.UShort,
            out aRet.Long, out aRet.ULong, out aRet.Hyper, out aRet.UHyper,
            out aRet.Float, out aRet.Double, out aRet.Enum, out aRet.String,
            out aRet.Interface, out aRet.Any, out aRet.Sequence, out aRet2 );

            bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) , "getValues test") && bRet;

            // set last retrieved values
            TestDataElements aSV2ret = xLBT.setValues2(
            ref aRet.Bool, ref aRet.Char, ref aRet.Byte, ref aRet.Short, ref aRet.UShort,
            ref aRet.Long, ref aRet.ULong, ref aRet.Hyper, ref aRet.UHyper, ref aRet.Float,
            ref aRet.Double, ref aRet.Enum, ref aRet.String, ref aRet.Interface, ref aRet.Any,
            ref aRet.Sequence, ref aRet2 );

            // check inout sequence order
            // => inout sequence parameter was switched by test objects
            TestElement temp = aRet.Sequence[ 0 ];
            aRet.Sequence[ 0 ] = aRet.Sequence[ 1 ];
            aRet.Sequence[ 1 ] = temp;

            bRet = check(
            compareData( aData, aSV2ret ) && compareData( aData, aRet2 ),
            "getValues2 test") && bRet;
            }
            {
            TestDataElements aRet = new TestDataElements();
            TestDataElements aRet2 = new TestDataElements();
            TestDataElements aGVret = xLBT.getValues(
            out aRet.Bool, out aRet.Char, out aRet.Byte, out aRet.Short,
            out aRet.UShort, out aRet.Long, out aRet.ULong, out aRet.Hyper,
            out aRet.UHyper, out aRet.Float, out aRet.Double, out aRet.Enum,
            out aRet.String, out aRet.Interface, out aRet.Any, out aRet.Sequence,
            out aRet2 );

            bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) && compareData( aData, aGVret ), "getValues test" ) && bRet;

            // set last retrieved values
            xLBT.Bool = aRet.Bool;
            xLBT.Char = aRet.Char;
            xLBT.Byte = aRet.Byte;
            xLBT.Short = aRet.Short;
            xLBT.UShort = aRet.UShort;
            xLBT.Long = aRet.Long;
            xLBT.ULong = aRet.ULong;
            xLBT.Hyper = aRet.Hyper;
            xLBT.UHyper = aRet.UHyper;
            xLBT.Float = aRet.Float;
            xLBT.Double = aRet.Double;
            xLBT.Enum = aRet.Enum;
            xLBT.String = aRet.String;
            xLBT.Interface = aRet.Interface;
            xLBT.Any = aRet.Any;
            xLBT.Sequence = aRet.Sequence;
            xLBT.Struct = aRet2;
            }
            {
            TestDataElements aRet = new TestDataElements();
            TestDataElements aRet2 = new TestDataElements();
            aRet.Hyper = xLBT.Hyper;
            aRet.UHyper = xLBT.UHyper;
            aRet.Float = xLBT.Float;
            aRet.Double = xLBT.Double;
            aRet.Byte = xLBT.Byte;
            aRet.Char = xLBT.Char;
            aRet.Bool = xLBT.Bool;
            aRet.Short = xLBT.Short;
            aRet.UShort = xLBT.UShort;
            aRet.Long = xLBT.Long;
            aRet.ULong = xLBT.ULong;
            aRet.Enum = xLBT.Enum;
            aRet.String = xLBT.String;
            aRet.Interface = xLBT.Interface;
            aRet.Any = xLBT.Any;
            aRet.Sequence = xLBT.Sequence;
            aRet2 = xLBT.Struct;

            bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) , "struct comparison test") && bRet;

            bRet = check(performSequenceTest(xLBT), "sequence test") && bRet;

            // any test
            bRet = check( performAnyTest( xLBT , aData ) , "any test" ) && bRet;

            // sequence of call test
            bRet = check( performSequenceOfCallTest( xLBT ) , "sequence of call test" ) && bRet;

            // recursive call test
            bRet = check( performRecursiveCallTest( xLBT ) , "recursive test" ) && bRet;

            bRet = (compareData( aData, aRet ) && compareData( aData, aRet2 )) && bRet ;

            // check setting of null reference
            xLBT.Interface = null;
            aRet.Interface = xLBT.Interface;
            bRet = (aRet.Interface == null) && bRet;

            }
            // Test extended attributes that raise exceptions:
            try {
            int i = xLBT.RaiseAttr1;
            bRet &= check(false, "getRaiseAttr1 did not throw");
            } catch (RuntimeException )
            {
            }
            catch (System.Exception) {
            bRet &= check(false, "getRaiseAttr1 threw wrong type");
            }
            try {
            xLBT.RaiseAttr1 = 0;
            bRet &= check(false, "setRaiseAttr1 did not throw");
            } catch (IllegalArgumentException) {
            } catch (System.Exception) {
            bRet &= check(false, "setRaiseAttr1 threw wrong type");
            }
            try {
            int i = xLBT.RaiseAttr2;
            bRet &= check(false, "getRaiseAttr2 did not throw");
            } catch (IllegalArgumentException ) {
            } catch (System.Exception) {
            bRet &= check(false, "getRaiseAttr2 threw wrong type");
            }

               // Test instantiated polymorphic struct types:
            {
            TestPolyStruct poly = new TestPolyStruct(true);
            bRet &= check(
            (bool) xLBT.transportPolyBoolean(poly).member,
            "transportPolyBoolean");
            poly = new TestPolyStruct(12345L);
            xLBT.transportPolyHyper(ref poly);
            bRet &= check((long)poly.member == 12345L, "transportPolyUnsignedHyper");

            Any[] seq = {  new Any(33), new Any("ABC")};
            poly = new TestPolyStruct(seq);
            TestPolyStruct poly2;
            xLBT.transportPolySequence(poly, out poly2);
            try {
            Any[] ar = (Any[]) poly2.member;
            bRet &= check(
            ar.Length == 2, "transportPolySequence, length");

            int v0;
            v0 = (int) ar[0].Value;
            bRet &= check(v0 == 33, "transportPolySequence, element 0");

            string v1 = (string) ar[1].Value;
            bRet &= check(
            v1.Equals("ABC"),
            "transportPolySequence, element 1");
            } catch (InvalidCastException )
            {
            bRet &= check(false, "transportPolySequence");
            }

            try {
            //When the test object is a cli object then them member is null
            //otherwise the bridge has provided a default value.
            TestPolyStruct s =  xLBT.getNullPolyLong();
            if (s.member != null)
                bRet &= check(((int) s.member) == 0, "getNullPolyLong");

            s = xLBT.getNullPolyString();
            if (s.member != null)
                bRet &= check(((string) s.member).Length == 0,
                              "getNullPolyString");
            s = xLBT.getNullPolyType();
            if (s.member != null)
                bRet &= check(((Type) s.member) == typeof(void),
                              "getNullPolyType");
            s = xLBT.getNullPolyAny();
            if (s.member != null)
            {
                Any nullAny = (Any) s.member;
                //???
                bRet &= check(nullAny.Type == typeof(void),
                    "getNullPolyAny");
            }
            s = xLBT.getNullPolySequence();
            if (s.member != null)
                bRet &= check(((bool[]) s.member).Length == 0,
                              "getNullPolySequence");
            s = xLBT.getNullPolyEnum();
            if (s.member != null)
                bRet &= check(((TestEnum) s.member) == TestEnum.TEST,
                              "getNullPolyEnum");
            s = xLBT.getNullPolyStruct();
            if (s.member != null)
                bRet &= check(((TestStruct) s.member).member == 0,
                              "getNullPolyStruct");
            s = xLBT.getNullPolyInterface();
                bRet &= check(s.member == null, "getNullPolyInterface");

            s = xLBT.getNullPolyBadEnum();
            bRet &= check(((TestBadEnum)s.member) == TestBadEnum.M, "getNullPolyBadEnum");

            } catch(InvalidCastException)
            {
            bRet &= check(false, "getNullPolyXXX, InvalidCastException");
            }

            }

            XBridgeTest2 xBT2 = xLBT as XBridgeTest2;
            if (xBT2 != null) {
            try {
            xBT2.testConstructorsService(m_xContext);
            } catch (BadConstructorArguments) {
            bRet = false;
            }
            }

            return bRet;
        }