Esempio n. 1
0
 public void DanglingPointerDerefSimple(TestClassMethod initializationMethod,
                                        InferError expectedError)
 {
     // We provide the "false" argument because it is required to initialize the object.
     TestRunManager.Run(InitVars(state: TestClassState.Initialized) +
                        CallTestClassMethod(initializationMethod,
                                            true,
                                            args: new string[] { false.ToString().ToLower() }) +
                        DerefObject(VarName.InstanceObjectField),
                        GetString(expectedError));
 }
Esempio n. 2
0
 public void NullExceptionStaticFieldDeref(TestClassMethod initializationMethod,
                                           bool initializeToNull,
                                           InferError expectedError)
 {
     TestRunManager.Run(CallTestClassMethod(initializationMethod,
                                            true,
                                            args: new string[]
     {
         initializeToNull.ToString().ToLower()
     }) +
                        DerefObject(VarName.StaticObjectField),
                        GetString(expectedError));
 }
Esempio n. 3
0
        /// <summary>
        /// Method for generating a string representation of a call to a method of TestClass.
        /// </summary>
        /// <param name="method">The method to be called.</param>
        /// <param name="withLineEnding">True if that call should have a semicolon ending.</param>
        /// <param name="args">The list of arguments of the method.</param>
        /// <returns>A string representation of the method call.</returns>
        public static string CallTestClassMethod(TestClassMethod method,
                                                 bool withLineEnding,
                                                 string[] args = null)
        {
            switch (method)
            {
            case TestClassMethod.ReturnInitializedMemoryStream:
                if (args != null)
                {
                    throw new ArgumentException(
                              "ReturnInitializedMemoryStream requires no argument.");
                }
                return(GetMethodCall(true));

            case TestClassMethod.ReturnInitializedStreamReader:
                if (args != null)
                {
                    throw new ArgumentException(
                              "ReturnInitializedStreamReader requires no argument.");
                }
                return(GetMethodCall(true));

            case TestClassMethod.CloseStream:
                if (args == null || args.Length != 1)
                {
                    throw new ArgumentException(
                              "CloseStream requires one argument.");
                }
                return(GetMethodCall(true));

            case TestClassMethod.InitializeStreamReaderObjectField:
                if (args != null)
                {
                    throw new ArgumentException(
                              "InitializeStreamReaderObjectField requires no argument.");
                }
                return(GetMethodCall(false));

            case TestClassMethod.None:
                return(string.Empty);

            case TestClassMethod.ExpectNonNullParam:
                if (args == null || args.Length != 1)
                {
                    throw new ArgumentException(
                              "ExpectNonNullParam requires 1 argument.");
                }
                return(GetMethodCall(true));

            case TestClassMethod.ReturnNullOnFalse:
                if (args == null || args.Length != 1)
                {
                    throw new ArgumentException(
                              "ReturnNullOnFalse requires 1 arguments.");
                }
                return(GetMethodCall(true));

            case TestClassMethod.IncrementRefParameter:
                if (args == null || args.Length != 1)
                {
                    throw new ArgumentException(
                              "IncrementRefParameter requires 1 argument.");
                }
                return(GetMethodCall(true));

            case TestClassMethod.IncrementStructFieldViaAddress:
                if (args == null || args.Length != 1)
                {
                    throw new ArgumentException(
                              "IncrementStructFieldViaAddress requires 1 argument.");
                }
                return(GetMethodCall(true));

            case TestClassMethod.InitializeStaticObjectField:
                if (args == null || args.Length != 1)
                {
                    throw new ArgumentException(
                              "InitializeStaticObjectField requires 1 argument.");
                }
                return(GetMethodCall(true));

            case TestClassMethod.InitializeStaticObjectFieldViaReference:
                if (args == null || args.Length != 1)
                {
                    throw new ArgumentException(
                              "InitializeStaticObjectFieldViaReference requires 1 argument.");
                }
                return(GetMethodCall(true));

            case TestClassMethod.InitializeInstanceObjectField:
                if (args == null || args.Length != 1)
                {
                    throw new ArgumentException(
                              "InitializeInstanceObjectField requires 1 argument.");
                }
                return(GetMethodCall(false));

            case TestClassMethod.InitializeInstanceObjectFieldViaReference:
                if (args == null || args.Length != 1)
                {
                    throw new ArgumentException(
                              "InitializeInstanceObjectFieldViaReference requires 1 argument.");
                }
                return(GetMethodCall(false));

            case TestClassMethod.ReturnElementFromInstanceArrayField:
                if (args == null || args.Length != 1)
                {
                    throw new ArgumentException(
                              "ReturnElementFromInstanceArrayField requires 1 argument.");
                }
                return(GetMethodCall(false));

            case TestClassMethod.ReturnOneDimArray:
                if (args == null || args.Length != 2)
                {
                    throw new ArgumentException("ReturnOneDimArray requires 2 arguments.");
                }
                return(GetMethodCall(true));

            case TestClassMethod.ReturnTwoDimArray:
                if (args == null || args.Length != 1)
                {
                    throw new ArgumentException("ReturnTwoDimArray requires 1 argument.");
                }
                return(GetMethodCall(true));

            case TestClassMethod.TestBox:
                if (args == null || args.Length != 1)
                {
                    throw new ArgumentException("TestBox requires 1 argument.");
                }
                return(GetMethodCall(true));

            case TestClassMethod.TestIsInst:
                if (args == null || args.Length != 1)
                {
                    throw new ArgumentException("TestIsInst requires 1 argument.");
                }
                return(GetMethodCall(true));

            case TestClassMethod.TestStarg:
                if (args == null || args.Length != 2)
                {
                    throw new ArgumentException("TestStarg requires 2 arguments");
                }
                return(GetMethodCall(true));

            case TestClassMethod.CatchReturnsNullIfTrue:
                if (args == null || args.Length != 1)
                {
                    throw new ArgumentException("CatchReturnsNullIfTrue requires 1 argument.");
                }
                return(GetMethodCall(true));

            case TestClassMethod.FinallyReturnsNullIfTrue:
                if (args == null || args.Length != 1)
                {
                    throw new ArgumentException("FinallyReturnsNullIfTrue requires 1 argument.");
                }
                return(GetMethodCall(true));

            default:
                throw new NotImplementedException("Unhandled TestClassMethod.");
            }
            string GetMethodCall(bool isStatic)
            {
                var enclosingObject = isStatic ?
                                      GetString(VarType.TestClass) : GetString(VarName.Tc);
                var concatArgs = args == null ? string.Empty : string.Join(",", args);
                var callEnding = withLineEnding ? ";\n" : string.Empty;

                return(enclosingObject + "." + method.ToString() +
                       "(" + concatArgs + ")" + callEnding);
            }
        }