示例#1
0
    private static void TestMethod_CLPStr_In()
    {
        TestFramework.BeginScenario("Cdecl,LPStr,In");

        try
        {
            StringBuilder sb   = GetInvalidString();
            string        str  = sb.ToString();
            string        rstr = CLPStr_In(str);

            //Check the return value and the parameter.
            StringBuilder sbTemp = GetInvalidString();
            if (!Compare(str, rstr))
            {
                Fails++;
                TestFramework.LogError("001", "TestMethod_CLPStr_In");
            }
            if (!sb.Equals(sbTemp))
            {
                Fails++;
                TestFramework.LogError("002", "TestMethod_CLPStr_In");
            }
        }
        catch (Exception e)
        {
            Fails++;
            TestFramework.LogError("e01", "TestMethod_CLPStr_In:Unexpected Exception Occured:" + e.ToString());
        }
    }
示例#2
0
    public bool Test3()
    {
        string id     = "Scenario3";
        bool   result = true;

        TestFramework.BeginScenario("Scenario 3: Setting capacity to > length < capacity");
        try
        {
            StringBuilder sb = new StringBuilder("Test", 10);
            sb.Capacity = 8;
            string output   = sb.ToString();
            int    capacity = sb.Capacity;
            if (output != "Test")
            {
                result = false;
                TestFramework.LogError("007", "Error in " + id + ", unexpected string. Actual string " + output + ", Expected: Test");
            }
            if (capacity != 8)
            {
                result = false;
                TestFramework.LogError("008", "Error in " + id + ", unexpected legnth. Actual capacity" + capacity + ", Expected: 8");
            }
        }
        catch (Exception exc)
        {
            result = false;
            TestFramework.LogError("009", "Unexpected exception in " + id + ", exception: " + exc.ToString());
        }
        return(result);
    }
示例#3
0
    public bool Test5()
    {
        string id     = "Scenario5";
        bool   result = true;

        TestFramework.BeginScenario("Scenario 5: Setting capacity to something very large");
        try
        {
            StringBuilder sb = new StringBuilder("Test");
            sb.Capacity = 10004;
            string output   = sb.ToString();
            int    capacity = sb.Capacity;
            if (output != "Test")
            {
                result = false;
                TestFramework.LogError("013", "Error in " + id + ", unexpected string. Actual string " + output + ", Expected: Test");
            }
            if (capacity != 10004)
            {
                result = false;
                TestFramework.LogError("014", "Error in " + id + ", unexpected legnth. Actual capacity " + capacity + ", Expected: 10004");
            }
        }
        catch (Exception exc)
        {
            result = false;
            TestFramework.LogError("015", "Unexpected exception in " + id + ", exception: " + exc.ToString());
        }
        return(result);
    }
示例#4
0
    public bool Test(CultureInfo culture, string str1, string str2, int expected, CompareOptions options, string id)
    {
		if (!Utilities.IsVistaOrLater || !culture.Name.Equals("tr-TR")) //Due Windows 7 bug 130925
			expected = GlobLocHelper.OSCompare(culture, str1, 0, str1.Length, str2, 0, str2.Length, options);

        CompareInfo ci = culture.CompareInfo;
        bool result = true;
        if (str1 == null || str2 == null || (str1.Length < 100 && str2.Length < 100))
            TestFramework.BeginScenario(id + ": Comparing " + ((str1 == null) ? "null" : str1) + " / " + ((str2 == null) ? "null" : str2) + "; options: " + options + "; culture: " + ci.Name);
        else
            TestFramework.BeginScenario(id + ": Comparing LongStr (" + str1.Length + ") / LongStr(" + str2.Length + "); options: " + options + "; culture: " + ci.Name);
        try
        {
            int i = ci.Compare(str1, str2, options);
            i = (i == 0) ? 0 : i / Math.Abs(i); // We don't care what i is, just whether it's =,>, or < 0
            if (i != expected)
            {
                result = false;
                TestFramework.LogError("001", "Error in " + id + ", unexpected comparison result. Actual: " + i + ", Expected: " + expected);
            }
            i = ci.Compare(str2, str1, options);
            i = (i == 0) ? 0 : i / Math.Abs(i); // We don't care what i is, just whether it's =,>, or < 0
            if (i != (0 - expected))
            {
                result = false;
                TestFramework.LogError("002", "Error in " + id + ", unexpected comparison result. Actual: " + i + ", Expected: " + (0 - expected));
            }
        }
        catch (Exception exc)
        {
            result = false;
            TestFramework.LogError("003", "Unexpected exception in " + id + ", excpetion: " + exc.ToString());
        }
        return result;
    }
    private static bool TestMethod_DelegatePInvokeStdcall()
    {
        TestFramework.BeginScenario("DelegatePinvoke,Cdecl");

        bool bresult = true;

        try
        {
            char[] p = new char[LEN];
            for (int i = 0; i < LEN; i++)
            {
                p[i] = (char)('a' + i);
            }

            DelegatePInvokeStdcall caller = DelegatePinvoke_Stdcall();
            if (!caller(ref p))
            {
                bresult = false;
                TestFramework.LogError("009", "TestMethod_DelegatePInvokeStdcall:The return value is wrong");
            }
            if ('z' != p[0])
            {
                bresult = false;
                TestFramework.LogError("010", "TestMethod_DelegatePInvokeStdcall:The value hasnt changed");
            }
        }
        catch (Exception e)
        {
            bresult = false;
            TestFramework.LogError("e06", "Unexpected Exception" + e.ToString());
        }
        return(bresult);
    }
