Commit 40982c0c authored by Brickner_cp's avatar Brickner_cp

Code Coverage 96.26%

parent 83dc50e8
......@@ -2,6 +2,8 @@ using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.IpV6;
using PcapDotNet.Packets.TestUtils;
using PcapDotNet.Packets.Transport;
......@@ -67,6 +69,13 @@ namespace PcapDotNet.Packets.Test
Assert.AreNotEqual(random.NextEthernetLayer().ToString(), packet.Ethernet.ExtractLayer().ToString(), "Ethernet Layer ToString()");
Assert.AreNotEqual(2, packet.Ethernet.Source, "Ethernet Source");
if (packet.Ethernet.EtherType == EthernetType.IpV4)
Assert.IsInstanceOfType(packet.Ethernet.Ip, typeof(IpV4Datagram));
else if (packet.Ethernet.EtherType == EthernetType.IpV6)
Assert.IsInstanceOfType(packet.Ethernet.Ip, typeof(IpV6Datagram));
else
Assert.IsNull(packet.Ethernet.Ip);
Assert.AreEqual(payloadLayer.Data, packet.Ethernet.Payload);
}
}
......
......@@ -4,6 +4,7 @@ using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.IpV6;
using PcapDotNet.Packets.TestUtils;
using PcapDotNet.Packets.Transport;
using PcapDotNet.TestUtils;
......@@ -155,9 +156,16 @@ namespace PcapDotNet.Packets.Test
Assert.IsInstanceOfType(packet.Ethernet.IpV4.Transport, typeof(TcpDatagram));
else if (packet.Ethernet.IpV4.Protocol == IpV4Protocol.Udp)
Assert.IsInstanceOfType(packet.Ethernet.IpV4.Transport, typeof(UdpDatagram));
else
else
Assert.IsNull(packet.Ethernet.IpV4.Transport);
if (packet.Ethernet.IpV4.Protocol == IpV4Protocol.Ip)
Assert.IsInstanceOfType(packet.Ethernet.IpV4.Ip, typeof(IpV4Datagram));
else if (packet.Ethernet.IpV4.Protocol == IpV4Protocol.IpV6)
Assert.IsInstanceOfType(packet.Ethernet.IpV4.Ip, typeof(IpV6Datagram));
else
Assert.IsNull(packet.Ethernet.IpV4.Ip);
Assert.AreEqual(payloadLayer.Data, packet.Ethernet.IpV4.Payload, "IP Payload");
}
}
......
......@@ -69,7 +69,7 @@ namespace PcapDotNet.Packets.Test
Random random = new Random();
int seed = random.Next();
Console.WriteLine("Seed: " + seed);
random = new Random(1930237499);
random = new Random(seed);
for (int i = 0; i != 1000; ++i)
{
......@@ -77,9 +77,6 @@ namespace PcapDotNet.Packets.Test
PayloadLayer payloadLayer = random.NextPayloadLayer(random.NextInt(0, 50 * 1024));
if (i < 26)
continue;
List<ILayer> layers = new List<ILayer> {ethernetLayer, ipV6Layer};
if (ipV6Layer.ExtensionHeaders.LastHeader != IpV4Protocol.EncapsulatingSecurityPayload)
layers.Add(payloadLayer);
......@@ -299,6 +296,38 @@ namespace PcapDotNet.Packets.Test
// IpV6ExtensionHeader tests.
[TestMethod]
public void IpV6ExtensionHeadersAutomaticNextHeaderByNextExtensionHeader()
{
Packet packet = PacketBuilder.Build(
DateTime.Now,
new EthernetLayer(),
new IpV6Layer
{
ExtensionHeaders = new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderDestinationOptions(null, IpV6Options.Empty),
new IpV6ExtensionHeaderDestinationOptions(IpV4Protocol.Skip, IpV6Options.Empty))
});
Assert.IsTrue(packet.IsValid);
Assert.AreEqual(IpV4Protocol.IpV6Opts, packet.Ethernet.IpV6.ExtensionHeaders[0].NextHeader);
}
[TestMethod]
[ExpectedException(typeof(InvalidOperationException), AllowDerivedTypes = false)]
public void IpV6ExtensionHeadersAutomaticNextHeaderFailure()
{
Assert.IsNull(PacketBuilder.Build(
DateTime.Now,
new EthernetLayer(),
new IpV6Layer
{
ExtensionHeaders = new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderDestinationOptions(null, IpV6Options.Empty))
}));
Assert.Fail();
}
[TestMethod]
public void IpV6ExtensionHeaderAuthenticationBadPayloadLength()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment