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"); }
/// <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); }
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"); }
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"); }
public CPPTranslator Constructor() { CPPTranslator target = new CPPTranslator(); MEFUtilities.Compose(target); return target; // TODO: add assertions to method CPPTranslatorTest.Constructor() }
public CPPTranslator Constructor() { CPPTranslator target = new CPPTranslator(); MEFUtilities.Compose(target); return(target); // TODO: add assertions to method CPPTranslatorTest.Constructor() }
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"); }
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"); }
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"); }
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"); }
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"); }
/// <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; }
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"); }
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"); }
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"); }