Mercurial > projects > dil
comparison src/docgen/tests/graphs.d @ 806:bcb74c9b895c
Moved out files in the trunk folder to the root.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sun, 09 Mar 2008 00:12:19 +0100 |
parents | trunk/src/docgen/tests/graphs.d@231c9a44ba8e |
children |
comparison
equal
deleted
inserted
replaced
805:a3fab8b74a7d | 806:bcb74c9b895c |
---|---|
1 /** | |
2 * Author: Jari-Matti Mäkelä | |
3 * License: GPL3 | |
4 */ | |
5 module docgen.tests.graphs; | |
6 | |
7 import docgen.tests.common; | |
8 import docgen.misc.parser; | |
9 import docgen.graphutils.writers; | |
10 import docgen.page.writers; | |
11 import tango.io.FileConduit; | |
12 import dil.semantic.Module; | |
13 | |
14 alias DepGraph.Edge Edge; | |
15 alias DepGraph.Vertex Vertex; | |
16 | |
17 void saveDefaultGraph(DepGraph depGraph, char[] fname) { | |
18 auto gen = new TestDocGenerator; | |
19 gen.options.graph.highlightCyclicVertices = true; | |
20 gen.options.graph.imageFormat = ImageFormat.SVG; | |
21 //gen.options.graph.graphFormat = GraphFormat.ModuleNames; | |
22 //gen.options.graph.graphFormat = GraphFormat.ModulePaths; | |
23 gen.options.graph.depth = 5; | |
24 auto ddf = new DefaultPageWriterFactory(gen); | |
25 auto gwf = new DefaultGraphWriterFactory(gen); | |
26 auto file = new FileConduit("docgen/teststuff/" ~ fname, FileConduit.WriteCreate); | |
27 auto file2 = new FileConduit("docgen/teststuff/" ~ fname ~ "-2", FileConduit.WriteCreate); | |
28 | |
29 auto writer = gwf.createGraphWriter( | |
30 ddf.createPageWriter( [ file2 ], DocFormat.LaTeX), | |
31 GraphFormat.Dot | |
32 ); | |
33 | |
34 writer.generateDepGraph(depGraph, file); | |
35 | |
36 file.close(); | |
37 file2.close(); | |
38 } | |
39 | |
40 // no edges | |
41 //@unittest | |
42 void graph1() { | |
43 auto g = new DepGraph; | |
44 g.add(new Vertex("mod_a", "path.to.mod_a", 1)); | |
45 g.add(new Vertex("mod_b", "path.to.mod_b", 2)); | |
46 g.add(new Vertex("mod_c", "path.to.mod_c", 3)); | |
47 | |
48 saveDefaultGraph(g, "graph1.dot"); | |
49 } | |
50 | |
51 | |
52 // simple tree structure | |
53 //@unittest | |
54 void graph2() { | |
55 auto g = new DepGraph; | |
56 g.add(new Vertex("mod_a", "path.to.mod_a", 1)); | |
57 g.add(new Vertex("mod_b", "path.to.mod_b", 2)); | |
58 g.add(new Vertex("mod_c", "path.to.mod_c", 3)); | |
59 g.add(new Vertex("mod_d", "path.to.mod_d", 4)); | |
60 | |
61 g.connect(1, 0); | |
62 g.connect(2, 0); | |
63 g.connect(3, 2); | |
64 | |
65 saveDefaultGraph(g, "graph2.dot"); | |
66 } | |
67 | |
68 // circular imports | |
69 //@unittest | |
70 void graph3() { | |
71 auto g = new DepGraph; | |
72 g.add(new Vertex("mod_a", "path.to.mod_a", 1)); | |
73 g.add(new Vertex("mod_b", "path.to.mod_b", 2)); | |
74 g.add(new Vertex("mod_c", "path.to.mod_c", 3)); | |
75 g.add(new Vertex("mod_d", "path.to.mod_d", 4)); | |
76 | |
77 g.connect(1, 0); | |
78 g.connect(2, 1); | |
79 g.connect(0, 2); | |
80 | |
81 saveDefaultGraph(g, "graph3.dot"); | |
82 } | |
83 | |
84 // more complex graph | |
85 //@unittest | |
86 void graph4() { | |
87 auto g = new DepGraph; | |
88 g.add(new Vertex("mod_a", "path.to.mod_a", 1)); | |
89 g.add(new Vertex("mod_b", "path.to.mod_b", 2)); | |
90 g.add(new Vertex("mod_c", "path.to.mod_c", 3)); | |
91 g.add(new Vertex("mod_d", "path.to.mod_d", 4)); | |
92 g.add(new Vertex("mod_e", "path.to.mod_e", 5)); | |
93 g.add(new Vertex("mod_f", "path.to.mod_f", 6)); | |
94 g.add(new Vertex("mod_g", "path.to.mod_g", 7)); | |
95 | |
96 g.connect(1, 0); | |
97 g.connect(2, 1); | |
98 g.connect(0, 2); | |
99 g.connect(0, 3); | |
100 g.connect(0, 4); | |
101 g.connect(3, 1); | |
102 g.connect(4, 1); | |
103 g.connect(0, 6); | |
104 g.connect(5, 1); | |
105 g.connect(5, 6); | |
106 g.connect(6, 0); | |
107 | |
108 saveDefaultGraph(g, "graph4.dot"); | |
109 } | |
110 | |
111 | |
112 // parses the test modules and creates a dep graph | |
113 //@unittest | |
114 void graph5() { | |
115 auto gen = new TestDocGenerator; | |
116 gen.options.graph.highlightCyclicVertices = true; | |
117 gen.options.graph.imageFormat = ImageFormat.PDF; | |
118 gen.options.outputFormats = [ DocFormat.LaTeX ]; | |
119 auto fname = "dependencies.tex"; | |
120 auto imgFname = "depgraph.dot"; | |
121 | |
122 auto ddf = new DefaultPageWriterFactory(gen); | |
123 auto gwf = new DefaultGraphWriterFactory(gen); | |
124 auto file = new FileConduit("docgen/teststuff/" ~ fname, FileConduit.WriteCreate); | |
125 auto imgFile = new FileConduit("docgen/teststuff/" ~ imgFname, FileConduit.WriteCreate); | |
126 | |
127 Module[] modules; | |
128 Edge[] edges; | |
129 Vertex[char[]] vertices; | |
130 int id = 1; | |
131 | |
132 Parser.loadModules( | |
133 [ "c" ], [ "docgen/teststuff/" ], | |
134 null, true, -1, | |
135 (char[] fqn, char[] path, Module m) { | |
136 vertices[m.moduleFQN] = new DepGraph.Vertex(m.moduleFQN, m.filePath, id++); | |
137 }, | |
138 (Module imported, Module importer, bool isPublic, bool isStatic) { | |
139 auto edge = vertices[imported.moduleFQN].addChild(vertices[importer.moduleFQN]); | |
140 edge.isPublic = isPublic; | |
141 edge.isStatic = isStatic; | |
142 edges ~= edge; | |
143 }, | |
144 modules | |
145 ); | |
146 | |
147 auto writer = gwf.createGraphWriter( | |
148 ddf.createPageWriter( [ file ], DocFormat.LaTeX ), | |
149 GraphFormat.Dot | |
150 ); | |
151 | |
152 auto graph = new DepGraph; | |
153 graph.edges = edges; | |
154 graph.vertices = vertices.values; | |
155 | |
156 writer.generateDepGraph(graph, imgFile); | |
157 | |
158 file.close(); | |
159 imgFile.close(); | |
160 } |