Files
ss14-wl/Content.IntegrationTests/Tests/DeviceNetwork/DeviceNetworkTest.cs
T
Moony d42adbf05d Gametest Part 2: Preliminary refactor every test to use GameTest as the framework. (#43207)
* Pass 1.

* i'm FREE

* Prevent hangups.

* okay fine here's an attribute for settings, will polish later and prolly remove the overridable thing.

* sigh.

* fix singular trigger bug so LatheTest doesn't flake.

* Remove SystemAttribute usage.

* Poke

* I used the shotgun. You know why? Cause the shot gun doesn’t miss, and unlike the shitty hybrid taser it stops a criminal in their tracks in two hits. Bang, bang, and they’re fucking done. I use four shots just to make damn sure. Because, once again, I’m not there to coddle a buncha criminal scum sucking f------, I’m there to 1) Survive the fucking round. 2) Guard the armory. So you can absolutely get fucked. If I get unbanned, which I won’t, you can guarantee I will continue to use the shotgun to apprehend criminals. Because it’s quick, clean and effective as fuck. Why in the seven hells would I fuck around with the disabler shots, which take half a clip just to bring someone down, or with the tazer bolts which are slow as balls, impossible to aim and do about next to jack shit, fuck all. The shotgun is the superior law enforcement weapon. Because it stops crime. And it stops crime by reducing the number of criminals roaming the fucking halls.

* Change the faulty store test into two tests, one of which is ignored for failing.
2026-04-01 16:06:26 +00:00

275 lines
10 KiB
C#