示例#6
0
    private static bool TestMethod_PInvke_Stdcall()
    {
        TestFramework.BeginScenario("PInvoke,Stdcall");

        bool breturn = true;

        try
        {
            int i = 10;
            if (!MarshalRefInt_Stdcall(ref i))
            {
                breturn = false;
                TestFramework.LogError("003", "MarshalRefInt_Stdcall:The Input(From Managed To Native) is wrong");
            }

            if (iNative != i)
            {
                breturn = false;
                TestFramework.LogError("004", "MarshalRefInt_Stdcall:The value(i) hasnt changed by Native");
            }
        }
        catch (Exception e)
        {
            breturn = false;
            TestFramework.LogError("010", "UnExpected Exception" + e.ToString());
        }
        return(breturn);
    }
示例#7
0
    public bool Test(CultureInfo culture, string str1, string str2, bool expected, CompareOptions options, string id)
    {
        if (!id.Contains("s") || !Utilities.IsVistaOrLater)         //Due Windows 7 bug 130925
        {
            expected = GlobLocHelper.OSIsPrefix(culture, str1, str2, options);
        }
        CompareInfo ci     = culture.CompareInfo;
        bool        result = true;

        if (str1 == null || str2 == null || (str1.Length < 100 && str2.Length < 100))
        {
            TestFramework.BeginScenario(id + ": Comparing " + ((str1 == null) ? "null" : str1) + " / " + ((str2 == null) ? "null" : str2) + "; options: " + options + "; culture: " + ci.Name);
        }
        else
        {
            TestFramework.BeginScenario(id + ": Comparing LongStr (" + str1.Length + ") / LongStr(" + str2.Length + "); options: " + options + "; culture: " + ci.Name);
        }
        try
        {
            bool i = ci.IsPrefix(str1, str2, options);
            if (i != expected)
            {
                result = false;
                TestFramework.LogError("001z", "Error in " + id + ", unexpected comparison result. Actual: " + i + ", Expected: " + expected);
            }
        }
        catch (Exception exc)
        {
            result = false;
            TestFramework.LogError("003z", "Unexpected exception in " + id + ", excpetion: " + exc.ToString());
        }
        return(result);
    }
示例#8
0
    private static void TestMethod_SLPStr_DelegatePInvoke()
    {
        TestFramework.BeginScenario("StdCall,LPStr,DelegatePInvoke");
        try
        {
            DelegatePInvoke_StdCall caller = SLPStr_DelegatePInvoke();
            StringBuilder           sb     = GetInvalidString();
            string rstr = caller(ref sb);

            //Check the return value
            string sTemp = (GetInvalidString()).ToString();
            if (!Compare(sTemp, rstr))
            {
                Fails++;
                TestFramework.LogError("027", "TestMethod_SLPStr_DelegatePInvoke:The Return value is wrong.");
            }
            //Check the Parameter
            if (!Compare(sTemp, sb.ToString()))
            {
                Fails++;
                TestFramework.LogError("028", "TestMethod_SLPStr_DelegatePInvoke:The Parameter value is wrong.");
            }
        }
        catch (Exception e)
        {
            Fails++;
            TestFramework.LogError("e14", "TestMethod_SLPStr_DelegatePInvoke:Unexpected Exception Occured:" + e.ToString());
        }
    }
