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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
|
// System.Net.Sockets.MulticastOptionTest.cs
//
// Authors:
// Gert Driesen (drieseng@users.sourceforge.net)
//
// Copyright (c) 2009 Gert Driesen
//
using System;
using System.Net;
using System.Net.Sockets;
using NUnit.Framework;
namespace MonoTests.System.Net.Sockets
{
[TestFixture]
public class MulticastOptionTest
{
[Test] // .ctor (IPAddress)
public void Constructor1 ()
{
MulticastOption option;
IPAddress group;
group = IPAddress.Parse ("239.255.255.250");
option = new MulticastOption (group);
Assert.AreSame (group, option.Group, "#A:Group");
#if NET_2_0
Assert.AreEqual (0, option.InterfaceIndex, "#A:InterfaceIndex");
#endif
Assert.AreEqual (IPAddress.Any, option.LocalAddress, "#A:LocalAddress");
group = IPAddress.Parse ("ff02::1");
option = new MulticastOption (group);
Assert.AreSame (group, option.Group, "#B:Group");
#if NET_2_0
Assert.AreEqual (0, option.InterfaceIndex, "#B:InterfaceIndex");
#endif
Assert.AreEqual (IPAddress.Any, option.LocalAddress, "#B:LocalAddress");
}
[Test] // .ctor (IPAddress)
public void Constructor1_Group_Null ()
{
try {
new MulticastOption ((IPAddress) null);
Assert.Fail ("#1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.AreEqual ("group", ex.ParamName, "#5");
}
}
[Test] // .ctor (IPAddress, IPAddress)
public void Constructor2 ()
{
MulticastOption option;
IPAddress group;
IPAddress mcint;
group = IPAddress.Parse ("239.255.255.250");
mcint = IPAddress.Any;
option = new MulticastOption (group, mcint);
Assert.AreSame (group, option.Group, "#A:Group");
#if NET_2_0
Assert.AreEqual (0, option.InterfaceIndex, "#A:InterfaceIndex");
#endif
Assert.AreEqual (mcint, option.LocalAddress, "#A:LocalAddress");
group = IPAddress.Parse ("ff02::1");
mcint = IPAddress.IPv6Any;
option = new MulticastOption (group, mcint);
Assert.AreSame (group, option.Group, "#B:Group");
#if NET_2_0
Assert.AreEqual (0, option.InterfaceIndex, "#B:InterfaceIndex");
#endif
Assert.AreEqual (mcint, option.LocalAddress, "#B:LocalAddress");
}
[Test] // .ctor (IPAddress, IPAddress)
public void Constructor2_Group_Null ()
{
IPAddress group = null;
IPAddress mcint = IPAddress.Any;
try {
new MulticastOption (group, mcint);
Assert.Fail ("#1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.AreEqual ("group", ex.ParamName, "#5");
}
}
[Test] // .ctor (IPAddress, IPAddress)
public void Constructor2_Mcint_Null ()
{
IPAddress group = IPAddress.Parse ("239.255.255.250");
IPAddress mcint = null;
try {
new MulticastOption (group, mcint);
Assert.Fail ("#1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.AreEqual ("mcint", ex.ParamName, "#5");
}
}
#if NET_2_0
[Test] // .ctor (IPAddress, Int32)
public void Constructor3 ()
{
MulticastOption option;
IPAddress group;
int interfaceIndex;
group = IPAddress.Parse ("239.255.255.250");
interfaceIndex = 0;
option = new MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#A:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#A:InterfaceIndex");
Assert.AreEqual (null, option.LocalAddress, "#A:LocalAddress");
group = IPAddress.Parse ("ff02::1");
interfaceIndex = 0;
option = new MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#B:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#B:InterfaceIndex");
Assert.AreEqual (null, option.LocalAddress, "#B:LocalAddress");
group = IPAddress.Parse ("239.255.255.250");
interfaceIndex = 124;
option = new MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#C:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#C:InterfaceIndex");
Assert.AreEqual (null, option.LocalAddress, "#C:LocalAddress");
group = IPAddress.Parse ("ff02::1");
interfaceIndex = 124;
option = new MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#D:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#D:InterfaceIndex");
Assert.AreEqual (null, option.LocalAddress, "#D:LocalAddress");
group = IPAddress.Parse ("239.255.255.250");
interfaceIndex = 0xFFFFFF;
option = new MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#E:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#E:InterfaceIndex");
Assert.AreEqual (null, option.LocalAddress, "#E:LocalAddress");
group = IPAddress.Parse ("ff02::1");
interfaceIndex = 0xFFFFFF;
option = new MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#F:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#F:InterfaceIndex");
Assert.AreEqual (null, option.LocalAddress, "#F:LocalAddress");
}
[Test] // .ctor (IPAddress, Int32)
public void Constructor3_Group_Null ()
{
IPAddress group = null;
try {
new MulticastOption (group, int.MaxValue);
Assert.Fail ("#1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.AreEqual ("group", ex.ParamName, "#5");
}
}
[Test] // .ctor (IPAddress, Int32)
public void Constructor3_InterfaceIndex_OutOfRange ()
{
IPAddress group = IPAddress.Parse ("239.255.255.250");
try {
new MulticastOption (group, -1);
Assert.Fail ("#A1");
} catch (ArgumentOutOfRangeException ex) {
// Specified argument was out of the range of valid values
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
Assert.IsNull (ex.InnerException, "#A3");
Assert.IsNotNull (ex.Message, "#A4");
Assert.AreEqual ("interfaceIndex", ex.ParamName, "#A5");
}
try {
new MulticastOption (group, 0x1000000);
Assert.Fail ("#B1");
} catch (ArgumentOutOfRangeException ex) {
// Specified argument was out of the range of valid values
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
Assert.IsNull (ex.InnerException, "#B3");
Assert.IsNotNull (ex.Message, "#B4");
Assert.AreEqual ("interfaceIndex", ex.ParamName, "#B5");
}
}
#endif
[Test]
public void Group ()
{
IPAddress group;
IPAddress local;
MulticastOption option;
#if NET_2_0
local = Dns.GetHostEntry (string.Empty).AddressList [0];
#else
local = IPAddress.Loopback;
#endif
group = IPAddress.Parse ("239.255.255.250");
option = new MulticastOption (group, local);
group = IPAddress.Parse ("224.0.0.23");
option.Group = group;
Assert.AreSame (group, option.Group, "#A1");
Assert.AreSame (local, option.LocalAddress, "#A2");
group = IPAddress.Parse ("239.255.255.250");
option.Group = group;
Assert.AreSame (group, option.Group, "#B1");
Assert.AreSame (local, option.LocalAddress, "#B2");
group = IPAddress.Parse ("ff02::1");
option.Group = group;
Assert.AreSame (group, option.Group, "#C1");
Assert.AreSame (local, option.LocalAddress, "#C2");
option.Group = null;
Assert.IsNull (option.Group, "#D1");
Assert.AreSame (local, option.LocalAddress, "#D2");
#if NET_2_0
option = new MulticastOption (group, 5);
group = IPAddress.Parse ("224.0.0.23");
option.Group = group;
Assert.AreSame (group, option.Group, "#E1");
Assert.AreEqual (5, option.InterfaceIndex, "#E2");
Assert.IsNull (option.LocalAddress, "#E3");
#endif
}
#if NET_2_0
[Test]
public void InterfaceIndex ()
{
IPAddress group;
IPAddress local;
MulticastOption option;
group = IPAddress.Parse ("239.255.255.250");
option = new MulticastOption (group, 10);
option.InterfaceIndex = 0;
Assert.AreSame (group, option.Group, "#A1");
Assert.AreEqual (0, option.InterfaceIndex, "#A2");
Assert.IsNull (option.LocalAddress, "#A3");
option.InterfaceIndex = 124;
Assert.AreSame (group, option.Group, "#B1");
Assert.AreEqual (124, option.InterfaceIndex, "#B2");
Assert.IsNull (option.LocalAddress, "#B3");
option.InterfaceIndex = 0xFFFFFF;
Assert.AreSame (group, option.Group, "#C1");
Assert.AreEqual (0xFFFFFF, option.InterfaceIndex, "#C2");
Assert.IsNull (option.LocalAddress, "#C3");
local = Dns.GetHostEntry (string.Empty).AddressList [0];
option = new MulticastOption (group, local);
option.InterfaceIndex = 10;
Assert.AreSame (group, option.Group, "#D1");
Assert.AreEqual (10, option.InterfaceIndex, "#D2");
Assert.IsNull (option.LocalAddress, "#D3");
}
[Test]
public void InterfaceIndex_Value_OutOfRange ()
{
IPAddress group = IPAddress.Parse ("239.255.255.250");
MulticastOption option = new MulticastOption (group, 10);
try {
option.InterfaceIndex = -1;
Assert.Fail ("#A1");
} catch (ArgumentOutOfRangeException ex) {
// Specified argument was out of the range of valid values
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
Assert.IsNull (ex.InnerException, "#A3");
Assert.IsNotNull (ex.Message, "#A4");
Assert.AreEqual ("value", ex.ParamName, "#A5");
}
try {
option.InterfaceIndex = 0x1000000;
Assert.Fail ("#B1");
} catch (ArgumentOutOfRangeException ex) {
// Specified argument was out of the range of valid values
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
Assert.IsNull (ex.InnerException, "#B3");
Assert.IsNotNull (ex.Message, "#B4");
Assert.AreEqual ("value", ex.ParamName, "#B5");
}
// ensure original value was retained
Assert.AreEqual (10, option.InterfaceIndex, "#C");
}
#endif
[Test]
public void LocalAddress ()
{
IPAddress group;
IPAddress local;
MulticastOption option;
#if NET_2_0
local = Dns.GetHostEntry (string.Empty).AddressList [0];
#else
local = IPAddress.Loopback;
#endif
group = IPAddress.Parse ("239.255.255.250");
option = new MulticastOption (group, local);
local = IPAddress.Loopback;
option.LocalAddress = local;
Assert.AreSame (group, option.Group, "#A1");
#if NET_2_0
Assert.AreEqual (0, option.InterfaceIndex, "#A2");
#endif
Assert.AreSame (local, option.LocalAddress, "#A3");
#if NET_2_0
local = Dns.GetHostEntry (string.Empty).AddressList [0];
#else
local = IPAddress.Loopback;
#endif
option.LocalAddress = local;
Assert.AreSame (group, option.Group, "#B1");
#if NET_2_0
Assert.AreEqual (0, option.InterfaceIndex, "#B2");
#endif
Assert.AreSame (local, option.LocalAddress, "#B3");
option.LocalAddress = null;
Assert.AreSame (group, option.Group, "#C1");
#if NET_2_0
Assert.AreEqual (0, option.InterfaceIndex, "#C2");
#endif
Assert.IsNull (option.LocalAddress, "#C3");
#if NET_2_0
option = new MulticastOption (group, 5);
local = IPAddress.Loopback;
option.LocalAddress = local;
Assert.AreSame (group, option.Group, "#D1");
Assert.AreEqual (0, option.InterfaceIndex, "#D2");
Assert.AreSame (local, option.LocalAddress, "#D3");
#endif
}
}
}
|