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();
}
} }
} }
...@@ -195,20 +195,6 @@ namespace PcapDotNet.Packets.Test ...@@ -195,20 +195,6 @@ namespace PcapDotNet.Packets.Test
Options = new IpV4Options(new IpV4OptionTimestampOnly(0, 0)), 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); Assert.IsTrue(packet.Ethernet.IpV4.Options.IsValid);
// Bad Length // Bad Length
...@@ -264,11 +250,6 @@ namespace PcapDotNet.Packets.Test ...@@ -264,11 +250,6 @@ namespace PcapDotNet.Packets.Test
Protocol = 0, Protocol = 0,
Options = new IpV4Options(new IpV4OptionLooseSourceRouting()) 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); Assert.IsTrue(packet.Ethernet.IpV4.Options.IsValid);
byte[] buffer = packet.Buffer; byte[] buffer = packet.Buffer;
...@@ -304,7 +285,7 @@ namespace PcapDotNet.Packets.Test ...@@ -304,7 +285,7 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4OptionsTooLongErrorTest() public void IpV4OptionsTooLongErrorTest()
{ {
IpV4Options options = new IpV4Options( IpV4Options options = new IpV4Options(
...@@ -319,7 +300,7 @@ namespace PcapDotNet.Packets.Test ...@@ -319,7 +300,7 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4FragmentationOffsetErrorTest() public void IpV4FragmentationOffsetErrorTest()
{ {
IpV4Fragmentation fragmentation = new IpV4Fragmentation(IpV4FragmentationOptions.None, 2); IpV4Fragmentation fragmentation = new IpV4Fragmentation(IpV4FragmentationOptions.None, 2);
...@@ -328,7 +309,7 @@ namespace PcapDotNet.Packets.Test ...@@ -328,7 +309,7 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4FragmentationOptionsErrorTest() public void IpV4FragmentationOptionsErrorTest()
{ {
IpV4Fragmentation fragmentation = new IpV4Fragmentation((IpV4FragmentationOptions)12345, 8); IpV4Fragmentation fragmentation = new IpV4Fragmentation((IpV4FragmentationOptions)12345, 8);
...@@ -368,7 +349,7 @@ namespace PcapDotNet.Packets.Test ...@@ -368,7 +349,7 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4OptionBasicSecurityConstructorNoProtectionAuthoritiesButWithValueTest() public void IpV4OptionBasicSecurityConstructorNoProtectionAuthoritiesButWithValueTest()
{ {
IpV4OptionBasicSecurity option = new IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel.Secret, IpV4OptionSecurityProtectionAuthorities.Nsa, 3); IpV4OptionBasicSecurity option = new IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel.Secret, IpV4OptionSecurityProtectionAuthorities.Nsa, 3);
...@@ -377,7 +358,7 @@ namespace PcapDotNet.Packets.Test ...@@ -377,7 +358,7 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4OptionBasicSecurityConstructorBadClassificationLevelTest() public void IpV4OptionBasicSecurityConstructorBadClassificationLevelTest()
{ {
IpV4OptionBasicSecurity option = new IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel.None); IpV4OptionBasicSecurity option = new IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel.None);
...@@ -397,12 +378,6 @@ namespace PcapDotNet.Packets.Test ...@@ -397,12 +378,6 @@ namespace PcapDotNet.Packets.Test
Options = new IpV4Options(new IpV4OptionBasicSecurity()), 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); Assert.IsTrue(packet.Ethernet.IpV4.Options.IsValid);
byte[] buffer = packet.Buffer; byte[] buffer = packet.Buffer;
buffer[packet.Length - packet.Ethernet.IpV4.Length + IpV4Datagram.HeaderMinimumLength + 1] = 2; buffer[packet.Length - packet.Ethernet.IpV4.Length + IpV4Datagram.HeaderMinimumLength + 1] = 2;
...@@ -418,12 +393,6 @@ namespace PcapDotNet.Packets.Test ...@@ -418,12 +393,6 @@ namespace PcapDotNet.Packets.Test
Options = new IpV4Options(new IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel.Secret)), 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); Assert.IsTrue(packet.Ethernet.IpV4.Options.IsValid);
buffer = packet.Buffer; buffer = packet.Buffer;
buffer[packet.Length - packet.Ethernet.IpV4.Length + IpV4Datagram.HeaderMinimumLength + 2] = 0; buffer[packet.Length - packet.Ethernet.IpV4.Length + IpV4Datagram.HeaderMinimumLength + 2] = 0;
...@@ -438,11 +407,6 @@ namespace PcapDotNet.Packets.Test ...@@ -438,11 +407,6 @@ namespace PcapDotNet.Packets.Test
Protocol = 0, Protocol = 0,
Options = new IpV4Options(new IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel.Confidential, IpV4OptionSecurityProtectionAuthorities.Nsa, 5)), 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); Assert.IsTrue(packet.Ethernet.IpV4.Options.IsValid);
buffer = packet.Buffer; buffer = packet.Buffer;
...@@ -460,7 +424,7 @@ namespace PcapDotNet.Packets.Test ...@@ -460,7 +424,7 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4OptionQuickStartBadFunctionTest() public void IpV4OptionQuickStartBadFunctionTest()
{ {
IpV4OptionQuickStart option = new IpV4OptionQuickStart((IpV4OptionQuickStartFunction)2, 1, 2, 16); IpV4OptionQuickStart option = new IpV4OptionQuickStart((IpV4OptionQuickStartFunction)2, 1, 2, 16);
...@@ -478,7 +442,7 @@ namespace PcapDotNet.Packets.Test ...@@ -478,7 +442,7 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4OptionQuickStartBadNonceTest() public void IpV4OptionQuickStartBadNonceTest()
{ {
IpV4OptionQuickStart option = new IpV4OptionQuickStart(IpV4OptionQuickStartFunction.RateRequest, 1, 1, 2); IpV4OptionQuickStart option = new IpV4OptionQuickStart(IpV4OptionQuickStartFunction.RateRequest, 1, 1, 2);
...@@ -487,7 +451,7 @@ namespace PcapDotNet.Packets.Test ...@@ -487,7 +451,7 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4OptionTimestampAndAddressBadTypeTest() public void IpV4OptionTimestampAndAddressBadTypeTest()
{ {
IpV4OptionTimestampAndAddress option = new IpV4OptionTimestampAndAddress((IpV4OptionTimestampType)166, 1, 2); IpV4OptionTimestampAndAddress option = new IpV4OptionTimestampAndAddress((IpV4OptionTimestampType)166, 1, 2);
...@@ -514,11 +478,6 @@ namespace PcapDotNet.Packets.Test ...@@ -514,11 +478,6 @@ namespace PcapDotNet.Packets.Test
Destination = new IpV4Address(2), 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); Assert.IsTrue(packet.IsValid);
byte[] badPacketBuffer = new byte[packet.Length - 5]; byte[] badPacketBuffer = new byte[packet.Length - 5];
...@@ -534,10 +493,6 @@ namespace PcapDotNet.Packets.Test ...@@ -534,10 +493,6 @@ namespace PcapDotNet.Packets.Test
{ {
Protocol = 0, 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); Assert.IsTrue(packet.IsValid);
...@@ -577,7 +532,7 @@ namespace PcapDotNet.Packets.Test ...@@ -577,7 +532,7 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4NoNextLayerTest() public void IpV4NoNextLayerTest()
{ {
Packet packet = PacketBuilder.Build(DateTime.Now, Packet packet = PacketBuilder.Build(DateTime.Now,
...@@ -587,7 +542,7 @@ namespace PcapDotNet.Packets.Test ...@@ -587,7 +542,7 @@ namespace PcapDotNet.Packets.Test
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentException))] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4BadNextLayerTest() public void IpV4BadNextLayerTest()
{ {
Packet packet = PacketBuilder.Build(DateTime.Now, Packet packet = PacketBuilder.Build(DateTime.Now,
...@@ -608,6 +563,44 @@ namespace PcapDotNet.Packets.Test ...@@ -608,6 +563,44 @@ namespace PcapDotNet.Packets.Test
Assert.IsNotNull(layer.GetHashCode()); 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) private static Packet HexToPacket(string hexString, DataLinkKind dataLinkKind)
{ {
return Packet.FromHexadecimalString(hexString, DateTime.MinValue, dataLinkKind); return Packet.FromHexadecimalString(hexString, DateTime.MinValue, dataLinkKind);
......
...@@ -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