~ubuntu-branches/ubuntu/saucy/monodevelop/saucy

« back to all changes in this revision

Viewing changes to external/mono-tools/gendarme/rules/Gendarme.Rules.Design.Generic/Test/DoNotExposeNestedGenericSignaturesTest.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2012-05-27 18:08:20 UTC
  • mfrom: (1.8.5) (1.5.8 sid)
  • Revision ID: package-import@ubuntu.com-20120527180820-f1ub6lhg0s50wci1
Tags: 3.0.2+dfsg-3
* [fcecfe7] Fix monodevelop-core-addins.pc.in to point to actual 
  installed location of assemblies.
* [26e1a07] DebSrc 3.0 does not support Quilt's -p parameter, so 
  manually adjust the path in the patch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Unit Tests for DoNotExposeNestedGenericSignaturesRule
 
3
//
 
4
// Authors:
 
5
//      Sebastien Pouliot <sebastien@ximian.com>
 
6
//
 
7
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining
 
10
// a copy of this software and associated documentation files (the
 
11
// "Software"), to deal in the Software without restriction, including
 
12
// without limitation the rights to use, copy, modify, merge, publish,
 
13
// distribute, sublicense, and/or sell copies of the Software, and to
 
14
// permit persons to whom the Software is furnished to do so, subject to
 
15
// the following conditions:
 
16
// 
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
// 
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
27
//
 
28
 
 
29
using System;
 
30
using System.Collections;
 
31
using System.Collections.Generic;
 
32
using System.Linq;
 
33
using System.Xml.Linq;
 
34
 
 
35
using Mono.Cecil;
 
36
 
 
37
using Gendarme.Framework;
 
38
using Gendarme.Rules.Design.Generic;
 
39
 
 
40
using NUnit.Framework;
 
41
using Test.Rules.Fixtures;
 
42
 
 
43
namespace Test.Rules.Design.Generic {
 
44
 
 
45
        [TestFixture]
 
46
        public class DoNotExposeNestedGenericSignaturesTest : MethodRuleTestFixture<DoNotExposeNestedGenericSignaturesRule> {
 
47
 
 
48
                public class IntegerCollection : List<int> {
 
49
                }
 
50
 
 
51
                public class Generic<T> {
 
52
 
 
53
                        public ICollection NonGenericReturnValue ()
 
54
                        {
 
55
                                return null;
 
56
                        }
 
57
 
 
58
                        public ICollection<string> GenericReturnValue ()
 
59
                        {
 
60
                                return null;
 
61
                        }
 
62
 
 
63
                        public ICollection<KeyValuePair<T, T>> NestedReturnValue ()
 
64
                        {
 
65
                                return null;
 
66
                        }
 
67
 
 
68
                        public void NonGenericParameter (ICollection value)
 
69
                        {
 
70
                        }
 
71
 
 
72
                        public void GenericParameter (ICollection<int> value)
 
73
                        {
 
74
                        }
 
75
 
 
76
                        public void NestedParameter (KeyValuePair<T, ICollection<int>> value)
 
77
                        {
 
78
                        }
 
79
 
 
80
                        public void UnnestedParameter (KeyValuePair<T, IntegerCollection> value)
 
81
                        {
 
82
                        }
 
83
 
 
84
                        public void TwoNestedParameters (KeyValuePair<T, ICollection<int>> value,
 
85
                                int max, int min, ICollection<KeyValuePair<T,string>> template)
 
86
                        {
 
87
                        }
 
88
 
 
89
                        protected ICollection<KeyValuePair<T, T>> All (KeyValuePair<T, ICollection<int>> value,
 
90
                                int max, int min, ICollection<KeyValuePair<T, string>> template)
 
91
                        {
 
92
                                return null;
 
93
                        }
 
94
                }
 
95
 
 
96
                [Test]
 
97
                public void ReturnValue ()
 
98
                {
 
99
                        AssertRuleSuccess<Generic<int>> ("NonGenericReturnValue");
 
100
                        AssertRuleSuccess<Generic<int>> ("GenericReturnValue");
 
101
                        AssertRuleFailure<Generic<int>> ("NestedReturnValue", 1);
 
102
                }
 
103
 
 
104
                [Test]
 
105
                public void Parameters ()
 
106
                {
 
107
                        AssertRuleSuccess<Generic<int>> ("NonGenericParameter");
 
108
                        AssertRuleSuccess<Generic<int>> ("GenericParameter");
 
109
                        AssertRuleFailure<Generic<int>> ("NestedParameter", 1);
 
110
                        AssertRuleSuccess<Generic<int>> ("UnnestedParameter");
 
111
                        AssertRuleFailure<Generic<int>> ("TwoNestedParameters", 2);
 
112
                }
 
113
 
 
114
                [Test]
 
115
                public void Both ()
 
116
                {
 
117
                        AssertRuleFailure<Generic<int>> ("All", 3);
 
118
                }
 
119
 
 
120
                // adapted from XmlResultWriter
 
121
 
 
122
                public XElement CreateDefects ()
 
123
                {
 
124
                        var query = from n in Runner.Defects
 
125
                                    group n by n.Rule into a
 
126
//gmcs bug//                        orderby a.Key.Name
 
127
                                    select new {
 
128
                                            Rule = a.Key,
 
129
                                            Value = from o in a
 
130
                                                    group o by o.Target into r
 
131
                                                    orderby (r.Key == null ? String.Empty : a.Key.Name)
 
132
                                                    select new {
 
133
                                                            Target = r.Key,
 
134
                                                            Value = r
 
135
                                                    }
 
136
                                    };
 
137
 
 
138
                        return new XElement ("results",
 
139
                                from value in query
 
140
                                select new XElement ("rule",
 
141
                                        CreateRuleDetails (value.Rule),
 
142
                                        from v2 in value.Value
 
143
                                        select new XElement ("target",
 
144
                                                CreateTargetDetails (v2.Target),
 
145
                                                from Defect defect in v2.Value
 
146
                                                select CreateDefect (defect))));
 
147
                }
 
148
 
 
149
                static XObject [] CreateRuleDetails (IRule rule)
 
150
                {
 
151
                        return null;
 
152
                }
 
153
 
 
154
                static XObject [] CreateTargetDetails (IMetadataTokenProvider target)
 
155
                {
 
156
                        return null;
 
157
                }
 
158
 
 
159
                static XElement CreateDefect (Defect defect)
 
160
                {
 
161
                        return null;
 
162
                }
 
163
 
 
164
                [Test]
 
165
                public void Linq ()
 
166
                {
 
167
                        AssertRuleSuccess<DoNotExposeNestedGenericSignaturesTest> ("CreateDefects");
 
168
                }
 
169
 
 
170
                public IEnumerable<int?> NullableReturnValue ()
 
171
                {
 
172
                        return null;
 
173
                }
 
174
 
 
175
                public void NullableParameter (ICollection<DateTime?> value)
 
176
                {
 
177
                }
 
178
 
 
179
                [Test]
 
180
                public void Nullable ()
 
181
                {
 
182
                        AssertRuleSuccess<DoNotExposeNestedGenericSignaturesTest> ("NullableReturnValue");
 
183
                        AssertRuleSuccess<DoNotExposeNestedGenericSignaturesTest> ("NullableParameter");
 
184
                }
 
185
        }
 
186
}