示例#1
0
        public void CPPRenameVariables()
        {
            // two identical expressions
            var target  = new TypeHandlerCPPCode();
            var gc      = new GeneratedCode();
            var context = new CodeContext();

            var p_pt_1 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(double));
            var p_eta  = DeclarableParameter.CreateDeclarableParameterExpression(typeof(double));
            var p_phi  = DeclarableParameter.CreateDeclarableParameterExpression(typeof(double));
            var p_E    = DeclarableParameter.CreateDeclarableParameterExpression(typeof(double));

            // Create call
            var e1      = Expression.Call(typeof(TLZHelper).GetMethod("CreateTLZBE"), p_pt_1, p_eta, p_phi, p_E);
            var e1Value = target.CodeMethodCall(e1, gc, MEFUtilities.MEFContainer);

            gc.DumpCodeToConsole();

            // Now, extract the main statement.
            Assert.AreEqual(1, gc.CodeBody.Statements.Count(), "# of statements");
            var s1 = gc.CodeBody.Statements.First() as IStatement;

            // Make sure the variable is there and then isn't.
            var p_pt_2 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(double));

            Assert.IsTrue(gc.DumpCode().Where(l => l.Contains(p_pt_1.RawValue)).Any(), "the pt variable should be there.");
            Assert.IsFalse(gc.DumpCode().Where(l => l.Contains(p_pt_2.RawValue)).Any(), "the pt variable should be there.");

            s1.RenameVariable(p_pt_1.RawValue, p_pt_2.RawValue);
            Assert.IsFalse(gc.DumpCode().Where(l => l.Contains(p_pt_1.RawValue)).Any(), "the pt variable should be there.");
            Assert.IsTrue(gc.DumpCode().Where(l => l.Contains(p_pt_2.RawValue)).Any(), "the pt variable should be there.");
        }
示例#2
0
        public void QueryAnonymousObjectToTTree()
        {
            GeneratedCode query1 = GeneratedCodeFor(QueryTupleAnonyoumsObject);

            // Check that we have a Fill somewhere in the statement.
            Assert.IsTrue(query1.DumpCode().Where(l => l.Contains("->Fill()")).Any(), "At least one Fill statement.");
        }
示例#3
0
        public void CustomObjectStreamToCSVFileGeneratesOutput()
        {
            GeneratedCode query1 = GeneratedCodeFor(QueryTupleOurCustomObject);

            // Check that we have a cout somewhere in the statement.
            Assert.IsTrue(query1.DumpCode().Where(l => l.Contains("<<") && l.Contains(".run")).Any(), "At least one cout statement.");
        }
示例#4
0
        public void RenameCPPResultVariable()
        {
            var target  = new TypeHandlerCPPCode();
            var gc      = new GeneratedCode();
            var context = new CodeContext();

            var param     = Expression.Parameter(typeof(int), "p");
            var paramplus = Expression.MakeBinary(ExpressionType.Add, param, Expression.Constant(1));
            var expr      = Expression.Call(typeof(DoItClass).GetMethod("DoIt"), paramplus);

            var result = target.CodeMethodCall(expr, gc, MEFUtilities.MEFContainer);

            gc.CodeBody.RenameVariable(result.RawValue, "abogus_1234");

            gc.DumpCodeToConsole();

            Assert.IsTrue(gc.DumpCode().Where(s => s.Contains("int abogus_1234")).Any(), "Didn't find the variable name in the code");
        }
        /// <summary>Test stub for ProcessResultOperator(ResultOperatorBase, QueryModel, IGeneratedCode)</summary>
        internal GeneratedCode ProcessResultOperator(
            ROTakeSkipOperators target,
            ResultOperatorBase resultOperator,
            QueryModel queryModel,
            GeneratedCode codeEnv
            )
        {
            if (codeEnv.ResultValue != null)
            {
                throw new ArgumentException("this should not be null for this test");
            }
            if (codeEnv.CodeBody.DeclaredVariables == null)
            {
                throw new ArgumentException("Need this declare variables to be defined");
            }

            ///
            /// We always expect to be inside a loop - and depend on it for doing our declares, so add something...
            ///

            var inlineBlock = new StatementInlineBlock();

            codeEnv.Add(inlineBlock);

            ///
            /// Get the environment setup and run it
            ///

            CodeContext c = new CodeContext();

            c.SetLoopVariable(Expression.Variable(typeof(int), "d"), null);

            target.ProcessResultOperator(resultOperator, queryModel, codeEnv, c, MEFUtilities.MEFContainer);

            codeEnv.DumpCodeToConsole();

            ///
            /// First, there should be a counter now declared and ready to go in the current variable block - which will
            /// be the outer one for this test. If this is the outter most, then this is going to be burried.
            ///

            var declBlock = inlineBlock.Parent.Parent as IBookingStatementBlock;

            Assert.IsNotNull(declBlock, "Expecting a declaration block above!");

            Assert.AreEqual(1, inlineBlock.Statements.Count(), "Expected an if block/increment!");
            Assert.IsInstanceOfType(inlineBlock.Statements.First(), typeof(StatementIfOnCount), "if statement not found!");

            var s = inlineBlock.Statements.First() as StatementIfOnCount;

            bool isTopLevel = codeEnv.DumpCode().Where(l => l.Contains("static int")).Any();

            if (!isTopLevel)
            {
                Assert.AreEqual(1, declBlock.DeclaredVariables.Count(), "Expected only 1 variable to be declared");
                Assert.IsInstanceOfType(declBlock.DeclaredVariables.First(), typeof(DeclarableParameter), "Expected it to be a counter");
            }
            else
            {
                Assert.AreEqual(1, (s.Parent as IBookingStatementBlock).DeclaredVariables.Count());
            }

            string count = "";

            if (resultOperator is SkipResultOperator)
            {
                count = (resultOperator as SkipResultOperator).Count.ToString();
            }
            else if (resultOperator is TakeResultOperator)
            {
                count = (resultOperator as TakeResultOperator).Count.ToString();
            }
            Assert.AreEqual(count, s.Limit.RawValue, "bad count made it through");

            ///
            /// Finally, the current loop variable should be identical, and there should be no result set.
            ///

            Assert.IsNull(codeEnv.ResultValue, "result value");
            Assert.IsInstanceOfType(c.LoopVariable, typeof(ParameterExpression), "loop variable type");
            var lv = c.LoopVariable as ParameterExpression;

            Assert.AreEqual("d", lv.Name, "loop variable name");

            //
            // Dump everything and return. To force it out, add a dummy statement
            // (because if statements, etc., are smart enough to not print anything if they
            // are empty).
            //

            codeEnv.Add(new StatementSimpleStatement("fork = left"));
            codeEnv.DumpCodeToConsole();

            return(codeEnv);
        }
        public void CPPRenameVariables()
        {
            // two identical expressions
            var target = new TypeHandlerCPPCode();
            var gc = new GeneratedCode();
            var context = new CodeContext();

            var p_pt_1 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(double));
            var p_eta = DeclarableParameter.CreateDeclarableParameterExpression(typeof(double));
            var p_phi = DeclarableParameter.CreateDeclarableParameterExpression(typeof(double));
            var p_E = DeclarableParameter.CreateDeclarableParameterExpression(typeof(double));

            // Create call
            var e1 = Expression.Call(typeof(TLZHelper).GetMethod("CreateTLZBE"), p_pt_1, p_eta, p_phi, p_E);
            var e1Value = target.CodeMethodCall(e1, gc, MEFUtilities.MEFContainer);

            gc.DumpCodeToConsole();

            // Now, extract the main statement.
            Assert.AreEqual(1, gc.CodeBody.Statements.Count(), "# of statements");
            var s1 = gc.CodeBody.Statements.First() as IStatement;

            // Make sure the variable is there and then isn't.
            var p_pt_2 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(double));
            Assert.IsTrue(gc.DumpCode().Where(l => l.Contains(p_pt_1.RawValue)).Any(), "the pt variable should be there.");
            Assert.IsFalse(gc.DumpCode().Where(l => l.Contains(p_pt_2.RawValue)).Any(), "the pt variable should be there.");

            s1.RenameVariable(p_pt_1.RawValue, p_pt_2.RawValue);
            Assert.IsFalse(gc.DumpCode().Where(l => l.Contains(p_pt_1.RawValue)).Any(), "the pt variable should be there.");
            Assert.IsTrue(gc.DumpCode().Where(l => l.Contains(p_pt_2.RawValue)).Any(), "the pt variable should be there.");
        }
        public void RenameCPPResultVariable()
        {
            var target = new TypeHandlerCPPCode();
            var gc = new GeneratedCode();
            var context = new CodeContext();

            var param = Expression.Parameter(typeof(int), "p");
            var paramplus = Expression.MakeBinary(ExpressionType.Add, param, Expression.Constant(1));
            var expr = Expression.Call(typeof(DoItClass).GetMethod("DoIt"), paramplus);

            var result = target.CodeMethodCall(expr, gc, MEFUtilities.MEFContainer);
            gc.CodeBody.RenameVariable(result.RawValue, "abogus_1234");

            gc.DumpCodeToConsole();

            Assert.IsTrue(gc.DumpCode().Where(s => s.Contains("int abogus_1234")).Any(), "Didn't find the variable name in the code");
        }
示例#8
0
 /// <summary>
 /// Dump the code to the console - for debugging a test...
 /// </summary>
 /// <param name="code"></param>
 public static void DumpCodeToConsole(this GeneratedCode code)
 {
     code.DumpCode().DumpToConsole();
 }
        /// <summary>Test stub for ProcessResultOperator(ResultOperatorBase, QueryModel, IGeneratedCode)</summary>
        internal GeneratedCode ProcessResultOperator(
            ROTakeSkipOperators target,
            ResultOperatorBase resultOperator,
            QueryModel queryModel,
            GeneratedCode codeEnv
        )
        {
            if (codeEnv.ResultValue != null)
                throw new ArgumentException("this should not be null for this test");
            if (codeEnv.CodeBody.DeclaredVariables == null)
                throw new ArgumentException("Need this declare variables to be defined");

            ///
            /// We always expect to be inside a loop - and depend on it for doing our declares, so add something...
            /// 

            var inlineBlock = new StatementInlineBlock();
            codeEnv.Add(inlineBlock);

            ///
            /// Get the environment setup and run it
            /// 

            CodeContext c = new CodeContext();
            c.SetLoopVariable(Expression.Variable(typeof(int), "d"), null);

            target.ProcessResultOperator(resultOperator, queryModel, codeEnv, c, MEFUtilities.MEFContainer);

            codeEnv.DumpCodeToConsole();

            ///
            /// First, there should be a counter now declared and ready to go in the current variable block - which will
            /// be the outer one for this test. If this is the outter most, then this is going to be burried.
            /// 

            var declBlock = inlineBlock.Parent.Parent as IBookingStatementBlock;
            Assert.IsNotNull(declBlock, "Expecting a declaration block above!");

            Assert.AreEqual(1, inlineBlock.Statements.Count(), "Expected an if block/increment!");
            Assert.IsInstanceOfType(inlineBlock.Statements.First(), typeof(StatementIfOnCount), "if statement not found!");

            var s = inlineBlock.Statements.First() as StatementIfOnCount;

            bool isTopLevel = codeEnv.DumpCode().Where(l => l.Contains("static int")).Any();
            if (!isTopLevel)
            {
                Assert.AreEqual(1, declBlock.DeclaredVariables.Count(), "Expected only 1 variable to be declared");
                Assert.IsInstanceOfType(declBlock.DeclaredVariables.First(), typeof(DeclarableParameter), "Expected it to be a counter");
            } else
            {
                Assert.AreEqual(1, (s.Parent as IBookingStatementBlock).DeclaredVariables.Count());
            }

            string count = "";
            if (resultOperator is SkipResultOperator)
            {
                count = (resultOperator as SkipResultOperator).Count.ToString();
            }
            else if (resultOperator is TakeResultOperator)
            {
                count = (resultOperator as TakeResultOperator).Count.ToString();
            }
            Assert.AreEqual(count, s.Limit.RawValue, "bad count made it through");

            ///
            /// Finally, the current loop variable should be identical, and there should be no result set.
            /// 

            Assert.IsNull(codeEnv.ResultValue, "result value");
            Assert.IsInstanceOfType(c.LoopVariable, typeof(ParameterExpression), "loop variable type");
            var lv = c.LoopVariable as ParameterExpression;
            Assert.AreEqual("d", lv.Name, "loop variable name");

            //
            // Dump everything and return. To force it out, add a dummy statement
            // (because if statements, etc., are smart enough to not print anything if they
            // are empty).
            //

            codeEnv.Add(new StatementSimpleStatement("fork = left"));
            codeEnv.DumpCodeToConsole();

            return codeEnv;
        }