CatStation/Content.IntegrationTests/Tests/DeviceLinking/DeviceLinkingTest.cs
TemporalOroboros 84b2f07157
The IMapManager is dead (#44002)
* Axes the easy IMapManager references

* Axes the references to unported (obsolete) IMapManager methods

* Converts salvageruler command to a LocalizedEntityCommand so it can use SharedMapSystem

* Removes IMapManager from GameTicker
This required axing the map nuke during restart, but that should be fine?
Maps are entities so EntityManager.FlushEntities should delete them all and that's the preceding line

* submodule update(?)

---------

Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
2026-07-01 20:44:54 -07:00

81 lines
3.2 KiB
C#

using Content.IntegrationTests.Fixtures;
using Content.IntegrationTests.Utility;
using Content.Server.DeviceLinking.Systems;
using Content.Shared.DeviceLinking;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.IntegrationTests.Tests.DeviceLinking;
public sealed class DeviceLinkingTest : GameTest
{
private const string PortTesterProtoId = "DeviceLinkingSinkPortTester";
[TestPrototypes]
private const string Prototypes = $@"
- type: entity
id: {PortTesterProtoId}
components:
- type: DeviceLinkSource
ports:
- Output
";
private static string[] _entitiesWithDeviceLinkSink = GameDataScrounger.EntitiesWithComponent("DeviceLinkSink");
[Test]
[TestOf(typeof(DeviceLinkSinkComponent))]
[TestCaseSource(nameof(_entitiesWithDeviceLinkSink))]
[Description("Ensures all devices that can sink signals will not cause exceptions when signaled.")]
public async Task DeviceLinkSinkAllPortsTest(string protoKey)
{
var pair = Pair;
var server = pair.Server;
var protoMan = server.ProtoMan;
var compFact = server.ResolveDependency<IComponentFactory>();
var mapSys = server.System<SharedMapSystem>();
var deviceLinkSys = server.System<DeviceLinkSystem>();
await server.WaitAssertion(() =>
{
using (Assert.EnterMultipleScope())
{
var proto = protoMan.Index(protoKey);
Assert.That(proto.TryComp<DeviceLinkSinkComponent>(out var protoSinkComp, compFact));
foreach (var port in protoSinkComp!.Ports)
{
// Create a map for each entity/port combo so they can't interfere
mapSys.CreateMap(out var mapId);
var grid = mapSys.CreateGridEntity(mapId);
mapSys.SetTile(grid.Owner, grid.Comp, Vector2i.Zero, new Tile(1));
var coord = new EntityCoordinates(grid.Owner, 0, 0);
// Spawn the sink entity
var sinkEnt = server.EntMan.SpawnEntity(proto.ID, coord);
// Get the actual sink component, since the one we got from the prototype isn't initialized.
var sinkComp = server.EntMan.GetComponent<DeviceLinkSinkComponent>(sinkEnt);
// Spawn the tester
var sourceEnt = server.EntMan.SpawnEntity(PortTesterProtoId, coord);
var sourceComp = server.EntMan.GetComponent<DeviceLinkSourceComponent>(sourceEnt);
// Create a link from the tester's output to the target port on the sink
deviceLinkSys.SaveLinks(null,
sourceEnt,
sinkEnt,
[("Output", port.Id)],
sourceComp,
sinkComp);
// Send a signal to the port
Assert.DoesNotThrow(() => { deviceLinkSys.InvokePort(sourceEnt, "Output", null, sourceComp); },
$"Exception thrown while triggering port {port.Id} of the sink device.");
mapSys.DeleteMap(mapId);
}
}
});
}
}