Commit 0808ef5b authored by Brickner_cp's avatar Brickner_cp

Code Coverage 97.91%

parent 0f4c9f93
......@@ -47,7 +47,7 @@ namespace PcapDotNet.Core.Test
#endregion
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void BadFilterErrorTest()
{
using (PacketCommunicator communicator = LivePacketDeviceTests.OpenLiveDevice())
......
......@@ -136,7 +136,7 @@ namespace PcapDotNet.Core.Test
// Break loop
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]
......
......@@ -96,7 +96,7 @@ namespace PcapDotNet.Core.Test
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void InvalidNameErrorTest()
{
PcapDataLink dataLink = new PcapDataLink("Invalid Name");
......
......@@ -109,7 +109,7 @@ namespace PcapDotNet.Packets.Test
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void ArpIncosistentSenderAddressSizeTest()
{
Packet packet = PacketBuilder.Build(DateTime.Now,
......@@ -131,7 +131,7 @@ namespace PcapDotNet.Packets.Test
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void ArpIncosistentTargetAddressSizeTest()
{
Packet packet = PacketBuilder.Build(DateTime.Now,
......@@ -151,5 +151,21 @@ namespace PcapDotNet.Packets.Test
Assert.IsNull(packet);
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
}
}
}
[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
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void AutomaticEthernetTypeNoNextLayer()
{
Packet packet = PacketBuilder.Build(DateTime.Now, new EthernetLayer());
......@@ -87,7 +87,7 @@ namespace PcapDotNet.Packets.Test
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void AutomaticEthernetTypeBadNextLayer()
{
Packet packet = PacketBuilder.Build(DateTime.Now, new EthernetLayer(), new TcpLayer());
......
......@@ -188,7 +188,7 @@ namespace PcapDotNet.Packets.Test
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void GreAutomaticProtocolTypeNoNextLayer()
{
Packet packet = PacketBuilder.Build(DateTime.Now, new EthernetLayer(), new IpV4Layer(), new GreLayer());
......@@ -196,7 +196,7 @@ namespace PcapDotNet.Packets.Test
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void GreAutomaticProtocolTypeBadNextLayer()
{
Packet packet = PacketBuilder.Build(DateTime.Now, new EthernetLayer(), new IpV4Layer(), new GreLayer(), new PayloadLayer());
......
......@@ -196,5 +196,19 @@ namespace PcapDotNet.Packets.Test
Assert.AreNotEqual(entry1, entry2);
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
MoreAssert.IsSmallerOrEqual(IgmpDatagram.MaxMaxResponseTime, packet.Ethernet.IpV4.Igmp.MaxResponseTime);
if (packet.Ethernet.IpV4.Igmp.MessageType != IgmpMessageType.MembershipQuery)
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)
Assert.IsNotNull(groupRecord.ToString());
}
......@@ -333,7 +373,7 @@ namespace PcapDotNet.Packets.Test
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IgmpGroupRecordBadAuxiliaryDataLengthTest()
{
IgmpGroupRecord record = new IgmpGroupRecord(IgmpRecordType.SourceListChangeAllowNewSources, IpV4Address.Zero, new List<IpV4Address>(),
......@@ -396,5 +436,13 @@ namespace PcapDotNet.Packets.Test
};
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
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
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV6AddressNoColonTest()
{
IpV6Address ipV6Address = new IpV6Address("123");
......@@ -163,11 +163,19 @@ namespace PcapDotNet.Packets.Test
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV6AddressDoubleColonsWithoutMissingColonsTest()
{
IpV6Address ipV6Address = new IpV6Address("1::2:3:4:5:6:7:8");
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
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void MacAddressBadStringErrorTest()
{
MacAddress address = new MacAddress("12:34:56:78");
Assert.IsNotNull(address);
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
#endregion
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void NoLayersTest()
{
PacketBuilder packetBuilder = new PacketBuilder();
......@@ -54,11 +54,20 @@ namespace PcapDotNet.Packets.Test
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void BadFirstLayerTest()
{
PacketBuilder packetBuilder = new PacketBuilder(new TcpLayer());
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
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 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ArpTests.cs" />
<Compile Include="ByteArrayExtensionsTests.cs" />
<Compile Include="DatagramTests.cs" />
<Compile Include="DataLinkTests.cs" />
<Compile Include="EndianitiyTests.cs" />
......
......@@ -144,7 +144,7 @@ namespace PcapDotNet.Packets.Test
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void TcpOptionMd5SignatureConstructorErrorDataLengthTest()
{
new TcpOptionMd5Signature(new byte[10]);
......@@ -172,5 +172,27 @@ namespace PcapDotNet.Packets.Test
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
public override void Write(byte[] buffer, int offset, int payloadLength, ILayer previousLayer, ILayer nextLayer)
{
if (previousLayer == null)
throw new ArgumentException("Must have a previous layer");
throw new ArgumentNullException("previousLayer");
IArpPreviousLayer arpPreviousLayer = previousLayer as IArpPreviousLayer;
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