Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into change_license_mit
Browse files Browse the repository at this point in the history
  • Loading branch information
kayoub5 committed Dec 31, 2023
2 parents 1ba86f1 + 83e332a commit 107f46f
Show file tree
Hide file tree
Showing 27 changed files with 193 additions and 189 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
if: always()
with:
report_paths: Test/TestResults/TestResults.xml
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: failure()
with:
name: artifacts
Expand Down
2 changes: 1 addition & 1 deletion Test/ArpTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void TestArp()
var arp = new ARP(d);

// timeout should not be null
Assert.IsNotNull(arp.Timeout);
Assert.That(arp.Timeout.Ticks, Is.Not.Zero);

// and we can set a timeout
arp.Timeout = new TimeSpan(0, 0, 2);
Expand Down
4 changes: 2 additions & 2 deletions Test/CaptureDeviceListTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class CaptureDeviceListTest
public void CaptureDeviceListNew()
{
var deviceList = CaptureDeviceList.New();
Assert.IsNotNull(deviceList);
Assert.IsNotEmpty(deviceList);
Assert.That(deviceList, Is.Not.Null);
Assert.That(deviceList, Is.Not.Empty);
}
}
}
26 changes: 13 additions & 13 deletions Test/CaptureFileReaderDeviceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public void CaptureTimestampResolution(TimestampResolution resolution, string ti
TimestampResolution = resolution
};
device.Open(configuration);
Assert.AreEqual(resolution, device.TimestampResolution);
Assert.That(device.TimestampResolution, Is.EqualTo(resolution));
device.GetNextPacket(out var packet);
Assert.AreEqual(timeval, packet.Header.Timeval.ToString());
Assert.That(packet.Header.Timeval.ToString(), Is.EqualTo(timeval));
}

[Test]
Expand All @@ -49,7 +49,7 @@ public void CaptureProperties()
var filename = "ipv6_http.pcap";
using var device = new CaptureFileReaderDevice(TestHelper.GetFile(filename));
device.Open();
Assert.IsNotEmpty(device.Description);
Assert.That(device.Description, Is.Not.Empty);
}

/// <summary>
Expand All @@ -65,15 +65,15 @@ public void CaptureInfinite()
device.OnPacketArrival += HandleDeviceOnPacketArrival;
device.Open();
var ipv6FilesizeInBytes = 3451;
Assert.AreEqual(ipv6FilesizeInBytes, device.FileSize);
Assert.AreEqual(fileToOpen, device.Name);
Assert.AreEqual(filename, device.FileName);
Assert.That(device.FileSize, Is.EqualTo(ipv6FilesizeInBytes));
Assert.That(device.Name, Is.EqualTo(fileToOpen));
Assert.That(device.FileName, Is.EqualTo(filename));

var expectedPackets = 10;
capturedPackets = 0;
device.Capture();

Assert.AreEqual(expectedPackets, capturedPackets);
Assert.That(capturedPackets, Is.EqualTo(expectedPackets));
}

/// <summary>
Expand All @@ -91,7 +91,7 @@ public void CaptureFinite()
capturedPackets = 0;
device.Capture(expectedPackets);

Assert.AreEqual(expectedPackets, capturedPackets);
Assert.That(capturedPackets, Is.EqualTo(expectedPackets));
}

void HandleDeviceOnPacketArrival(object sender, PacketCapture e)
Expand All @@ -110,7 +110,7 @@ public void StatisticsUnsupported()
using (var device = new CaptureFileReaderDevice(TestHelper.GetFile("ipv6_http.pcap")))
{
device.Open();
Assert.IsNull(device.Statistics);
Assert.That(device.Statistics, Is.Null);
}
}

Expand All @@ -134,14 +134,14 @@ public void SetFilter()
rawPacket = e.GetPacket();
Packet p = Packet.ParsePacket(rawPacket.LinkLayerType, rawPacket.Data);
var udpPacket = p.Extract<UdpPacket>();
Assert.IsNotNull(udpPacket);
Assert.That(udpPacket, Is.Not.Null);
int dnsPort = 53;
Assert.AreEqual(dnsPort, udpPacket.DestinationPort);
Assert.That(udpPacket.DestinationPort, Is.EqualTo(dnsPort));
count++;
}
} while (retval == GetPacketStatus.PacketRead);

