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());
        }
Beispiel #2
0
        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 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 InputWithSpacesTest()
        {
            var runner = new Src2SrcMLRunner(Path.Combine(".", "SrcML"));
            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(".", "SrcML"));

            var doc = srcmlObject.GenerateSrcMLFromFile("srcmltest\\CSHARP.cs", "srcml_xml\\differentlanguage_java.xml", Language.Java);

            Assert.IsNotNull(doc);
        }
Beispiel #6
0
        public void MethodWithFunctionPointerAsParameter()
        {
            var srcmlObject = new Src2SrcMLRunner(Path.Combine(".", "SrcML"));

            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());
        }
Beispiel #7
0
        public void FunctionWithElseInCpp()
        {
            var srcmlObject = new Src2SrcMLRunner();

            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 InvalidLanguageTest()
        {
            var srcmlObject = new Src2SrcMLRunner(Path.Combine(".", "SrcML"));

            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);
        }
Beispiel #9
0
        public void DestructorWithIfStatement()
        {
            var srcmlObject = new Src2SrcMLRunner(Path.Combine(".", "SrcML"));

            var doc = srcmlObject.GenerateSrcMLFromFile("external\\DestructorWithIfStatement.cpp", "external_xml\\DestructorWithIfStatement.cpp.xml");

            Assert.AreEqual(1, doc.FileUnits.First().Descendants(SRC.Destructor).Count());
        }
Beispiel #10
0
        public void MacroWithoutSemicolon()
        {
            var srcmlObject = new Src2SrcMLRunner(Path.Combine(".", "SrcML"));

            var doc = srcmlObject.GenerateSrcMLFromFile("external\\MacroWithoutSemicolon.cpp", "external_xml\\MacroWithoutSemicolon.cpp.xml");

            Assert.AreEqual(2, doc.FileUnits.First().Descendants(SRC.If).Count());
        }
Beispiel #11
0
        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 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);
        }
Beispiel #13
0
        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 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 SingleFileTest()
        {
            var srcmlObject = new Src2SrcMLRunner(Path.Combine(".", "SrcML"));

            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);
        }
Beispiel #16
0
        public void JavaClassWithConstructor()
        {
            var srcmlObject = new Src2SrcMLRunner();

            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(".", "SrcML"));

            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 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());
        }
Beispiel #19
0
        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);
        }
Beispiel #20
0
        public void ToSourceTest()
        {
            var text = File.ReadAllText("srctest\\foo.c");

            var srcmlObject = new Src2SrcMLRunner();

            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);
        }
Beispiel #21
0
        public void GetSrcLineNumberWithSingleUnit()
        {
            File.WriteAllText("srctest\\singleunitlinenum.c", @"int foo() {
printf(""hello world!"");
}");
            var srcmlObject = new Src2SrcMLRunner();

            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());
        }
Beispiel #22
0
        public void ParentStatementTest()
        {
            var srcmlObject = new Src2SrcMLRunner();

            var doc       = srcmlObject.GenerateSrcMLFromFile("srctest\\foo.c", "srctest_xml\\srctest_parentstatement.xml");
            var firstUnit = doc.FileUnits.First();
            var function  = firstUnit.Element(SRC.Function);

            var expression = function.Element(SRC.Block).Element(SRC.ExpressionStatement);
            var call       = expression.Descendants(SRC.Call).First();

            var declaration = function.Element(SRC.Block).Element(SRC.DeclarationStatement);
            var variable    = declaration.Element(SRC.Declaration).Element(SRC.Name);

            var unitParent     = firstUnit.ParentStatement();
            var functionParent = function.ParentStatement();
            var callParent     = call.ParentStatement();
            var variableParent = variable.ParentStatement();

            Assert.IsNull(unitParent);
            Assert.IsNull(functionParent);
            Assert.AreEqual(callParent, expression);
            Assert.AreEqual(declaration, variableParent);
        }