Beispiel #1
0
        public void CustomGraphParseDGML()
        {
            string filenameTestOutput  = "testdata/output.dgml";
            string filenameComparision = "testdata/includegraph.dgml";

            string[] noParseDirectories = new[] { Utils.GetExactPathName("testdata/subdir/subdir") };

            IncludeGraph graph = new IncludeGraph();

            graph.AddIncludesRecursively_ManualParsing(Utils.GetExactPathName("testdata/source0.cpp"), Enumerable.Empty <string>(), noParseDirectories);
            graph.AddIncludesRecursively_ManualParsing(Utils.GetExactPathName("testdata/source1.cpp"), Enumerable.Empty <string>(), noParseDirectories);

            // Formatting...
            var includeDirectories = new[] { Path.Combine(System.Environment.CurrentDirectory, "testdata") };

            foreach (var item in graph.GraphItems)
            {
                item.FormattedName = IncludeFormatter.FormatPath(item.AbsoluteFilename, FormatterOptionsPage.PathMode.Shortest_AvoidUpSteps, includeDirectories);
            }

            // To DGML and save.
            // Since we don't want to have absolute paths in our compare/output dgml we hack the graph before writing it out.
            var dgml = RemoveAbsolutePathsFromDGML(graph.ToDGMLGraph(), new[] { System.Environment.CurrentDirectory });

            dgml.Serialize(filenameTestOutput);

            string expectedFile = File.ReadAllText(filenameComparision);
            string writtenFile  = File.ReadAllText(filenameTestOutput);

            Assert.AreEqual(expectedFile, writtenFile);

            // For a clean environment!
            File.Delete(filenameTestOutput);
        }
 private void RemoveAbsolutePathsFromDGML(DGMLGraph dgml, IEnumerable <string> includeDirectories)
 {
     foreach (var item in dgml.Nodes)
     {
         item.Id    = IncludeFormatter.FormatPath(item.Id, FormatterOptionsPage.PathMode.Shortest, includeDirectories);
         item.Label = IncludeFormatter.FormatPath(item.Label, FormatterOptionsPage.PathMode.Shortest, includeDirectories);
     }
     foreach (var link in dgml.Links)
     {
         link.Source = IncludeFormatter.FormatPath(link.Source, FormatterOptionsPage.PathMode.Shortest, includeDirectories);
         link.Target = IncludeFormatter.FormatPath(link.Target, FormatterOptionsPage.PathMode.Shortest, includeDirectories);
     }
 }
Beispiel #3
0
        private DGMLGraph RemoveAbsolutePathsFromDGML(DGMLGraph dgml, IEnumerable <string> includeDirectories)
        {
            var dgml2 = new DGMLGraph();

            foreach (var item in dgml.Nodes)
            {
                DGMLGraph.Node newNode = item;
                newNode.Id = IncludeFormatter.FormatPath(item.Id, FormatterOptionsPage.PathMode.Shortest_AvoidUpSteps, includeDirectories);
                dgml2.Nodes.Add(newNode);
            }
            foreach (var link in dgml.Links)
            {
                DGMLGraph.Link newLink = link;
                newLink.Source = IncludeFormatter.FormatPath(newLink.Source, FormatterOptionsPage.PathMode.Shortest_AvoidUpSteps, includeDirectories);
                newLink.Target = IncludeFormatter.FormatPath(newLink.Target, FormatterOptionsPage.PathMode.Shortest_AvoidUpSteps, includeDirectories);
                dgml2.Links.Add(newLink);
            }

            return(dgml2);
        }