Mercurial > projects > dil
annotate trunk/src/docgen/tests/graphs.d @ 452:f658ec4a15dd
Simple docgen ui util, some fixes.
author | Jari-Matti M?kel? <jmjm@iki.fi> |
---|---|
date | Wed, 24 Oct 2007 22:31:38 +0300 |
parents | 3f44c38bf870 |
children | 4e5b35df3060 |
rev | line source |
---|---|
441 | 1 /** |
2 * Author: Jari-Matti Mäkelä | |
3 * License: GPL3 | |
4 */ | |
5 module docgen.tests.graphs; | |
6 | |
446 | 7 import docgen.tests.common; |
449
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
8 import docgen.misc.parser; |
441 | 9 import docgen.graphutils.writers; |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
10 import docgen.document.writers; |
441 | 11 import tango.io.Stdout; |
12 import tango.io.FileConduit; | |
449
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
13 import dil.Module; |
441 | 14 |
15 void saveDefaultGraph(Vertex[] vertices, Edge[] edges, char[] fname) { | |
446 | 16 auto gen = new TestDocGenerator; |
452
f658ec4a15dd
Simple docgen ui util, some fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
451
diff
changeset
|
17 gen.options.graph.highlightCyclicVertices = true; |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
18 gen.options.graph.imageFormat = ImageFormat.SVG; |
446 | 19 gen.options.graph.graphFormat = GraphFormat.Dot; |
20 //gen.options.graph.graphFormat = GraphFormat.ModuleNames; | |
21 //gen.options.graph.graphFormat = GraphFormat.ModulePaths; | |
22 gen.options.graph.depth = 5; | |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
23 auto ddf = new DefaultDocumentWriterFactory(gen); |
446 | 24 auto gwf = new DefaultGraphWriterFactory(gen); |
441 | 25 auto file = new FileConduit("docgen/teststuff/" ~ fname, FileConduit.WriteCreate); |
26 auto file2 = new FileConduit("docgen/teststuff/" ~ fname ~ "-2", FileConduit.WriteCreate); | |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
27 auto writer = gwf.createGraphWriter( ddf.createDocumentWriter( [ file2 ] ) ); |
441 | 28 |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
29 writer.generateGraph(vertices, edges, file); |
441 | 30 |
31 file.close(); | |
32 file2.close(); | |
33 } | |
34 | |
35 // no edges | |
36 //@unittest | |
37 void graph1() { | |
38 auto a = new Vertex("mod_a", "path.to.mod_a", 1); | |
39 auto b = new Vertex("mod_b", "path.to.mod_b", 2); | |
40 auto c = new Vertex("mod_c", "path.to.mod_c", 3); | |
41 | |
42 saveDefaultGraph( [a,b,c], null, "graph1.dot" ); | |
43 } | |
44 | |
45 | |
46 // simple tree structure | |
47 //@unittest | |
48 void graph2() { | |
49 auto a = new Vertex("mod_a", "path.to.mod_a", 1); | |
50 auto b = new Vertex("mod_b", "path.to.mod_b", 2); | |
51 auto c = new Vertex("mod_c", "path.to.mod_c", 3); | |
52 auto d = new Vertex("mod_d", "path.to.mod_d", 4); | |
53 | |
54 Edge[] edges; | |
55 edges ~= a.addChild(b); | |
56 edges ~= a.addChild(c); | |
57 edges ~= c.addChild(d); | |
58 | |
59 saveDefaultGraph( [a,b,c,d], edges, "graph2.dot" ); | |
60 } | |
61 | |
62 // circular imports | |
63 //@unittest | |
64 void graph3() { | |
65 auto a = new Vertex("mod_a", "path.to.mod_a", 1); | |
66 auto b = new Vertex("mod_b", "path.to.mod_b", 2); | |
67 auto c = new Vertex("mod_c", "path.to.mod_c", 3); | |
68 auto d = new Vertex("mod_d", "path.to.mod_d", 4); | |
69 | |
70 Edge[] edges; | |
71 edges ~= a.addChild(b); | |
72 edges ~= b.addChild(c); | |
73 edges ~= c.addChild(a); | |
74 | |
75 saveDefaultGraph( [a,b,c,d], edges, "graph3.dot" ); | |
76 } | |
77 | |
78 // more complex graph | |
79 //@unittest | |
80 void graph4() { | |
81 auto a = new Vertex("mod_a", "path.to.mod_a", 1); | |
82 auto b = new Vertex("mod_b", "path.to.mod_b", 2); | |
83 auto c = new Vertex("mod_c", "path.to.mod_c", 3); | |
84 auto d = new Vertex("mod_d", "path.to.mod_d", 4); | |
85 auto e = new Vertex("mod_e", "path.to.mod_e", 5); | |
86 auto f = new Vertex("mod_f", "path.to.mod_f", 6); | |
87 auto g = new Vertex("mod_g", "path.to.mod_g", 7); | |
88 | |
89 Edge[] edges; | |
90 edges ~= a.addChild(b); | |
91 edges ~= b.addChild(c); | |
92 edges ~= c.addChild(a); | |
93 edges ~= d.addChild(a); | |
94 edges ~= e.addChild(a); | |
95 edges ~= b.addChild(d); | |
96 edges ~= b.addChild(e); | |
97 edges ~= g.addChild(a); | |
98 edges ~= b.addChild(f); | |
99 edges ~= g.addChild(f); | |
100 edges ~= a.addChild(g); | |
101 | |
102 saveDefaultGraph( [a,b,c,d,e,f,g], edges, "graph4.dot" ); | |
449
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
103 } |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
104 |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
105 |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
106 // parses the test modules and creates a dep graph |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
107 //@unittest |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
108 void graph5() { |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
109 auto gen = new TestDocGenerator; |
452
f658ec4a15dd
Simple docgen ui util, some fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
451
diff
changeset
|
110 gen.options.graph.highlightCyclicVertices = true; |
449
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
111 gen.options.graph.graphFormat = GraphFormat.Dot; |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
112 gen.options.graph.imageFormat = ImageFormat.SVG; |
449
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
113 gen.options.docFormat = DocFormat.LaTeX; |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
114 auto fname = "dependencies.tex"; |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
115 auto imgFname = "depgraph.dot"; |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
116 |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
117 auto ddf = new DefaultDocumentWriterFactory(gen); |
449
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
118 auto gwf = new DefaultGraphWriterFactory(gen); |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
119 auto file = new FileConduit("docgen/teststuff/" ~ fname, FileConduit.WriteCreate); |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
120 auto imgFile = new FileConduit("docgen/teststuff/" ~ imgFname, FileConduit.WriteCreate); |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
121 |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
122 Module[] modules; |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
123 Edge[] edges; |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
124 Vertex[char[]] vertices; |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
125 int id = 1; |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
126 |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
127 Parser.loadModules( |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
128 [ "c" ], [ "docgen/teststuff/" ], |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
129 null, true, -1, |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
130 (char[] fqn, char[] path, Module m) { |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
131 vertices[m.moduleFQN] = new Vertex(m.moduleFQN, m.filePath, id++); |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
132 }, |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
133 (Module imported, Module importer) { |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
134 edges ~= vertices[imported.moduleFQN].addChild(vertices[importer.moduleFQN]); |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
135 }, |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
136 modules |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
137 ); |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
138 |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
139 auto writer = gwf.createGraphWriter( ddf.createDocumentWriter( [ file ] ) ); |
449
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
140 |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
141 writer.generateGraph(vertices.values, edges, imgFile); |
449
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
142 |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
143 file.close(); |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
144 imgFile.close(); |
452
f658ec4a15dd
Simple docgen ui util, some fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
451
diff
changeset
|
145 } |