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
|
// System.Net.Sockets.IPv6MulticastOptionTest.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 IPv6MulticastOptionTest
{
[Test] // .ctor (IPAddress)
public void Constructor1 ()
{
IPv6MulticastOption option;
IPAddress group;
group = IPAddress.Parse ("ff02::1");
option = new IPv6MulticastOption (group);
Assert.AreSame (group, option.Group, "#A:Group");
Assert.AreEqual (0, option.InterfaceIndex, "#A:InterfaceIndex");
group = IPAddress.Parse ("224.0.0.23");
option = new IPv6MulticastOption (group);
Assert.AreSame (group, option.Group, "#B:Group");
Assert.AreEqual (0, option.InterfaceIndex, "#B:InterfaceIndex");
}
[Test] // .ctor (IPAddress)
public void Constructor1_Group_Null ()
{
try {
new IPv6MulticastOption ((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, Int64)
public void Constructor2 ()
{
IPv6MulticastOption option;
IPAddress group;
long interfaceIndex;
group = IPAddress.Parse ("239.255.255.250");
interfaceIndex = 0;
option = new IPv6MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#A:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#A:InterfaceIndex");
group = IPAddress.Parse ("ff02::1");
interfaceIndex = 0;
option = new IPv6MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#B:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#B:InterfaceIndex");
group = IPAddress.Parse ("239.255.255.250");
interfaceIndex = 124;
option = new IPv6MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#C:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#C:InterfaceIndex");
group = IPAddress.Parse ("ff02::1");
interfaceIndex = 124;
option = new IPv6MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#D:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#D:InterfaceIndex");
group = IPAddress.Parse ("239.255.255.250");
interfaceIndex = 0xFFFFFFFF;
option = new IPv6MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#E:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#E:InterfaceIndex");
group = IPAddress.Parse ("ff02::1");
interfaceIndex = 0xFFFFFFFF;
option = new IPv6MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#F:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#F:InterfaceIndex");
}
[Test] // .ctor (IPAddress, Int64)
public void Constructor2_Group_Null ()
{
IPAddress group = null;
try {
new IPv6MulticastOption (group, 0);
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, Int64)
public void Constructor2_Ifindex_OutOfRange ()
{
IPAddress group = IPAddress.Parse ("ff02::1");
try {
new IPv6MulticastOption (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 ("ifindex", ex.ParamName, "#A5");
}
try {
new IPv6MulticastOption (group, 0x100000000);
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 ("ifindex", ex.ParamName, "#B5");
}
}
[Test]
public void Group ()
{
IPAddress group;
IPv6MulticastOption option;
group = IPAddress.Parse ("239.255.255.250");
option = new IPv6MulticastOption (group, 5L);
group = IPAddress.Parse ("224.0.0.23");
option.Group = group;
Assert.AreSame (group, option.Group, "#A1");
Assert.AreEqual (5L, option.InterfaceIndex, "#A2");
group = IPAddress.Parse ("239.255.255.250");
option.Group = group;
Assert.AreSame (group, option.Group, "#B1");
Assert.AreEqual (5L, option.InterfaceIndex, "#B2");
group = IPAddress.Parse ("ff02::1");
option.Group = group;
Assert.AreSame (group, option.Group, "#C1");
Assert.AreEqual (5L, option.InterfaceIndex, "#C2");
}
[Test]
public void Group_Value_Null ()
{
IPAddress group = IPAddress.Parse ("239.255.255.250");
IPv6MulticastOption option = new IPv6MulticastOption (group, 10);
try {
option.Group = 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 ("value", ex.ParamName, "#5");
}
}
[Test]
public void InterfaceIndex ()
{
IPAddress group;
IPv6MulticastOption option;
group = IPAddress.Parse ("239.255.255.250");
option = new IPv6MulticastOption (group, 10);
option.InterfaceIndex = 0;
Assert.AreSame (group, option.Group, "#A1");
Assert.AreEqual (0, option.InterfaceIndex, "#A2");
option.InterfaceIndex = 124;
Assert.AreSame (group, option.Group, "#B1");
Assert.AreEqual (124, option.InterfaceIndex, "#B2");
option.InterfaceIndex = 0xFFFFFFFF;
Assert.AreSame (group, option.Group, "#C1");
Assert.AreEqual (0xFFFFFFFF, option.InterfaceIndex, "#C3");
}
[Test]
public void InterfaceIndex_Value_OutOfRange ()
{
IPAddress group = IPAddress.Parse ("239.255.255.250");
IPv6MulticastOption option = new IPv6MulticastOption (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 = 0x100000000;
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");
}
}
}
|