public void TestConstCStyleArray() { // Simple set of types for an index array var vArray = new ItemCStyleArray("int[]", new ItemSimpleType("arr", "int")); vArray.Add(0, "10", true); var vIndex = new ItemSimpleType("n", "int"); ROOTClassShell mainClass = new ROOTClassShell("TestSimpleRename") { }; mainClass.Add(vIndex); mainClass.Add(vArray); var ntup = new NtupleTreeInfo() { Classes = new ROOTClassShell[] { mainClass }, ClassImplimintationFiles = new string[0] }; var userinfo = new TTreeUserInfo() { Groups = new ArrayGroup[] { new ArrayGroup() { Name = "ungrouped", Variables = new VariableInfo[] { new VariableInfo() { NETName = "n", TTreeName = "n" }, new VariableInfo() { NETName = "arr", TTreeName = "arr" } } } } }; var cg = new ClassGenerator(); var outputFile = new FileInfo("TestConstCStyleArray.cs"); cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary <string, TTreeUserInfo>() { { "TestSimpleRename", userinfo } }); CopyToOutput(outputFile); /// Look through this to see if we can make sure there are no renames! Assert.IsTrue(FindInFile(outputFile, "int[] arr"), "Array Decl missing"); Assert.IsTrue(FindInFile(outputFile, "int n"), "Index decl missing"); Assert.IsTrue(FindInFile(outputFile, "[ArraySizeIndex(\"10\", IsConstantExpression = true, Index = 0)]"), "Missing array size index attribute"); }
private IClassItem ExtractSimpleItem(SimpleLeafInfo leaf) { string className = TypeDefTranslator.ResolveTypedef(leaf.TypeName); // // Check if it is a c-style array. If it is, then the title will contain // the specification we need to look at for the c-style array bit. This will get // called recursively to parse the actual type after the c-style array bit is stripped off. // if (leaf.Title.Contains("[")) { return(ExtractCArrayInfo(leaf)); } // // Next, if the type is a template, special parse that. // var result = TemplateParser.ParseForTemplates(className); if (result is TemplateParser.TemplateInfo) { return(ExtractTemplateItem(leaf, result as TemplateParser.TemplateInfo)); } /// /// Ok - so it is a single "object" or similar. So we need to look at it and figure /// out how to deal with it. It could be a root object or just an "int" /// var ln = NormalizeLeafName(leaf.Name); IClassItem toAdd = null; if (IsROOTClass(className) && className != "string") { toAdd = new ItemROOTClass(ln, className); } else { toAdd = new ItemSimpleType(ln, className.SimpleCPPTypeToCSharpType()); } if (toAdd == null || toAdd.ItemType == null) { throw new InvalidOperationException("Unknown type - can't translate '" + className + "'."); } return(toAdd); }
public void TestNonIntIndex() { /// Create simple user info - but don't do anything with it! ItemSimpleType simpleIndex = new ItemSimpleType("index", "float[]"); ItemSimpleType simpleVal = new ItemSimpleType("var1", "float[]"); ROOTClassShell mainClass = new ROOTClassShell("TestNonIntIndex") { }; mainClass.Add(simpleIndex); mainClass.Add(simpleVal); var ntup = new NtupleTreeInfo() { Classes = new ROOTClassShell[] { mainClass }, ClassImplimintationFiles = new string[0] }; var userinfo = new TTreeUserInfo() { Groups = new ArrayGroup[] { new ArrayGroup() { Name = "jets", Variables = new VariableInfo[] { new VariableInfo() { NETName = "index", TTreeName = "index", IndexToGroup = "muons" } } }, new ArrayGroup() { Name = "muons", Variables = new VariableInfo[] { new VariableInfo() { NETName = "var1", TTreeName = "var1" } } } } }; var cg = new ClassGenerator(); var outputFile = new FileInfo("TestNonIntIndex.cs"); cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary <string, TTreeUserInfo>() { { "TestNonIntIndex", userinfo } }); }
public void GroupWithArrayLengthSpecification() { ItemSimpleType simple1 = new ItemSimpleType("avar", "int[]"); ItemSimpleType simple2 = new ItemSimpleType("bvar", "int[]"); ROOTClassShell mainClass = new ROOTClassShell("GroupWithArrayLengthSpecification") { }; mainClass.Add(simple1); mainClass.Add(simple2); var ntup = new NtupleTreeInfo() { Classes = new ROOTClassShell[] { mainClass }, ClassImplimintationFiles = new string[0] }; var userinfo = new TTreeUserInfo() { Groups = new ArrayGroup[] { new ArrayGroup() { Name = "jets", NETNameOfVariableToUseAsArrayLength = "b", Variables = new VariableInfo[] { new VariableInfo() { NETName = "a", TTreeName = "avar" }, new VariableInfo() { NETName = "b", TTreeName = "bvar" }, } } } }; var cg = new ClassGenerator(); var outputFile = new FileInfo("GroupWithArrayLengthSpecification.cs"); cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary <string, TTreeUserInfo>() { { "GroupWithArrayLengthSpecification", userinfo } }); DumpOutputFile(outputFile); /// Look through this to see if we can make sure there are no renames! Assert.IsTrue(FindInFile(outputFile, "UseAsArrayLength"), "Missing the UseAsArrayLength attribute!!"); }
public void TestSimpleGroupWithCustomClassName() { /// Create simple user info - but don't do anything with it! ItemSimpleType simple = new ItemSimpleType("var1", "int[]"); ROOTClassShell mainClass = new ROOTClassShell("TestSimpleGroupAndRename") { }; mainClass.Add(simple); var ntup = new NtupleTreeInfo() { Classes = new ROOTClassShell[] { mainClass }, ClassImplimintationFiles = new string[0] }; var userinfo = new TTreeUserInfo() { Groups = new ArrayGroup[] { new ArrayGroup() { Name = "jets", ClassName = "Jet", Variables = new VariableInfo[] { new VariableInfo() { NETName = "myvar", TTreeName = "var1" } } } } }; var cg = new ClassGenerator(); var outputFile = new FileInfo("TestSimpleGroupAndRename.cs"); cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary <string, TTreeUserInfo>() { { "TestSimpleGroupAndRename", userinfo } }); DumpOutputFile(outputFile); /// Look through this to see if we can make sure there are no renames! Assert.IsTrue(FindInFile(outputFile, "RenameVariable(\"var1\")"), "Rename missing!"); Assert.IsTrue(FindInFile(outputFile, "TTreeVariableGrouping"), "Missing TTreeVariableGrouping"); Assert.IsTrue(FindInFile(outputFile, "jets"), "missing a reference to jets"); Assert.IsTrue(FindInFile(outputFile, "int myvar"), "myvar missing"); Assert.IsTrue(FindInFile(outputFile, "int[] var1"), "val1 missing"); Assert.IsFalse(FindInFile(outputFile, "ungrouped"), "group found"); Assert.IsFalse(FindInFile(outputFile, "TestSimpleGroupAndRenamejets"), "Found the non-class name default class name"); Assert.IsTrue(FindInFile(outputFile, "Jet"), "Did not find the Jet custom class name"); }
public void TestCStyleArrayBadIndexName() { // Simple set of types for an index array var vArray = new ItemCStyleArray("int[]", new ItemSimpleType("arr", "int")); vArray.Add(0, "i", false); var vIndex = new ItemSimpleType("n", "int"); ROOTClassShell mainClass = new ROOTClassShell("TestSimpleRename") { }; mainClass.Add(vIndex); mainClass.Add(vArray); var ntup = new NtupleTreeInfo() { Classes = new ROOTClassShell[] { mainClass }, ClassImplimintationFiles = new string[0] }; var userinfo = new TTreeUserInfo() { Groups = new ArrayGroup[] { new ArrayGroup() { Name = "ungrouped", Variables = new VariableInfo[] { new VariableInfo() { NETName = "n", TTreeName = "n" }, new VariableInfo() { NETName = "arr", TTreeName = "arr" } } } } }; var cg = new ClassGenerator(); var outputFile = new FileInfo("TestCStyleArray.cs"); cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary <string, TTreeUserInfo>() { { "TestSimpleRename", userinfo } }); }
public void TestDuplicateClassNames() { var vIndex = new ItemSimpleType("n", "int"); ROOTClassShell mainClass = new ROOTClassShell("TestSimpleRename") { }; mainClass.Add(vIndex); ROOTClassShell mainClass1 = new ROOTClassShell("TestSimpleRename") { }; mainClass1.Add(vIndex); var ntup = new NtupleTreeInfo() { Classes = new ROOTClassShell[] { mainClass, mainClass1 }, ClassImplimintationFiles = new string[0] }; var userinfo = new TTreeUserInfo() { Groups = new ArrayGroup[] { new ArrayGroup() { Name = "ungrouped", Variables = new VariableInfo[] { new VariableInfo() { NETName = "n", TTreeName = "n" }, } } } }; var cg = new ClassGenerator(); var outputFile = new FileInfo("TestDuplicateClassNames.cs"); cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary <string, TTreeUserInfo>() { { "TestDuplicateClassNames", userinfo } }); }
public void TestColonsInVarName() { ItemSimpleType simple = new ItemSimpleType("dude::fork", "int[]"); ROOTClassShell mainClass = new ROOTClassShell("TestSimpleGroupAndRename") { }; mainClass.Add(simple); var ntup = new NtupleTreeInfo() { Classes = new ROOTClassShell[] { mainClass }, ClassImplimintationFiles = new string[0] }; var userinfo = new TTreeUserInfo() { Groups = new ArrayGroup[] { new ArrayGroup() { Name = "jets", Variables = new VariableInfo[] { new VariableInfo() { NETName = "dude::fork", TTreeName = "dude::fork" } } } } }; var cg = new ClassGenerator(); var outputFile = new FileInfo("TestSimpleGroupAndRename.cs"); cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary <string, TTreeUserInfo>() { { "TestSimpleGroupAndRename", userinfo } }); DumpOutputFile(outputFile); /// Look through this to see if we can make sure there are no renames! Assert.IsFalse(FindInFile(outputFile, "dude::fork"), "Saw the double colon!!"); Assert.IsTrue(FindInFile(outputFile, "dude__fork"), "Missing the variable!!"); }
public void TestNoGroups() { /// Create simple user info - but don't do anything with it! ItemSimpleType simple = new ItemSimpleType("var1", "int[]"); Assert.IsFalse(simple.NotAPointer, "not a pointer"); ROOTClassShell mainClass = new ROOTClassShell("TestSimpleRename") { }; mainClass.Add(simple); var ntup = new NtupleTreeInfo() { Classes = new ROOTClassShell[] { mainClass }, ClassImplimintationFiles = new string[0] }; var userinfo = new TTreeUserInfo() { Groups = new ArrayGroup[] { new ArrayGroup() { Name = "ungrouped", Variables = new VariableInfo[] { new VariableInfo() { NETName = "var1", TTreeName = "var1" } } } } }; var cg = new ClassGenerator(); var outputFile = new FileInfo("TestNoGroups.cs"); cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary <string, TTreeUserInfo>() { { "TestSimpleRename", userinfo } }); /// Look through this to see if we can make sure there are no renames! Assert.IsFalse(FindInFile(outputFile, "RenameVariable"), "We saw a rename!"); Assert.IsFalse(FindInFile(outputFile, "ungrouped"), "group found"); }
public void TestCharactersInClassName() { ItemSimpleType simple = new ItemSimpleType("fork", "int"); ROOTClassShell mainClass = new ROOTClassShell("##Shapes") { }; mainClass.Add(simple); var ntup = new NtupleTreeInfo() { Classes = new ROOTClassShell[] { mainClass }, ClassImplimintationFiles = new string[0] }; var userinfo = new TTreeUserInfo() { Groups = new ArrayGroup[] { new ArrayGroup() { Name = "jets", Variables = new VariableInfo[] { new VariableInfo() { NETName = "fork", TTreeName = "fork" } } } } }; var cg = new ClassGenerator(); var outputFile = new FileInfo("TestCharactersInClassName.cs"); cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary <string, TTreeUserInfo>() { { "TestSimpleGroupAndRename", userinfo } }); DumpOutputFile(outputFile); Assert.AreEqual(3, CountInFile(outputFile, "##Shapes"), "Missing reference ot the shapes object"); }
public void TestCStyleArrayBadIndexName() { // Simple set of types for an index array var vArray = new ItemCStyleArray("int[]", new ItemSimpleType("arr", "int")); vArray.Add(0, "i", false); var vIndex = new ItemSimpleType("n", "int"); FileInfo proxyFile = new FileInfo("TestCStyleArray.cpp"); using (var writer = proxyFile.CreateText()) { writer.WriteLine(); writer.Close(); } ROOTClassShell mainClass = new ROOTClassShell("TestSimpleRename") { NtupleProxyPath = proxyFile.FullName }; mainClass.Add(vIndex); mainClass.Add(vArray); var ntup = new NtupleTreeInfo() { Classes = new ROOTClassShell[] { mainClass }, ClassImplimintationFiles = new string[0] }; var userinfo = new TTreeUserInfo() { Groups = new ArrayGroup[] { new ArrayGroup() { Name = "ungrouped", Variables = new VariableInfo[] { new VariableInfo() { NETName = "n", TTreeName = "n" }, new VariableInfo() { NETName = "arr", TTreeName = "arr"} } } } }; var cg = new ClassGenerator(); var outputFile = new FileInfo("TestCStyleArray.cs"); cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary<string, TTreeUserInfo>() { { "TestSimpleRename", userinfo } }); }
public void GenerateClassFromClasses( ClassGenerator target, int outputChoice, int numExtraFiles, int numExtraFilesToCreate, int extraFileIndexNull, string nameSName, int NumObjectCollection) { if (numExtraFiles < 0 || numExtraFilesToCreate < 0 || extraFileIndexNull < 0 || outputChoice < 0 || NumObjectCollection < 0) { return; } /// /// Kill off the directory we might have left behind from a previous run, and create a new one. /// DirectoryInfo testDir = new DirectoryInfo(".\\GenerateClassFromClasses"); if (testDir.Exists) { testDir.Delete(true); } testDir.Create(); /// /// Setup the input stuff so Pex can play /// FileInfo outputCSFile; if (outputChoice == 1) { outputCSFile = new FileInfo(testDir.FullName + "\\output.cs"); } else { outputCSFile = null; } ROOTClassShell[] objCollect = null; if (NumObjectCollection > 0) { List <ROOTClassShell> objs = new List <ROOTClassShell>(); for (int i = 0; i < NumObjectCollection; i++) { ROOTClassShell rcs = new ROOTClassShell(); rcs.Name = "dude_" + i.ToString(); for (int j = 0; j < i; j++) { IClassItem item = null; switch (NumObjectCollection % 4) { case 0: item = null; break; case 1: var itm = new ItemSimpleType() { ItemType = "int" }; item = itm; break; case 2: var itmv = new ItemVector() { ItemType = "int[]" }; item = itmv; break; case 3: var itmr = new ItemROOTClass() { ItemType = "TLorentzVector" }; item = itmr; break; } if (item != null) { item.Name = "item_" + j.ToString(); } rcs.Items.Add(item); } objs.Add(rcs); } objCollect = objs.ToArray(); } /// /// Create the final object, and any extra files needed! /// NtupleTreeInfo info = new NtupleTreeInfo() { Classes = objCollect }; info.ClassImplimintationFiles = (from c in Enumerable.Range(0, numExtraFiles) let f = new FileInfo(testDir.FullName + "\\GenerateClassFromClasses_extra_" + c.ToString() + ".cpp") select f.FullName ).ToArray(); int maxFilesToCreate = numExtraFilesToCreate > numExtraFiles ? numExtraFiles : numExtraFilesToCreate; for (int i = 0; i < maxFilesToCreate; i++) { using (var w = File.CreateText(info.ClassImplimintationFiles[i])) { w.WriteLine(); w.Close(); } } if (extraFileIndexNull < numExtraFiles) { info.ClassImplimintationFiles[extraFileIndexNull] = null; } /// /// Ok, do the investigation /// target.GenerateClasss(info, outputCSFile, nameSName); Assert.IsFalse(info.ClassImplimintationFiles.Any(c => c == null), "no null implementation files allowed"); Assert.IsFalse(info.ClassImplimintationFiles.Any(c => !File.Exists(c)), "all implimntation files must exist"); /// Check that all the ntuple proxy guys and the temp file guys appear in the file foreach (var item in info.ClassImplimintationFiles) { Assert.IsTrue(FindInFile(outputCSFile, item), "coul dnot find impl file '" + item + "'"); } }
public void GroupWithArrayLengthSpecification() { ItemSimpleType simple1 = new ItemSimpleType("avar", "int[]"); ItemSimpleType simple2 = new ItemSimpleType("bvar", "int[]"); FileInfo proxyFile = new FileInfo("TestColonsInVarNameWRename.cpp"); using (var writer = proxyFile.CreateText()) { writer.WriteLine(); writer.Close(); } ROOTClassShell mainClass = new ROOTClassShell("GroupWithArrayLengthSpecification") { NtupleProxyPath = proxyFile.FullName }; mainClass.Add(simple1); mainClass.Add(simple2); var ntup = new NtupleTreeInfo() { Classes = new ROOTClassShell[] { mainClass }, ClassImplimintationFiles = new string[0] }; var userinfo = new TTreeUserInfo() { Groups = new ArrayGroup[] { new ArrayGroup() { Name = "jets", NETNameOfVariableToUseAsArrayLength ="b", Variables = new VariableInfo[] { new VariableInfo() { NETName = "a", TTreeName = "avar" }, new VariableInfo() { NETName = "b", TTreeName = "bvar" }, } } } }; var cg = new ClassGenerator(); var outputFile = new FileInfo("GroupWithArrayLengthSpecification.cs"); cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary<string, TTreeUserInfo>() { { "GroupWithArrayLengthSpecification", userinfo } }); DumpOutputFile(outputFile); /// Look through this to see if we can make sure there are no renames! Assert.IsTrue(FindInFile(outputFile, "UseAsArrayLength"), "Missing the UseAsArrayLength attribute!!"); }
public void TestColonsInVarName() { ItemSimpleType simple = new ItemSimpleType("dude::fork", "int[]"); FileInfo proxyFile = new FileInfo("TestColonsInVarName.cpp"); using (var writer = proxyFile.CreateText()) { writer.WriteLine(); writer.Close(); } ROOTClassShell mainClass = new ROOTClassShell("TestSimpleGroupAndRename") { NtupleProxyPath = proxyFile.FullName }; mainClass.Add(simple); var ntup = new NtupleTreeInfo() { Classes = new ROOTClassShell[] { mainClass }, ClassImplimintationFiles = new string[0] }; var userinfo = new TTreeUserInfo() { Groups = new ArrayGroup[] { new ArrayGroup() { Name = "jets", Variables = new VariableInfo[] { new VariableInfo() { NETName = "dude::fork", TTreeName = "dude::fork" } } } } }; var cg = new ClassGenerator(); var outputFile = new FileInfo("TestSimpleGroupAndRename.cs"); cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary<string, TTreeUserInfo>() { { "TestSimpleGroupAndRename", userinfo } }); DumpOutputFile(outputFile); /// Look through this to see if we can make sure there are no renames! Assert.IsFalse(FindInFile(outputFile, "dude::fork"), "Saw the double colon!!"); Assert.IsTrue(FindInFile(outputFile, "dude__fork"), "Missing the variable!!"); }
public void TestCharactersInClassName() { ItemSimpleType simple = new ItemSimpleType("fork", "int"); FileInfo proxyFile = new FileInfo("TestColonsInVarName.cpp"); using (var writer = proxyFile.CreateText()) { writer.WriteLine(); writer.Close(); } ROOTClassShell mainClass = new ROOTClassShell("##Shapes") { NtupleProxyPath = proxyFile.FullName }; mainClass.Add(simple); var ntup = new NtupleTreeInfo() { Classes = new ROOTClassShell[] { mainClass }, ClassImplimintationFiles = new string[0] }; var userinfo = new TTreeUserInfo() { Groups = new ArrayGroup[] { new ArrayGroup() { Name = "jets", Variables = new VariableInfo[] { new VariableInfo() { NETName = "fork", TTreeName = "fork" } } } } }; var cg = new ClassGenerator(); var outputFile = new FileInfo("TestCharactersInClassName.cs"); cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary<string, TTreeUserInfo>() { { "TestSimpleGroupAndRename", userinfo } }); DumpOutputFile(outputFile); Assert.AreEqual(3, CountInFile(outputFile, "##Shapes"), "Missing reference ot the shapes object"); }
public void TestNoGroups() { /// Create simple user info - but don't do anything with it! ItemSimpleType simple = new ItemSimpleType("var1", "int[]"); Assert.IsFalse(simple.NotAPointer, "not a pointer"); FileInfo proxyFile = new FileInfo("TestNoGroupsProxy.cpp"); using (var writer = proxyFile.CreateText()) { writer.WriteLine(); writer.Close(); } ROOTClassShell mainClass = new ROOTClassShell("TestSimpleRename") { NtupleProxyPath = proxyFile.FullName }; mainClass.Add(simple); var ntup = new NtupleTreeInfo() { Classes = new ROOTClassShell[] { mainClass }, ClassImplimintationFiles = new string[0] }; var userinfo = new TTreeUserInfo() { Groups = new ArrayGroup[] { new ArrayGroup() { Name = "ungrouped", Variables = new VariableInfo[] { new VariableInfo() { NETName = "var1", TTreeName = "var1" } } } } }; var cg = new ClassGenerator(); var outputFile = new FileInfo("TestNoGroups.cs"); cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary<string, TTreeUserInfo>() { { "TestSimpleRename", userinfo } }); /// Look through this to see if we can make sure there are no renames! Assert.IsFalse(FindInFile(outputFile, "RenameVariable"), "We saw a rename!"); Assert.IsFalse(FindInFile(outputFile, "ungrouped"), "group found"); }
public void TestSimpleGroupWithCustomClassName() { /// Create simple user info - but don't do anything with it! ItemSimpleType simple = new ItemSimpleType("var1", "int[]"); FileInfo proxyFile = new FileInfo("TestSimpleGroupAndRename.cpp"); using (var writer = proxyFile.CreateText()) { writer.WriteLine(); writer.Close(); } ROOTClassShell mainClass = new ROOTClassShell("TestSimpleGroupAndRename") { NtupleProxyPath = proxyFile.FullName }; mainClass.Add(simple); var ntup = new NtupleTreeInfo() { Classes = new ROOTClassShell[] { mainClass }, ClassImplimintationFiles = new string[0] }; var userinfo = new TTreeUserInfo() { Groups = new ArrayGroup[] { new ArrayGroup() { Name = "jets", ClassName = "Jet", Variables = new VariableInfo[] { new VariableInfo() { NETName = "myvar", TTreeName = "var1" } } } } }; var cg = new ClassGenerator(); var outputFile = new FileInfo("TestSimpleGroupAndRename.cs"); cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary<string, TTreeUserInfo>() { { "TestSimpleGroupAndRename", userinfo } }); DumpOutputFile(outputFile); /// Look through this to see if we can make sure there are no renames! Assert.IsTrue(FindInFile(outputFile, "RenameVariable(\"var1\")"), "Rename missing!"); Assert.IsTrue(FindInFile(outputFile, "TTreeVariableGrouping"), "Missing TTreeVariableGrouping"); Assert.IsTrue(FindInFile(outputFile, "jets"), "missing a reference to jets"); Assert.IsTrue(FindInFile(outputFile, "int myvar"), "myvar missing"); Assert.IsTrue(FindInFile(outputFile, "int[] var1"), "val1 missing"); Assert.IsFalse(FindInFile(outputFile, "ungrouped"), "group found"); Assert.IsFalse(FindInFile(outputFile, "TestSimpleGroupAndRenamejets"), "Found the non-class name default class name"); Assert.IsTrue(FindInFile(outputFile, "Jet"), "Did not find the Jet custom class name"); }
public void TestConstCStyleArray() { // Simple set of types for an index array var vArray = new ItemCStyleArray("int[]", new ItemSimpleType("arr", "int")); vArray.Add(0, "10", true); var vIndex = new ItemSimpleType("n", "int"); FileInfo proxyFile = new FileInfo("TestConstCStyleArray.cpp"); using (var writer = proxyFile.CreateText()) { writer.WriteLine(); writer.Close(); } ROOTClassShell mainClass = new ROOTClassShell("TestSimpleRename") { NtupleProxyPath = proxyFile.FullName }; mainClass.Add(vIndex); mainClass.Add(vArray); var ntup = new NtupleTreeInfo() { Classes = new ROOTClassShell[] { mainClass }, ClassImplimintationFiles = new string[0] }; var userinfo = new TTreeUserInfo() { Groups = new ArrayGroup[] { new ArrayGroup() { Name = "ungrouped", Variables = new VariableInfo[] { new VariableInfo() { NETName = "n", TTreeName = "n" }, new VariableInfo() { NETName = "arr", TTreeName = "arr"} } } } }; var cg = new ClassGenerator(); var outputFile = new FileInfo("TestConstCStyleArray.cs"); cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary<string, TTreeUserInfo>() { { "TestSimpleRename", userinfo } }); CopyToOutput(outputFile); /// Look through this to see if we can make sure there are no renames! Assert.IsTrue(FindInFile(outputFile, "int[] arr"), "Array Decl missing"); Assert.IsTrue(FindInFile(outputFile, "int n"), "Index decl missing"); Assert.IsTrue(FindInFile(outputFile, "[ArraySizeIndex(\"10\", IsConstantExpression = true, Index = 0)]"), "Missing array size index attribute"); }
public void TestRenamedIndex() { /// Create simple user info - but don't do anything with it! ItemSimpleType simpleIndex = new ItemSimpleType("index", "int[]"); ItemSimpleType simpleVal = new ItemSimpleType("var1", "float[]"); FileInfo proxyFile = new FileInfo("TestRenamedIndex.cpp"); using (var writer = proxyFile.CreateText()) { writer.WriteLine(); writer.Close(); } ROOTClassShell mainClass = new ROOTClassShell("TestRenamedIndex") { NtupleProxyPath = proxyFile.FullName }; mainClass.Add(simpleIndex); mainClass.Add(simpleVal); var ntup = new NtupleTreeInfo() { Classes = new ROOTClassShell[] { mainClass }, ClassImplimintationFiles = new string[0] }; var userinfo = new TTreeUserInfo() { Groups = new ArrayGroup[] { new ArrayGroup() { Name = "jets", Variables = new VariableInfo[] { new VariableInfo() { NETName = "muons", TTreeName = "index", IndexToGroup="muons" } } }, new ArrayGroup() { Name = "muons", Variables = new VariableInfo[] { new VariableInfo() { NETName = "var1", TTreeName = "var1"} } } } }; var cg = new ClassGenerator(); var outputFile = new FileInfo("TestRenamedIndex.cs"); cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary<string, TTreeUserInfo>() { { "TestRenamedIndex", userinfo } }); DumpOutputFile(outputFile); /// Look through this to see if we can make sure there are no renames! Assert.IsTrue(FindInFile(outputFile, "TTreeVariableGrouping"), "Missing TTreeVariableGrouping"); Assert.IsTrue(FindInFile(outputFile, "jets"), "missing a reference to jets"); Assert.IsTrue(FindInFile(outputFile, "muons"), "missing a reference to jets"); Assert.IsTrue(FindInFile(outputFile, "IndexToOtherObjectArray(typeof("), "Missing IndexToOtherObject"); Assert.IsTrue(FindInFile(outputFile, "TestRenamedIndexmuons muons"), "Muon reference is imporper"); Assert.IsTrue(FindInFile(outputFile, "float var1"), "var1 missing"); Assert.IsFalse(FindInFile(outputFile, "ungrouped"), "group found"); }
public void TestNonIntIndex() { /// Create simple user info - but don't do anything with it! ItemSimpleType simpleIndex = new ItemSimpleType("index", "float[]"); ItemSimpleType simpleVal = new ItemSimpleType("var1", "float[]"); FileInfo proxyFile = new FileInfo("TestNonIntIndex.cpp"); using (var writer = proxyFile.CreateText()) { writer.WriteLine(); writer.Close(); } ROOTClassShell mainClass = new ROOTClassShell("TestNonIntIndex") { NtupleProxyPath = proxyFile.FullName }; mainClass.Add(simpleIndex); mainClass.Add(simpleVal); var ntup = new NtupleTreeInfo() { Classes = new ROOTClassShell[] { mainClass }, ClassImplimintationFiles = new string[0] }; var userinfo = new TTreeUserInfo() { Groups = new ArrayGroup[] { new ArrayGroup() { Name = "jets", Variables = new VariableInfo[] { new VariableInfo() { NETName = "index", TTreeName = "index", IndexToGroup="muons" } } }, new ArrayGroup() { Name = "muons", Variables = new VariableInfo[] { new VariableInfo() { NETName = "var1", TTreeName = "var1"} } } } }; var cg = new ClassGenerator(); var outputFile = new FileInfo("TestNonIntIndex.cs"); cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary<string, TTreeUserInfo>() { { "TestNonIntIndex", userinfo } }); }
public void GenerateClassFromClasses( ClassGenerator target, int outputChoice, int numExtraFiles, int numExtraFilesToCreate, int extraFileIndexNull, int proxyPathChoice, string nameSName, int NumObjectCollection) { if (numExtraFiles < 0 || numExtraFilesToCreate < 0 || extraFileIndexNull < 0 || outputChoice < 0 || proxyPathChoice < 0 || NumObjectCollection < 0) return; /// /// Kill off the directory we might have left behind from a previous run, and create a new one. /// DirectoryInfo testDir = new DirectoryInfo(".\\GenerateClassFromClasses"); if (testDir.Exists) { testDir.Delete(true); } testDir.Create(); /// /// Setup the input stuff so Pex can play /// FileInfo outputCSFile; if (outputChoice == 1) { outputCSFile = new FileInfo(testDir.FullName + "\\output.cs"); } else { outputCSFile = null; } ROOTClassShell[] objCollect = null; if (NumObjectCollection > 0) { List<ROOTClassShell> objs = new List<ROOTClassShell>(); for (int i = 0; i < NumObjectCollection; i++) { ROOTClassShell rcs = new ROOTClassShell(); rcs.Name = "dude_" + i.ToString(); for (int j = 0; j < i; j++) { IClassItem item = null; switch (NumObjectCollection % 4) { case 0: item = null; break; case 1: var itm = new ItemSimpleType() { ItemType = "int" }; item = itm; break; case 2: var itmv = new ItemVector() { ItemType = "int[]" }; item = itmv; break; case 3: var itmr = new ItemROOTClass() { ItemType = "TLorentzVector" }; item = itmr; break; } if (item != null) item.Name = "item_" + j.ToString(); rcs.Items.Add(item); } objs.Add(rcs); } if (NumObjectCollection > 0) { if (proxyPathChoice == 1) { var proxyFile = new FileInfo(testDir.FullName + "\\GenerateClassFromClasses_" + proxyPathChoice.ToString() + ".h"); using (var w = proxyFile.CreateText()) { w.WriteLine("hi"); w.Close(); } objs[0].NtupleProxyPath = proxyFile.FullName; } if (proxyPathChoice == 2) { var proxyFile = new FileInfo(testDir.FullName + "\\GenerateClassFromClasses_" + proxyPathChoice.ToString() + ".h"); objs[0].NtupleProxyPath = proxyFile.FullName; } if (proxyPathChoice == 3) { var proxyFile = new FileInfo(testDir.FullName + "\\GenerateClassFromClasses_" + proxyPathChoice.ToString() + ".h"); using (var w = proxyFile.CreateText()) { w.WriteLine("hi"); w.Close(); } foreach (var item in objs) { item.NtupleProxyPath = proxyFile.FullName; } } } objCollect = objs.ToArray(); } /// /// Create the final object, and any extra files needed! /// NtupleTreeInfo info = new NtupleTreeInfo() { Classes = objCollect }; info.ClassImplimintationFiles = (from c in Enumerable.Range(0, numExtraFiles) let f = new FileInfo(testDir.FullName + "\\GenerateClassFromClasses_extra_" + c.ToString() + ".cpp") select f.FullName ).ToArray(); int maxFilesToCreate = numExtraFilesToCreate > numExtraFiles ? numExtraFiles : numExtraFilesToCreate; for (int i = 0; i < maxFilesToCreate; i++) { using (var w = File.CreateText(info.ClassImplimintationFiles[i])) { w.WriteLine(); w.Close(); } } if (extraFileIndexNull < numExtraFiles) { info.ClassImplimintationFiles[extraFileIndexNull] = null; } /// /// Ok, do the investigation /// target.GenerateClasss(info, outputCSFile, nameSName); Assert.IsFalse(info.Classes.Any(c => c.NtupleProxyPath == null), "No null proxy paths allowed"); Assert.IsFalse(info.Classes.Any(c => !File.Exists(c.NtupleProxyPath)), "proxy files must exist"); Assert.IsFalse(info.ClassImplimintationFiles.Any(c => c == null), "no null implementation files allowed"); Assert.IsFalse(info.ClassImplimintationFiles.Any(c => !File.Exists(c)), "all implimntation files must exist"); /// Check that all the ntuple proxy guys and the temp file guys appear in the file foreach (var item in info.Classes.Where(c => c.IsTopLevelClass)) { Assert.IsTrue(FindInFile(outputCSFile, item.NtupleProxyPath), "Could not find the proxy path '" + item.NtupleProxyPath + "'"); } foreach (var item in info.ClassImplimintationFiles) { Assert.IsTrue(FindInFile(outputCSFile, item), "coul dnot find impl file '" + item + "'"); } }
public void TestRenamedIndex() { /// Create simple user info - but don't do anything with it! ItemSimpleType simpleIndex = new ItemSimpleType("index", "int[]"); ItemSimpleType simpleVal = new ItemSimpleType("var1", "float[]"); ROOTClassShell mainClass = new ROOTClassShell("TestRenamedIndex") { }; mainClass.Add(simpleIndex); mainClass.Add(simpleVal); var ntup = new NtupleTreeInfo() { Classes = new ROOTClassShell[] { mainClass }, ClassImplimintationFiles = new string[0] }; var userinfo = new TTreeUserInfo() { Groups = new ArrayGroup[] { new ArrayGroup() { Name = "jets", Variables = new VariableInfo[] { new VariableInfo() { NETName = "muons", TTreeName = "index", IndexToGroup = "muons" } } }, new ArrayGroup() { Name = "muons", Variables = new VariableInfo[] { new VariableInfo() { NETName = "var1", TTreeName = "var1" } } } } }; var cg = new ClassGenerator(); var outputFile = new FileInfo("TestRenamedIndex.cs"); cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary <string, TTreeUserInfo>() { { "TestRenamedIndex", userinfo } }); DumpOutputFile(outputFile); /// Look through this to see if we can make sure there are no renames! Assert.IsTrue(FindInFile(outputFile, "TTreeVariableGrouping"), "Missing TTreeVariableGrouping"); Assert.IsTrue(FindInFile(outputFile, "jets"), "missing a reference to jets"); Assert.IsTrue(FindInFile(outputFile, "muons"), "missing a reference to jets"); Assert.IsTrue(FindInFile(outputFile, "IndexToOtherObjectArray(typeof("), "Missing IndexToOtherObject"); Assert.IsTrue(FindInFile(outputFile, "TestRenamedIndexmuons muons"), "Muon reference is imporper"); Assert.IsTrue(FindInFile(outputFile, "float var1"), "var1 missing"); Assert.IsFalse(FindInFile(outputFile, "ungrouped"), "group found"); }
public void TestDuplicateClassNames() { var vIndex = new ItemSimpleType("n", "int"); FileInfo proxyFile = new FileInfo("TestCStyleArray.cpp"); using (var writer = proxyFile.CreateText()) { writer.WriteLine(); writer.Close(); } ROOTClassShell mainClass = new ROOTClassShell("TestSimpleRename") { NtupleProxyPath = proxyFile.FullName }; mainClass.Add(vIndex); ROOTClassShell mainClass1 = new ROOTClassShell("TestSimpleRename") { NtupleProxyPath = proxyFile.FullName }; mainClass1.Add(vIndex); var ntup = new NtupleTreeInfo() { Classes = new ROOTClassShell[] { mainClass, mainClass1 }, ClassImplimintationFiles = new string[0] }; var userinfo = new TTreeUserInfo() { Groups = new ArrayGroup[] { new ArrayGroup() { Name = "ungrouped", Variables = new VariableInfo[] { new VariableInfo() { NETName = "n", TTreeName = "n" }, } } } }; var cg = new ClassGenerator(); var outputFile = new FileInfo("TestDuplicateClassNames.cs"); cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary<string, TTreeUserInfo>() { { "TestDuplicateClassNames", userinfo } }); }
/// <summary> /// No parameters b/c that is required for serialization. /// </summary> public ItemCStyleArray() { Indicies = new List<IndexInfo>(); BaseItem = new ItemSimpleType("dude", "int"); // Dummy so we are immune to set order! NotAPointer = false; }
private IClassItem ExtractSimpleItem(SimpleLeafInfo leaf) { string className = TypeDefTranslator.ResolveTypedef(leaf.TypeName); // // Check if it is a c-style array. If it is, then the title will contain // the specification we need to look at for the c-style array bit. This will get // called recursively to parse the actual type after the c-style array bit is stripped off. // if (leaf.Title.Contains("[")) return ExtractCArrayInfo(leaf); // // Next, if the type is a template, special parse that. // var result = TemplateParser.ParseForTemplates(className); if (result is TemplateParser.TemplateInfo) { return ExtractTemplateItem(leaf, result as TemplateParser.TemplateInfo); } /// /// Ok - so it is a single "object" or similar. So we need to look at it and figure /// out how to deal with it. It could be a root object or just an "int" /// var ln = NormalizeLeafName(leaf.Name); IClassItem toAdd = null; if (IsROOTClass(className) && className != "string") { toAdd = new ItemROOTClass(ln, className); } else { toAdd = new ItemSimpleType(ln, className.SimpleCPPTypeToCSharpType()); } if (toAdd == null || toAdd.ItemType == null) { throw new InvalidOperationException("Unknown type - can't translate '" + className + "'."); } return toAdd; }