using System.Numerics;
using Content.IntegrationTests.Fixtures;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Shared.DeviceNetwork;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Content.Shared.DeviceNetwork.Components;
namespace Content.IntegrationTests.Tests.DeviceNetwork
{
[TestFixture]
[TestOf(typeof(DeviceNetworkComponent))]
[TestOf(typeof(WiredNetworkComponent))]
[TestOf(typeof(WirelessNetworkComponent))]
public sealed class DeviceNetworkTest : GameTest
{
[TestPrototypes]
private const string Prototypes = @"
- type: entity
name: DummyNetworkDevice
id: DummyNetworkDevice
components:
- type: DeviceNetwork
transmitFrequency: 100
receiveFrequency: 100
- type: entity
name: DummyWiredNetworkDevice
id: DummyWiredNetworkDevice
components:
- type: DeviceNetwork
deviceNetId: Wired
transmitFrequency: 0
receiveFrequency: 0
- type: WiredNetworkConnection
- type: ApcPowerReceiver
- type: entity
name: WirelessNetworkDeviceDummy
id: WirelessNetworkDeviceDummy
components:
- type: DeviceNetwork
transmitFrequency: 100
receiveFrequency: 100
deviceNetId: Wireless
- type: WirelessNetworkConnection
range: 100
";
[Test]
public async Task NetworkDeviceSendAndReceive()
{
var pair = Pair;
var server = pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
var deviceNetSystem = entityManager.EntitySysManager.GetEntitySystem<DeviceNetworkSystem>();
var deviceNetTestSystem = entityManager.EntitySysManager.GetEntitySystem<DeviceNetworkTestSystem>();
EntityUid device1 = default;
EntityUid device2 = default;
DeviceNetworkComponent networkComponent1 = null;
DeviceNetworkComponent networkComponent2 = null;
var testValue = "test";
var payload = new NetworkPayload
{
["Test"] = testValue,
["testnumber"] = 1,
["testbool"] = true
};
await server.WaitAssertion(() =>
{
device1 = entityManager.SpawnEntity("DummyNetworkDevice", MapCoordinates.Nullspace);
Assert.That(entityManager.TryGetComponent(device1, out networkComponent1), Is.True);
Assert.Multiple(() =>
{
Assert.That(networkComponent1.ReceiveFrequency, Is.Not.Null);
Assert.That(networkComponent1.Address, Is.Not.EqualTo(string.Empty));
});
device2 = entityManager.SpawnEntity("DummyNetworkDevice", MapCoordinates.Nullspace);
Assert.That(entityManager.TryGetComponent(device2, out networkComponent2), Is.True);
Assert.Multiple(() =>
{
Assert.That(networkComponent1.ReceiveFrequency, Is.Not.Null);
Assert.That(networkComponent2.Address, Is.Not.EqualTo(string.Empty));
Assert.That(networkComponent1.Address, Is.Not.EqualTo(networkComponent2.Address));
});
deviceNetSystem.QueuePacket(device1, networkComponent2.Address, payload, networkComponent2.ReceiveFrequency.Value);
});
await server.WaitRunTicks(2);
await server.WaitIdleAsync();
await server.WaitAssertion(() =>
{
Assert.That(payload, Is.EquivalentTo(deviceNetTestSystem.LastPayload));
});
}
[Test]
public async Task WirelessNetworkDeviceSendAndReceive()
{
var pair = Pair;
var server = pair.Server;
var testMap = await pair.CreateTestMap();
var coordinates = testMap.GridCoords;
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
var deviceNetSystem = entityManager.EntitySysManager.GetEntitySystem<DeviceNetworkSystem>();
var deviceNetTestSystem = entityManager.EntitySysManager.GetEntitySystem<DeviceNetworkTestSystem>();
EntityUid device1 = default;
EntityUid device2 = default;
DeviceNetworkComponent networkComponent1 = null;
DeviceNetworkComponent networkComponent2 = null;
WirelessNetworkComponent wirelessNetworkComponent = null;
var testValue = "test";
var payload = new NetworkPayload
{
["Test"] = testValue,
["testnumber"] = 1,
["testbool"] = true
};
await server.WaitAssertion(() =>
{
device1 = entityManager.SpawnEntity("WirelessNetworkDeviceDummy", coordinates);
Assert.Multiple(() =>
{
Assert.That(entityManager.TryGetComponent(device1, out networkComponent1), Is.True);
Assert.That(entityManager.TryGetComponent(device1, out wirelessNetworkComponent), Is.True);
});
Assert.Multiple(() =>
{
Assert.That(networkComponent1.ReceiveFrequency, Is.Not.Null);
Assert.That(networkComponent1.Address, Is.Not.EqualTo(string.Empty));
});
device2 = entityManager.SpawnEntity("WirelessNetworkDeviceDummy", new MapCoordinates(new Vector2(0, 50), testMap.MapId));
Assert.That(entityManager.TryGetComponent(device2, out networkComponent2), Is.True);
Assert.Multiple(() =>
{
Assert.That(networkComponent2.ReceiveFrequency, Is.Not.Null);
Assert.That(networkComponent2.Address, Is.Not.EqualTo(string.Empty));
Assert.That(networkComponent1.Address, Is.Not.EqualTo(networkComponent2.Address));
});
deviceNetSystem.QueuePacket(device1, networkComponent2.Address, payload, networkComponent2.ReceiveFrequency.Value);
});
await server.WaitRunTicks(2);
await server.WaitIdleAsync();
await server.WaitAssertion(() =>
{
Assert.That(payload, Is.EqualTo(deviceNetTestSystem.LastPayload).AsCollection);
payload = new NetworkPayload
{
["Wirelesstest"] = 5
};
wirelessNetworkComponent.Range = 0;
deviceNetSystem.QueuePacket(device1, networkComponent2.Address, payload, networkComponent2.ReceiveFrequency.Value);
});
await server.WaitRunTicks(1);
await server.WaitIdleAsync();
await server.WaitAssertion(() =>
{
Assert.That(payload, Is.Not.EqualTo(deviceNetTestSystem.LastPayload).AsCollection);
});
}
[Test]
public async Task WiredNetworkDeviceSendAndReceive()
{
var pair = Pair;
var server = pair.Server;
var testMap = await pair.CreateTestMap();
var coordinates = testMap.GridCoords;
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
var deviceNetSystem = entityManager.EntitySysManager.GetEntitySystem<DeviceNetworkSystem>();
var deviceNetTestSystem = entityManager.EntitySysManager.GetEntitySystem<DeviceNetworkTestSystem>();
EntityUid device1 = default;
EntityUid device2 = default;
DeviceNetworkComponent networkComponent1 = null;
DeviceNetworkComponent networkComponent2 = null;
WiredNetworkComponent wiredNetworkComponent = null;
var grid = testMap.Grid.Comp;
var testValue = "test";
var payload = new NetworkPayload
{
["Test"] = testValue,
["testnumber"] = 1,
["testbool"] = true
};
await server.WaitRunTicks(2);
await server.WaitIdleAsync();
await server.WaitAssertion(() =>
{
device1 = entityManager.SpawnEntity("DummyWiredNetworkDevice", coordinates);
Assert.Multiple(() =>
{
Assert.That(entityManager.TryGetComponent(device1, out networkComponent1), Is.True);
Assert.That(entityManager.TryGetComponent(device1, out wiredNetworkComponent), Is.True);
});
Assert.Multiple(() =>
{
Assert.That(networkComponent1.ReceiveFrequency, Is.Not.Null);
Assert.That(networkComponent1.Address, Is.Not.EqualTo(string.Empty));
});
device2 = entityManager.SpawnEntity("DummyWiredNetworkDevice", coordinates);
Assert.That(entityManager.TryGetComponent(device2, out networkComponent2), Is.True);
Assert.Multiple(() =>
{
Assert.That(networkComponent2.ReceiveFrequency, Is.Not.Null);
Assert.That(networkComponent2.Address, Is.Not.EqualTo(string.Empty));
Assert.That(networkComponent1.Address, Is.Not.EqualTo(networkComponent2.Address));
});
deviceNetSystem.QueuePacket(device1, networkComponent2.Address, payload, networkComponent2.ReceiveFrequency.Value);
});
await server.WaitRunTicks(1);
await server.WaitIdleAsync();
await server.WaitAssertion(() =>
{
//CollectionAssert.AreNotEqual(deviceNetTestSystem.LastPayload, payload);
entityManager.SpawnEntity("CableApcExtension", coordinates);
deviceNetSystem.QueuePacket(device1, networkComponent2.Address, payload, networkComponent2.ReceiveFrequency.Value);
});
await server.WaitRunTicks(1);
await server.WaitIdleAsync();
await server.WaitAssertion(() =>
{
Assert.That(payload, Is.EqualTo(deviceNetTestSystem.LastPayload).AsCollection);
});
}
}
}