Assert.AreEqual(1, count);
Assert.That(count, Is.EqualTo(1));
}

[Test]
Expand All @@ -162,7 +162,7 @@ public void StringMarshalling()

using var device = new CaptureFileReaderDevice(file);
device.Open();
Assert.AreEqual(GetPacketStatus.PacketRead, device.GetNextPacket(out var _));
Assert.That(device.GetNextPacket(out var _), Is.EqualTo(GetPacketStatus.PacketRead));
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions Test/CaptureFileWriterDeviceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: MIT

using System;
using System.IO;
using NUnit.Framework;
using SharpPcap;
using SharpPcap.LibPcap;
Expand All @@ -11,7 +12,7 @@ namespace Test
[TestFixture]
public class CaptureFileWriterDeviceTest
{
static string filename = @"abc.pcap";
static string filename = "abc.pcap";

public CaptureFileWriterDeviceTest()
{
Expand All @@ -27,8 +28,8 @@ public void TestFileCreationAndDeletion()
using (var wd = new CaptureFileWriterDevice(filename))
{
wd.Open();
Assert.AreEqual(filename, wd.Name);
Assert.IsNotEmpty(wd.Description);
Assert.That(wd.Name, Is.EqualTo(filename));
Assert.That(wd.Description, Is.Not.Empty);
var bytes = new byte[] { 1, 2, 3, 4 };
wd.Write(bytes);

Expand Down Expand Up @@ -103,7 +104,7 @@ public void StatisticsUnsupported()
using (var wd = new CaptureFileWriterDevice(filename))
{
wd.Open();
Assert.IsNull(wd.Statistics);
Assert.That(wd.Statistics, Is.Null);
}
}

Expand All @@ -113,8 +114,8 @@ public void TestInjectable()
using (var wd = new CaptureFileWriterDevice(filename))
{
wd.Open();
Assert.AreEqual(filename, wd.Name);
Assert.IsNotEmpty(wd.Description);
Assert.That(wd.Name, Is.EqualTo(filename));
Assert.That(wd.Description, Is.Not.Empty);

var bytes = new byte[] { 1, 2, 3, 4 };

Expand All @@ -126,7 +127,7 @@ public void TestInjectable()
var span = new ReadOnlySpan<byte>(bytes, 0, bytes.Length);
injectionDevice.SendPacket(span);
}
System.IO.File.Delete(@"abc.pcap");
File.Delete(filename);
}

}
Expand Down
26 changes: 13 additions & 13 deletions Test/CaptureHandleReaderDeviceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,23 @@ public void CaptureTimestampResolution(TimestampResolution resolution, string ti
TimestampResolution = resolution
};
device.Open(configuration);
Assert.AreEqual(resolution, device.TimestampResolution);
Assert.That(device.TimestampResolution, Is.EqualTo(resolution));
device.GetNextPacket(out var packet);
Assert.AreEqual(timeval, packet.Header.Timeval.ToString());
Assert.That(packet.Header.Timeval.ToString(), Is.EqualTo(timeval));
}

[Test]
public void FileHandleInvalidUponClose()
{
const string filename = "ipv6_http.pcap";
using var handle = GetTestFileHandle(filename);
Assert.IsFalse(handle.IsInvalid);
Assert.IsFalse(handle.IsClosed);
Assert.That(handle.IsInvalid, Is.False);
Assert.That(handle.IsClosed, Is.False);
{
using var device = new CaptureHandleReaderDevice(handle);
device.Open();
}
Assert.IsTrue(handle.IsClosed);
Assert.That(handle.IsClosed, Is.True);
}

[Test]
Expand All @@ -72,8 +72,8 @@ public void CaptureProperties()
using var handle = GetTestFileHandle(filename);
using var device = new CaptureHandleReaderDevice(handle);
device.Open();
Assert.IsNotEmpty(device.Description);
Assert.AreEqual(handle, device.FileHandle);
Assert.That(device.Description, Is.Not.Empty);
Assert.That(device.FileHandle, Is.EqualTo(handle));
}

