Commit 71149a30 authored by Brickner_cp's avatar Brickner_cp

Code Coverage 94.31%

parent 60f12a94
......@@ -75,5 +75,13 @@ namespace PcapDotNet.Base.Test
Assert.IsFalse(dic1.DictionaryEquals(dic2));
Assert.IsFalse(dic2.DictionaryEquals(dic1));
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void DictionaryEqualsNullTest()
{
Assert.IsFalse(new Dictionary<int, int>().DictionaryEquals(new Dictionary<int, int>(), null));
Assert.Fail();
}
}
}
\ No newline at end of file
......@@ -79,5 +79,19 @@ namespace PcapDotNet.Base.Test
Assert.IsNotNull(IEnumerableExtensions.SequenceToString<int>(null));
Assert.Fail();
}
[TestMethod]
public void XorTest()
{
int[] intValues = new[] {0x0001, 0x0020, 0x0300, 0x4000};
Assert.AreEqual(0x4321, intValues.Xor());
long[] longValues = new[]
{
0x00000001L, 0x00000020L, 0x00000300L, 0x00004000L,
0x00050000L, 0x00600000L, 0x07000000L, 0x80000000L
};
Assert.AreEqual(0x87654321L, longValues.Xor());
}
}
}
\ No newline at end of file
......@@ -850,6 +850,7 @@ namespace PcapDotNet.Core.Test
MoreAssert.IsMatch(@"Network adapter '.*' on local host", device.Description);
Assert.AreEqual(DeviceAttributes.None, device.Attributes);
Assert.AreNotEqual(MacAddress.Zero, device.GetMacAddress());
Assert.AreNotEqual(string.Empty, device.GetPnpDeviceId());
MoreAssert.IsInRange(1, 2, device.Addresses.Count);
foreach (DeviceAddress address in device.Addresses)
{
......
......@@ -88,5 +88,62 @@ namespace PcapDotNet.Packets.Test
Assert.IsNotNull(ByteArrayExtensions.ReadByte(null, 0));
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ByteArrayCompareFirstNullTest()
{
Assert.IsNotNull(ByteArrayExtensions.Compare(null, 1, new byte[1], 0, 1));
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ByteArrayCompareSecondNullTest()
{
Assert.IsNotNull(new byte[1].Compare(1, null, 0, 1));
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ByteArrayFindNullArrayTest()
{
Assert.IsNotNull(ByteArrayExtensions.Find(null, 1, 1, new byte[1]));
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ByteArrayFindNullOtherTest()
{
Assert.IsNotNull(new byte[5].Find(1, 1, null));
Assert.Fail();
}
[TestMethod]
public void ByteArrayFindOtherCountTooBigTest()
{
Assert.AreEqual(10, new byte[10].Find(1, 1, new byte[5], 1, 2));
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ByteArraySequenceEqualNullArrayTest()
{
Assert.IsNotNull(ByteArrayExtensions.SequenceEqual(null, 1, new byte[1], 0, 1));
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ByteArrayWriteNullEncodingTest()
{
int offset = 0;
byte[] buffer = new byte[5];
buffer.Write(ref offset, "123", null);
Assert.IsNotNull(buffer);
Assert.Fail();
}
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ using PcapDotNet.Packets.Http;
using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.TestUtils;
using PcapDotNet.Packets.Transport;
using PcapDotNet.TestUtils;
namespace PcapDotNet.Packets.Test
{
......@@ -67,6 +68,8 @@ namespace PcapDotNet.Packets.Test
HttpDatagram httpDatagram = packet.Ethernet.IpV4.Tcp.Http;
Assert.AreEqual(httpLayer.Version, httpDatagram.Version);
if (httpLayer.Version != null)
Assert.AreEqual(httpLayer.Version.GetHashCode(), httpDatagram.Version.GetHashCode());
if (httpLayer is HttpRequestLayer)
{
Assert.IsTrue(httpDatagram.IsRequest);
......@@ -78,7 +81,10 @@ namespace PcapDotNet.Packets.Test
HttpRequestDatagram httpRequestDatagram = (HttpRequestDatagram)httpDatagram;
Assert.AreEqual(httpRequestLayer.Method, httpRequestDatagram.Method);
if (httpRequestLayer.Method != null)
{
Assert.AreEqual(httpRequestLayer.Method.GetHashCode(), httpRequestDatagram.Method.GetHashCode());
Assert.AreEqual(httpRequestLayer.Method.KnownMethod, httpRequestDatagram.Method.KnownMethod);
}
Assert.AreEqual(httpRequestLayer.Uri, httpRequestDatagram.Uri);
}
else
......@@ -96,14 +102,20 @@ namespace PcapDotNet.Packets.Test
Assert.AreEqual(httpLayer.Header, httpDatagram.Header);
if (httpLayer.Header != null)
{
Assert.AreEqual(httpLayer.Header.GetHashCode(), httpDatagram.Header.GetHashCode());
foreach (var field in httpLayer.Header)
Assert.IsFalse(field.Equals("abc"));
MoreAssert.AreSequenceEqual(httpLayer.Header.Select(field => field.GetHashCode()), httpDatagram.Header.Select(field => field.GetHashCode()));
if (httpLayer.Header.ContentType != null)
{
var parameters = httpLayer.Header.ContentType.Parameters;
Assert.IsNotNull(((IEnumerable)parameters).GetEnumerator());
Assert.AreEqual<object>(parameters, httpDatagram.Header.ContentType.Parameters);
Assert.AreEqual(parameters.GetHashCode(), httpDatagram.Header.ContentType.Parameters.GetHashCode());
Assert.AreEqual(parameters.Count, httpDatagram.Header.ContentType.Parameters.Count);
int maxParameterNameLength = parameters.Any() ? parameters.Max(pair => pair.Key.Length) : 0;
Assert.IsNull(parameters[new string('a', maxParameterNameLength + 1)]);
}
......@@ -111,8 +123,6 @@ namespace PcapDotNet.Packets.Test
Assert.AreEqual(httpLayer.Body, httpDatagram.Body);
Assert.AreEqual(httpLayer, httpDatagram.ExtractLayer(), "HTTP Layer");
Assert.AreEqual(httpLayer.Length, httpDatagram.Length);
// Ethernet
}
}
......@@ -521,6 +531,24 @@ namespace PcapDotNet.Packets.Test
Assert.IsNull(packet.Ethernet.IpV4.Tcp.Http.Header.TransferEncoding.TransferCodings);
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void HttpCreateFieldNullEncoding()
{
HttpField field = HttpField.CreateField("abc", "cde", null);
Assert.IsNull(field);
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void HttpCreateFieldNullName()
{
HttpField field = HttpField.CreateField(null, "cde");
Assert.IsNull(field);
Assert.Fail();
}
private static void TestHttpResponse(string httpString, HttpVersion expectedVersion = null, uint? expectedStatusCode = null, string expectedReasonPhrase = null, HttpHeader expectedHeader = null, string expectedBodyString = null)
{
Datagram expectedBody = expectedBodyString == null ? null : new Datagram(Encoding.ASCII.GetBytes(expectedBodyString));
......
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