public void TestDataFileNameMap(bool compressionEnabled)
        {
            //I'm not exactly sure what this test is testing for, but the way files are named by the library
            //is not playing well with this test. Seems like it wants a specific file extension. Some decision
            //will have to be made about how to handle this problem. Does the library need to generate names differently?
            //Or maybe this test should be different?
            var generator  = new DataGenerator();
            var mapping    = new DataFileNameMapping(TEST_DIRECTORY, compressionEnabled);
            var sourcePath = @"..\..\TestInputs\function_def.cpp";
            var srcmlPath  = @"..\..\TestInputs\function_def.xml";

            var mappedPath = mapping.GetTargetPath(sourcePath);

            var actualExtension   = Path.GetExtension(mappedPath);
            var expectedExtension = (compressionEnabled ? XmlSerialization.DEFAULT_COMPRESSED_EXTENSION : XmlSerialization.DEFAULT_EXTENSION);

            StringAssert.AreEqualIgnoringCase(expectedExtension, actualExtension);

            //generator.Generate(srcmlPath, mappedPath);
            LibSrcMLRunner runner = new LibSrcMLRunner();

            runner.GenerateSrcMLFromFile(srcmlPath, mappedPath, Language.CPlusPlus, new Collection <uint> {
                LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION
            }, new Dictionary <string, Language> {
            });


            Assert.That(File.Exists(mappedPath), String.Format("Could not generate {0}", mappedPath));

            var data = XmlSerialization.Load(mappedPath, compressionEnabled);

            Assert.IsNotNull(data, String.Format("Could not load data from {0}. It should {1}be compressed", mappedPath, compressionEnabled ? String.Empty : "not "));
        }
Beispiel #2
0
        public void TestGenerateSrcMLFromFile()
        {
            LibSrcMLRunner run = new LibSrcMLRunner();

            try {
                run.GenerateSrcMLFromFile(Path.Combine(TestInputPath, "input.cpp"), "output", Language.CPlusPlus, new List <UInt32>()
                {
                    LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_MODIFIER
                }, new Dictionary <string, Language>()
                {
                });

                Assert.True(File.Exists("output0.cpp.xml"));
                SrcMLFile srcFile = new SrcMLFile("output0.cpp.xml");
                Assert.IsNotNull(srcFile);

                var files = srcFile.FileUnits.ToList();
                Assert.AreEqual(1, files.Count());

                string file = Path.Combine(TestInputPath, "input.cpp");
                var    f1   = (from ele in files
                               where ele.Attribute("filename").Value == file
                               select ele);
                Assert.AreEqual(file, f1.FirstOrDefault().Attribute("filename").Value);
            }
            catch (SrcMLException e) {
                throw new SrcMLException(e.Message, e);
            }
        }
        public void TestDataFileNameMap(bool compressionEnabled) {
            //I'm not exactly sure what this test is testing for, but the way files are named by the library
            //is not playing well with this test. Seems like it wants a specific file extension. Some decision
            //will have to be made about how to handle this problem. Does the library need to generate names differently?
            //Or maybe this test should be different?
            var generator = new DataGenerator();
            var mapping = new DataFileNameMapping(TEST_DIRECTORY, compressionEnabled);
            var sourcePath = @"..\..\TestInputs\function_def.cpp";
            var srcmlPath = @"..\..\TestInputs\function_def.xml";

            var mappedPath = mapping.GetTargetPath(sourcePath);

            var actualExtension = Path.GetExtension(mappedPath);
            var expectedExtension = (compressionEnabled ? XmlSerialization.DEFAULT_COMPRESSED_EXTENSION : XmlSerialization.DEFAULT_EXTENSION);
            StringAssert.AreEqualIgnoringCase(expectedExtension, actualExtension);

            //generator.Generate(srcmlPath, mappedPath);
            LibSrcMLRunner runner = new LibSrcMLRunner();
            runner.GenerateSrcMLFromFile(srcmlPath, mappedPath, Language.CPlusPlus, new Collection<uint> { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, new Dictionary<string, Language> { });


            Assert.That(File.Exists(mappedPath), String.Format("Could not generate {0}", mappedPath));

            var data = XmlSerialization.Load(mappedPath, compressionEnabled);
            Assert.IsNotNull(data, String.Format("Could not load data from {0}. It should {1}be compressed", mappedPath, compressionEnabled ? String.Empty : "not "));
        }
        public void TestRoundTripWithDefaultExtension(string sourceFileName, bool useCompression)
        {
            var sourceFilePath = Path.Combine(TestInputPath, sourceFileName);
            var destFilePath   = Path.Combine(TestInputPath, DefaultInputName);

            LibSrcMLRunner runner = new LibSrcMLRunner();

            runner.GenerateSrcMLFromFile(sourceFilePath, destFilePath + ".cpp", Language.CPlusPlus, new Collection <UInt32>()
            {
                LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION
            }, new Dictionary <string, Language>()
            {
            });
            Assert.That(File.Exists(destFilePath + ".cpp0.xml"));

            var fileUnit      = SrcMLElement.Load(destFilePath + ".cpp0.xml");
            var dataGenerator = new DataGenerator();
            var nsd           = dataGenerator.Parse(fileUnit.Element(SRC.Unit)) as NamespaceDefinition;

            string outputFileName = Path.ChangeExtension(DefaultOutputName, useCompression ? XmlSerialization.DEFAULT_COMPRESSED_EXTENSION : XmlSerialization.DEFAULT_EXTENSION);

            XmlSerialization.WriteElement(nsd, outputFileName);
            var nsdFromFile = XmlSerialization.Load(outputFileName) as NamespaceDefinition;

            DataAssert.StatementsAreEqual(nsd, nsdFromFile);
        }
        public void TestRoundTrip(string sourceFileName, bool compressOutput) {
            var sourceFilePath = Path.Combine(TestInputPath, sourceFileName);
            var destFilePath = Path.Combine(TestInputPath, DefaultInputName);

            LibSrcMLRunner runner = new LibSrcMLRunner();
            runner.GenerateSrcMLFromFile(sourceFilePath, destFilePath + ".cpp", Language.CPlusPlus, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, new Dictionary<string, Language>() { });
            Assert.That(File.Exists(destFilePath + ".cpp0.xml"));

            var fileUnit = SrcMLElement.Load(destFilePath + ".cpp0.xml");
            var dataGenerator = new DataGenerator();
            var nsd = dataGenerator.Parse(fileUnit.Element(SRC.Unit)) as NamespaceDefinition;

            XmlSerialization.WriteElement(nsd, DefaultOutputName, compressOutput);
            var nsdFromFile = XmlSerialization.Load(DefaultOutputName, compressOutput) as NamespaceDefinition;
            DataAssert.StatementsAreEqual(nsd, nsdFromFile);
        }