示例#9
0
    public bool Test5()
    {
        string id     = "Scenario5";
        bool   result = true;

        TestFramework.BeginScenario("Scenario 5: Setting Length to something very large");
        try
        {
            StringBuilder sb = new StringBuilder("Test");
            sb.Length = 10004;
            string output = sb.ToString();
            int    length = sb.Length;
            if (output != ("Test" + new string('\0', 10000)))
            {
                result = false;
                TestFramework.LogError("013", "Error in " + id + ", unexpected string. Actual string " + output + ", Expected: Test");
            }
            if (length != 10004)
            {
                result = false;
                TestFramework.LogError("014", "Error in " + id + ", unexpected legnth. Actual length " + length + ", Expected: 10004");
            }
        }
        catch (Exception exc)
        {
            result = false;
            TestFramework.LogError("015", "Unexpected exception in " + id + ", excpetion: " + exc.ToString());
        }
        return(result);
    }
示例#10
0
    private static void TestMethod_SLPStr_OutRef()
    {
        TestFramework.BeginScenario("StdCall,LPStr,OutRef");

        try
        {
            StringBuilder sb   = new StringBuilder(10);
            string        rstr = SLPStr_OutByRef(out sb);

            //Check the return value
            string sNative = "AAAA";
            if (!sNative.Equals(rstr))
            {
                Fails++;
                TestFramework.LogError("023", "TestMethod_CLPStr_OutRef:The Return value is wrong.");
            }
            //Check the Parameter
            if (!sNative.Equals(sb.ToString()))
            {
                Fails++;
                Console.WriteLine(sb.ToString());
                TestFramework.LogError("024", "TestMethod_CLPStr_OutRef:The Parameter value is wrong.");
            }
        }
        catch (Exception e)
        {
            Fails++;
            TestFramework.LogError("e12", "TestMethod_SLPStr_OutRef:Unexpected Exception Occured:" + e.ToString());
        }
    }
示例#11
0
    private static void TestMethod_SLPStr_InOutRef()
    {
        TestFramework.BeginScenario("StdCall,LPStr,InOutRef");

        try
        {
            StringBuilder sb   = GetInvalidString();
            string        rstr = SLPStr_InOutByRef(ref sb);

            //Check the return value
            string sTemp = (GetInvalidString()).ToString();
            if (!Compare(sTemp, rstr))
            {
                Fails++;
                TestFramework.LogError("025", "TestMethod_SLPStr_InOutRef:The Return value is wrong.");
            }
            //Check the Parameter
            if (!Compare(sTemp, sb.ToString()))
            {
                Fails++;
                TestFramework.LogError("026", "TestMethod_SLPStr_InOutRef:The Parameter value is wrong.");
            }
        }
        catch (Exception e)
        {
            Fails++;
            TestFramework.LogError("e13", "TestMethod_SLPStr_InOutRef:Unexpected Exception Occured:" + e.ToString());
        }
    }
示例#12
0
    private static void TestMethod_SLPStr_Out()
    {
        TestFramework.BeginScenario("StdCall,LPStr,Out");

        try
        {
            StringBuilder sb   = new StringBuilder();
            string        rstr = SLPStr_Out(sb);

            string NativeString = "AAAA";
            //check the return value
            if (!NativeString.Equals(rstr))
            {
                Fails++;
                TestFramework.LogError("017", "TestMethod_SLPStr_Out:The Return value is wrong.");
            }
            //Check the Parameter
            if (!NativeString.Equals(sb.ToString()))
            {
                Fails++;
                TestFramework.LogError("018", "TestMethod_SLPStr_Out:The Parameter value is wrong.");
            }
        }
        catch (Exception e)
        {
            Fails++;
            TestFramework.LogError("e09", "TestMethod_SLPStr_Out:Unexpected Exception Occured:" + e.ToString());
        }
    }
