This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
CoverageView.cs
311 lines (247 loc) · 7.4 KB
/
CoverageView.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
//
// Missing:
// DoubleClick action:
// DoubleClick onmethod, call ShowSrouceFor (method.Parent)
// Context menu.
// Images for namespaces open/close and class.
//
using Gtk;
using GLib;
using Gdk;
using Gnome;
using Glade;
using GtkSharp;
using System;
using System.Collections;
namespace MonoCov.Gui.Gtk {
public class CoverageView {
public class TreeItem {
public string title;
public TreeStore store;
public TreeItem parent;
public TreeIter iter;
public CoverageItem model;
public TreeItem (TreeStore store, TreeItem parent, CoverageItem model, string title) {
this.store = store;
this.parent = parent;
this.model = model;
if (parent == null)
iter = store.AppendValues (title);
else
iter = store.AppendValues (parent.Iter, title);
FillColumns ();
}
public TreeIter Iter {
get {
return iter;
}
set {
this.iter = value;
}
}
public void FillColumns () {
double coverage;
if (model.hit + model.missed == 0)
coverage = 1.0;
else
coverage = (double)model.hit / (model.hit + model.missed);
store.SetValue (iter, 1, "" + model.hit);
store.SetValue (iter, 2, "" + model.missed);
string coveragePercent
= String.Format ("{0:###0}", coverage * 100);
store.SetValue (iter, 3, coveragePercent + "%");
store.SetValue (iter, 4, this);
}
}
public class MethodItem : TreeItem {
public ClassItem ParentClass;
public MethodItem (TreeStore store, TreeItem parent, ClassItem parent_class, CoverageItem model, string title)
: base (store, parent, model, title)
{
ParentClass = parent_class;
}
public MethodCoverageItem Model {
get {
return (MethodCoverageItem)model;
}
}
}
public class ClassItem : TreeItem {
public ClassItem (TreeStore store, TreeItem parent, CoverageItem model, string title)
: base (store, parent, model, title)
{
}
public ClassCoverageItem Model {
get {
return (ClassCoverageItem) model;
}
}
}
public class NamespaceItem : TreeItem {
public NamespaceItem (TreeStore store, TreeItem parent, CoverageItem model, string title)
: base (store, parent, model, title)
{
}
}
public static string[] DEFAULT_FILTERS = {
"-PrivateImplementationDetails"
};
TreeView tree;
Hashtable namespaces;
Hashtable classes;
CoverageModel model;
Hashtable source_views, window_maps;
public CoverageView (string fileName)
{
TreeStore store = new TreeStore (typeof (string), typeof (string), typeof (string), typeof (string), typeof (object));
tree = new TreeView (store);
CellRendererText renderer = new CellRendererText ();
// LAME: Why is this property a float instead of a double ?
renderer.Xalign = 0.5f;
tree.AppendColumn ("Classes", new CellRendererText (), "text", 0);
tree.AppendColumn ("Lines Hit", renderer, "text", 1);
tree.AppendColumn ("Lines Missed", renderer, "text", 2);
tree.AppendColumn ("Coverage", renderer, "text", 3);
tree.GetColumn (0).Resizable = true;
tree.GetColumn (1).Alignment = 0.0f;
tree.GetColumn (1).Resizable = true;
tree.GetColumn (2).Alignment = 0.0f;
tree.GetColumn (2).Resizable = true;
tree.GetColumn (3).Alignment = 0.0f;
tree.GetColumn (3).Resizable = true;
tree.HeadersVisible = true;
model = new CoverageModel ();
foreach (string filter in DEFAULT_FILTERS) {
model.AddFilter (filter);
}
model.ReadFromFile (fileName);
TreeItem root = new TreeItem (store, null, model, "PROJECT");
Hashtable classes2 = model.Classes;
namespaces = new Hashtable ();
foreach (string name in classes2.Keys) {
ClassCoverageItem klass = (ClassCoverageItem)classes2 [name];
if (klass.filtered)
continue;
string namespace2 = klass.name_space;
TreeItem nsItem = (TreeItem)namespaces [namespace2];
if (nsItem == null) {
nsItem = new TreeItem (store, root, (CoverageItem)model.Namespaces [namespace2], namespace2);
// nsItem.SetPixmap (0, namespaceOpenPixmap);
namespaces [namespace2] = nsItem;
}
if (nsItem.model.filtered)
continue;
ClassItem classItem = new ClassItem (store, nsItem, klass, klass.name);
// We should create the method nodes only when the class item
// is opened
foreach (MethodCoverageItem method in klass.Methods) {
if (method.filtered)
continue;
string title = method.Name;
if (title.Length > 64)
title = title.Substring (0, 63) + "...)";
new MethodItem (store, classItem, classItem, method, title);
}
}
tree.ExpandRow (store.GetPath (root.Iter), false);
foreach (string ns in namespaces.Keys)
tree.ExpandRow (store.GetPath (((TreeItem)namespaces [ns]).Iter), false);
tree.ButtonPressEvent += new ButtonPressEventHandler (OnButtonPress);
tree.Selection.Mode = SelectionMode.Single;
source_views = new Hashtable ();
window_maps = new Hashtable ();
// LAME: Why doesn't widgets visible by default ???
tree.Show ();
}
[GLib.ConnectBefore]
void OnButtonPress (object o, ButtonPressEventArgs args)
{
if (args.Event.Type == Gdk.EventType.TwoButtonPress)
OnDoubleClick ();
}
SourceWindow ShowSourceFor (ClassItem item)
{
SourceWindow SourceView = (SourceWindow)source_views [item.Model.sourceFile];
if (SourceView != null) {
SourceView.Show ();
} else {
SourceView = new SourceWindow (item);
source_views [item.Model.sourceFile] = SourceView;
window_maps [SourceView] = item.Model.sourceFile;
SourceView.Show ();
SourceView.DeleteEvent += new DeleteEventHandler (OnDeleteEvent);
}
return SourceView;
}
void OnDeleteEvent (object sender, DeleteEventArgs e)
{
if (window_maps [sender] != null){
source_views [window_maps [sender]] = null;
window_maps [sender] = null;
}
}
void OnDoubleClick ()
{
TreeModel model;
TreeIter iter;
if (!tree.Selection.GetSelected (out model, out iter))
return;
GLib.Value value = new GLib.Value ();
model.GetValue (iter, 4, ref value);
object item = value.Val;
if (item is MethodItem){
MethodItem method = (MethodItem)item;
SourceWindow sourceView = ShowSourceFor (method.ParentClass);
sourceView.CenterOnMethod (method);
} else {
if (tree.ExpandRow (model.GetPath (iter), true)) {
// LAME: This seems to collapse the entire tree...
tree.CollapseRow (model.GetPath (iter));
} else {
tree.ExpandRow (model.GetPath (iter), false);
}
}
}
/*
public void SlotDoubleClick (QListViewItem item) {
if (item is MethodItem) {
MethodItem method = (MethodItem)item;
ClassItem parent = method.parent;
if (parent.sourceBrowser != null) {
parent.sourceBrowser.ShowNormal ();
parent.sourceBrowser.Raise ();
}
else {
parent.sourceBrowser = new SourceWindow (this, parent);
parent.sourceBrowser.Show ();
}
parent.sourceBrowser.CenterOnMethod (method);
}
}
*/
public Widget Widget {
get {
return tree;
}
}
void FillCoverageColumns (TreeItem item, int hit, int missed) {
double coverage;
if (hit + missed == 0)
coverage = 100.0;
else
coverage = (double)hit / (hit + missed);
item.store.SetValue (item.iter, 1, "" + hit);
item.store.SetValue (item.iter, 2, "" + missed);
string coveragePercent
= String.Format ("{0:##0}%", coverage * 100);
item.store.SetValue (item.iter, 3, coveragePercent);
}
public void ExportAsXml (string destDir)
{
XmlExporter exporter = new XmlExporter ();
exporter.DestinationDir = destDir;
exporter.Export (model);
Environment.Exit (1);
}
}
}