4 using System.Net.NetworkInformation;
6 namespace MonoTests.System.Net.NetworkInformation
9 public class PhysicalAddressTest
12 public void CreateNormal()
14 // Normal case, creation of physical address
15 PhysicalAddress phys = new PhysicalAddress(new byte [] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
19 public void CreateWithLarger()
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 });
26 public void CreateWithSmaller()
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 });
33 public void ParseNull()
35 // MS.NET 2.0 returns empty PhysicalAddress when passed null
36 PhysicalAddress phys = PhysicalAddress.Parse(null);
37 Assert.AreEqual(0, phys.GetAddressBytes().Length);
41 [ExpectedException(typeof(FormatException))]
42 public void ParseEmpty()
44 // MS.NET 2.0 Fails parse when empty
45 PhysicalAddress phys = PhysicalAddress.Parse("");
49 public void ParseWithoutDash()
51 // MS.NET 2.0 Parses without the dash separator
52 PhysicalAddress phys = PhysicalAddress.Parse("010203040506");
56 [ExpectedException(typeof(FormatException))]
57 public void ParseWithoutDashToFewChars()
59 // MS.NET 2.0 Fails parse when too few characters
60 PhysicalAddress phys = PhysicalAddress.Parse("01020304050");
64 [ExpectedException(typeof(FormatException))]
65 public void ParseWithoutDashToManyChars()
67 // MS.NET 2.0 Fails parse when too many characters
68 PhysicalAddress phys = PhysicalAddress.Parse("0102030405060");
72 public void ParseWithDash()
74 PhysicalAddress phys = PhysicalAddress.Parse("01-02-03-04-05-06");
78 [ExpectedException(typeof(IndexOutOfRangeException))]
79 public void ParseWithDashToFewChars()
81 PhysicalAddress phys = PhysicalAddress.Parse("01-02-03-04-05-0");
85 [ExpectedException(typeof(FormatException))]
86 public void ParseWithDashToManyChars()
88 PhysicalAddress phys = PhysicalAddress.Parse("01-02-03-04-05-060");
92 public void GetHashCodeEqual()
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 });
97 Assert.AreEqual(phys1.GetHashCode(), phys2.GetHashCode());
101 public void GetHashCodeNotEqual()
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 });
106 Assert.IsFalse(phys1.GetHashCode().Equals(phys2.GetHashCode()));
110 public void ToStringTest()
112 PhysicalAddress phys1 = new PhysicalAddress(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
113 Assert.AreEqual("010203040506", phys1.ToString());
117 public void EqualsNormal()
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 });
122 Assert.IsTrue(phys1.Equals(phys2));
126 public void EqualsNot()
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 });
131 Assert.IsTrue(!phys1.Equals(phys2));