Commit 0808ef5b authored by Brickner_cp's avatar Brickner_cp

Code Coverage 97.91%

parent 0f4c9f93
...@@ -47,7 +47,7 @@ namespace PcapDotNet.Core.Test ...@@ -47,7 +47,7 @@ namespace PcapDotNet.Core.Test
#endregion #endregion
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void BadFilterErrorTest() public void BadFilterErrorTest()
{ {
using (PacketCommunicator communicator = LivePacketDeviceTests.OpenLiveDevice()) using (PacketCommunicator communicator = LivePacketDeviceTests.OpenLiveDevice())
......
...@@ -136,7 +136,7 @@ namespace PcapDotNet.Core.Test ...@@ -136,7 +136,7 @@ namespace PcapDotNet.Core.Test
// Break loop // Break loop
TestReceivePackets(NumPacketsToSend, NumPacketsToSend, 0, 2, PacketSize, PacketCommunicatorReceiveResult.BreakLoop, 0, 0, 0.027); TestReceivePackets(NumPacketsToSend, NumPacketsToSend, 0, 2, PacketSize, PacketCommunicatorReceiveResult.BreakLoop, 0, 0, 0.027);
TestReceivePackets(NumPacketsToSend, NumPacketsToSend, NumPacketsToSend / 2, 2, PacketSize, PacketCommunicatorReceiveResult.BreakLoop, NumPacketsToSend / 2, 0, 0.02); TestReceivePackets(NumPacketsToSend, NumPacketsToSend, NumPacketsToSend / 2, 2, PacketSize, PacketCommunicatorReceiveResult.BreakLoop, NumPacketsToSend / 2, 0, 0.031);
} }
[TestMethod] [TestMethod]
......
...@@ -96,7 +96,7 @@ namespace PcapDotNet.Core.Test ...@@ -96,7 +96,7 @@ namespace PcapDotNet.Core.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void InvalidNameErrorTest() public void InvalidNameErrorTest()
{ {
PcapDataLink dataLink = new PcapDataLink("Invalid Name"); PcapDataLink dataLink = new PcapDataLink("Invalid Name");
......
...@@ -109,7 +109,7 @@ namespace PcapDotNet.Packets.Test ...@@ -109,7 +109,7 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void ArpIncosistentSenderAddressSizeTest() public void ArpIncosistentSenderAddressSizeTest()
{ {
Packet packet = PacketBuilder.Build(DateTime.Now, Packet packet = PacketBuilder.Build(DateTime.Now,
...@@ -131,7 +131,7 @@ namespace PcapDotNet.Packets.Test ...@@ -131,7 +131,7 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void ArpIncosistentTargetAddressSizeTest() public void ArpIncosistentTargetAddressSizeTest()
{ {
Packet packet = PacketBuilder.Build(DateTime.Now, Packet packet = PacketBuilder.Build(DateTime.Now,
...@@ -151,5 +151,21 @@ namespace PcapDotNet.Packets.Test ...@@ -151,5 +151,21 @@ namespace PcapDotNet.Packets.Test
Assert.IsNull(packet); Assert.IsNull(packet);
Assert.Fail(); Assert.Fail();
} }
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void ArpWriteNullPreviousLayerTest()
{
new ArpLayer().Write(new byte[0], 0, 0, null, new PayloadLayer());
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void ArpWriteBadPreviousLayerTest()
{
new ArpLayer().Write(new byte[0], 0, 0, new PayloadLayer(), new PayloadLayer());
Assert.Fail();
}
} }
} }
\ No newline at end of file
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace PcapDotNet.Packets.Test
{
/// <summary>
/// Summary description for ByteArrayExtensionsTests
/// </summary>
[TestClass]
public class ByteArrayExtensionsTests
{
public ByteArrayExtensionsTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext { get; set; }
#region Additional test attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#endregion
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void WriteByteNullBufferTest()
{
ByteArrayExtensions.Write(null, 0, 1);
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void WriteEnumerableNullBufferTest()
{
int offset = 0;
ByteArrayExtensions.Write(null, ref offset, new byte[0]);
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void WriteEnumerableNullEnumerableTest()
{
int offset = 0;
new byte[0].Write(ref offset, (IEnumerable<byte>)null);
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void WriteDatagramNullBufferTest()
{
new byte[0].Write(0, null);
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void WriteRefDatagramNullBufferTest()
{
int offset = 0;
new byte[0].Write(ref offset, null);
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void ReadByteNullBufferTest()
{
Assert.IsNotNull(ByteArrayExtensions.ReadByte(null, 0));
Assert.Fail();
}
}
}
\ No newline at end of file
...@@ -128,5 +128,13 @@ namespace PcapDotNet.Packets.Test ...@@ -128,5 +128,13 @@ namespace PcapDotNet.Packets.Test
} }
} }
} }
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void DatagramConstructorNullBufferTest()
{
Assert.IsNotNull(new Datagram(null));
Assert.Fail();
}
} }
} }
\ No newline at end of file
...@@ -79,7 +79,7 @@ namespace PcapDotNet.Packets.Test ...@@ -79,7 +79,7 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void AutomaticEthernetTypeNoNextLayer() public void AutomaticEthernetTypeNoNextLayer()
{ {
Packet packet = PacketBuilder.Build(DateTime.Now, new EthernetLayer()); Packet packet = PacketBuilder.Build(DateTime.Now, new EthernetLayer());
...@@ -87,7 +87,7 @@ namespace PcapDotNet.Packets.Test ...@@ -87,7 +87,7 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void AutomaticEthernetTypeBadNextLayer() public void AutomaticEthernetTypeBadNextLayer()
{ {
Packet packet = PacketBuilder.Build(DateTime.Now, new EthernetLayer(), new TcpLayer()); Packet packet = PacketBuilder.Build(DateTime.Now, new EthernetLayer(), new TcpLayer());
......
...@@ -188,7 +188,7 @@ namespace PcapDotNet.Packets.Test ...@@ -188,7 +188,7 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void GreAutomaticProtocolTypeNoNextLayer() public void GreAutomaticProtocolTypeNoNextLayer()
{ {
Packet packet = PacketBuilder.Build(DateTime.Now, new EthernetLayer(), new IpV4Layer(), new GreLayer()); Packet packet = PacketBuilder.Build(DateTime.Now, new EthernetLayer(), new IpV4Layer(), new GreLayer());
...@@ -196,7 +196,7 @@ namespace PcapDotNet.Packets.Test ...@@ -196,7 +196,7 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void GreAutomaticProtocolTypeBadNextLayer() public void GreAutomaticProtocolTypeBadNextLayer()
{ {
Packet packet = PacketBuilder.Build(DateTime.Now, new EthernetLayer(), new IpV4Layer(), new GreLayer(), new PayloadLayer()); Packet packet = PacketBuilder.Build(DateTime.Now, new EthernetLayer(), new IpV4Layer(), new GreLayer(), new PayloadLayer());
......
...@@ -196,5 +196,19 @@ namespace PcapDotNet.Packets.Test ...@@ -196,5 +196,19 @@ namespace PcapDotNet.Packets.Test
Assert.AreNotEqual(entry1, entry2); Assert.AreNotEqual(entry1, entry2);
Assert.AreNotEqual(entry1.GetHashCode(), entry2.GetHashCode()); Assert.AreNotEqual(entry1.GetHashCode(), entry2.GetHashCode());
} }
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void IcmpDatagramCreateDatagramNullBufferTest()
{
Assert.IsNotNull(IcmpDatagram.CreateDatagram(null, 0, 0));
Assert.Fail();
}
[TestMethod]
public void IcmpDatagramCreateDatagramBadOffsetTest()
{
Assert.IsInstanceOfType(IcmpDatagram.CreateDatagram(new byte[0], -1, 0), typeof(IcmpUnknownDatagram));
}
} }
} }
\ No newline at end of file
...@@ -96,6 +96,46 @@ namespace PcapDotNet.Packets.Test ...@@ -96,6 +96,46 @@ namespace PcapDotNet.Packets.Test
MoreAssert.IsSmallerOrEqual(IgmpDatagram.MaxMaxResponseTime, packet.Ethernet.IpV4.Igmp.MaxResponseTime); MoreAssert.IsSmallerOrEqual(IgmpDatagram.MaxMaxResponseTime, packet.Ethernet.IpV4.Igmp.MaxResponseTime);
if (packet.Ethernet.IpV4.Igmp.MessageType != IgmpMessageType.MembershipQuery) if (packet.Ethernet.IpV4.Igmp.MessageType != IgmpMessageType.MembershipQuery)
Assert.AreEqual(IgmpQueryVersion.None, packet.Ethernet.IpV4.Igmp.QueryVersion); Assert.AreEqual(IgmpQueryVersion.None, packet.Ethernet.IpV4.Igmp.QueryVersion);
switch (igmpLayer.MessageType)
{
case IgmpMessageType.MembershipQuery:
switch (igmpLayer.QueryVersion)
{
case IgmpQueryVersion.Version1:
Assert.AreEqual(1, packet.Ethernet.IpV4.Igmp.Version);
break;
case IgmpQueryVersion.Version2:
Assert.AreEqual(2, packet.Ethernet.IpV4.Igmp.Version);
break;
case IgmpQueryVersion.Version3:
Assert.AreEqual(3, packet.Ethernet.IpV4.Igmp.Version);
break;
default:
Assert.Fail(igmpLayer.QueryVersion.ToString());
break;
}
break;
case IgmpMessageType.MembershipReportVersion1:
Assert.AreEqual(1, packet.Ethernet.IpV4.Igmp.Version);
break;
case IgmpMessageType.MembershipReportVersion2:
case IgmpMessageType.LeaveGroupVersion2:
Assert.AreEqual(2, packet.Ethernet.IpV4.Igmp.Version);
break;
case IgmpMessageType.MembershipReportVersion3:
Assert.AreEqual(3, packet.Ethernet.IpV4.Igmp.Version);
break;
default:
Assert.Fail(igmpLayer.MessageType.ToString());
break;
}
foreach (IgmpGroupRecordDatagram groupRecord in packet.Ethernet.IpV4.Igmp.GroupRecords) foreach (IgmpGroupRecordDatagram groupRecord in packet.Ethernet.IpV4.Igmp.GroupRecords)
Assert.IsNotNull(groupRecord.ToString()); Assert.IsNotNull(groupRecord.ToString());
} }
...@@ -333,7 +373,7 @@ namespace PcapDotNet.Packets.Test ...@@ -333,7 +373,7 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IgmpGroupRecordBadAuxiliaryDataLengthTest() public void IgmpGroupRecordBadAuxiliaryDataLengthTest()
{ {
IgmpGroupRecord record = new IgmpGroupRecord(IgmpRecordType.SourceListChangeAllowNewSources, IpV4Address.Zero, new List<IpV4Address>(), IgmpGroupRecord record = new IgmpGroupRecord(IgmpRecordType.SourceListChangeAllowNewSources, IpV4Address.Zero, new List<IpV4Address>(),
...@@ -396,5 +436,13 @@ namespace PcapDotNet.Packets.Test ...@@ -396,5 +436,13 @@ namespace PcapDotNet.Packets.Test
}; };
Assert.IsFalse(layer1.Equals(layer2)); Assert.IsFalse(layer1.Equals(layer2));
} }
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void IgmpGroupRecordConstructorNullTest()
{
Assert.IsNotNull(new IgmpGroupRecord(IgmpRecordType.FilterModeChangeToExclude, IpV4Address.Zero, new IpV4Address[0], null));
Assert.Fail();
}
} }
} }
\ No newline at end of file
...@@ -116,5 +116,13 @@ namespace PcapDotNet.Packets.Test ...@@ -116,5 +116,13 @@ namespace PcapDotNet.Packets.Test
Assert.AreNotEqual(address, buffer.ReadIpV4Address(0, Endianity.Big)); Assert.AreNotEqual(address, buffer.ReadIpV4Address(0, Endianity.Big));
} }
} }
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void IpV4AddressConstructorNullTest()
{
Assert.IsNotNull(new IpV4Address(null));
Assert.Fail();
}
} }
} }
...@@ -155,7 +155,7 @@ namespace PcapDotNet.Packets.Test ...@@ -155,7 +155,7 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV6AddressNoColonTest() public void IpV6AddressNoColonTest()
{ {
IpV6Address ipV6Address = new IpV6Address("123"); IpV6Address ipV6Address = new IpV6Address("123");
...@@ -163,11 +163,19 @@ namespace PcapDotNet.Packets.Test ...@@ -163,11 +163,19 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV6AddressDoubleColonsWithoutMissingColonsTest() public void IpV6AddressDoubleColonsWithoutMissingColonsTest()
{ {
IpV6Address ipV6Address = new IpV6Address("1::2:3:4:5:6:7:8"); IpV6Address ipV6Address = new IpV6Address("1::2:3:4:5:6:7:8");
Assert.AreEqual(ipV6Address, ipV6Address); Assert.AreEqual(ipV6Address, ipV6Address);
} }
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void IpV6AddressConstructorNullTest()
{
Assert.IsNotNull(new IpV6Address(null));
Assert.Fail();
}
} }
} }
\ No newline at end of file
...@@ -101,12 +101,20 @@ namespace PcapDotNet.Packets.Test ...@@ -101,12 +101,20 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void MacAddressBadStringErrorTest() public void MacAddressBadStringErrorTest()
{ {
MacAddress address = new MacAddress("12:34:56:78"); MacAddress address = new MacAddress("12:34:56:78");
Assert.IsNotNull(address); Assert.IsNotNull(address);
Assert.Fail(); Assert.Fail();
} }
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void MacAddressConstructorNullTest()
{
Assert.IsNotNull(new MacAddress(null));
Assert.Fail();
}
} }
} }
\ No newline at end of file
...@@ -46,7 +46,7 @@ namespace PcapDotNet.Packets.Test ...@@ -46,7 +46,7 @@ namespace PcapDotNet.Packets.Test
#endregion #endregion
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void NoLayersTest() public void NoLayersTest()
{ {
PacketBuilder packetBuilder = new PacketBuilder(); PacketBuilder packetBuilder = new PacketBuilder();
...@@ -54,11 +54,20 @@ namespace PcapDotNet.Packets.Test ...@@ -54,11 +54,20 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void BadFirstLayerTest() public void BadFirstLayerTest()
{ {
PacketBuilder packetBuilder = new PacketBuilder(new TcpLayer()); PacketBuilder packetBuilder = new PacketBuilder(new TcpLayer());
Assert.IsNull(packetBuilder); Assert.IsNull(packetBuilder);
} }
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void PacketBuilderConstructorNullTest()
{
ILayer[] layers = null;
Assert.IsNotNull(new PacketBuilder(layers));
Assert.Fail();
}
} }
} }
\ No newline at end of file
...@@ -131,5 +131,13 @@ namespace PcapDotNet.Packets.Test ...@@ -131,5 +131,13 @@ namespace PcapDotNet.Packets.Test
Assert.Fail(); Assert.Fail();
} }
} }
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void PacketFromHexadecimalStringNullTest()
{
Assert.IsNotNull(Packet.FromHexadecimalString(null, DateTime.MinValue, DataLinkKind.Ethernet));
Assert.Fail();
}
} }
} }
\ No newline at end of file
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="ArpTests.cs" /> <Compile Include="ArpTests.cs" />
<Compile Include="ByteArrayExtensionsTests.cs" />
<Compile Include="DatagramTests.cs" /> <Compile Include="DatagramTests.cs" />
<Compile Include="DataLinkTests.cs" /> <Compile Include="DataLinkTests.cs" />
<Compile Include="EndianitiyTests.cs" /> <Compile Include="EndianitiyTests.cs" />
......
...@@ -144,7 +144,7 @@ namespace PcapDotNet.Packets.Test ...@@ -144,7 +144,7 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void TcpOptionMd5SignatureConstructorErrorDataLengthTest() public void TcpOptionMd5SignatureConstructorErrorDataLengthTest()
{ {
new TcpOptionMd5Signature(new byte[10]); new TcpOptionMd5Signature(new byte[10]);
...@@ -172,5 +172,27 @@ namespace PcapDotNet.Packets.Test ...@@ -172,5 +172,27 @@ namespace PcapDotNet.Packets.Test
Assert.IsFalse(packet.Ethernet.IpV4.Tcp.Options.IsValid); Assert.IsFalse(packet.Ethernet.IpV4.Tcp.Options.IsValid);
} }
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void TcpOptionMd5SignatureConstructorNullTest()
{
Assert.IsNotNull(new TcpOptionMd5Signature(null));
Assert.Fail();
}
[TestMethod]
public void TcpOptionCreateInstanceBadValueLengthTest()
{
int offset = 0;
Assert.IsNull(new TcpOptionPartialOrderServiceProfile().CreateInstance(new byte[0], ref offset, 123));
Assert.IsNull(new TcpOptionTimestamp().CreateInstance(new byte[0], ref offset, 123));
Assert.IsNull(new TcpOptionAlternateChecksumRequest().CreateInstance(new byte[0], ref offset, 123));
Assert.IsNull(new TcpOptionConnectionCount().CreateInstance(new byte[0], ref offset, 123));
Assert.IsNull(new TcpOptionConnectionCountEcho().CreateInstance(new byte[0], ref offset, 123));
Assert.IsNull(new TcpOptionEcho().CreateInstance(new byte[0], ref offset, 123));
Assert.IsNull(new TcpOptionSelectiveAcknowledgment().CreateInstance(new byte[0], ref offset, 1));
Assert.IsNull(new TcpOptionWindowScale().CreateInstance(new byte[0], ref offset, 123));
}
} }
} }
\ No newline at end of file
...@@ -91,7 +91,7 @@ namespace PcapDotNet.Packets.Arp ...@@ -91,7 +91,7 @@ namespace PcapDotNet.Packets.Arp
public override void Write(byte[] buffer, int offset, int payloadLength, ILayer previousLayer, ILayer nextLayer) public override void Write(byte[] buffer, int offset, int payloadLength, ILayer previousLayer, ILayer nextLayer)
{ {
if (previousLayer == null) if (previousLayer == null)
throw new ArgumentException("Must have a previous layer"); throw new ArgumentNullException("previousLayer");
IArpPreviousLayer arpPreviousLayer = previousLayer as IArpPreviousLayer; IArpPreviousLayer arpPreviousLayer = previousLayer as IArpPreviousLayer;
if (arpPreviousLayer == null) if (arpPreviousLayer == null)
......
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