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();
}
}
}
......@@ -195,20 +195,6 @@ namespace PcapDotNet.Packets.Test
Options = new IpV4Options(new IpV4OptionTimestampOnly(0, 0)),
});
// public static Packet EthernetIpV4(DateTime timestamp,
// MacAddress ethernetSource, MacAddress ethernetDestination,
// byte ipV4TypeOfService, ushort ipV4Identification, IpV4Fragmentation ipV4Fragmentation,
// byte ipV4Ttl, IpV4Protocol ipV4Protocol,
// IpV4Address ipV4SourceAddress, IpV4Address ipV4DestinationAddress,
// IpV4Options ipV4Options,
// Datagram ipV4Payload)
// PacketBuilder.EthernetIpV4(DateTime.Now,
// new MacAddress(), new MacAddress(),
// 0, 0, new IpV4Fragmentation(), 0, 0, new IpV4Address(), new IpV4Address(),
// new IpV4Options(new IpV4OptionTimestampOnly(0, 0)),
// Datagram.Empty);
Assert.IsTrue(packet.Ethernet.IpV4.Options.IsValid);
// Bad Length
......@@ -264,11 +250,6 @@ namespace PcapDotNet.Packets.Test
Protocol = 0,
Options = new IpV4Options(new IpV4OptionLooseSourceRouting())
});
// PacketBuilder.EthernetIpV4(DateTime.Now,
// new MacAddress(), new MacAddress(),
// 0, 0, new IpV4Fragmentation(), 0, 0, new IpV4Address(), new IpV4Address(),
// new IpV4Options(new IpV4OptionLooseSourceRouting()),
// Datagram.Empty);
Assert.IsTrue(packet.Ethernet.IpV4.Options.IsValid);
byte[] buffer = packet.Buffer;
......@@ -304,7 +285,7 @@ namespace PcapDotNet.Packets.Test
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4OptionsTooLongErrorTest()
{
IpV4Options options = new IpV4Options(
......@@ -319,7 +300,7 @@ namespace PcapDotNet.Packets.Test
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4FragmentationOffsetErrorTest()
{
IpV4Fragmentation fragmentation = new IpV4Fragmentation(IpV4FragmentationOptions.None, 2);
......@@ -328,7 +309,7 @@ namespace PcapDotNet.Packets.Test
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4FragmentationOptionsErrorTest()
{
IpV4Fragmentation fragmentation = new IpV4Fragmentation((IpV4FragmentationOptions)12345, 8);
......@@ -368,7 +349,7 @@ namespace PcapDotNet.Packets.Test
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4OptionBasicSecurityConstructorNoProtectionAuthoritiesButWithValueTest()
{
IpV4OptionBasicSecurity option = new IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel.Secret, IpV4OptionSecurityProtectionAuthorities.Nsa, 3);
......@@ -377,7 +358,7 @@ namespace PcapDotNet.Packets.Test
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4OptionBasicSecurityConstructorBadClassificationLevelTest()
{
IpV4OptionBasicSecurity option = new IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel.None);
......@@ -397,12 +378,6 @@ namespace PcapDotNet.Packets.Test
Options = new IpV4Options(new IpV4OptionBasicSecurity()),
});
// Packet packet = PacketBuilder.EthernetIpV4(DateTime.Now,
// new MacAddress(), new MacAddress(),
// 0, 0, new IpV4Fragmentation(), 0, 0, new IpV4Address(), new IpV4Address(),
// new IpV4Options(new IpV4OptionBasicSecurity()),
// Datagram.Empty);
Assert.IsTrue(packet.Ethernet.IpV4.Options.IsValid);
byte[] buffer = packet.Buffer;
buffer[packet.Length - packet.Ethernet.IpV4.Length + IpV4Datagram.HeaderMinimumLength + 1] = 2;
......@@ -418,12 +393,6 @@ namespace PcapDotNet.Packets.Test
Options = new IpV4Options(new IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel.Secret)),
});
// packet = PacketBuilder.EthernetIpV4(DateTime.Now,
// new MacAddress(), new MacAddress(),
// 0, 0, new IpV4Fragmentation(), 0, 0, new IpV4Address(), new IpV4Address(),
// new IpV4Options(new IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel.Secret)),
// Datagram.Empty);
Assert.IsTrue(packet.Ethernet.IpV4.Options.IsValid);
buffer = packet.Buffer;
buffer[packet.Length - packet.Ethernet.IpV4.Length + IpV4Datagram.HeaderMinimumLength + 2] = 0;
......@@ -438,11 +407,6 @@ namespace PcapDotNet.Packets.Test
Protocol = 0,
Options = new IpV4Options(new IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel.Confidential, IpV4OptionSecurityProtectionAuthorities.Nsa, 5)),
});
// packet = PacketBuilder.EthernetIpV4(DateTime.Now,
// new MacAddress(), new MacAddress(),
// 0, 0, new IpV4Fragmentation(), 0, 0, new IpV4Address(), new IpV4Address(),
// new IpV4Options(new IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel.Confidential, IpV4OptionSecurityProtectionAuthorities.Nsa, 5)),
// Datagram.Empty);
Assert.IsTrue(packet.Ethernet.IpV4.Options.IsValid);
buffer = packet.Buffer;
......@@ -460,7 +424,7 @@ namespace PcapDotNet.Packets.Test
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4OptionQuickStartBadFunctionTest()
{
IpV4OptionQuickStart option = new IpV4OptionQuickStart((IpV4OptionQuickStartFunction)2, 1, 2, 16);
......@@ -478,7 +442,7 @@ namespace PcapDotNet.Packets.Test
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4OptionQuickStartBadNonceTest()
{
IpV4OptionQuickStart option = new IpV4OptionQuickStart(IpV4OptionQuickStartFunction.RateRequest, 1, 1, 2);
......@@ -487,7 +451,7 @@ namespace PcapDotNet.Packets.Test
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4OptionTimestampAndAddressBadTypeTest()
{
IpV4OptionTimestampAndAddress option = new IpV4OptionTimestampAndAddress((IpV4OptionTimestampType)166, 1, 2);
......@@ -514,11 +478,6 @@ namespace PcapDotNet.Packets.Test
Destination = new IpV4Address(2),
});
// Packet packet = PacketBuilder.EthernetIpV4(DateTime.Now,
// new MacAddress(1), new MacAddress(2),
// 0, 1, new IpV4Fragmentation(IpV4FragmentationOptions.MoreFragments, 8), 1,
// IpV4Protocol.WidebandExpak, new IpV4Address(1), new IpV4Address(2), new IpV4Options(),
// Datagram.Empty);
Assert.IsTrue(packet.IsValid);
byte[] badPacketBuffer = new byte[packet.Length - 5];
......@@ -534,10 +493,6 @@ namespace PcapDotNet.Packets.Test
{
Protocol = 0,
});
// Packet packet = PacketBuilder.EthernetIpV4(DateTime.Now,
// new MacAddress(), new MacAddress(),
// 0, 0, new IpV4Fragmentation(), 0, 0, IpV4Address.Zero, IpV4Address.Zero, IpV4Options.None,
// Datagram.Empty);
Assert.IsTrue(packet.IsValid);
......@@ -577,7 +532,7 @@ namespace PcapDotNet.Packets.Test
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4NoNextLayerTest()
{
Packet packet = PacketBuilder.Build(DateTime.Now,
......@@ -587,7 +542,7 @@ namespace PcapDotNet.Packets.Test
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4BadNextLayerTest()
{
Packet packet = PacketBuilder.Build(DateTime.Now,
......@@ -608,6 +563,44 @@ namespace PcapDotNet.Packets.Test
Assert.IsNotNull(layer.GetHashCode());
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void IpV4OptionQuickStartCreateInstanceNullBufferTest()
{
int offset = 0;
Assert.IsNotNull(new IpV4OptionQuickStart().CreateInstance(null, ref offset, 0));
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void IpV4OptionBasicSecurityCreateInstanceNullBufferTest()
{
int offset = 0;
Assert.IsNotNull(new IpV4OptionBasicSecurity().CreateInstance(null, ref offset, 0));
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void IpV4OptionLooseSourceRoutingCreateInstanceNullBufferTest()
{
int offset = 0;
Assert.IsNotNull(new IpV4OptionLooseSourceRouting().CreateInstance(null, ref offset, 0));
Assert.Fail();
}
[TestMethod]
public void IpV4OptionCreateInstanceBadValueLengthTest()
{
int offset = 0;
Assert.IsNull(new IpV4OptionQuickStart().CreateInstance(new byte[0], ref offset, 0));
Assert.IsNull(new IpV4OptionTraceRoute().CreateInstance(new byte[0], ref offset, 123));
Assert.IsNull(new IpV4OptionRecordRoute().CreateInstance(new byte[0], ref offset, 0));
Assert.IsNull(new IpV4OptionRouterAlert().CreateInstance(new byte[0], ref offset, 123));
Assert.IsNull(new IpV4OptionStreamIdentifier().CreateInstance(new byte[0], ref offset, 123));
Assert.IsNull(new IpV4OptionStrictSourceRouting().CreateInstance(new byte[0], ref offset, 0));
}
private static Packet HexToPacket(string hexString, DataLinkKind dataLinkKind)
{
return Packet.FromHexadecimalString(hexString, DateTime.MinValue, dataLinkKind);
......
......@@ -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