/// <summary>
Expand All @@ -93,7 +93,7 @@ public void CaptureInfinite()
capturedPackets = 0;
device.Capture();

Assert.AreEqual(expectedPackets, capturedPackets);
Assert.That(capturedPackets, Is.EqualTo(expectedPackets));
}

/// <summary>
Expand All @@ -113,7 +113,7 @@ public void CaptureFinite()
capturedPackets = 0;
device.Capture(expectedPackets);

Assert.AreEqual(expectedPackets, capturedPackets);
Assert.That(capturedPackets, Is.EqualTo(expectedPackets));
}

void HandleDeviceOnPacketArrival(object sender, PacketCapture e)
Expand All @@ -133,7 +133,7 @@ public void StatisticsUnsupported()
using var handle = GetTestFileHandle(filename);
using var device = new CaptureHandleReaderDevice(handle);
device.Open();
Assert.IsNull(device.Statistics);
Assert.That(device.Statistics, Is.Null);
}

[Test]
Expand All @@ -158,14 +158,14 @@ public void SetFilter()
rawPacket = e.GetPacket();
Packet p = Packet.ParsePacket(rawPacket.LinkLayerType, rawPacket.Data);
var udpPacket = p.Extract<UdpPacket>();
Assert.IsNotNull(udpPacket);
Assert.That(udpPacket, Is.Not.Null);
int dnsPort = 53;
Assert.AreEqual(dnsPort, udpPacket.DestinationPort);
Assert.That(udpPacket.DestinationPort, Is.EqualTo(dnsPort));
count++;
}
} while (retval == GetPacketStatus.PacketRead);

Assert.AreEqual(1, count);
Assert.That(count, Is.EqualTo(1));
}
}

Expand Down
26 changes: 13 additions & 13 deletions Test/CheckFilterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public class CheckFilterTest
public void TestFilters()
{
// test a known failing filter
Assert.IsFalse(LibPcapLiveDevice.CheckFilter("some bogus filter", out string errorString));
Assert.IsNotNull(errorString);
Assert.IsNotEmpty(errorString);
Assert.That(LibPcapLiveDevice.CheckFilter("some bogus filter", out string errorString), Is.False);
Assert.That(errorString, Is.Not.Null);
Assert.That(errorString, Is.Not.Empty);

// test a known working filter
Assert.IsTrue(LibPcapLiveDevice.CheckFilter("port 23", out errorString));
Assert.IsNull(errorString);
Assert.That(LibPcapLiveDevice.CheckFilter("port 23", out errorString), Is.True);
Assert.That(errorString, Is.Null);
}

/// <summary>
Expand All @@ -37,10 +37,10 @@ public void BpfProgramMatches()
var f = "(dst host 192.168.42.1) and (arp or tcp dst port 40499)";
// Make filter work with or without VLAN
using var bpfProgram = BpfProgram.Create(LinkLayers.Ethernet, $"({f}) or (vlan and ({f}))");
Assert.IsFalse(bpfProgram.IsInvalid);
Assert.That(bpfProgram.IsInvalid, Is.False);

device.GetNextPacket(out var packet);
Assert.IsTrue(bpfProgram.Matches(packet.Data));
Assert.That(bpfProgram.Matches(packet.Data), Is.True);
}
/// <summary>
/// Test BpfProgram.Matches() when creating BpfProgram without device
Expand All @@ -52,10 +52,10 @@ public void BpfProgramNoDeviceMatches()
device.Open();

using var bpfProgram = BpfProgram.Create(device.Handle, "tcp");
Assert.IsFalse(bpfProgram.IsInvalid);
Assert.That(bpfProgram.IsInvalid, Is.False);

device.GetNextPacket(out var packet);
Assert.IsTrue(bpfProgram.Matches(packet.Data));
Assert.That(bpfProgram.Matches(packet.Data), Is.True);
}

/// <summary>
Expand All @@ -69,7 +69,7 @@ public void FilterMethods()

