Merge pull request #1109 from adbre/iss358
[mono.git] / mcs / class / System / Test / System.Net.NetworkInformation / PhysicalAddressTest.cs
1 using NUnit.Framework;
2 using System;
3 #if NET_2_0
4 using System.Net.NetworkInformation;
5
6 namespace MonoTests.System.Net.NetworkInformation
7 {
8         [TestFixture]
9         public class PhysicalAddressTest
10         {
11                 [Test] 
12                 public void CreateNormal()
13                 {
14                         // Normal case, creation of physical address
15                         PhysicalAddress phys = new PhysicalAddress(new byte [] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
16                 }
17
18                 [Test]
19                 public void CreateWithLarger()
20                 {
21                         // MS.NET 2.0 Allows Physical Address to be created if array larger than normal
22                         PhysicalAddress phys = new PhysicalAddress(new byte [] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
23                 }
24
25                 [Test]
26                 public void CreateWithSmaller()
27                 {
28                         // MS.NET 2.0 Allows Physical Address to be created if array smaller than normal
29                         PhysicalAddress phys = new PhysicalAddress(new byte [] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
30                 }
31
32                 [Test]
33                 public void ParseNull()
34                 {
35                         // MS.NET 2.0 returns empty PhysicalAddress when passed null
36                         PhysicalAddress phys = PhysicalAddress.Parse(null);
37                         Assert.AreEqual(0, phys.GetAddressBytes().Length);
38                 }
39
40                 [Test]
41                 [ExpectedException(typeof(FormatException))]
42                 public void ParseEmpty()
43                 {
44                         // MS.NET 2.0 Fails parse when empty
45                         PhysicalAddress phys = PhysicalAddress.Parse("");
46                 }
47
48                 [Test]
49                 public void ParseWithoutDash()
50                 {
51                         // MS.NET 2.0 Parses without the dash separator
52                         PhysicalAddress phys = PhysicalAddress.Parse("010203040506");
53                 }
54
55                 [Test]
56                 [ExpectedException(typeof(FormatException))]
57                 public void ParseWithoutDashToFewChars()
58                 {
59                         // MS.NET 2.0 Fails parse when too few characters
60                         PhysicalAddress phys = PhysicalAddress.Parse("01020304050");
61                 }
62
63                 [Test]
64                 [ExpectedException(typeof(FormatException))]
65                 public void ParseWithoutDashToManyChars()
66                 {
67                         // MS.NET 2.0 Fails parse when too many characters
68                         PhysicalAddress phys = PhysicalAddress.Parse("0102030405060");
69                 }
70
71                 [Test]
72                 public void ParseWithDash()
73                 {
74                         PhysicalAddress phys = PhysicalAddress.Parse("01-02-03-04-05-06");
75                 }
76
77                 [Test]
78                 [ExpectedException(typeof(IndexOutOfRangeException))]
79                 public void ParseWithDashToFewChars()
80                 {
81                         PhysicalAddress phys = PhysicalAddress.Parse("01-02-03-04-05-0");
82                 }
83
84                 [Test]
85                 [ExpectedException(typeof(FormatException))]
86                 public void ParseWithDashToManyChars()
87                 {
88                         PhysicalAddress phys = PhysicalAddress.Parse("01-02-03-04-05-060");
89                 }
90
91                 [Test]
92                 public void GetHashCodeEqual()
93                 {
94                         PhysicalAddress phys1 = new PhysicalAddress(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
95                         PhysicalAddress phys2 = new PhysicalAddress(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
96
97                         Assert.AreEqual(phys1.GetHashCode(), phys2.GetHashCode());
98                 }
99
100                 [Test]
101                 public void GetHashCodeNotEqual()
102                 {
103                         PhysicalAddress phys1 = new PhysicalAddress(new byte[] { 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 });
104                         PhysicalAddress phys2 = new PhysicalAddress(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
105
106                         Assert.IsFalse(phys1.GetHashCode().Equals(phys2.GetHashCode()));
107                 }
108
109                 [Test]
110                 public void ToStringTest()
111                 {
112                         PhysicalAddress phys1 = new PhysicalAddress(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
113                         Assert.AreEqual("010203040506", phys1.ToString());
114                 }
115
116                 [Test]
117                 public void EqualsNormal()
118                 {
119                         PhysicalAddress phys1 = new PhysicalAddress(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
120                         PhysicalAddress phys2 = new PhysicalAddress(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
121
122                         Assert.IsTrue(phys1.Equals(phys2));
123                 }
124
125                 [Test]
126                 public void EqualsNot()
127                 {
128                         PhysicalAddress phys1 = new PhysicalAddress(new byte[] { 0x06, 0x5, 0x04, 0x03, 0x02, 0x01 });
129                         PhysicalAddress phys2 = new PhysicalAddress(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
130
131                         Assert.IsTrue(!phys1.Equals(phys2));
132                 }
133         }
134 }
135
136 #endif