Fix content.integration tests warnings (#17817)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
TemporalOroboros
2023-07-05 21:54:25 -07:00
committed by GitHub
parent 20c1754abd
commit ba91023a85
121 changed files with 3658 additions and 1961 deletions

View File

@@ -1,4 +1,3 @@
using System.Threading.Tasks;
using Content.Server.Body.Systems;
using Content.Shared.Buckle;
using Content.Shared.ActionBlocker;
@@ -8,7 +7,6 @@ using Content.Shared.Buckle.Components;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Standing;
using NUnit.Framework;
using Robust.Shared.GameObjects;
namespace Content.IntegrationTests.Tests.Buckle
@@ -50,15 +48,16 @@ namespace Content.IntegrationTests.Tests.Buckle
public async Task BuckleUnbuckleCooldownRangeTest()
{
await using var pairTracker =
await PoolManager.GetServerClient(new PoolSettings {ExtraPrototypes = Prototypes});
await PoolManager.GetServerClient(new PoolSettings { ExtraPrototypes = Prototypes });
var server = pairTracker.Pair.Server;
var testMap = await PoolManager.CreateTestMap(pairTracker);
var coordinates = testMap.GridCoords;
var entityManager = server.ResolveDependency<IEntityManager>();
var actionBlocker = entityManager.EntitySysManager.GetEntitySystem<ActionBlockerSystem>();
var buckleSystem = entityManager.EntitySysManager.GetEntitySystem<SharedBuckleSystem>();
var standingState = entityManager.EntitySysManager.GetEntitySystem<StandingStateSystem>();
var actionBlocker = entityManager.System<ActionBlockerSystem>();
var buckleSystem = entityManager.System<SharedBuckleSystem>();
var standingState = entityManager.System<StandingStateSystem>();
var xformSystem = entityManager.System<SharedTransformSystem>();
EntityUid human = default;
EntityUid chair = default;
@@ -71,47 +70,58 @@ namespace Content.IntegrationTests.Tests.Buckle
chair = entityManager.SpawnEntity(StrapDummyId, coordinates);
// Default state, unbuckled
Assert.True(entityManager.TryGetComponent(human, out buckle));
Assert.NotNull(buckle);
Assert.Null(buckle.BuckledTo);
Assert.False(buckle.Buckled);
Assert.True(actionBlocker.CanMove(human));
Assert.True(actionBlocker.CanChangeDirection(human));
Assert.True(standingState.Down(human));
Assert.True(standingState.Stand(human));
Assert.That(entityManager.TryGetComponent(human, out buckle));
Assert.Multiple(() =>
{
Assert.That(buckle, Is.Not.Null);
Assert.That(buckle.BuckledTo, Is.Null);
Assert.That(buckle.Buckled, Is.False);
Assert.That(actionBlocker.CanMove(human));
Assert.That(actionBlocker.CanChangeDirection(human));
Assert.That(standingState.Down(human));
Assert.That(standingState.Stand(human));
});
// Default state, no buckled entities, strap
Assert.True(entityManager.TryGetComponent(chair, out strap));
Assert.NotNull(strap);
Assert.IsEmpty(strap.BuckledEntities);
Assert.Zero(strap.OccupiedSize);
Assert.That(entityManager.TryGetComponent(chair, out strap));
Assert.Multiple(() =>
{
Assert.That(strap, Is.Not.Null);
Assert.That(strap.BuckledEntities, Is.Empty);
Assert.That(strap.OccupiedSize, Is.Zero);
});
// Side effects of buckling
Assert.True(buckleSystem.TryBuckle(human, human, chair, buckle));
Assert.NotNull(buckle.BuckledTo);
Assert.True(buckle.Buckled);
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckle));
Assert.Multiple(() =>
{
Assert.That(buckle.BuckledTo, Is.Not.Null);
Assert.That(buckle.Buckled);
Assert.False(actionBlocker.CanMove(human));
Assert.False(actionBlocker.CanChangeDirection(human));
Assert.False(standingState.Down(human));
Assert.That(
(entityManager.GetComponent<TransformComponent>(human).WorldPosition -
entityManager.GetComponent<TransformComponent>(chair).WorldPosition).Length,
Is.LessThanOrEqualTo(0));
Assert.That(actionBlocker.CanMove(human), Is.False);
Assert.That(actionBlocker.CanChangeDirection(human), Is.False);
Assert.That(standingState.Down(human), Is.False);
Assert.That(
(xformSystem.GetWorldPosition(human) - xformSystem.GetWorldPosition(chair)).LengthSquared,
Is.LessThanOrEqualTo(0)
);
// Side effects of buckling for the strap
Assert.That(strap.BuckledEntities, Does.Contain(human));
Assert.That(strap.OccupiedSize, Is.EqualTo(buckle.Size));
Assert.Positive(strap.OccupiedSize);
// Side effects of buckling for the strap
Assert.That(strap.BuckledEntities, Does.Contain(human));
Assert.That(strap.OccupiedSize, Is.EqualTo(buckle.Size));
Assert.Positive(strap.OccupiedSize);
});
#pragma warning disable NUnit2045 // Interdependent asserts.
// Trying to buckle while already buckled fails
Assert.False(buckleSystem.TryBuckle(human, human, chair, buckle));
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckle), Is.False);
// Trying to unbuckle too quickly fails
Assert.False(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle));
Assert.True(buckle.Buckled);
Assert.False(buckleSystem.ToggleBuckle(human, human, chair, buckle: buckle));
Assert.True(buckle.Buckled);
Assert.That(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle), Is.False);
Assert.That(buckle.Buckled);
Assert.That(buckleSystem.ToggleBuckle(human, human, chair, buckle: buckle), Is.False);
Assert.That(buckle.Buckled);
#pragma warning restore NUnit2045
});
// Wait enough ticks for the unbuckling cooldown to run out
@@ -119,32 +129,39 @@ namespace Content.IntegrationTests.Tests.Buckle
await server.WaitAssertion(() =>
{
#pragma warning disable NUnit2045 // Interdependent asserts.
Assert.That(buckle.Buckled);
// Still buckled
Assert.True(buckle.Buckled);
#pragma warning restore NUnit2045
// Unbuckle
Assert.True(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle));
Assert.Null(buckle.BuckledTo);
Assert.False(buckle.Buckled);
Assert.True(actionBlocker.CanMove(human));
Assert.True(actionBlocker.CanChangeDirection(human));
Assert.True(standingState.Down(human));
Assert.That(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle));
Assert.Multiple(() =>
{
Assert.That(buckle.BuckledTo, Is.Null);
Assert.That(buckle.Buckled, Is.False);
Assert.That(actionBlocker.CanMove(human));
Assert.That(actionBlocker.CanChangeDirection(human));
Assert.That(standingState.Down(human));
// Unbuckle, strap
Assert.IsEmpty(strap.BuckledEntities);
Assert.Zero(strap.OccupiedSize);
// Unbuckle, strap
Assert.That(strap.BuckledEntities, Is.Empty);
Assert.That(strap.OccupiedSize, Is.Zero);
});
#pragma warning disable NUnit2045 // Interdependent asserts.
// Re-buckling has no cooldown
Assert.True(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
Assert.True(buckle.Buckled);
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
Assert.That(buckle.Buckled);
// On cooldown
Assert.False(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle));
Assert.True(buckle.Buckled);
Assert.False(buckleSystem.ToggleBuckle(human, human, chair, buckle: buckle));
Assert.True(buckle.Buckled);
Assert.False(buckleSystem.ToggleBuckle(human, human, chair, buckle: buckle));
Assert.True(buckle.Buckled);
Assert.That(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle), Is.False);
Assert.That(buckle.Buckled);
Assert.That(buckleSystem.ToggleBuckle(human, human, chair, buckle: buckle), Is.False);
Assert.That(buckle.Buckled);
Assert.That(buckleSystem.ToggleBuckle(human, human, chair, buckle: buckle), Is.False);
Assert.That(buckle.Buckled);
#pragma warning restore NUnit2045
});
// Wait enough ticks for the unbuckling cooldown to run out
@@ -152,45 +169,57 @@ namespace Content.IntegrationTests.Tests.Buckle
await server.WaitAssertion(() =>
{
#pragma warning disable NUnit2045 // Interdependent asserts.
// Still buckled
Assert.True(buckle.Buckled);
Assert.That(buckle.Buckled);
// Unbuckle
Assert.True(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle));
Assert.False(buckle.Buckled);
Assert.That(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle));
Assert.That(buckle.Buckled, Is.False);
#pragma warning restore NUnit2045
// Move away from the chair
entityManager.GetComponent<TransformComponent>(human).WorldPosition += (1000, 1000);
var xformQuery = entityManager.GetEntityQuery<TransformComponent>();
var oldWorldPosition = xformSystem.GetWorldPosition(chair, xformQuery);
xformSystem.SetWorldPosition(human, oldWorldPosition + (1000, 1000), xformQuery);
// Out of range
Assert.False(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
Assert.False(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle));
Assert.False(buckleSystem.ToggleBuckle(human, human, chair, buckle: buckle));
#pragma warning disable NUnit2045 // Interdependent asserts.
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle), Is.False);
Assert.That(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle), Is.False);
Assert.That(buckleSystem.ToggleBuckle(human, human, chair, buckle: buckle), Is.False);
#pragma warning restore NUnit2045
// Move near the chair
entityManager.GetComponent<TransformComponent>(human).WorldPosition =
entityManager.GetComponent<TransformComponent>(chair).WorldPosition + (0.5f, 0);
oldWorldPosition = xformSystem.GetWorldPosition(chair, xformQuery);
xformSystem.SetWorldPosition(human, oldWorldPosition + (0.5f, 0), xformQuery);
// In range
Assert.True(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
Assert.True(buckle.Buckled);
Assert.False(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle));
Assert.True(buckle.Buckled);
Assert.False(buckleSystem.ToggleBuckle(human, human, chair, buckle: buckle));
Assert.True(buckle.Buckled);
#pragma warning disable NUnit2045 // Interdependent asserts.
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
Assert.That(buckle.Buckled);
Assert.That(buckleSystem.TryUnbuckle(human, human, buckleComp: buckle), Is.False);
Assert.That(buckle.Buckled);
Assert.That(buckleSystem.ToggleBuckle(human, human, chair, buckle: buckle), Is.False);
Assert.That(buckle.Buckled);
#pragma warning restore NUnit2045
// Force unbuckle
Assert.True(buckleSystem.TryUnbuckle(human, human, true, buckleComp: buckle));
Assert.False(buckle.Buckled);
Assert.True(actionBlocker.CanMove(human));
Assert.True(actionBlocker.CanChangeDirection(human));
Assert.True(standingState.Down(human));
Assert.That(buckleSystem.TryUnbuckle(human, human, true, buckleComp: buckle));
Assert.Multiple(() =>
{
Assert.That(buckle.Buckled, Is.False);
Assert.That(actionBlocker.CanMove(human));
Assert.That(actionBlocker.CanChangeDirection(human));
Assert.That(standingState.Down(human));
});
// Re-buckle
Assert.True(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
// Move away from the chair
entityManager.GetComponent<TransformComponent>(human).WorldPosition += (1, 0);
oldWorldPosition = xformSystem.GetWorldPosition(chair, xformQuery);
xformSystem.SetWorldPosition(human, oldWorldPosition + (1, 0), xformQuery);
});
await server.WaitRunTicks(1);
@@ -198,9 +227,12 @@ namespace Content.IntegrationTests.Tests.Buckle
await server.WaitAssertion(() =>
{
// No longer buckled
Assert.False(buckle.Buckled);
Assert.Null(buckle.BuckledTo);
Assert.IsEmpty(strap.BuckledEntities);
Assert.Multiple(() =>
{
Assert.That(buckle.Buckled, Is.False);
Assert.That(buckle.BuckledTo, Is.Null);
Assert.That(strap.BuckledEntities, Is.Empty);
});
});
await pairTracker.CleanReturnAsync();
@@ -210,7 +242,10 @@ namespace Content.IntegrationTests.Tests.Buckle
public async Task BuckledDyingDropItemsTest()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
{NoClient = true, ExtraPrototypes = Prototypes});
{
NoClient = true,
ExtraPrototypes = Prototypes
});
var server = pairTracker.Pair.Server;
var testMap = await PoolManager.CreateTestMap(pairTracker);
@@ -233,22 +268,28 @@ namespace Content.IntegrationTests.Tests.Buckle
var chair = entityManager.SpawnEntity(StrapDummyId, coordinates);
// Component sanity check
Assert.True(entityManager.TryGetComponent(human, out buckle));
Assert.True(entityManager.HasComponent<StrapComponent>(chair));
Assert.True(entityManager.TryGetComponent(human, out hands));
Assert.True(entityManager.TryGetComponent(human, out body));
Assert.Multiple(() =>
{
Assert.That(entityManager.TryGetComponent(human, out buckle));
Assert.That(entityManager.HasComponent<StrapComponent>(chair));
Assert.That(entityManager.TryGetComponent(human, out hands));
Assert.That(entityManager.TryGetComponent(human, out body));
});
// Buckle
Assert.True(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
Assert.NotNull(buckle.BuckledTo);
Assert.True(buckle.Buckled);
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
Assert.Multiple(() =>
{
Assert.That(buckle.BuckledTo, Is.Not.Null);
Assert.That(buckle.Buckled);
});
// Put an item into every hand
for (var i = 0; i < hands.Count; i++)
{
var akms = entityManager.SpawnEntity(ItemDummyId, coordinates);
Assert.True(handsSys.TryPickupAnyHand(human, akms));
Assert.That(handsSys.TryPickupAnyHand(human, akms));
}
});
@@ -257,16 +298,16 @@ namespace Content.IntegrationTests.Tests.Buckle
await server.WaitAssertion(() =>
{
// Still buckled
Assert.True(buckle.Buckled);
Assert.That(buckle.Buckled);
// With items in all hands
foreach (var hand in hands.Hands.Values)
{
Assert.NotNull(hand.HeldEntity);
Assert.That(hand.HeldEntity, Is.Not.Null);
}
var bodySystem = entityManager.System<BodySystem>();
var legs = bodySystem.GetBodyChildrenOfType(body.Owner, BodyPartType.Leg, body);
var legs = bodySystem.GetBodyChildrenOfType(human, BodyPartType.Leg, body);
// Break our guy's kneecaps
foreach (var leg in legs)
@@ -280,12 +321,12 @@ namespace Content.IntegrationTests.Tests.Buckle
await server.WaitAssertion(() =>
{
// Still buckled
Assert.True(buckle.Buckled);
Assert.That(buckle.Buckled);
// Now with no item in any hand
foreach (var hand in hands.Hands.Values)
{
Assert.Null(hand.HeldEntity);
Assert.That(hand.HeldEntity, Is.Null);
}
buckleSystem.TryUnbuckle(human, human, true, buckleComp: buckle);
@@ -298,13 +339,17 @@ namespace Content.IntegrationTests.Tests.Buckle
public async Task ForceUnbuckleBuckleTest()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
{NoClient = true, ExtraPrototypes = Prototypes});
{
NoClient = true,
ExtraPrototypes = Prototypes
});
var server = pairTracker.Pair.Server;
var testMap = await PoolManager.CreateTestMap(pairTracker);
var coordinates = testMap.GridCoords;
var entityManager = server.ResolveDependency<IEntityManager>();
var buckleSystem = entityManager.System<SharedBuckleSystem>();
var xformSystem = entityManager.System<SharedTransformSystem>();
EntityUid human = default;
EntityUid chair = default;
@@ -316,31 +361,44 @@ namespace Content.IntegrationTests.Tests.Buckle
chair = entityManager.SpawnEntity(StrapDummyId, coordinates);
// Component sanity check
Assert.True(entityManager.TryGetComponent(human, out buckle));
Assert.True(entityManager.HasComponent<StrapComponent>(chair));
Assert.Multiple(() =>
{
Assert.That(entityManager.TryGetComponent(human, out buckle));
Assert.That(entityManager.HasComponent<StrapComponent>(chair));
});
// Buckle
Assert.True(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
Assert.NotNull(buckle.BuckledTo);
Assert.True(buckle.Buckled);
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
Assert.Multiple(() =>
{
Assert.That(buckle.BuckledTo, Is.Not.Null);
Assert.That(buckle.Buckled);
});
// Move the buckled entity away
entityManager.GetComponent<TransformComponent>(human).WorldPosition += (100, 0);
var xformQuery = entityManager.GetEntityQuery<TransformComponent>();
var oldWorldPosition = xformSystem.GetWorldPosition(chair, xformQuery);
xformSystem.SetWorldPosition(human, oldWorldPosition + (100, 0), xformQuery);
});
await PoolManager.WaitUntil(server, () => !buckle.Buckled, 10);
Assert.False(buckle.Buckled);
Assert.That(buckle.Buckled, Is.False);
await server.WaitAssertion(() =>
{
// Move the now unbuckled entity back onto the chair
entityManager.GetComponent<TransformComponent>(human).WorldPosition -= (100, 0);
var xformQuery = entityManager.GetEntityQuery<TransformComponent>();
var oldWorldPosition = xformSystem.GetWorldPosition(chair, xformQuery);
xformSystem.SetWorldPosition(human, oldWorldPosition, xformQuery);
// Buckle
Assert.True(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
Assert.NotNull(buckle.BuckledTo);
Assert.True(buckle.Buckled);
Assert.That(buckleSystem.TryBuckle(human, human, chair, buckleComp: buckle));
Assert.Multiple(() =>
{
Assert.That(buckle.BuckledTo, Is.Not.Null);
Assert.That(buckle.Buckled);
});
});
await server.WaitRunTicks(60);
@@ -348,8 +406,11 @@ namespace Content.IntegrationTests.Tests.Buckle
await server.WaitAssertion(() =>
{
// Still buckled
Assert.NotNull(buckle.BuckledTo);
Assert.True(buckle.Buckled);
Assert.Multiple(() =>
{
Assert.That(buckle.BuckledTo, Is.Not.Null);
Assert.That(buckle.Buckled);
});
});
await pairTracker.CleanReturnAsync();
}