Commit 8a4d4e61 authored by Brickner_cp's avatar Brickner_cp

Code Coverage 92.64%.

parent dcd019a4
using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.TestUtils;
namespace PcapDotNet.Base.Test
{
/// <summary>
/// Summary description for MoreIEnumerableTests
/// </summary>
[TestClass]
public class MoreIEnumerableTests
{
public MoreIEnumerableTests()
{
//
// TODO: Add constructor logic here
//
}
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#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 SequenceToStringTest()
{
int[] sequence = new[]{1,2,3,4,5};
Assert.AreEqual("12345",sequence.SequenceToString());
}
[TestMethod]
public void SequenceGetHashCodeTest()
{
int[] sequence = new[]{1,2,3,4,5};
Assert.AreEqual(1.GetHashCode() ^ 2.GetHashCode() ^ 3.GetHashCode() ^ 4.GetHashCode() ^ 5.GetHashCode(),sequence.SequenceGetHashCode());
}
[TestMethod]
public void BytesSequenceGetHashCodeTest()
{
byte[] sequence = new byte[] { 1, 2, 3, 4, 5 };
Assert.AreEqual(1 ^ (2 << 8) ^ (3 << 16) ^ (4 << 24) ^ 5, sequence.BytesSequenceGetHashCode());
}
[TestMethod]
public void ConcatTest()
{
int[] sequence = new[] {1, 2, 3, 4, 5};
Assert.IsTrue(sequence.SequenceEqual(new[] {1,2,3}.Concat(4, 5)));
}
}
}
\ No newline at end of file
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{20BCB32F-6B86-41D4-8DF4-191F3D233087}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PcapDotNet.Base.Test</RootNamespace>
<AssemblyName>PcapDotNet.Base.Test</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="MoreIEnumerableTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TupleTests.cs" />
<Compile Include="UInt24Tests.cs" />
<Compile Include="UInt48Tests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PcapDotNet.Base\PcapDotNet.Base.csproj">
<Project>{83E805C9-4D29-4E34-A27E-5A78690FBD2B}</Project>
<Name>PcapDotNet.Base</Name>
</ProjectReference>
<ProjectReference Include="..\PcapDotNet.TestUtils\PcapDotNet.TestUtils.csproj">
<Project>{540F21A8-CD9F-4288-ADCA-DB17027FF309}</Project>
<Name>PcapDotNet.TestUtils</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PcapDotNet.Base.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PcapDotNet.Base.Test")]
[assembly: AssemblyCopyright("Copyright © 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM componenets. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("fe9e3b83-a06c-4fc0-876b-3640318225e2")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace PcapDotNet.Base.Test
{
/// <summary>
/// Summary description for TupleTests
/// </summary>
[TestClass]
public class TupleTests
{
public TupleTests()
{
//
// TODO: Add constructor logic here
//
}
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#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 TupleTest()
{
Random random = new Random();
for (int i = 0; i != 100; ++i)
{
Tuple<int, double> expected = new Tuple<int, double>(random.Next(), random.NextDouble());
Tuple<int, double> equal = new Tuple<int, double>(expected.Value1, expected.Value2);
Tuple<int, double> different = new Tuple<int, double>(expected.Value1 + 1, expected.Value2);
Assert.AreEqual(expected, equal);
Assert.AreEqual(expected.GetHashCode(), equal.GetHashCode());
Assert.IsTrue(expected == equal);
Assert.IsFalse(expected != equal);
Assert.AreNotEqual(expected, different);
Assert.AreNotEqual(expected.GetHashCode(), different.GetHashCode());
Assert.IsFalse(expected == different);
Assert.IsTrue(expected != different);
}
}
}
}
\ No newline at end of file
using System;
using System.Globalization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.TestUtils;
namespace PcapDotNet.Base.Test
{
/// <summary>
/// Summary description for UInt24Tests
/// </summary>
[TestClass]
public class UInt24Tests
{
public UInt24Tests()
{
//
// TODO: Add constructor logic here
//
}
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#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 UInt24Test()
{
Random random = new Random();
for (int i = 0; i != 1000; ++i)
{
UInt24 value = random.NextUInt24();
Assert.AreEqual(value, value);
Assert.IsTrue(value == value);
Assert.IsFalse(value != value);
Assert.IsNotNull(value.GetHashCode());
Assert.AreEqual(((int)value).ToString(), value.ToString());
}
}
}
}
\ No newline at end of file
using System;
using System.Globalization;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.TestUtils;
namespace PcapDotNet.Base.Test
{
/// <summary>
/// Summary description for UInt48Tests
/// </summary>
[TestClass]
public class UInt48Tests
{
public UInt48Tests()
{
//
// TODO: Add constructor logic here
//
}
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#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 ParseTest()
{
Random random = new Random();
for (int i = 0; i != 100; ++i)
{
UInt48 expected = (UInt48)random.NextLong(UInt48.MaxValue + 1);
UInt48 actual = UInt48.Parse(expected.ToString(), NumberStyles.Integer, CultureInfo.InvariantCulture);
Assert.AreEqual(expected, actual);
}
}
[TestMethod]
public void UInt48Test()
{
Random random = new Random();
for (int i = 0; i != 1000; ++i)
{
UInt48 value = random.NextUInt48();
Assert.AreEqual(value, value);
Assert.IsTrue(value == value);
Assert.IsFalse(value != value);
Assert.IsNotNull(value.GetHashCode());
if (value < uint.MaxValue)
Assert.AreEqual(value, uint.Parse(value.ToString()));
Assert.AreEqual((byte)value, (byte)(value % 256));
}
}
}
}
...@@ -45,7 +45,12 @@ namespace PcapDotNet.TestUtils ...@@ -45,7 +45,12 @@ namespace PcapDotNet.TestUtils
public static uint NextUInt(this Random random) public static uint NextUInt(this Random random)
{ {
return (uint)random.Next(); return (uint)random.Next(int.MinValue, int.MaxValue);
}
public static uint NextUInt(this Random random, uint maxValue)
{
return random.NextUInt() % maxValue;
} }
public static UInt48 NextUInt48(this Random random) public static UInt48 NextUInt48(this Random random)
......
...@@ -22,9 +22,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PcapDotNet.Packets", "PcapD ...@@ -22,9 +22,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PcapDotNet.Packets", "PcapD
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PcapDotNet.Packets.Test", "PcapDotNet.Packets.Test\PcapDotNet.Packets.Test.csproj", "{6C7326EB-F230-4934-B74B-F99F87204E44}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PcapDotNet.Packets.Test", "PcapDotNet.Packets.Test\PcapDotNet.Packets.Test.csproj", "{6C7326EB-F230-4934-B74B-F99F87204E44}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PcapDotNet.Base.Test", "PcapDotNet.Base.Test\PcapDotNet.Base.Test.csproj", "{20BCB32F-6B86-41D4-8DF4-191F3D233087}"
EndProject
Global Global
GlobalSection(TeamFoundationVersionControl) = preSolution GlobalSection(TeamFoundationVersionControl) = preSolution
SccNumberOfProjects = 8 SccNumberOfProjects = 9
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C} SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
SccTeamFoundationServer = https://tfs06.codeplex.com/ SccTeamFoundationServer = https://tfs06.codeplex.com/
SccLocalPath0 = . SccLocalPath0 = .
...@@ -49,6 +51,9 @@ Global ...@@ -49,6 +51,9 @@ Global
SccProjectUniqueName7 = PcapDotNet.Packets\\PcapDotNet.Packets.csproj SccProjectUniqueName7 = PcapDotNet.Packets\\PcapDotNet.Packets.csproj
SccProjectName7 = PcapDotNet.Packets SccProjectName7 = PcapDotNet.Packets
SccLocalPath7 = PcapDotNet.Packets SccLocalPath7 = PcapDotNet.Packets
SccProjectUniqueName8 = PcapDotNet.Base.Test\\PcapDotNet.Base.Test.csproj
SccProjectName8 = PcapDotNet.Base.Test
SccLocalPath8 = PcapDotNet.Base.Test
EndGlobalSection EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = PcapDotNet.vsmdi CategoryFile = PcapDotNet.vsmdi
...@@ -146,6 +151,16 @@ Global ...@@ -146,6 +151,16 @@ Global
{6C7326EB-F230-4934-B74B-F99F87204E44}.Release|Mixed Platforms.Build.0 = Release|Any CPU {6C7326EB-F230-4934-B74B-F99F87204E44}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{6C7326EB-F230-4934-B74B-F99F87204E44}.Release|Win32.ActiveCfg = Release|Any CPU {6C7326EB-F230-4934-B74B-F99F87204E44}.Release|Win32.ActiveCfg = Release|Any CPU
{6C7326EB-F230-4934-B74B-F99F87204E44}.Release|Win32.Build.0 = Release|Any CPU {6C7326EB-F230-4934-B74B-F99F87204E44}.Release|Win32.Build.0 = Release|Any CPU
{20BCB32F-6B86-41D4-8DF4-191F3D233087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20BCB32F-6B86-41D4-8DF4-191F3D233087}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20BCB32F-6B86-41D4-8DF4-191F3D233087}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{20BCB32F-6B86-41D4-8DF4-191F3D233087}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{20BCB32F-6B86-41D4-8DF4-191F3D233087}.Debug|Win32.ActiveCfg = Debug|Any CPU
{20BCB32F-6B86-41D4-8DF4-191F3D233087}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20BCB32F-6B86-41D4-8DF4-191F3D233087}.Release|Any CPU.Build.0 = Release|Any CPU
{20BCB32F-6B86-41D4-8DF4-191F3D233087}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{20BCB32F-6B86-41D4-8DF4-191F3D233087}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{20BCB32F-6B86-41D4-8DF4-191F3D233087}.Release|Win32.ActiveCfg = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
......
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