Example #1
0
        public void ConstructorTest()
        {
            ContextInstruction target = new ContextInstruction();

            // TODO: Implement code to verify target
            Assert.Inconclusive("TODO: Implement code to verify target");
        }
Example #2
0
        public void AcceptTest()
        {
            ContextInstruction target = new ContextInstruction();

            IVisitor visitor = null; // TODO: Initialize to an appropriate value

            target.Accept(visitor);

            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
Example #3
0
        public void WeavingContextInstructionAddsFilterContextLogic()
        {
            // set up model
            LanguageModelAccessorMock model = new LanguageModelAccessorMock();

            // Create inputfilters
            Block block  = new Block();
            Block block2 = new Block();

            ContextInstruction ci  = new ContextInstruction(ContextInstruction.CHECK_INNER_CALL, 1000, block2);
            ContextInstruction ci2 = new ContextInstruction(ContextInstruction.RESET_INNER_CALL, 1000, null);
            ContextInstruction ci3 = new ContextInstruction(ContextInstruction.SET_INNER_CALL, 1000, null);

            block.addInstruction(ci);
            block.addInstruction(ci2);
            block.addInstruction(ci3);

            model.AddInputFilter("TestTarget.Program", "System.Void TestTarget.Program::TestMethod(System.Int32)", block);

            // create configuration
            CecilWeaverConfiguration configuration = CecilWeaverConfiguration.CreateDefaultConfiguration(CreateFullPath("TestTarget.exe"), CreateFullPath(OutputFileName));

            // do weaving
            IILWeaver weaver = DIHelper.CreateObject <CecilILWeaver>(CreateTestContainer(model, configuration));

            weaver.DoWeave();

            ILReader il = new ILReader();

            il.OpenAssembly(CreateFullPath(OutputFileName));
            List <ILInstruction> ils = il.GetILInstructions("TestTarget.Program", "TestMethod");

            List <ILInstruction> shouldContainCheck = new List <ILInstruction>();

            shouldContainCheck.Add(new ILInstruction(0, "ldarg", "this"));
            shouldContainCheck.Add(new ILInstruction(0, "ldc.i4", "1000"));
            shouldContainCheck.Add(new ILInstruction(0, "call", "System.Boolean Composestar.StarLight.ContextInfo.FilterContext::IsInnerCall(System.Object,System.Int32)"));

            Assert.IsTrue(il.ContainsILInstructions(ils, shouldContainCheck), "Generated IL code did not contain the check for IsInnerCall");

            List <ILInstruction> shouldContainReset = new List <ILInstruction>();

            shouldContainReset.Add(new ILInstruction(0, "call", "System.Void Composestar.StarLight.ContextInfo.FilterContext::ResetInnerCall()"));

            Assert.IsTrue(il.ContainsILInstructions(ils, shouldContainReset), "Generated IL code did not contain the call to the ResetInnerCall");

            List <ILInstruction> shouldContainSet = new List <ILInstruction>();

            shouldContainSet.Add(new ILInstruction(0, "ldarg", "this"));
            shouldContainSet.Add(new ILInstruction(0, "ldc.i4", "1000"));
            shouldContainSet.Add(new ILInstruction(0, "call", "System.Void Composestar.StarLight.ContextInfo.FilterContext::SetInnerCall(System.Object,System.Int32)"));

            Assert.IsTrue(il.ContainsILInstructions(ils, shouldContainSet), "Generated IL code did not contain the call to the SetInnerCall");
        }
Example #4
0
        public void CodeTest()
        {
            ContextInstruction target = new ContextInstruction();

            int val = 0; // TODO: Assign to an appropriate value for the property

            target.Code = val;


            Assert.AreEqual(val, target.Code, "Composestar.StarLight.Entities.WeaveSpec.Instructions.ContextInstruction.Code was" +
                            " not set correctly.");
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Example #5
0
        public void InnerBlockTest()
        {
            ContextInstruction target = new ContextInstruction();

            Block val = null; // TODO: Assign to an appropriate value for the property

            target.InnerBlock = val;


            Assert.AreEqual(val, target.InnerBlock, "Composestar.StarLight.Entities.WeaveSpec.Instructions.ContextInstruction.InnerBlo" +
                            "ck was not set correctly.");
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Example #6
0
        public void ConstructorTest1()
        {
            ContextType type = ContextType.Removed; // TODO: Initialize to an appropriate value

            int code = 0;                           // TODO: Initialize to an appropriate value

            Block innerBlock = null;                // TODO: Initialize to an appropriate value

            ContextInstruction target = new ContextInstruction(type, code, innerBlock);

            // TODO: Implement code to verify target
            Assert.Inconclusive("TODO: Implement code to verify target");
        }
Example #7
0
        public void WeavingErrorActionAddsExceptionFilter()
        {
            string outputFileName = "WeavingErrorActionAddsExceptionFilter.exe";

            // set up model
            LanguageModelAccessorMock model = new LanguageModelAccessorMock();

            // Create inputfilters
            Block block  = new Block();
            Block block2 = new Block();

            ContextInstruction ci  = new ContextInstruction(ContextInstruction.CHECK_INNER_CALL, 1000, block2);
            ContextInstruction ci2 = new ContextInstruction(ContextInstruction.RESET_INNER_CALL, 1000, null);
            ContextInstruction ci3 = new ContextInstruction(ContextInstruction.SET_INNER_CALL, 1000, null);

            FilterAction errorAction = new FilterAction("ErrorAction", "", "");

            block2.addInstruction(errorAction);

            block.addInstruction(ci);
            block.addInstruction(ci2);
            block.addInstruction(ci3);

            model.AddInputFilter("TestTarget.Program", "System.Void TestTarget.Program::TestMethod(System.Int32)", block);

            // create configuration
            CecilWeaverConfiguration configuration = CecilWeaverConfiguration.CreateDefaultConfiguration(CreateFullPath("TestTarget.exe"), CreateFullPath(outputFileName));

            // do weaving
            IILWeaver weaver = DIHelper.CreateObject <CecilILWeaver>(CreateTestContainer(model, configuration));

            weaver.DoWeave();

            ILReader il = new ILReader();

            il.OpenAssembly(CreateFullPath(outputFileName));
            List <ILInstruction> ils = il.GetILInstructions("TestTarget.Program", "TestMethod");

            // Expecting the following IL code
            List <ILInstruction> shouldContainThrow = new List <ILInstruction>();

            shouldContainThrow.Add(new ILInstruction(0, "newobj", "System.Void System.Exception::.ctor()"));
            shouldContainThrow.Add(new ILInstruction(0, "throw", ""));

            Assert.IsTrue(il.ContainsILInstructions(ils, shouldContainThrow), "Generated IL code did not contain the throw exception code");
        }
Example #8
0
        public void WeavingBeforeActionAddsPointCutContextLogic()
        {
            string outputFileName = "WeavingBeforeActionAddsPintCutContextLogic.exe";

            // set up model
            LanguageModelAccessorMock model = new LanguageModelAccessorMock();

            // Create inputfilters
            Block block  = new Block();
            Block block2 = new Block();

            ContextInstruction ci  = new ContextInstruction(ContextInstruction.CHECK_INNER_CALL, 1000, block2);
            ContextInstruction ci2 = new ContextInstruction(ContextInstruction.RESET_INNER_CALL, 1000, null);
            ContextInstruction ci3 = new ContextInstruction(ContextInstruction.SET_INNER_CALL, 1000, null);

            FilterAction errorAction = new FilterAction("BeforeAction", "", "");

            block2.addInstruction(errorAction);

            block.addInstruction(ci);
            block.addInstruction(ci2);
            block.addInstruction(ci3);

            model.AddInputFilter("TestTarget.Program", "System.Void TestTarget.Program::TestMethod(System.Int32)", block);

            // create configuration
            CecilWeaverConfiguration configuration = CecilWeaverConfiguration.CreateDefaultConfiguration(CreateFullPath("TestTarget.exe"), CreateFullPath(outputFileName));

            // do weaving
            IILWeaver weaver = DIHelper.CreateObject <CecilILWeaver>(CreateTestContainer(model, configuration));

            weaver.DoWeave();

            // Expecting the following IL code
            List <ILInstruction> shouldContainBefore = new List <ILInstruction>();

            shouldContainBefore.Add(new ILInstruction(0, "", ""));
            shouldContainBefore.Add(new ILInstruction(0, "", ""));

            // Assert.IsTrue(il.ContainsILInstructions(ils, shouldContainBefore), "Generated IL code did not contain the before action code");

            Assert.Inconclusive("Add the expected IL code to make this test work.");
        }
Example #9
0
        public void AnalyzeAndWeaveTestFilters()
        {
            NameValueCollection config = new NameValueCollection();

            config.Add("OutputImagePath", AppDomain.CurrentDomain.BaseDirectory);
            config.Add("ShouldSignAssembly", "false");
            config.Add("OutputImageSNK", "");
            config.Add("RepositoryFilename", CreateFullPath("starlight.yap"));
            config.Add("InstallFolder", installationFolder);

            CecilILAnalyzer analyzer = new CecilILAnalyzer();

            analyzer.Initialize(FilenameSource, config);

            // Run the analyzer
            IList <TypeElement> ret = analyzer.ExtractTypeElements();

            analyzer.Close();

            // Change the types
            Composestar.Repository.RepositoryAccess repository = new Composestar.Repository.RepositoryAccess(CreateFullPath("starlight.yap"));

            TypeElement te = null;

            te = repository.GetTypeElement("ConsoleTestTarget.HelloWorld");
            MethodElement me = null;

            me = repository.GetMethodElementBySignature(te, "System.String GetMessage()");

            // Add some inputfilters

            Block block  = new Block();
            Block block2 = new Block();

            block2.Label.Id = 4;
            FilterAction beforeAction = new FilterAction("BeforeAction", "", "");

            Composestar.Repository.LanguageModel.ConditionExpressions.ConditionExpression ce = new Composestar.Repository.LanguageModel.ConditionExpressions.True();
            Branch branch = new Composestar.Repository.LanguageModel.Inlining.Branch(ce);

            branch.TrueBlock  = block;
            branch.FalseBlock = block2;
            FilterAction errorAction = new FilterAction("ErrorAction", "", "");
            Jump         jump        = new Jump(new Label(2));

            block.Label.Id        = 2;
            beforeAction.Label.Id = 3;
            block2.addInstruction(beforeAction);
            block2.addInstruction(errorAction);

            ContextInstruction ci  = new ContextInstruction(ContextInstruction.CHECK_INNER_CALL, 1000, block2);
            ContextInstruction ci2 = new ContextInstruction(ContextInstruction.RESET_INNER_CALL, 1000, null);
            ContextInstruction ci3 = new ContextInstruction(ContextInstruction.SET_INNER_CALL, 1000, null);

            block.addInstruction(ci);
            block.addInstruction(ci2);
            block.addInstruction(ci3);

            // block2.addInstruction(branch);
            // block2.addInstruction(jump);

            me.MethodBody.InputFilter = block;
            Composestar.Repository.DataStoreContainer.Instance.StoreObject(me);

            repository.CloseDatabase();

            // Run the weaver
            // OC: CecilWeaver should not be created directly!
            //CecilILWeaver weaver = new CecilILWeaver();
            //weaver.Initialize(FilenameSource, config);
            //weaver.DoWeave(); // Place debugger here or perform Asserts
            //weaver.Close();
        }