Commit 80e525f9 authored by Brickner_cp's avatar Brickner_cp

Code Coverage 94.73%

parent 5e6eba25
......@@ -5,8 +5,8 @@
<Regular>
<CodeCoverageItem binaryFile="C:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Base.dll" pdbFile="C:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Base.pdb" instrumentInPlace="true" />
<CodeCoverageItem binaryFile="c:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Core.dll" pdbFile="c:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Core.pdb" instrumentInPlace="true" />
<CodeCoverageItem binaryFile="C:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Core.Extensions.dll" pdbFile="C:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Core.Extensions.pdb" instrumentInPlace="true" />
<CodeCoverageItem binaryFile="C:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Packets.dll" pdbFile="C:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Packets.pdb" instrumentInPlace="true" />
<CodeCoverageItem binaryFile="C:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Core.Extensions.dll" pdbFile="C:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Core.Extensions.pdb" instrumentInPlace="true" />
</Regular>
</CodeCoverage>
<TestTypeSpecific>
......
......@@ -155,7 +155,7 @@ namespace PcapDotNet.Core.Test
const int PacketSize = 100;
// Normal
TestReceivePacketsEnumerable(NumPacketsToSend, NumPacketsToSend, int.MaxValue, 2, PacketSize, NumPacketsToSend, 0, 0.05);
TestReceivePacketsEnumerable(NumPacketsToSend, NumPacketsToSend, int.MaxValue, 2, PacketSize, NumPacketsToSend, 0, 0.3);
// Wait for less packets
TestReceivePacketsEnumerable(NumPacketsToSend, NumPacketsToSend / 2, int.MaxValue, 2, PacketSize, NumPacketsToSend / 2, 0, 0.02);
......
......@@ -93,5 +93,25 @@ namespace PcapDotNet.Packets.Test
MoreAssert.AreSequenceEqual(arpTargetProtocolAddress, packet.Ethernet.Arp.TargetProtocolAddress, "Arp TargetProtocolAddress");
}
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void ArpIncosistentSenderAddressSizeTest()
{
Packet packet = PacketBuilder.EthernetArp(DateTime.Now, new MacAddress(), EthernetType.IpV4, ArpOperation.Request,
new byte[4], new byte[6], new byte[5], new byte[6]);
Assert.IsNull(packet);
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void ArpIncosistentTargetAddressSizeTest()
{
Packet packet = PacketBuilder.EthernetArp(DateTime.Now, new MacAddress(), EthernetType.IpV4, ArpOperation.Request,
new byte[4], new byte[6], new byte[4], new byte[7]);
Assert.IsNull(packet);
Assert.Fail();
}
}
}
\ No newline at end of file
......@@ -64,6 +64,8 @@ namespace PcapDotNet.Packets.Test
[TestMethod]
public void IpV4AddressRandomTest()
{
Assert.AreEqual(IpV4Address.AllHostsHroupAddress, new IpV4Address("224.0.0.1"));
Random random = new Random();
for (int i = 0; i != 1000; ++i)
......@@ -82,6 +84,7 @@ namespace PcapDotNet.Packets.Test
Assert.AreNotEqual(address.GetHashCode(), random.NextIpV4Address().GetHashCode());
Assert.AreNotEqual(2, address);
Assert.IsFalse(address.Equals(null));
}
}
......
......@@ -563,16 +563,12 @@ namespace PcapDotNet.Packets.Igmp
case IgmpMessageType.MembershipQuery:
switch (QueryVersion)
{
case IgmpQueryVersion.Version1:
return Length == HeaderLength && MaxResponseCode == 0;
case IgmpQueryVersion.Version1: // Version 1 actually means that the MaxResponseCode is 0.
case IgmpQueryVersion.Version2:
return Length == HeaderLength;
case IgmpQueryVersion.Version3:
return Length >= QueryVersion3HeaderLength &&
Length == GetQueryVersion3Length(NumberOfSources) &&
NumberOfSources == SourceAddresses.Count;
return Length == GetQueryVersion3Length(NumberOfSources);
default:
return false;
......@@ -586,7 +582,7 @@ namespace PcapDotNet.Packets.Igmp
return Length == HeaderLength;
case IgmpMessageType.MembershipReportVersion3:
return MaxResponseCode == 0 && NumberOfGroupRecords == GroupRecords.Count &&
return MaxResponseCode == 0 &&
Length == HeaderLength + GroupRecords.Sum(record => record.Length) &&
GroupRecords.All(record => record.IsValid);
......@@ -629,11 +625,11 @@ namespace PcapDotNet.Packets.Igmp
{
int exp = (int)(Math.Log(value, 2) - 7);
if (exp > 7 || exp < 0)
throw new ArgumentOutOfRangeException("exp", exp, "value " + value + " is out of range");
throw new ArgumentOutOfRangeException("value", value, "exp " + exp + " is out of range");
int mant = (int)(value * Math.Pow(2, -exp - 3) - 16);
if (mant > 15 || mant < 0)
throw new ArgumentOutOfRangeException("mant", mant, "value " + value + " is out of range");
throw new ArgumentOutOfRangeException("value", value, "mant " + mant + " is out of range");
return (byte)(0x80 | (exp << 4) | mant);
}
......
......@@ -150,7 +150,7 @@ namespace PcapDotNet.Packets.Igmp
/// <summary>
/// The record is valid if the length is correct according to the header fields.
/// </summary>
protected override bool CalculateIsValid()
protected override bool CalculateIsValid()
{
return Length >= HeaderLength &&
Length == HeaderLength + IpV4Address.SizeOf * NumberOfSources + AuxiliaryDataLength;
......
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