示例#13
0
    //Stdcall

    private static void TestMethod_SLPStr_In()
    {
        TestFramework.BeginScenario("StdCall,LPStr,In");
        try
        {
            StringBuilder sb   = GetInvalidString();
            string        rstr = SLPStr_In(sb.ToString());
            //Check the return value and the parameter.
            StringBuilder sbTemp = GetInvalidString();
            if (!Compare(sbTemp.ToString(), rstr))
            {
                Fails++;
                TestFramework.LogError("015", "TestMethod_SLPStr_In:The Return value is wrong.");
            }
            if (!sb.Equals(sbTemp))
            {
                Fails++;
                TestFramework.LogError("016", "TestMethod_SLPStr_In:The Parameter value is wrong.");
            }
        }
        catch (Exception e)
        {
            Fails++;
            TestFramework.LogError("e08", "TestMethod_SLPStr_In:Unexpected Exception Occured:" + e.ToString());
        }
    }
示例#14
0
    private static void TestMethod_CLPStr_InRef()
    {
        TestFramework.BeginScenario("Cdecl,LPStr,InRef");
        try
        {
            StringBuilder sb   = GetInvalidString();
            string        rstr = CLPStr_InByRef(ref sb);

            //Check the return value
            string sTemp = (GetInvalidString()).ToString();
            if (!Compare(sTemp, rstr))
            {
                Fails++;
                TestFramework.LogError("007", "TestMethod_CLPStr_InRef:The Return value is wrong.");
            }
            //Check the Parameter
            if (!sTemp.Equals(sb.ToString()))
            {
                Fails++;
                TestFramework.LogError("008", "TestMethod_CLPStr_InRef:The Parameter value is wrong.");
            }
        }
        catch (Exception e)
        {
            Fails++;
            TestFramework.LogError("e04", "TestMethod_CLPStr_InRef:Unexpected Exception Occured:" + e.ToString());
        }
    }
示例#15
0
        public static bool NestedLayoutClass()
        {
            string       s      = "before";
            bool         retval = true;
            SeqClass     p      = new SeqClass(0, false, s);
            NestedLayout target = new NestedLayout
            {
                value = p
            };

            TestFramework.BeginScenario("Test #4 Nested sequential layout class in a structure.");

            try
            {
                retval = SimpleNestedLayoutClassByValue(target);

                if (retval == false)
                {
                    TestFramework.LogError("01", "PInvokeTests->NestedLayoutClass : Unexpected error occured on unmanaged side");
                    return(false);
                }
            }
            catch (Exception e)
            {
                TestFramework.LogError("04", "Unexpected exception: " + e.ToString());
                retval = false;
            }

            return(retval);
        }
示例#16
0
    public bool Test1()
    {
        string id     = "Scenario1";
        bool   result = true;

        TestFramework.BeginScenario("Scenario 1: Setting Length to 0");
        try
        {
            StringBuilder sb = new StringBuilder("Test");
            sb.Length = 0;
            string output = sb.ToString();
            int    length = sb.Length;
            if (output != string.Empty)
            {
                result = false;
                TestFramework.LogError("001", "Error in " + id + ", unexpected string. Actual string " + output + ", Expected: " + string.Empty);
            }
            if (length != 0)
            {
                result = false;
                TestFramework.LogError("002", "Error in " + id + ", unexpected legnth. Actual length " + length + ", Expected: 0");
            }
        }
        catch (Exception exc)
        {
            result = false;
            TestFramework.LogError("003", "Unexpected exception in " + id + ", excpetion: " + exc.ToString());
        }
        return(result);
    }
示例#17
0
    private static bool TestMethod_DelegatePInvokeStdcall()
    {
        TestFramework.BeginScenario("Delegate Pinvoke stdcall");

        bool breturn = true;

        try
        {
            DelegatePInvokeStdcall caller = MarshalRefInt_DelegatePInvoke_StdCall();
            int i = 10;
            if (!caller(ref i))
            {
                breturn = false;
                TestFramework.LogError("009", "TestMethod_DelegatePInvokeStdcall:The return value is wrong(Managed Side)");
            }

            if (iNative != i)
            {
                breturn = false;
                TestFramework.LogError("010", "TestMethod_DelegatePInvokeStdcall:The value(i) hasnt changed by Native");
            }
        }
        catch (Exception e)
        {
            breturn = false;
            TestFramework.LogError("010", "UnExpected Exception" + e.ToString());
        }
        return(breturn);
    }