var filterExpression = "arp";
using var bpfProgram = BpfProgram.Create(device.Handle, filterExpression);
Assert.IsFalse(bpfProgram.IsInvalid);
Assert.That(bpfProgram.IsInvalid, Is.False);

var arp = new ARP(device);
var destinationIP = new System.Net.IPAddress(new byte[] { 8, 8, 8, 8 });
Expand All @@ -96,8 +96,8 @@ public void FilterMethods()
{
packetsToTry--;

Assert.AreNotEqual(IntPtr.Zero, header);
Assert.AreNotEqual(IntPtr.Zero, data);
Assert.That(header, Is.Not.EqualTo(IntPtr.Zero));
Assert.That(data, Is.Not.EqualTo(IntPtr.Zero));

// and test it against the bpf filter to confirm an exception is not thrown
Assert.DoesNotThrow(() =>
Expand All @@ -112,7 +112,7 @@ public void FilterMethods()
}
}

Assert.IsTrue(foundBpfMatch);
Assert.That(foundBpfMatch, Is.True);
}
}
}
2 changes: 1 addition & 1 deletion Test/DeviceFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static IEnumerable<ILiveDevice> GetDevices()
};
foreach (var list in lists)
{
Assert.IsNotEmpty(list.Value, "{0} should not be empty", list.Key);
Assert.That(list.Value, Is.Not.Empty, $"{list.Key} should not be empty");
}
return lists.SelectMany(l => l.Value)
// The bluetooth-monitor break the tests on circleci
Expand Down
14 changes: 7 additions & 7 deletions Test/LibPcapLiveDeviceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public class LibPcapLiveDeviceTest
public void LibPcapLiveDeviceProperties()
{
var d = LibPcapLiveDeviceList.Instance[0];
Assert.IsNotNull(d);
Assert.That(d, Is.Not.Null);

Assert.IsNotNull(d.Addresses);
Assert.That(d.Addresses, Is.Not.Null);
Console.WriteLine("Flags: {0}", d.Flags);
Console.WriteLine("Loopback: {0}", d.Loopback);
}
Expand All @@ -38,7 +38,7 @@ public void DeviceOpenWithTimestampType([CaptureDevices] DeviceFixture fixture)

var timestampTypes = liveDevice.Interface.TimestampsSupported;

Assert.IsNotEmpty(timestampTypes);
Assert.That(timestampTypes, Is.Not.Empty);

// open the device with each of its supported timestamp types
foreach (var pcapClock in timestampTypes)
Expand All @@ -47,7 +47,7 @@ public void DeviceOpenWithTimestampType([CaptureDevices] DeviceFixture fixture)
configuration.TimestampType = pcapClock.TimestampType;
liveDevice.Open(configuration);

Assert.IsNotNull(liveDevice.Interface.TimestampsSupported);
Assert.That(liveDevice.Interface.TimestampsSupported, Is.Not.Null);

liveDevice.Close();
}
Expand All @@ -57,7 +57,7 @@ public void DeviceOpenWithTimestampType([CaptureDevices] DeviceFixture fixture)
public void NonBlockingMode()
{
using var d = LibPcapLiveDeviceList.Instance[0];
Assert.IsNotNull(d);
Assert.That(d, Is.Not.Null);

// assert that setting and getting non blocking mode
// with a closed device
Expand All @@ -67,9 +67,9 @@ public void NonBlockingMode()
// test that we can set the blocking mode on an open device
d.Open();
d.NonBlockingMode = true;
Assert.IsTrue(d.NonBlockingMode);
Assert.That(d.NonBlockingMode, Is.True);
d.NonBlockingMode = false;
Assert.IsFalse(d.NonBlockingMode);
Assert.That(d.NonBlockingMode, Is.False);
}
}
}
2 changes: 1 addition & 1 deletion Test/LivePcapDeviceListTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void ListTest()
// test that we can look up devices by name
foreach (var d in dl)
{
Assert.IsNotNull(dl[d.Name]);
Assert.That(dl[d.Name], Is.Not.Null);
}
}
}
Expand Down
Loading

0 comments on commit 107f46f

Please sign in to comment.