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

« back to all changes in this revision

Viewing changes to external/mono-tools/gendarme/rules/Gendarme.Rules.Security/Test/NativeFieldsShouldNotBeVisibleTest.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 NativeFieldsShouldNotBeVisibleRule
 
3
//
 
4
// Authors:
 
5
//      Andreas Noever <andreas.noever@gmail.com>
 
6
//
 
7
//  (C) 2008 Andreas Noever
 
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 Gendarme.Rules.Security;
 
31
 
 
32
using NUnit.Framework;
 
33
using Test.Rules.Definitions;
 
34
using Test.Rules.Fixtures;
 
35
 
 
36
namespace Test.Rules.Security {
 
37
 
 
38
        public class HasPublicNativeField {
 
39
                public IntPtr Native;
 
40
        }
 
41
 
 
42
        public class HasProtectedNativeField {
 
43
                protected IntPtr Native;
 
44
        }
 
45
 
 
46
        public class HasInternalNativeField {
 
47
                internal IntPtr Native;
 
48
        }
 
49
 
 
50
        public class HasPublicReadonlyNativeField {
 
51
                public readonly IntPtr Native;
 
52
        }
 
53
 
 
54
        public class HasPublicNativeFieldArray {
 
55
                public IntPtr [] Native;
 
56
        }
 
57
 
 
58
        public class HasPublicReadonlyNativeFieldArray {
 
59
                public IntPtr [] Native;
 
60
        }
 
61
 
 
62
        public class HasPublicNativeFieldArrayArray {
 
63
                public IntPtr [] [] Native;
 
64
        }
 
65
 
 
66
        public class HasPublicNonNativeField {
 
67
                public object Field;
 
68
        }
 
69
 
 
70
        public class HasPrivateNativeField {
 
71
                private IntPtr Native;
 
72
        }
 
73
 
 
74
        [TestFixture]
 
75
        public class NativeFieldsShouldNotBeVisibleTest : TypeRuleTestFixture<NativeFieldsShouldNotBeVisibleRule> {
 
76
 
 
77
                [Test]
 
78
                public void DoesNotApply ()
 
79
                {
 
80
                        AssertRuleDoesNotApply (SimpleTypes.Interface);
 
81
                        AssertRuleDoesNotApply (SimpleTypes.Enum);
 
82
                        AssertRuleDoesNotApply (SimpleTypes.Delegate);
 
83
                }
 
84
 
 
85
                [Test]
 
86
                public void TestHasPublicNativeField ()
 
87
                {
 
88
                        AssertRuleFailure<HasPublicNativeField> (1);
 
89
                }
 
90
 
 
91
                [Test]
 
92
                public void TestHasProtectedNativeField ()
 
93
                {
 
94
                        AssertRuleFailure<HasProtectedNativeField> (1);
 
95
                }
 
96
 
 
97
                [Test]
 
98
                public void TestHasInternalNativeField ()
 
99
                {
 
100
                        AssertRuleSuccess<HasInternalNativeField> ();
 
101
                }
 
102
 
 
103
                [Test]
 
104
                public void TestHasPublicReadonlyNativeField ()
 
105
                {
 
106
                        AssertRuleSuccess<HasPublicReadonlyNativeField> ();
 
107
                }
 
108
 
 
109
                [Test]
 
110
                public void TestHasPublicNativeFieldArray ()
 
111
                {
 
112
                        AssertRuleFailure<HasPublicNativeFieldArray> (1);
 
113
                }
 
114
 
 
115
                [Test]
 
116
                public void TestHasPublicReadonlyNativeFieldArray ()
 
117
                {
 
118
                        AssertRuleFailure<HasPublicReadonlyNativeFieldArray> (1);
 
119
                }
 
120
 
 
121
                [Test]
 
122
                public void TestHasPublicNativeFieldArrayArray ()
 
123
                {
 
124
                        AssertRuleFailure<HasPublicNativeFieldArrayArray> (1);
 
125
                }
 
126
 
 
127
                [Test]
 
128
                public void TestHasPublicNonNativeField ()
 
129
                {
 
130
                        AssertRuleSuccess<HasPublicNonNativeField> ();
 
131
                }
 
132
 
 
133
                [Test]
 
134
                public void TestHasPrivateNativeField ()
 
135
                {
 
136
                        AssertRuleSuccess<HasPrivateNativeField> ();
 
137
                }
 
138
        }
 
139
}