6
6
7
7
using nanoFramework . TestFramework ;
8
8
using System ;
9
- using System . Diagnostics ;
10
- using System . Reflection ;
11
9
12
10
namespace NFUnitTestClasses
13
11
{
14
12
[ TestClass ]
15
13
class UnitTestDestructorTests
16
14
{
17
15
// Removing as using something out of mscorlib
18
- //[TestMethod]
19
- //public void Destructors3_Test()
20
- //{
21
- // //Ported from Destructors3.cs
22
- // // Section 10.11
23
- // // Destructors implement the actions required to
24
- // // destruct the instances of a class.
25
- // //
26
- // // Note: This test may fail due to lengthy garbage collection, look for Destructor messages in later logs
27
- // Assert.IsTrue(DestructorsTestClass3.testMethod());
28
- //}
29
-
30
- //[TestMethod]
31
- //public void Destructors4_Test()
32
- //{
33
- // //Ported from Destructors4.cs
34
- // // Section 10.11
35
- // // Destructors implement the actions required to
36
- // // destruct the instances of a class.
37
- // //
38
- // // Note: This test may fail due to lengthy garbage collection, look for Destructor messages in later logs
39
- // Assert.IsTrue(DestructorsTestClass4.testMethod());
40
- //}
41
-
42
- // Removed as using a class out of mscorlib
43
- //[TestMethod]
44
- //public void Destructors7_Test()
45
- //{
46
- // //Ported from Destructors7.cs
47
- // // Section 10.12
48
- // // Destructors are not inherited. Thus, a class
49
- // // has no other destructors than those that are
50
- // // actually declared in the class.
51
- // //
52
- // // Note: This test may fail due to lengthy garbage collection, look for Destructor messages in later logs
53
- // Assert.IsTrue(DestructorsTestClass7.testMethod());
54
- //}
55
-
56
- //class DestructorsTestClass3
57
- //{
58
-
59
- // static int intI = 1;
60
-
61
- // ~DestructorsTestClass3()
62
- // {
63
- // // Calling Destructor for Test Class 3
64
- // intI = 2;
65
- // }
66
-
67
- // public static bool testMethod()
68
- // {
69
- // DestructorsTestClass3 mc = new DestructorsTestClass3();
70
- // mc = null;
71
- // nanoFramework.Runtime.Native.GC.Run(true);
72
- // int sleepTime = 5000;
73
- // int slept = 0;
74
- // while (intI != 2 && slept < sleepTime)
75
- // {
76
- // System.Threading.Thread.Sleep(10);
77
- // slept += 10;
78
- // }
79
- // // Thread has slept for
80
- // OutputHelper.WriteLine(slept.ToString());
81
- // if (intI == 2)
82
- // {
83
- // return true;
84
- // }
85
- // else
86
- // {
87
- // return false;
88
- // }
89
- // }
90
- //}
91
-
92
-
93
- class DestructorsTestClass4_Base
16
+ [ TestMethod ]
17
+ public void Destructors3_Test ( )
18
+ {
19
+ //Ported from Destructors3.cs
20
+ // Section 10.11
21
+ // Destructors implement the actions required to
22
+ // destruct the instances of a class.
23
+ //
24
+ // Note: This test may fail due to lengthy garbage collection, look for Destructor messages in later logs
25
+ Assert . IsTrue ( DestructorsTestClass3 . TestMethod ( ) ) ;
26
+ }
27
+
28
+ [ TestMethod ]
29
+ public void Destructors4_Test ( )
30
+ {
31
+ //Ported from Destructors4.cs
32
+ // Section 10.11
33
+ // Destructors implement the actions required to
34
+ // destruct the instances of a class.
35
+ //
36
+ // Note: This test may fail due to lengthy garbage collection, look for Destructor messages in later logs
37
+ Assert . IsTrue ( DestructorsTestClass4 . TestMethod ( ) ) ;
38
+ }
39
+
40
+ [ TestMethod ]
41
+ public void Destructors7_Test ( )
42
+ {
43
+ //Ported from Destructors7.cs
44
+ // Section 10.12
45
+ // Destructors are not inherited. Thus, a class
46
+ // has no other destructors than those that are
47
+ // actually declared in the class.
48
+ //
49
+ // Note: This test may fail due to lengthy garbage collection, look for Destructor messages in later logs
50
+ Assert . IsTrue ( DestructorsTestClass7 . TestMethod ( ) ) ;
51
+ }
52
+
53
+ public class DestructorsTestClass3
54
+ {
55
+ static int intI = 1 ;
56
+
57
+ ~ DestructorsTestClass3 ( )
58
+ {
59
+ // Calling Destructor for Test Class 3
60
+ intI = 2 ;
61
+
62
+ Console . WriteLine ( "Calling Destructor for Test Class 3" ) ;
63
+ }
64
+
65
+ public static bool TestMethod ( )
66
+ {
67
+ DestructorsTestClass3 mc = new DestructorsTestClass3 ( ) ;
68
+ mc = null ;
69
+
70
+ // the following call has been "replaced" with the setting commanding a GC run before new allocations, which will have the desired effect of
71
+ // nanoFramework.Runtime.Native.GC.Run(true);
72
+
73
+ int sleepTime = 5000 ;
74
+ int slept = 0 ;
75
+
76
+ while ( intI != 2 && slept < sleepTime )
77
+ {
78
+ // force GC run caused by memory allocation
79
+ var dummyArray = new byte [ 1024 * 1024 * 1 ] ;
80
+
81
+ System . Threading . Thread . Sleep ( 10 ) ;
82
+ slept += 10 ;
83
+ }
84
+
85
+ // Thread has slept for
86
+ OutputHelper . WriteLine ( $ "Thread as slept for{ slept } ") ;
87
+
88
+ if ( intI == 2 )
89
+ {
90
+ return true ;
91
+ }
92
+ else
93
+ {
94
+ return false ;
95
+ }
96
+ }
97
+ }
98
+
99
+ public class DestructorsTestClass4_Base
94
100
{
95
101
public static int intI = 2 ;
96
102
~ DestructorsTestClass4_Base ( )
97
103
{
98
- intI = intI * 2 ;
99
104
// Calling Destructor for Test Class 4 Base
105
+ intI = intI * 2 ;
106
+
107
+ Console . WriteLine ( "Calling Destructor for Test Class 4 Base" ) ;
100
108
}
101
109
}
102
110
103
- class DestructorsTestClass4 : DestructorsTestClass4_Base
111
+ public class DestructorsTestClass4 : DestructorsTestClass4_Base
104
112
{
105
113
106
114
~ DestructorsTestClass4 ( )
@@ -109,20 +117,29 @@ class DestructorsTestClass4 : DestructorsTestClass4_Base
109
117
// Calling Destructor for Test Class 4
110
118
}
111
119
112
- public static bool testMethod ( )
120
+ public static bool TestMethod ( )
113
121
{
114
122
DestructorsTestClass4 mc = new DestructorsTestClass4 ( ) ;
115
123
mc = null ;
124
+
125
+ // the following call has been "replaced" with the setting commanding a GC run before new allocations, which will have the desired effect of
116
126
// nanoFramework.Runtime.Native.GC.Run(true);
127
+
117
128
int sleepTime = 5000 ;
118
129
int slept = 0 ;
130
+
119
131
while ( intI != 8 && slept < sleepTime )
120
132
{
133
+ // force GC run caused by memory allocation
134
+ var dummyArray = new byte [ 1024 * 1024 * 1 ] ;
135
+
121
136
System . Threading . Thread . Sleep ( 10 ) ;
122
137
slept += 10 ;
123
138
}
139
+
124
140
// Thread has slept for
125
- OutputHelper . WriteLine ( slept . ToString ( ) ) ;
141
+ OutputHelper . WriteLine ( $ "Thread as slept for{ slept } ") ;
142
+
126
143
if ( intI == 8 )
127
144
{
128
145
return true ;
@@ -134,34 +151,45 @@ public static bool testMethod()
134
151
}
135
152
}
136
153
137
- class DestructorsTestClass7_Base
154
+ public class DestructorsTestClass7_Base
138
155
{
139
156
public static int intI = 2 ;
140
157
}
141
158
142
- class DestructorsTestClass7 : DestructorsTestClass7_Base
159
+ public class DestructorsTestClass7 : DestructorsTestClass7_Base
143
160
{
144
161
145
162
~ DestructorsTestClass7 ( )
146
163
{
147
- intI = 3 ;
148
164
// Calling Destructor for Test Class 7
165
+ intI = 3 ;
166
+
167
+ Console . WriteLine ( "Calling Destructor for Test Class 7" ) ;
149
168
}
150
169
151
- public static bool testMethod ( )
170
+ public static bool TestMethod ( )
152
171
{
153
172
DestructorsTestClass7 mc = new DestructorsTestClass7 ( ) ;
154
173
mc = null ;
174
+
175
+ // the following call has been "replaced" with the setting commanding a GC run before new allocations, which will have the desired effect of
155
176
//nanoFramework.Runtime.Native.GC.Run(true);
177
+
156
178
int sleepTime = 5000 ;
157
179
int slept = 0 ;
180
+
158
181
while ( intI != 3 && slept < sleepTime )
159
182
{
183
+ // force GC run caused by memory allocation
184
+ var dummyArray = new byte [ 1024 * 1024 * 1 ] ;
185
+
160
186
System . Threading . Thread . Sleep ( 10 ) ;
161
187
slept += 10 ;
162
188
}
189
+
163
190
// Thread has slept for
164
- OutputHelper . WriteLine ( slept . ToString ( ) ) ;
191
+ OutputHelper . WriteLine ( $ "Thread as slept for{ slept } ") ;
192
+
165
193
if ( intI == 3 )
166
194
{
167
195
return true ;
0 commit comments