Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pcap-Net
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Pcap-Net
Commits
7a3ec961
Commit
7a3ec961
authored
Apr 27, 2012
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code coverage 95.83%
parent
4cf6f1a4
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
185 additions
and
4 deletions
+185
-4
PacketTimestampTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/PacketTimestampTests.cs
+46
-0
PcapDataLinkTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/PcapDataLinkTests.cs
+20
-0
PcapDotNet.Core.Test.csproj
...tNet/src/PcapDotNet.Core.Test/PcapDotNet.Core.Test.csproj
+1
-0
PcapLibTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/PcapLibTests.cs
+1
-1
ByteArrayExtensionsTests.cs
...t/src/PcapDotNet.Packets.Test/ByteArrayExtensionsTests.cs
+27
-1
DataSegmentTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/DataSegmentTests.cs
+63
-0
DatagramTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/DatagramTests.cs
+1
-1
IpV4Tests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/IpV4Tests.cs
+1
-0
PcapDotNet.Packets.Test.csproj
...rc/PcapDotNet.Packets.Test/PcapDotNet.Packets.Test.csproj
+1
-0
TcpTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/TcpTests.cs
+24
-1
No files found.
PcapDotNet/src/PcapDotNet.Core.Test/PacketTimestampTests.cs
0 → 100644
View file @
7a3ec961
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
PcapDotNet/src/PcapDotNet.Core.Test/PcapDataLinkTests.cs
View file @
7a3ec961
using
System
;
using
System
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
PcapDotNet.Packets
;
namespace
PcapDotNet.Core.Test
namespace
PcapDotNet.Core.Test
{
{
...
@@ -70,6 +71,15 @@ 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
]
[
TestMethod
]
[
ExpectedException
(
typeof
(
NotSupportedException
),
AllowDerivedTypes
=
false
)]
[
ExpectedException
(
typeof
(
NotSupportedException
),
AllowDerivedTypes
=
false
)]
public
void
UnsupportedKindErrorTest
()
public
void
UnsupportedKindErrorTest
()
...
@@ -96,6 +106,16 @@ namespace PcapDotNet.Core.Test
...
@@ -96,6 +106,16 @@ namespace PcapDotNet.Core.Test
Assert
.
Fail
();
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
()
private
static
PcapDataLink
GetInvalidDataLink
()
{
{
for
(
int
i
=
0
;
i
!=
1000
;
++
i
)
for
(
int
i
=
0
;
i
!=
1000
;
++
i
)
...
...
PcapDotNet/src/PcapDotNet.Core.Test/PcapDotNet.Core.Test.csproj
View file @
7a3ec961
...
@@ -74,6 +74,7 @@
...
@@ -74,6 +74,7 @@
<Compile
Include=
"LivePacketDeviceTests.cs"
/>
<Compile
Include=
"LivePacketDeviceTests.cs"
/>
<Compile
Include=
"MarshalingServicesTests.cs"
/>
<Compile
Include=
"MarshalingServicesTests.cs"
/>
<Compile
Include=
"IpV4OptionExtensions.cs"
/>
<Compile
Include=
"IpV4OptionExtensions.cs"
/>
<Compile
Include=
"PacketTimestampTests.cs"
/>
<Compile
Include=
"TcpOptionExtensions.cs"
/>
<Compile
Include=
"TcpOptionExtensions.cs"
/>
<Compile
Include=
"WiresharkDatagramComparer.cs"
/>
<Compile
Include=
"WiresharkDatagramComparer.cs"
/>
<Compile
Include=
"WiresharkDatagramComparerArp.cs"
/>
<Compile
Include=
"WiresharkDatagramComparerArp.cs"
/>
...
...
PcapDotNet/src/PcapDotNet.Core.Test/PcapLibTests.cs
View file @
7a3ec961
...
@@ -4,7 +4,7 @@ using PcapDotNet.TestUtils;
...
@@ -4,7 +4,7 @@ using PcapDotNet.TestUtils;
namespace
PcapDotNet.Core.Test
namespace
PcapDotNet.Core.Test
{
{
/// <summary>
/// <summary>
/// Summary description for PcapLibTests
/// Summary description for PcapLibTests
.
/// </summary>
/// </summary>
[
TestClass
]
[
TestClass
]
public
class
PcapLibTests
public
class
PcapLibTests
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/ByteArrayExtensionsTests.cs
View file @
7a3ec961
...
@@ -150,13 +150,39 @@ namespace PcapDotNet.Packets.Test
...
@@ -150,13 +150,39 @@ namespace PcapDotNet.Packets.Test
[
TestMethod
]
[
TestMethod
]
public
void
ByteArrayUnsignedBigIntegerTest
()
public
void
ByteArrayUnsignedBigIntegerTest
()
{
{
byte
[]
buffer
=
new
byte
[
100
];
for
(
BigInteger
expectedValue
=
1
;
expectedValue
<=
ushort
.
MaxValue
;
expectedValue
*=
10
)
for
(
BigInteger
expectedValue
=
1
;
expectedValue
<=
ushort
.
MaxValue
;
expectedValue
*=
10
)
{
{
byte
[]
buffer
=
new
byte
[
100
];
buffer
.
WriteUnsigned
(
5
,
expectedValue
,
2
,
Endianity
.
Big
);
buffer
.
WriteUnsigned
(
5
,
expectedValue
,
2
,
Endianity
.
Big
);
BigInteger
actualValue
=
buffer
.
ReadUnsignedBigInteger
(
5
,
2
,
Endianity
.
Big
);
BigInteger
actualValue
=
buffer
.
ReadUnsignedBigInteger
(
5
,
2
,
Endianity
.
Big
);
Assert
.
AreEqual
(
expectedValue
,
actualValue
);
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
]
[
TestMethod
]
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/DataSegmentTests.cs
0 → 100644
View file @
7a3ec961
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
PcapDotNet/src/PcapDotNet.Packets.Test/DatagramTests.cs
View file @
7a3ec961
...
@@ -11,7 +11,7 @@ using PcapDotNet.Packets.Transport;
...
@@ -11,7 +11,7 @@ using PcapDotNet.Packets.Transport;
namespace
PcapDotNet.Packets.Test
namespace
PcapDotNet.Packets.Test
{
{
/// <summary>
/// <summary>
/// Summary description for DatagramTests
/// Summary description for DatagramTests
.
/// </summary>
/// </summary>
[
TestClass
]
[
TestClass
]
public
class
DatagramTests
public
class
DatagramTests
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/IpV4Tests.cs
View file @
7a3ec961
...
@@ -114,6 +114,7 @@ namespace PcapDotNet.Packets.Test
...
@@ -114,6 +114,7 @@ namespace PcapDotNet.Packets.Test
// IpV4
// IpV4
ipV4Layer
.
HeaderChecksum
=
((
IpV4Layer
)
packet
.
Ethernet
.
IpV4
.
ExtractLayer
()).
HeaderChecksum
;
ipV4Layer
.
HeaderChecksum
=
((
IpV4Layer
)
packet
.
Ethernet
.
IpV4
.
ExtractLayer
()).
HeaderChecksum
;
Assert
.
AreEqual
(
ipV4Layer
,
packet
.
Ethernet
.
IpV4
.
ExtractLayer
(),
"IP Layer"
);
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
,
null
);
Assert
.
AreNotEqual
(
ipV4Layer
,
new
PayloadLayer
());
Assert
.
AreNotEqual
(
ipV4Layer
,
new
PayloadLayer
());
Assert
.
IsNotNull
(
ipV4Layer
.
ToString
());
Assert
.
IsNotNull
(
ipV4Layer
.
ToString
());
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/PcapDotNet.Packets.Test.csproj
View file @
7a3ec961
...
@@ -71,6 +71,7 @@
...
@@ -71,6 +71,7 @@
<Compile
Include=
"ByteArrayExtensionsTests.cs"
/>
<Compile
Include=
"ByteArrayExtensionsTests.cs"
/>
<Compile
Include=
"DatagramTests.cs"
/>
<Compile
Include=
"DatagramTests.cs"
/>
<Compile
Include=
"DataLinkTests.cs"
/>
<Compile
Include=
"DataLinkTests.cs"
/>
<Compile
Include=
"DataSegmentTests.cs"
/>
<Compile
Include=
"DnsTests.cs"
/>
<Compile
Include=
"DnsTests.cs"
/>
<Compile
Include=
"EndianitiyTests.cs"
/>
<Compile
Include=
"EndianitiyTests.cs"
/>
<Compile
Include=
"EthernetTests.cs"
/>
<Compile
Include=
"EthernetTests.cs"
/>
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/TcpTests.cs
View file @
7a3ec961
...
@@ -175,9 +175,32 @@ namespace PcapDotNet.Packets.Test
...
@@ -175,9 +175,32 @@ namespace PcapDotNet.Packets.Test
[
TestMethod
]
[
TestMethod
]
[
ExpectedException
(
typeof
(
InvalidOperationException
),
AllowDerivedTypes
=
false
)]
[
ExpectedException
(
typeof
(
InvalidOperationException
),
AllowDerivedTypes
=
false
)]
public
void
TcpOptionMoodBadEmotionStringTest
()
public
void
TcpOptionMood
Constructor
BadEmotionStringTest
()
{
{
Assert
.
IsNotNull
(
new
TcpOptionMood
((
TcpOptionMoodEmotion
)
202
).
EmotionString
);
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
]
[
TestMethod
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment