Exemplo n.º 1
0
        public void TestForFunctionNumber()
        {
            CPPTranslator target = new CPPTranslator();
            var           vInt   = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));

            vInt.SetInitialValue("2");
            GeneratedCode code = new GeneratedCode();

            code.SetResult(vInt);

            var innerBlock = new StatementInlineBlock();
            var vInt2      = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));

            vInt2.SetInitialValue("5");
            innerBlock.Add(vInt2);
            code.Add(innerBlock);

            var r = TranslateGeneratedCode(target, code);

            Assert.IsTrue(r.ContainsKey("NumberOfQueryFunctions"), "Number of functions isn't here");
            Assert.IsInstanceOfType(r["NumberOfQueryFunctions"], typeof(int), "# function type");
            Assert.AreEqual(1, r["NumberOfQueryFunctions"], "# of functions");

            Assert.IsTrue(r.ContainsKey("QueryFunctionBlocks"), "Missing query function blocks");
            Assert.IsInstanceOfType(r["QueryFunctionBlocks"], typeof(IEnumerable <IEnumerable <string> >), "Type is incorrect");
            var codeBlocks = r["QueryFunctionBlocks"] as IEnumerable <IEnumerable <string> >;

            Assert.AreEqual(1, codeBlocks.Count(), "Wrong number of code blocks");
        }
Exemplo n.º 2
0
        /// <summary>Test stub for TranslateGeneratedCode(GeneratedCode)</summary>
        public Dictionary <string, object> TranslateGeneratedCode(CPPTranslator target, IExecutableCode code)
        {
            MEFUtilities.Compose(target);
            Dictionary <string, object> result = target.TranslateGeneratedCode(code);

            return(result);
        }
Exemplo n.º 3
0
        public void TestObjectInitalizerInInnerBlock()
        {
            CPPTranslator target = new CPPTranslator();
            var           vInt   = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));

            vInt.SetInitialValue("2");
            GeneratedCode code = new GeneratedCode();

            code.SetResult(vInt);

            var innerBlock = new StatementInlineBlock();
            var vInt2      = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));

            vInt2.SetInitialValue("5");
            innerBlock.Add(vInt2);
            innerBlock.Add(new StatementSimpleStatement("fork = dork"));
            code.Add(innerBlock);

            var r = TranslateGeneratedCode(target, code);

            var st = (r["QueryFunctionBlocks"] as IEnumerable <IEnumerable <string> >).First().ToArray();

            Assert.AreEqual(6, st.Length, "incorrect number of statements");
            Assert.AreEqual("int " + vInt2.RawValue + " = 5;", st[2].Trim(), "incorrect initialization");
        }
Exemplo n.º 4
0
        public void TestForFunctionNumber()
        {
            CPPTranslator target = new CPPTranslator();
            var vInt = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            vInt.SetInitialValue("2");
            GeneratedCode code = new GeneratedCode();
            code.SetResult(vInt);

            var innerBlock = new StatementInlineBlock();
            var vInt2 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            vInt2.SetInitialValue("5");
            innerBlock.Add(vInt2);
            code.Add(innerBlock);

            var r = TranslateGeneratedCode(target, code);

            Assert.IsTrue(r.ContainsKey("NumberOfQueryFunctions"), "Number of functions isn't here");
            Assert.IsInstanceOfType(r["NumberOfQueryFunctions"], typeof(int), "# function type");
            Assert.AreEqual(1, r["NumberOfQueryFunctions"], "# of functions");

            Assert.IsTrue(r.ContainsKey("QueryFunctionBlocks"), "Missing query function blocks");
            Assert.IsInstanceOfType(r["QueryFunctionBlocks"], typeof(IEnumerable<IEnumerable<string>>), "Type is incorrect");
            var codeBlocks = r["QueryFunctionBlocks"] as IEnumerable<IEnumerable<string>>;
            Assert.AreEqual(1, codeBlocks.Count(), "Wrong number of code blocks");
        }
Exemplo n.º 5
0
 public CPPTranslator Constructor()
 {
     CPPTranslator target = new CPPTranslator();
     MEFUtilities.Compose(target);
     return target;
     // TODO: add assertions to method CPPTranslatorTest.Constructor()
 }
Exemplo n.º 6
0
        public CPPTranslator Constructor()
        {
            CPPTranslator target = new CPPTranslator();

            MEFUtilities.Compose(target);
            return(target);
            // TODO: add assertions to method CPPTranslatorTest.Constructor()
        }
Exemplo n.º 7
0
        public void TestTranslateForIncludeFiles()
        {
            CPPTranslator target = new CPPTranslator();
            var           obj    = DeclarableParameter.CreateDeclarableParameterExpression(typeof(ROOTNET.NTH1F));
            GeneratedCode code   = new GeneratedCode();

            code.SetResult(obj);

            var r = TranslateGeneratedCode(target, code);

            Assert.AreEqual(1, code.IncludeFiles.Count(), "# of include files");
            Assert.AreEqual("TH1F.h", code.IncludeFiles.First(), "include file name is incorrect");
        }
Exemplo n.º 8
0
        public void TestForTooManyCodeBlocks()
        {
            CPPTranslator target = new CPPTranslator();

            MEFUtilities.Compose(target);

            var toomany = new TooManyStatemnets();

            var result = target.TranslateGeneratedCode(toomany);

            Assert.IsTrue(((int)result["NumberOfQueryFunctions"]) > 1, string.Format("Number of queries was not larger than 1, it was {0}", result["NumberOfQueryFunctions"]));
            var codeBlocks = result["QueryFunctionBlocks"] as IEnumerable <IEnumerable <string> >;

            Assert.AreEqual(result["NumberOfQueryFunctions"], codeBlocks.Count(), "Non-matching number of code blocks");
        }
Exemplo n.º 9
0
        public void TestTranslateWithInitialValue()
        {
            CPPTranslator target = new CPPTranslator();
            var vInt = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            vInt.SetInitialValue("2");
            GeneratedCode code = new GeneratedCode();
            code.SetResult(vInt);

            var r = TranslateGeneratedCode(target, code);

            Assert.IsTrue(r.ContainsKey("ResultVariables"), "Result variable is missing");
            Assert.IsInstanceOfType(r["ResultVariables"], typeof(IEnumerable<CPPTranslator.VarInfo>), "bad type for the result variable");
            var rList = r["ResultVariables"] as IEnumerable<CPPTranslator.VarInfo>;
            Assert.AreEqual(1, rList.Count(), "incorrect # of result variables");
            var rv = rList.First();
            Assert.AreEqual("2", rv.InitialValue, "initial value");
        }
Exemplo n.º 10
0
        public void TestTranslateWithInitialValue()
        {
            CPPTranslator target = new CPPTranslator();
            var           vInt   = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));

            vInt.SetInitialValue("2");
            GeneratedCode code = new GeneratedCode();

            code.SetResult(vInt);

            var r = TranslateGeneratedCode(target, code);

            Assert.IsTrue(r.ContainsKey("ResultVariables"), "Result variable is missing");
            Assert.IsInstanceOfType(r["ResultVariables"], typeof(IEnumerable <CPPTranslator.VarInfo>), "bad type for the result variable");
            var rList = r["ResultVariables"] as IEnumerable <CPPTranslator.VarInfo>;

            Assert.AreEqual(1, rList.Count(), "incorrect # of result variables");
            var rv = rList.First();

            Assert.AreEqual("2", rv.InitialValue, "initial value");
        }
