public void IgmpClient_AddressSpaceTest() { var client = new IgmpClient(); var arr = IPAddress.Parse("224.0.0.0").GetAddressBytes(); if (BitConverter.IsLittleEndian) { Array.Reverse(arr); } var validStartAddrRange = BitConverter.ToUInt32(arr, 0); arr = IPAddress.Parse("224.0.0.0").GetAddressBytes(); if (BitConverter.IsLittleEndian) { Array.Reverse(arr); } var validStopAddrRange = BitConverter.ToUInt32(arr, 0); for (uint i = validStartAddrRange; i <= validStopAddrRange; i++) { var ipAddr = BitConverter.GetBytes(i); if (BitConverter.IsLittleEndian) { Array.Reverse(ipAddr); } client.Start(new IPAddress(ipAddr), 2000, ExchangeType.Sender); client.Stop(); } client.Dispose(); }
public void IgmpClient_SendReceive1instanceTest() { var ipaddr = IPAddress.Parse("224.0.0.0"); var client1 = new IgmpClient(); client1.DataReceivedEvent += Client1_DataReceivedEvent; client1.ErrorEvent += Client_ErrorEvent; client1.Start(ipaddr, 2000, ExchangeType.SenderAndReceiver); Thread.Sleep(100); for (int i = 1; i < 10; i++) { var data = BitConverter.GetBytes(i); Client1DataReceivedEvent.Clear(); Assert.AreEqual(0, Client1DataReceivedEvent.Count); client1.SendData(data); Thread.Sleep(100); Assert.AreEqual(1, Client1DataReceivedEvent.Count); Assert.AreEqual(data.Length, Client1DataReceivedEvent[0].Data.Length); for (int j = 0; j < data.Length; j++) { Assert.AreEqual(data[j], Client1DataReceivedEvent[0].Data[j]); } } client1.Dispose(); }
public void IgmpClient_PropertiesTest() { var client = new IgmpClient(); client.ErrorEvent += Client_ErrorEvent; client.PropertyChanged += Client_PropertyChanged; ClientPropertyChangedEventArgs = null; Assert.IsNull(ClientPropertyChangedEventArgs); var intVal = client.ReadBufferSize + 1; client.ReadBufferSize = intVal; Assert.AreEqual("ReadBufferSize", ClientPropertyChangedEventArgs?.PropertyName); Assert.AreEqual(intVal, client.ReadBufferSize); client.DataTrace = false; ClientPropertyChangedEventArgs = null; Assert.IsNull(ClientPropertyChangedEventArgs); client.DataTrace = !client.DataTrace; Assert.AreEqual("DataTrace", ClientPropertyChangedEventArgs?.PropertyName); Assert.IsTrue(client.DataTrace); client.Start(IPAddress.Parse("224.0.0.0"), 2000, ExchangeType.Sender); Assert.AreEqual(IPAddress.Parse("224.0.0.0"), client.MulticastIpAddress); client.Dispose(); }
public void IgmpClient_CreateStartStopDisposeTest() { var client = new IgmpClient(); client.ErrorEvent += Client_ErrorEvent; Assert.IsFalse(client.DataTrace); Assert.IsFalse(client.IsStarted); Assert.IsFalse(client.IsDisposed); ClientPropertyChangedEventArgs = null; StoppedEventColled = false; StartedEventColled = false; Assert.IsNull(ClientPropertyChangedEventArgs); Assert.IsFalse(StoppedEventColled); Assert.IsFalse(StartedEventColled); //Check just properties and events client.Start(IPAddress.Parse("224.0.0.0"), 2000, ExchangeType.Sender); Assert.IsFalse(client.DataTrace); Assert.IsTrue(client.IsStarted); Assert.IsFalse(client.IsDisposed); Assert.IsNull(ClientPropertyChangedEventArgs); Assert.IsFalse(StoppedEventColled); Assert.IsFalse(StartedEventColled); client.Stop(); Assert.IsFalse(client.DataTrace); Assert.IsFalse(client.IsStarted); Assert.IsFalse(client.IsDisposed); Assert.IsNull(ClientPropertyChangedEventArgs); Assert.IsFalse(StoppedEventColled); Assert.IsFalse(StartedEventColled); client.PropertyChanged += Client_PropertyChanged; client.StartedEvent += Client_StartedEvent; client.StoppedEvent += Client_StoppedEvent; //Start with events client.Start(IPAddress.Parse("239.255.255.255"), 2000, ExchangeType.SenderAndReceiver); Assert.IsFalse(client.DataTrace); Assert.IsTrue(client.IsStarted); Assert.IsFalse(client.IsDisposed); Assert.AreEqual("IsStarted", ClientPropertyChangedEventArgs?.PropertyName); Assert.IsFalse(StoppedEventColled); Assert.IsTrue(StartedEventColled); ClientPropertyChangedEventArgs = null; StoppedEventColled = false; StartedEventColled = false; Assert.IsNull(ClientPropertyChangedEventArgs); Assert.IsFalse(StoppedEventColled); Assert.IsFalse(StartedEventColled); client.Stop(); Assert.IsFalse(client.DataTrace); Assert.IsFalse(client.IsStarted); Assert.IsFalse(client.IsDisposed); Assert.AreEqual("IsStarted", ClientPropertyChangedEventArgs?.PropertyName); Assert.IsTrue(StoppedEventColled); Assert.IsFalse(StartedEventColled); client.Start(IPAddress.Parse("224.0.0.0"), 2000, ExchangeType.Sender); client.Dispose(); Assert.IsFalse(client.IsStarted); Assert.IsTrue(client.IsDisposed); }