Commit 7a3ec961 authored by Brickner_cp's avatar Brickner_cp

Code coverage 95.83%

parent 4cf6f1a4
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.TestUtils;
namespace PcapDotNet.Core.Test
{
/// <summary>
/// Summary description for PacketTimestampTests.
/// </summary>
[TestClass]
public class PacketTimestampTests
{
/// <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]
public void MinMaxTests()
{
MoreAssert.IsBigger(PacketTimestamp.MinimumPacketTimestamp, PacketTimestamp.MaximumPacketTimestamp);
}
}
}
\ No newline at end of file
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Packets;
namespace PcapDotNet.Core.Test
{
......@@ -70,6 +71,15 @@ namespace PcapDotNet.Core.Test
}
}
[TestMethod]
public void ValidKindsTest()
{
foreach (DataLinkKind kind in typeof(DataLinkKind).GetEnumValues())
{
Assert.AreEqual(kind, new PcapDataLink(kind).Kind);
}
}
[TestMethod]
[ExpectedException(typeof(NotSupportedException), AllowDerivedTypes = false)]
public void UnsupportedKindErrorTest()
......@@ -96,6 +106,16 @@ namespace PcapDotNet.Core.Test
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(NotSupportedException), AllowDerivedTypes = false)]
public void InvalidKindTest()
{
const DataLinkKind InvalidKind = (DataLinkKind)100;
IDataLink dataLink = new PcapDataLink(InvalidKind);
Assert.IsNotNull(dataLink);
Assert.Fail();
}
private static PcapDataLink GetInvalidDataLink()
{
for (int i = 0; i != 1000; ++i)
......
......@@ -74,6 +74,7 @@
<Compile Include="LivePacketDeviceTests.cs" />
<Compile Include="MarshalingServicesTests.cs" />
<Compile Include="IpV4OptionExtensions.cs" />
<Compile Include="PacketTimestampTests.cs" />
<Compile Include="TcpOptionExtensions.cs" />
<Compile Include="WiresharkDatagramComparer.cs" />
<Compile Include="WiresharkDatagramComparerArp.cs" />
......
......@@ -4,7 +4,7 @@ using PcapDotNet.TestUtils;
namespace PcapDotNet.Core.Test
{
/// <summary>
/// Summary description for PcapLibTests
/// Summary description for PcapLibTests.
/// </summary>
[TestClass]
public class PcapLibTests
......
......@@ -150,15 +150,41 @@ namespace PcapDotNet.Packets.Test
[TestMethod]
public void ByteArrayUnsignedBigIntegerTest()
{
byte[] buffer = new byte[100];
for (BigInteger expectedValue = 1; expectedValue <= ushort.MaxValue; expectedValue *= 10)
{
byte[] buffer = new byte[100];
buffer.WriteUnsigned(5, expectedValue, 2, Endianity.Big);
BigInteger actualValue = buffer.ReadUnsignedBigInteger(5, 2, Endianity.Big);
Assert.AreEqual(expectedValue, actualValue);
buffer = new byte[100];
buffer.WriteUnsigned(5, expectedValue, 2, Endianity.Small);
actualValue = buffer.ReadUnsignedBigInteger(5, 2, Endianity.Small);
Assert.AreEqual(expectedValue, actualValue);
}
for (BigInteger expectedValue = ushort.MaxValue; expectedValue > 0; expectedValue /= 10)
{
byte[] buffer = new byte[100];
buffer.WriteUnsigned(5, expectedValue, 2, Endianity.Big);
BigInteger actualValue = buffer.ReadUnsignedBigInteger(5, 2, Endianity.Big);
Assert.AreEqual(expectedValue, actualValue);
buffer = new byte[100];
buffer.WriteUnsigned(5, expectedValue, 2, Endianity.Small);
actualValue = buffer.ReadUnsignedBigInteger(5, 2, Endianity.Small);
Assert.AreEqual(expectedValue, actualValue);
}
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void ByteArrayUnsignedBigIntegerNullBufferTest()
{
byte[] buffer = null;
Assert.IsNotNull(buffer.ReadUnsignedBigInteger(0, 0, Endianity.Big));
Assert.Fail();
}
[TestMethod]
public void ByteArrayULongTest()
{
......
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Base;
using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.TestUtils;
using PcapDotNet.Packets.Transport;
namespace PcapDotNet.Packets.Test
{
/// <summary>
/// Summary description for DataSegmentTests.
/// </summary>
[TestClass]
public class DataSegmentTests
{
/// <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]
public void ToHexadecimalStringTest()
{
byte[] input = new byte[] {1, 2, 3, 4, 5, 6};
Assert.AreEqual(HexEncoding.Instance.GetString(input), new DataSegment(input).ToHexadecimalString());
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void DecodeNullEncodingTest()
{
Assert.IsNotNull(new DataSegment(new byte[1]).Decode(null));
Assert.Fail();
}
}
}
\ No newline at end of file
......@@ -11,7 +11,7 @@ using PcapDotNet.Packets.Transport;
namespace PcapDotNet.Packets.Test
{
/// <summary>
/// Summary description for DatagramTests
/// Summary description for DatagramTests.
/// </summary>
[TestClass]
public class DatagramTests
......
......@@ -114,6 +114,7 @@ namespace PcapDotNet.Packets.Test
// IpV4
ipV4Layer.HeaderChecksum = ((IpV4Layer)packet.Ethernet.IpV4.ExtractLayer()).HeaderChecksum;
Assert.AreEqual(ipV4Layer, packet.Ethernet.IpV4.ExtractLayer(), "IP Layer");
Assert.AreEqual(ipV4Layer.Destination, packet.Ethernet.IpV4.Destination, "Destination");
Assert.AreNotEqual(ipV4Layer, null);
Assert.AreNotEqual(ipV4Layer, new PayloadLayer());
Assert.IsNotNull(ipV4Layer.ToString());
......
......@@ -71,6 +71,7 @@
<Compile Include="ByteArrayExtensionsTests.cs" />
<Compile Include="DatagramTests.cs" />
<Compile Include="DataLinkTests.cs" />
<Compile Include="DataSegmentTests.cs" />
<Compile Include="DnsTests.cs" />
<Compile Include="EndianitiyTests.cs" />
<Compile Include="EthernetTests.cs" />
......
......@@ -175,9 +175,32 @@ namespace PcapDotNet.Packets.Test
[TestMethod]
[ExpectedException(typeof(InvalidOperationException), AllowDerivedTypes = false)]
public void TcpOptionMoodBadEmotionStringTest()
public void TcpOptionMoodConstructorBadEmotionStringTest()
{
Assert.IsNotNull(new TcpOptionMood((TcpOptionMoodEmotion)202).EmotionString);
Assert.Fail();
}
[TestMethod]
public void TcpOptionMoodReadFromBufferBadEmotionStringTest()
{
Packet packet = PacketBuilder.Build(DateTime.Now,
new IpV4Layer(),
new TcpLayer
{
Options = new TcpOptions(new TcpOptionMood(TcpOptionMoodEmotion.Happy))
});
Assert.IsTrue(packet.IsValid);
Assert.AreEqual(1, packet.IpV4.Tcp.Options.Count);
byte[] newPacketBuffer = new byte[packet.Length];
packet.CopyTo(newPacketBuffer, 0);
newPacketBuffer[packet.Length - 1] = (byte)'a';
newPacketBuffer[packet.Length - 2] = (byte)'a';
Packet newPacket = new Packet(newPacketBuffer, DateTime.Now, DataLinkKind.IpV4);
Assert.IsFalse(newPacket.IsValid);
Assert.AreEqual(0, newPacket.IpV4.Tcp.Options.Count);
}
[TestMethod]
......
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