3 using System.Net.NetworkInformation;
5 namespace MonoTests.System.Net.NetworkInformation
8 public class PhysicalAddressTest
11 public void CreateNormal()
13 // Normal case, creation of physical address
14 PhysicalAddress phys = new PhysicalAddress(new byte [] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
18 public void CreateWithLarger()
20 // MS.NET 2.0 Allows Physical Address to be created if array larger than normal
21 PhysicalAddress phys = new PhysicalAddress(new byte [] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
25 public void CreateWithSmaller()
27 // MS.NET 2.0 Allows Physical Address to be created if array smaller than normal
28 PhysicalAddress phys = new PhysicalAddress(new byte [] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
32 public void ParseNull()
34 // MS.NET 2.0 returns empty PhysicalAddress when passed null
35 PhysicalAddress phys = PhysicalAddress.Parse(null);
36 Assert.AreEqual(0, phys.GetAddressBytes().Length);
40 [ExpectedException(typeof(FormatException))]
41 public void ParseEmpty()
43 // MS.NET 2.0 Fails parse when empty
44 PhysicalAddress phys = PhysicalAddress.Parse("");
48 public void ParseWithoutDash()
50 // MS.NET 2.0 Parses without the dash separator
51 PhysicalAddress phys = PhysicalAddress.Parse("010203040506");
55 [ExpectedException(typeof(FormatException))]
56 public void ParseWithoutDashToFewChars()
58 // MS.NET 2.0 Fails parse when too few characters
59 PhysicalAddress phys = PhysicalAddress.Parse("01020304050");
63 [ExpectedException(typeof(FormatException))]
64 public void ParseWithoutDashToManyChars()
66 // MS.NET 2.0 Fails parse when too many characters
67 PhysicalAddress phys = PhysicalAddress.Parse("0102030405060");
71 public void ParseWithDash()
73 PhysicalAddress phys = PhysicalAddress.Parse("01-02-03-04-05-06");
77 [ExpectedException(typeof(IndexOutOfRangeException))]
78 public void ParseWithDashToFewChars()
80 PhysicalAddress phys = PhysicalAddress.Parse("01-02-03-04-05-0");
84 [ExpectedException(typeof(FormatException))]
85 public void ParseWithDashToManyChars()
87 PhysicalAddress phys = PhysicalAddress.Parse("01-02-03-04-05-060");
91 public void GetHashCodeEqual()
93 PhysicalAddress phys1 = new PhysicalAddress(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
94 PhysicalAddress phys2 = new PhysicalAddress(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
96 Assert.AreEqual(phys1.GetHashCode(), phys2.GetHashCode());
100 public void GetHashCodeNotEqual()
102 PhysicalAddress phys1 = new PhysicalAddress(new byte[] { 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 });
103 PhysicalAddress phys2 = new PhysicalAddress(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
105 Assert.IsFalse(phys1.GetHashCode().Equals(phys2.GetHashCode()));
109 public void ToStringTest()
111 PhysicalAddress phys1 = new PhysicalAddress(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
112 Assert.AreEqual("010203040506", phys1.ToString());
116 public void EqualsNormal()
118 PhysicalAddress phys1 = new PhysicalAddress(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
119 PhysicalAddress phys2 = new PhysicalAddress(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
121 Assert.IsTrue(phys1.Equals(phys2));
125 public void EqualsNot()
127 PhysicalAddress phys1 = new PhysicalAddress(new byte[] { 0x06, 0x5, 0x04, 0x03, 0x02, 0x01 });
128 PhysicalAddress phys2 = new PhysicalAddress(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
130 Assert.IsTrue(!phys1.Equals(phys2));