Exemplo n.º 11
0
        public void TestObjectPointer()
        {
            CPPTranslator target = new CPPTranslator();
            var           obj    = DeclarableParameter.CreateDeclarableParameterExpression(typeof(ROOTNET.NTH1F));
            GeneratedCode code   = new GeneratedCode();

            code.SetResult(obj);

            var r = TranslateGeneratedCode(target, code);

            var rlist = r["ResultVariables"] as IEnumerable <CPPTranslator.VarInfo>;
            var rv    = rlist.First();

            Assert.AreEqual("TH1F*", rv.VariableType, "type is not right");
            var inFiles = code.IncludeFiles.ToArray();

            foreach (var item in inFiles)
            {
                Console.WriteLine("include file '{0}'", item);
            }

            Assert.IsTrue(inFiles.Contains("TH1F.h"), "Missing include file");
        }
Exemplo n.º 12
0
 /// <summary>Test stub for TranslateGeneratedCode(GeneratedCode)</summary>
 public Dictionary<string, object> TranslateGeneratedCode(CPPTranslator target, GeneratedCode code)
 {
     MEFUtilities.Compose(target);
     Dictionary<string, object> result = target.TranslateGeneratedCode(code);
     return result;
 }
Exemplo n.º 13
0
        public void TestTranslateForIncludeFiles()
        {
            CPPTranslator target = new CPPTranslator();
            var obj = DeclarableParameter.CreateDeclarableParameterExpression(typeof(ROOTNET.NTH1F));
            GeneratedCode code = new GeneratedCode();
            code.SetResult(obj);

            var r = TranslateGeneratedCode(target, code);

            Assert.AreEqual(1, code.IncludeFiles.Count(), "# of include files");
            Assert.AreEqual("TH1F.h", code.IncludeFiles.First(), "include file name is incorrect");
        }
Exemplo n.º 14
0
        public void TestObjectPointer()
        {
            CPPTranslator target = new CPPTranslator();
            var obj = DeclarableParameter.CreateDeclarableParameterExpression(typeof(ROOTNET.NTH1F));
            GeneratedCode code = new GeneratedCode();
            code.SetResult(obj);

            var r = TranslateGeneratedCode(target, code);

            var rlist = r["ResultVariables"] as IEnumerable<CPPTranslator.VarInfo>;
            var rv = rlist.First();
            Assert.AreEqual("TH1F*", rv.VariableType, "type is not right");
            var inFiles = code.IncludeFiles.ToArray();
            foreach (var item in inFiles)
            {
                Console.WriteLine("include file '{0}'", item);
            }

            Assert.IsTrue(inFiles.Contains("TH1F.h"), "Missing include file");
        }
Exemplo n.º 15
0
        public void TestObjectInitalizerInInnerBlock()
        {
            CPPTranslator target = new CPPTranslator();
            var vInt = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            vInt.SetInitialValue("2");
            GeneratedCode code = new GeneratedCode();
            code.SetResult(vInt);

            var innerBlock = new StatementInlineBlock();
            var vInt2 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            vInt2.SetInitialValue("5");
            innerBlock.Add(vInt2);
            innerBlock.Add(new StatementSimpleStatement("fork = dork"));
            code.Add(innerBlock);

            var r = TranslateGeneratedCode(target, code);

            var st = (r["QueryFunctionBlocks"] as IEnumerable<IEnumerable<string>>).First().ToArray();
            Assert.AreEqual(6, st.Length, "incorrect number of statements");
            Assert.AreEqual("int " + vInt2.RawValue + " = 5;", st[2].Trim(), "incorrect initialization");
        }
Exemplo n.º 16
0
        public void TestForTooManyCodeBlocks()
        {
            CPPTranslator target = new CPPTranslator();
            MEFUtilities.Compose(target);

            var toomany = new tooManyStatemnets();

            var result = target.TranslateGeneratedCode(toomany);

            Assert.IsTrue(((int)result["NumberOfQueryFunctions"]) > 1, string.Format("Number of queries was not larger than 1, it was {0}", result["NumberOfQueryFunctions"]));
            var codeBlocks = result["QueryFunctionBlocks"] as IEnumerable<IEnumerable<string>>;
            Assert.AreEqual(result["NumberOfQueryFunctions"], codeBlocks.Count(), "Non-matching number of code blocks");
        }