Commit b47f8f31 authored by Brickner_cp's avatar Brickner_cp

Code coverage 94.6%

parent 62def0bc
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
......@@ -584,6 +585,15 @@ namespace PcapDotNet.Packets.Test
Assert.IsTrue(dnsAddressPrefix.Equals((object)dnsAddressPrefix));
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void DnsAddressPrefixConstructorNullAddressFamilyDependentPartTtest()
{
var dnsAddressPrefix = new DnsAddressPrefix(AddressFamily.IpV4, 0, false, null);
Assert.IsNull(dnsAddressPrefix);
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void DnsResourceDataNextDomainSecure3NextHashedOwnerNameTooBigTest()
......@@ -638,6 +648,25 @@ namespace PcapDotNet.Packets.Test
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void DnsResourceDataCertificationAuthorityAuthorizationConstructorNullTagTest()
{
var resourceData = new DnsResourceDataCertificationAuthorityAuthorization(DnsCertificationAuthorityAuthorizationFlags.Critical, null,
DataSegment.Empty);
Assert.IsNull(resourceData);
Assert.Fail();
}
[TestMethod]
public void DnsResourceDataCertificationAuthorityAuthorizationParseWrongLengthTest()
{
var resourceData = new DnsResourceDataCertificationAuthorityAuthorization(DnsCertificationAuthorityAuthorizationFlags.Critical,
new DataSegment(new byte[5]), new DataSegment(new byte[5]));
TestResourceRecordIsNotCreatedWithNewLength(DnsType.CertificationAuthorityAuthorization, resourceData, -6);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.CertificationAuthorityAuthorization, resourceData, -11);
}
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void DnsResourceDataA6ConstructorAddressSuffixTooSmallTest()
......@@ -674,6 +703,42 @@ namespace PcapDotNet.Packets.Test
TestResourceRecordIsNotCreatedWithNewLength(DnsType.Apl, resourceData, -1);
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void DnsResourceDataNInfoConstructorNullStringsTest()
{
var resourceData = new DnsResourceDataNInfo(null as ReadOnlyCollection<DataSegment>);
Assert.IsNull(resourceData);
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void DnsResourceDataNInfoConstructorTooFewStringsTest()
{
var resourceData = new DnsResourceDataNInfo();
Assert.IsNull(resourceData);
Assert.Fail();
}
[TestMethod]
public void DnsResourceDataNInfoParseWrongLengthTest()
{
var resourceData = new DnsResourceDataNInfo(new DataSegment(new byte[5]), new DataSegment(new byte[5]));
TestResourceRecordIsNotCreatedWithNewLength(DnsType.NInfo, resourceData, -1);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.NInfo, resourceData, -12);
}
[TestMethod]
public void DnsResourceDataGeographicalPositionWrongLengthTest()
{
var resourceData = new DnsResourceDataGeographicalPosition("5.03", "-44.4", "22.1");
TestResourceRecordIsNotCreatedWithNewLength(DnsType.GPos, resourceData, 1);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.GPos, resourceData, -5);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.GPos, resourceData, -10);
TestResourceRecordIsNotCreatedWithNewLength(DnsType.GPos, resourceData, -14);
}
private static void TestDomainNameCompression(int expectedCompressionBenefit, DnsLayer dnsLayer)
{
dnsLayer.DomainNameCompressionMode = DnsDomainNameCompressionMode.Nothing;
......
......@@ -49,7 +49,7 @@ namespace PcapDotNet.Packets.Dns
internal override DnsResourceData CreateInstance(DataSegment data)
{
List<DataSegment> strings = ReadStrings(data, MinNumStrings);
if (strings == null || strings.Count < 1)
if (strings == null || strings.Count < MinNumStrings)
return null;
return new DnsResourceDataNInfo(strings.AsReadOnly());
......
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