示例#18
0
    public bool Test2()
    {
        string id     = "Scenario2";
        bool   result = true;

        TestFramework.BeginScenario("Scenario 2: Setting Length to current length");
        try
        {
            StringBuilder sb = new StringBuilder("Test");
            sb.Length = 4;
            string output = sb.ToString();
            int    length = sb.Length;
            if (output != "Test")
            {
                result = false;
                TestFramework.LogError("004", "Error in " + id + ", unexpected string. Actual string " + output + ", Expected: Test");
            }
            if (length != 4)
            {
                result = false;
                TestFramework.LogError("005", "Error in " + id + ", unexpected legnth. Actual length " + length + ", Expected: 4");
            }
        }
        catch (Exception exc)
        {
            result = false;
            TestFramework.LogError("006", "Unexpected exception in " + id + ", excpetion: " + exc.ToString());
        }
        return(result);
    }
示例#19
0
    public bool PosTest1()
    {
        bool retVal = true;

        TestFramework.BeginScenario("PosTest1: RuntimeHelpers.GetHashCode() on two non-reference-equals objects returns non-equal codes");
        Object a, b;

        try
        {
            a = new ClassWithEquivalence(10, 20);
            b = new ClassWithEquivalence(10, 20);

            if (!(a.Equals(b) && (a.GetHashCode() == b.GetHashCode())) ||
                (Object.ReferenceEquals(a, b)))
            {
                // Log: setup failed
                return(false);
            }

            if (RuntimeHelpers.GetHashCode(a) == RuntimeHelpers.GetHashCode(b))
            {
                // Log: RTH.GHC should have returned different hash codes since the
                //  objects are not reference-equals.
                TestFramework.LogError("001", "a and b are not reference equal, and yet RuntimeHelpers.GetHashCode returned same value for each");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestFramework.LogError("002", "Unexpected exception: " + e);
            retVal = false;
        }
        return(retVal);
    }
示例#20
0
    // ATTENTION!!! ATTENTION!!! ATTENTION!!!
    //
    // If you encounter issues with object lifetime, please see more comments in WeakReferenceCtor2.cs

    public bool PosTest1()
    {
        bool retVal = true;

        TestFramework.BeginScenario("Test IsAlive with short WeakReference");

        try
        {
            WeakReference extWR = new WeakReference(WRHelper.CreateAnObject("Test"), false);

            if (!extWR.IsAlive)
            {
                TestFramework.LogError("001", "WeakReference IsAlive not as expected. Expected : True; Actual: " + extWR.IsAlive);
                retVal = false;
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();

            //Dev10 Bug #413556: WeakReference object incorrectly kept alive. Enable after the test is fixed.
            //
            //if (extWR.IsAlive)
            //{
            //    TestFramework.LogError("002", "WeakReference IsAlive not as expected. Expected : False; Actual: " + extWR.IsAlive);
            //    retVal = false;
            //}
        }
        catch (Exception e)
        {
            TestFramework.LogError("003", "Unexpected exception occured: " + e);
            retVal = false;
        }

        return(retVal);
    }
示例#21
0
    public bool TestOrd(CultureInfo culture, string str1, string str2, bool expected, CompareOptions options, string id)
    {
        CompareInfo ci     = culture.CompareInfo;
        bool        result = true;

        if (str1 == null || str2 == null || (str1.Length < 100 && str2.Length < 100))
        {
            TestFramework.BeginScenario(id + ": Comparing " + ((str1 == null) ? "null" : str1) + " / " + ((str2 == null) ? "null" : str2) + "; options: " + options + "; culture: " + ci.Name);
        }
        else
        {
            TestFramework.BeginScenario(id + ": Comparing LongStr (" + str1.Length + ") / LongStr(" + str2.Length + "); options: " + options + "; culture: " + ci.Name);
        }
        try
        {
            bool i = ci.IsPrefix(str1, str2, options);
            if (i != expected)
            {
                result = false;
                TestFramework.LogError("001", "Error in " + id + ", unexpected comparison result. Actual: " + i + ", Expected: " + expected);
            }
        }
        catch (Exception exc)
        {
            result = false;
            TestFramework.LogError("003", "Unexpected exception in " + id + ", excpetion: " + exc.ToString());
        }
        return(result);
    }
示例#22
0
    public bool PosTest2()
    {
        bool retVal = true;

        TestFramework.BeginScenario("Test IsAlive with long WeakReference");

        try
        {
            WeakReference extWR = new WeakReference(WRHelper.CreateAnObject("Test"), true);

            if (!extWR.IsAlive)
            {
                TestFramework.LogError("004", "WeakReference IsAlive not as expected. Expected : True; Actual: " + extWR.IsAlive);
                retVal = false;
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();

            if (!extWR.IsAlive)
            {
                TestFramework.LogError("005", "WeakReference IsAlive not as expected. Expected : True; Actual: " + extWR.IsAlive);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestFramework.LogError("006", "Unexpected exception occured: " + e);
            retVal = false;
        }

        return(retVal);
    }
示例#23
0
 public bool TestOrd(CultureInfo culture, string str1, string str2, int expected, CompareOptions options, string id)
 {
     CompareInfo ci = culture.CompareInfo;
     bool result = true;
     if (str1 == null || str2 == null || (str1.Length < 100 && str2.Length < 100))
         TestFramework.BeginScenario(id + ": Comparing " + ((str1 == null) ? "null" : str1) + " / " + ((str2 == null) ? "null" : str2) + "; options: " + options + "; culture: " + ci.Name);
     else
         TestFramework.BeginScenario(id + ": Comparing LongStr (" + str1.Length + ") / LongStr(" + str2.Length + "); options: " + options + "; culture: " + ci.Name);
     try
     {
         int i = ci.Compare(str1, str2, options);
         i = (i == 0) ? 0 : i / Math.Abs(i); // We don't care what i is, just whether it's =,>, or < 0
         if (i != expected)
         {
             result = false;
             TestFramework.LogError("001z", "Error in " + id + ", unexpected comparison result. Actual: " + i + ", Expected: " + expected);
         }
         i = ci.Compare(str2, str1, options);
         i = (i == 0) ? 0 : i / Math.Abs(i); // We don't care what i is, just whether it's =,>, or < 0
         if (i != (0 - expected))
         {
             result = false;
             TestFramework.LogError("002z", "Error in " + id + ", unexpected comparison result. Actual: " + i + ", Expected: " + (0 - expected));
         }
     }
     catch (Exception exc)
     {
         result = false;
         TestFramework.LogError("003z", "Unexpected exception in " + id + ", excpetion: " + exc.ToString());
     }
     return result;
 }
示例#24
0
        public static bool SequentialClass()
        {
            string   s      = "before";
            bool     retval = true;
            SeqClass p      = new SeqClass(0, false, s);

            TestFramework.BeginScenario("Test #1 Pass a sequential layout class.");

            try
            {
                retval = SimpleSeqLayoutClassByRef(p);

                if (retval == false)
                {
                    TestFramework.LogError("01", "PInvokeTests->SequentialClass : Unexpected error occured on unmanaged side");
                    return(false);
                }
            }
            catch (Exception e)
            {
                TestFramework.LogError("04", "Unexpected exception: " + e.ToString());
                retval = false;
            }

            return(retval);
        }
示例#25
0
    //TestMethod2,Pinvoke,StdCall

    static bool TestMethod_PInvoke_StdCall()
    {
        TestFramework.BeginScenario("Pinvoke,StdCall");

        bool bresult = true;

        try
        {
            char[] pCharArray = new char[LEN];
            for (int i = 0; i < LEN; i++)
            {
                pCharArray[i] = (char)('a' + i);
            }
            if (!MarshalRefCharArray_Stdcall(ref pCharArray))
            {
                bresult = false;
                TestFramework.LogError("003", "MarshalRefCharArray_Stdcall:The Input(From Managed To Native) is wrong");
            }

            if ('z' != pCharArray[0])
            {
                bresult = false;
                TestFramework.LogError("004", "MarshalRefCharArray_Stdcall:The value hasnt changed");
            }
        }
        catch (Exception e)
        {
            bresult = false;
            TestFramework.LogError("e02", "Unexpected Exception" + e.ToString());
        }
        return(bresult);
    }
示例#26
0
        public static bool ExplicitClass()
        {
            ExpClass p;
            bool     retval = false;

            TestFramework.BeginScenario("Test #2 Pass an explicit layout class.");

            try
            {
                p      = new ExpClass(DialogResult.None, 10);
                retval = SimpleExpLayoutClassByRef(p);

                if (retval == false)
                {
                    TestFramework.LogError("01", "PInvokeTests->ExplicitClass : Unexpected error occured on unmanaged side");
                    return(false);
                }
            }
            catch (Exception e)
            {
                TestFramework.LogError("03", "Unexpected exception: " + e.ToString());
                retval = false;
            }

            return(retval);
        }
示例#27
0
    public bool Test4()
    {
        string id     = "Scenario4";
        bool   result = true;

        TestFramework.BeginScenario("Scenario 4: Setting capacity to > capacity");
        try
        {
            StringBuilder sb = new StringBuilder("Test", 10);
            sb.Capacity = 12;
            string output = sb.ToString();
            int    cap    = sb.Capacity;
            if (output != "Test")
            {
                result = false;
                TestFramework.LogError("010", "Error in " + id + ", unexpected string. Actual string " + output + ", Expected: Test");
            }
            if (cap != 12)
            {
                result = false;
                TestFramework.LogError("011", "Error in " + id + ", unexpected legnth. Actual capacity " + cap + ", Expected: 12");
            }
        }
        catch (Exception exc)
        {
            result = false;
            TestFramework.LogError("012", "Unexpected exception in " + id + ", exception: " + exc.ToString());
        }
        return(result);
    }
示例#28
0
        public static bool BlittableClass()
        {
            bool      retval = true;
            Blittable p      = new Blittable(10);

            TestFramework.BeginScenario("Test #3 Pass a blittable sequential layout class.");

            try
            {
                retval = SimpleBlittableSeqLayoutClassByRef(p);

                if (retval == false)
                {
                    TestFramework.LogError("01", "PInvokeTests->Blittable : Unexpected error occured on unmanaged side");
                    return(false);
                }
            }
            catch (Exception e)
            {
                TestFramework.LogError("04", "Unexpected exception: " + e.ToString());
                retval = false;
            }

            return(retval);
        }
示例#29
0
    public bool Test6()
    {
        string id     = "Scenario6";
        bool   result = true;

        TestFramework.BeginScenario("Scenario 6: Setting Capacity to > max capacity");
        try
        {
            StringBuilder sb = new StringBuilder(4, 10);
            sb.Append("Test");

            sb.Capacity = 12;
            string output = sb.ToString();
            result = false;
            TestFramework.LogError("016", "Error in " + id + ", Expected exception not thrown. No exception. Actual string " + output + ", Expected: " + typeof(ArgumentOutOfRangeException).ToString());
        }
        catch (Exception exc)
        {
            if (exc.GetType() != typeof(ArgumentOutOfRangeException))
            {
                result = false;
                TestFramework.LogError("017", "Unexpected exception in " + id + ", expected type: " + typeof(ArgumentOutOfRangeException).ToString() + ", Actual exception: " + exc.ToString());
            }
        }
        return(result);
    }
    public bool Test2()
    {
        string id     = "Scenario2";
        bool   result = true;

        TestFramework.BeginScenario("Scenario 2: Setting capacity to current capacity");
        try
        {
            StringBuilder sb = new StringBuilder("Test", 4);
            sb.Capacity = 4;
            string output = sb.ToString();
            int    cap    = sb.Capacity;
            if (output != "Test")
            {
                result = false;
                TestFramework.LogError("004", "Error in " + id + ", unexpected string. Actual string " + output + ", Expected: Test");
            }
            if (cap != 4)
            {
                result = false;
                TestFramework.LogError("005", "Error in " + id + ", unexpected capacity. Actual capacity " + cap + ", Expected: 4");
            }
        }
        catch (Exception exc)
        {
            result = false;
            TestFramework.LogError("006", "Unexpected exception in " + id + ", exception: " + exc.ToString());
        }
        return(result);
    }