public void MyTestMethod() { var runner = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); runner.GenerateSrcMLFromDirectory("srcmltest", "srcmltest1.xml"); runner.GenerateSrcMLFromFile("srcmltest\\File with spaces.cpp", "testfile.xml"); }
public void MultipleFilesTest_Language() { var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var doc = srcmlObject.GenerateSrcMLFromFiles(new string[] { "srcmltest\\foo.c", "srcmltest\\bar.c" }, "srcml_xml\\multiplefile.xml", Language.CPlusPlus); Assert.IsNotNull(doc); var files = doc.FileUnits.ToList(); Assert.AreEqual(2, files.Count()); string file = "srcmltest\\foo.c"; var f1 = (from ele in files where ele.Attribute("filename").Value == file select ele); Assert.AreEqual("srcmltest\\foo.c", f1.FirstOrDefault().Attribute("filename").Value); Assert.AreEqual("C++", f1.FirstOrDefault().Attribute("language").Value); string file2 = "srcmltest\\bar.c"; var f2 = (from ele in files where ele.Attribute("filename").Value == file2 select ele); Assert.AreEqual("srcmltest\\bar.c", f2.FirstOrDefault().Attribute("filename").Value); Assert.AreEqual("C++", f2.FirstOrDefault().Attribute("language").Value); }
public void MultipleFilesTest_DifferentDirectories() { var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var doc = srcmlObject.GenerateSrcMLFromFiles(new string[] { "srcmltest\\foo.c", "srcmltest\\bar.c", "..\\..\\TestInputs\\baz.cpp" }, "srcml_xml\\multiplefile.xml"); Assert.IsNotNull(doc); var files = doc.FileUnits.ToList(); Assert.AreEqual(3, files.Count()); string file = "srcmltest\\foo.c"; var f1 = (from ele in files where ele.Attribute("filename").Value == file select ele); Assert.AreEqual("srcmltest\\foo.c", f1.FirstOrDefault().Attribute("filename").Value); string file1 = "srcmltest\\bar.c"; var f2 = (from ele in files where ele.Attribute("filename").Value == file1 select ele); Assert.AreEqual("srcmltest\\bar.c", f2.FirstOrDefault().Attribute("filename").Value); string file2 = "\\..\\TestInputs\\baz.cpp"; var f3 = (from ele in files where ele.Attribute("filename").Value == file2 select ele); Console.WriteLine(f3.FirstOrDefault().Value); Assert.AreEqual("\\..\\TestInputs\\baz.cpp", f3.FirstOrDefault().Attribute("filename").Value); }
public void MethodWithFunctionPointerAsParameter() { var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var doc = srcmlObject.GenerateSrcMLFromFile("external\\MethodWithFunctionPointerParameters.cpp", "external_xml\\MethodWithFunctionPointerParameters.cpp.xml"); Assert.AreEqual(2, doc.FileUnits.First().Element(SRC.Function).Element(SRC.ParameterList).Elements(SRC.Parameter).Count()); }
public void DestructorWithIfStatement() { var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var doc = srcmlObject.GenerateSrcMLFromFile("external\\DestructorWithIfStatement.cpp", "external_xml\\DestructorWithIfStatement.cpp.xml"); Assert.AreEqual(1, doc.FileUnits.First().Descendants(SRC.Destructor).Count()); }
public void FunctionWithElseInCpp() { var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var doc = srcmlObject.GenerateSrcMLFromFile("external\\cpp_parsing_error.c", "external_xml\\cpp_parsing_error.c.xml"); Assert.AreEqual(1, doc.FileUnits.First().Elements().Count(), srcmlObject.ApplicationDirectory); }
public void MacroWithoutSemicolon() { var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var doc = srcmlObject.GenerateSrcMLFromFile("external\\MacroWithoutSemicolon.cpp", "external_xml\\MacroWithoutSemicolon.cpp.xml"); Assert.AreEqual(2, doc.FileUnits.First().Descendants(SRC.If).Count()); }
public void InputWithSpacesTest() { var runner = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var doc = runner.GenerateSrcMLFromFile("srcmltest\\File with spaces.cpp", "srcml_xml\\input_with_spaces.xml"); Assert.IsNotNull(doc); Assert.AreEqual(1, doc.FileUnits.Count()); }
public void DifferentLanguageTest() { var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var doc = srcmlObject.GenerateSrcMLFromFile("srcmltest\\CSHARP.cs", "srcml_xml\\differentlanguage_java.xml", Language.Java); Assert.IsNotNull(doc); }
public void SingleFileTest() { var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var doc = srcmlObject.GenerateSrcMLFromFile("srcmltest\\foo.c", "srcml_xml\\singlefile.xml"); Assert.IsNotNull(doc); Assert.AreEqual(1, doc.FileUnits.Count()); Assert.AreEqual("srcmltest\\foo.c", doc.FileUnits.First().Attribute("filename").Value); }
public void SingleFileToFileAndXElementTest() { var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); XElement xElement = srcmlObject.GenerateSrcMLAndXElementFromFile("srcmltest\\foo.c", "srcml_xml\\singlefile.xml"); Assert.IsNotNull(xElement); //Assert.AreEqual(1, doc.FileUnits.Count()); //Assert.AreEqual("srcmltest\\foo.c", doc.FileUnits.First().Attribute("filename").Value); Assert.That(File.Exists("srcml_xml\\singlefile.xml")); }
public void TestCSharpExpressionWithDefaultKeyword() { var generator = new SrcMLGenerator(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); generator.GenerateSrcMLFromFile("external\\TestCSharpExpressionWithDefaultKeyword.cs", "external_xml\\TestCSharpExpressionWithDefaultKeyword.cs.xml"); var fileUnit = SrcMLElement.Load("external_xml\\TestCSharpExpressionWithDefaultKeyword.cs.xml"); var classB = fileUnit.Element(SRC.Class); Assert.IsNotNull(classB); Assert.AreEqual(2, classB.Descendants(SRC.Function).Count()); }
public void GetSrcLineNumberWithMultipleUnit() { var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var doc = srcmlObject.GenerateSrcMLFromDirectory("srctest", "srctest_xml\\multipleunit_linenumber.xml"); var firstUnit = doc.FileUnits.First(); Assert.AreEqual(1, firstUnit.Element(SRC.Function).GetSrcLineNumber()); Assert.AreEqual(2, firstUnit.Descendants(SRC.Call).First().GetSrcLineNumber()); }
public void JavaClassWithConstructor() { var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var doc = srcmlObject.GenerateSrcMLFromFile("external\\ClassWithConstructor.java", "external_xml\\ClassWithConstructor.java.xml"); XElement classBlock = null; classBlock = doc.FileUnits.First().Element(SRC.Class).Element(SRC.Block); Assert.AreEqual(1, classBlock.Elements(SRC.Function).Count(), srcmlObject.ApplicationDirectory); }
public void EmptyOutputFileTest() { var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); File.WriteAllText("srcml_xml\\emptyFile.xml", ""); Assert.IsTrue(File.Exists("srcml_xml\\emptyFile.xml")); var doc = srcmlObject.GenerateSrcMLFromFile("srcmltest\\foo.c", "srcml_xml\\emptyFile.xml"); Assert.IsNotNull(doc); Assert.AreEqual(1, doc.FileUnits.Count()); }
public void OpenSolution(string testSolutionFilePath) { // Get the components service context = VsIdeTestHostContext.ServiceProvider.GetService(typeof(SComponentModel)) as IComponentModel; // Open a solution that is the initial state for your tests ModelSolution = VsIdeTestHostContext.Dte.Solution; ModelSolution.Open(Path.GetFullPath(testSolutionFilePath)); Assert.IsNotNull(ModelSolution, "VS solution not found"); // Start up srcMLService.StartMonitoring(true, SrcMLHelper.GetSrcMLDefaultDirectory()); System.Threading.Thread.Sleep(3000); }
public void SrcMLFromStringTest() { string sourceCode = @"int foo() { printf(""hello world!""); }"; var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); string xml = srcmlObject.GenerateSrcMLFromString(sourceCode, Language.C); XElement element = XElement.Parse(xml); Assert.IsNotNull(element); }
public void ExtraNewlinesInMergedDocumentTest() { var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var doc = srcmlObject.GenerateSrcMLFromDirectory("srcmlfiletest", "test.xml"); foreach (var unit in doc.FileUnits) { var path = doc.GetPathForUnit(unit); var firstElement = unit.Elements().First(); Assert.AreEqual(1, firstElement.GetSrcLineNumber(), path); } }
public void GetLineInfoWithString() { var source = @"int foo() { printf(""hello world!""); }"; var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var xml = srcmlObject.GenerateSrcMLFromString(source); var element = XElement.Parse(xml).Elements().First(); Assert.AreEqual(1, element.GetSrcLineNumber()); Assert.AreEqual(1, element.GetSrcLinePosition()); }
public void ToSourceTest() { var text = File.ReadAllText("srctest\\foo.c"); var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var doc = srcmlObject.GenerateSrcMLFromFile("srctest\\foo.c", "srctest_xml\\srctest_tosource.xml"); var firstUnit = doc.FileUnits.First(); string contentsFromXml = firstUnit.ToSource(); Assert.AreEqual(text, contentsFromXml); }
public void TestCppStaticTypeModifier() { var generator = new SrcMLGenerator(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); generator.GenerateSrcMLFromFile("external\\TestCppTypeModifiers.cpp", "external_xml\\TestCppStaticModifier.cpp.xml"); var fileUnit = SrcMLElement.Load("external_xml\\TestCppStaticModifier.cpp.xml"); var typeWithStatic = fileUnit.Descendants(SRC.Declaration).LastOrDefault(); Assert.IsNotNull(typeWithStatic); var staticModifier = typeWithStatic.Elements(SRC.Specifier).FirstOrDefault(); Assert.IsNotNull(staticModifier); Assert.AreEqual("static", staticModifier.Value); }
public void TestCSharpUsingStatement() { var generator = new SrcMLGenerator(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); generator.GenerateSrcMLFromFile("external\\TestCSharpUsingStatement.cs", "external_xml\\TestCSharpUsingStatement.cs.xml"); var fileUnit = SrcMLElement.Load("external_xml\\TestCSharpUsingStatement.cs.xml"); var usingBlock = fileUnit.Elements(SRC.Using_Stmt).FirstOrDefault(); Assert.IsNotNull(usingBlock); Assert.AreEqual(1, usingBlock.Elements(SRC.Init).Count()); Assert.AreEqual(1, usingBlock.Elements(SRC.Block).Count()); }
public Src2SrcMLPreviewWindow() { ToggleShowPositionCommand.InputGestures.Add(new KeyGesture(Key.P, ModifierKeys.Alt)); SelectSrcMLDirectoryCommand.InputGestures.Add(new KeyGesture(Key.D, ModifierKeys.Alt)); binDirIsValid = true; directorySelector = new System.Windows.Forms.FolderBrowserDialog(); directorySelector.ShowNewFolderButton = false; directorySelector.SelectedPath = SrcMLHelper.GetSrcMLDefaultDirectory(); _language = ABB.SrcML.Language.CPlusPlus; InitializeComponent(); XmlGenerator = new SrcMLGenerator(directorySelector.SelectedPath, _namespaceArguments); }
public void TestCSharpExpressionWithRemove() { var generator = new SrcMLGenerator(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); generator.GenerateSrcMLFromFile("external\\TestCSharpExpressionWithRemove.cs", "external_xml\\TestCSharpExpressionWithRemove.cs.xml"); var fileUnit = SrcMLElement.Load("external_xml\\TestCSharpExpressionWithRemove.cs.xml"); var method = fileUnit.Descendants(SRC.Function).FirstOrDefault(); Assert.IsNotNull(method); var methodBlock = method.Element(SRC.Block); Assert.IsNotNull(methodBlock); Assert.AreEqual(1, methodBlock.Elements(SRC.ExpressionStatement).Count()); }
public void ContainsCallToTest() { string source = @"int foo() { printf(""hello world!""); int x = 5; }"; var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var xml = srcmlObject.GenerateSrcMLFromString(source); var element = XElement.Parse(xml); var expression = element.Descendants(SRC.DeclarationStatement).First(); Assert.IsTrue(element.ContainsCallTo("printf")); Assert.IsFalse(expression.ContainsCallTo("printf")); }
public void GetSrcLineNumberWithSingleUnit() { File.WriteAllText("srctest\\singleunitlinenum.c", @"int foo() { printf(""hello world!""); }"); var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var doc = srcmlObject.GenerateSrcMLFromFile("srctest\\singleunitlinenum.c", @"srctest_xml\singleunit_linenumber.xml"); var unit = doc.FileUnits.First(); Assert.AreEqual(1, unit.GetSrcLineNumber()); Assert.AreEqual(1, unit.Element(SRC.Function).GetSrcLineNumber()); Assert.AreEqual(2, unit.Descendants(SRC.Call).First().GetSrcLineNumber()); }
public void InvalidLanguageTest() { var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var doc = srcmlObject.GenerateSrcMLFromFile("srcmltest\\foo.c", "srcml_xml\\invalidlanguage_java.xml", Language.Java); Assert.IsNotNull(doc); doc = null; doc = srcmlObject.GenerateSrcMLFromFile("srcmltest\\foo.c", "srcml_xml\\invalidlanguage_cpp.xml", Language.CPlusPlus); Assert.IsNotNull(doc); doc = null; doc = srcmlObject.GenerateSrcMLFromFile("srcmltest\\foo.c", "srcml_xml\\invalidlanguage_c.xml", Language.C); Assert.IsNotNull(doc); }
public void DeclStmtWithTwoDecl() { const int NumNamesInDecl = 1; const int NumInitInDecl = 1; var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var source = "int x = 0, y = 2;"; var xml = srcmlObject.GenerateSrcMLFromString(source); var element = XElement.Parse(xml); var decl = element.Element(SRC.DeclarationStatement).Element(SRC.Declaration); var nameCount = decl.Elements(SRC.Name).Count(); var initCount = decl.Elements(SRC.Init).Count(); Assert.AreEqual(NumNamesInDecl, nameCount, srcmlObject.ApplicationDirectory); Assert.AreEqual(NumInitInDecl, initCount, srcmlObject.ApplicationDirectory); }
public void CheckPositionNumberWithSingleUnit() { var srcmlObject = new ABB.SrcML.SrcML(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var doc = srcmlObject.GenerateSrcMLFromFile(@"srctest\foo.c", @"srctest_xml\singleunit_position.xml"); var firstUnit = doc.FileUnits.First(); Assert.AreEqual(0, firstUnit.GetSrcLinePosition()); Assert.AreEqual(1, firstUnit.Descendants(SRC.Type).First().Element(SRC.Name).GetSrcLinePosition()); Assert.AreEqual(1, firstUnit.Element(SRC.Function).GetSrcLinePosition()); Assert.AreEqual(5, firstUnit.Descendants(SRC.Name).First(n => n.Value == "foo").GetSrcLinePosition()); Assert.AreEqual(5, firstUnit.Descendants(SRC.Name).First(n => n.Value == "printf").GetSrcLinePosition()); Assert.AreEqual(45, firstUnit.Descendants(SRC.Name).First(n => n.Value == "printd").GetSrcLinePosition()); Assert.AreEqual(6, firstUnit.Descendants(SRC.Name).First(n => n.Value == "bar").GetSrcLinePosition()); Assert.AreEqual(10, firstUnit.Descendants(SRC.Condition).First().GetSrcLinePosition()); Assert.AreEqual(9, firstUnit.Descendants(SRC.Name).First(n => n.Value == "printg").GetSrcLinePosition()); }
public void ExclusionFilterTest() { var exclusionList = new List <string>(); exclusionList.Add("srcmltest\\bar.c"); exclusionList.Add("srcmltest\\BadPathâ„¢\\badPathTest.c"); exclusionList.Add("srcmltest\\fooBody.c"); var srcmlObject = new Src2SrcMLRunner(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var doc = srcmlObject.GenerateSrcMLFromDirectory("srcmltest", "srcml_xml\\exclusionfilter.xml", exclusionList, Language.C); var numFileUnits = doc.FileUnits.Count(); string firstSourceFile = null; if (numFileUnits > 0) { firstSourceFile = doc.FileUnits.First().Attribute("filename").Value; } Assert.AreEqual(1, numFileUnits, "test.xml should have only one file in it"); Assert.AreEqual(Path.GetFullPath("srcmltest\\foo.c"), firstSourceFile); }