Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 111 lines (87 sloc) 2.627 kb
57d0d6a Stephane Delcroix [cocos2d] add static analysis tests
authored
1 //
2 // ApiCompleteness.cs
3 //
4 // Author:
5 // Stephane Delcroix <stephane@delcroix.org>
6 //
7 // Copyright (c) 2013 S. Delcroix
8 //
9 using System;
10 using System.Linq;
11 using System.Reflection;
12 using System.Collections.Generic;
13
14 using MonoTouch.Foundation;
15
16 using NUnit.Framework;
17
18
19 namespace TouchUnit.Bindings
20 {
21 public class ApiCompleteness : ApiBaseTest
22 {
23 protected class Selector {
24 public string Class;
25 public string Category;
26 public string Sel;
27 }
28
29 public ApiCompleteness ()
30 {
31 }
32
33 protected virtual bool Skip (Type type)
34 {
35 return false;
36 }
37
38 protected virtual bool SkipCategory (string category)
39 {
40 return false;
41 }
42
43 [Test]
44 public void SelectorIsBound ()
45 {
46 int n=0;
47 int errors = 0;
48 foreach (var sel in Selectors ()) {
49 var match = false;
50
51 if (SkipCategory (sel.Category))
52 continue;
53
54 if (LogProgress)
55 Console.WriteLine ("{0}. {1}{2}{3}{4} {5}",
56 n,
57 sel.Class,
58 string.IsNullOrEmpty(sel.Category) ? "" : "(",
59 sel.Category,
60 string.IsNullOrEmpty(sel.Category) ? "" : ")",
61 sel.Sel);
62
63
64
65 foreach (Type t in Assembly.GetTypes ()) {
66
67 if (t.IsNested || !NSObjectType.IsAssignableFrom (t))
68 continue;
69
70 if (Skip (t))
71 continue;
72
73 if (t.Name != sel.Class)
74 continue;
75
76
77 foreach (var m in t.GetMethods (BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance))
78 foreach (var name in m.GetCustomAttributes (true).Where (ca => ca is ExportAttribute).Select(ca => (ca as ExportAttribute).Selector)) {
79 if (string.Compare (name, sel.Sel) == 0)
80 match = true;
81 }
82
83 foreach (var m in t.GetConstructors (BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance))
84 foreach (var name in m.GetCustomAttributes (true).Where (ca => ca is ExportAttribute).Select(ca => (ca as ExportAttribute).Selector)) {
85 if (string.Compare (name, sel.Sel) == 0)
86 match = true;
87 }
88
89 if (match)
90 break;
91 }
92
93 if (!ContinueOnFailure)
94 Assert.IsTrue (match);
95 else if (!match) {
96 Console.WriteLine ("[FAIL] selector {0} not exported by any method or constructor in {1}", sel.Sel, sel.Class);
97 errors ++;
98 }
99
100
101 n++;
102 }
103 Assert.AreEqual (0, errors, "{0} errors found in {1} signatures validated", errors, n);
104 }
105
106 protected virtual IEnumerable<Selector> Selectors ()
107 {
108 yield break;
109 }
110 }
111 }
Something went wrong with that request. Please try again.