// Headless tests of the player on foot (DESIGN_UE.md sections 5.1, 5.2, 3.1): the body, the movement settings that make walking on a // moving hull work, the game classes registered through the core seam, the mode names. #include "Tests/DescentTestCommon.h" #include "Core/DescentGameClasses.h" #include "Core/Tuning/DescentTune_Player.h" #include "Player/DescentCharacter.h" #include "Player/DescentCharacterMovement.h" #include "Player/DescentMode.h" #include "Player/DescentPlayerController.h" #include "Camera/CameraComponent.h" #include "Components/CapsuleComponent.h" #if WITH_DEV_AUTOMATION_TESTS IMPLEMENT_SIMPLE_AUTOMATION_TEST(FDescentPlayerBodyTest, "Descent.Player.Body", DESCENT_TEST_FLAGS) bool FDescentPlayerBodyTest::RunTest(const FString& Parameters) { namespace T = Descent::Tune::Player; const ADescentCharacter* C = GetDefault(); TestEqual(TEXT("capsule radius 0.34 m"), C->GetCapsuleComponent()->GetUnscaledCapsuleRadius(), 34.f, 1e-3f); TestEqual(TEXT("capsule half height 0.90 m"), C->GetCapsuleComponent()->GetUnscaledCapsuleHalfHeight(), 90.f, 1e-3f); TestEqual(TEXT("eye 1.65 m above the feet: camera 0.75 m above the capsule centre"), C->Camera->GetRelativeLocation().Z, 75.0, 1e-3); TestEqual(TEXT("FOV 72"), C->Camera->FieldOfView, 72.f, 1e-3f); TestTrue(TEXT("the camera uses the control rotation"), C->Camera->bUsePawnControlRotation); TestTrue(TEXT("the capsule is lit by channels 0 and 1"), C->GetCapsuleComponent()->LightingChannels.bChannel0 && C->GetCapsuleComponent()->LightingChannels.bChannel1); const UDescentCharacterMovement* M = Cast(C->GetCharacterMovement()); if (!TestNotNull(TEXT("the movement component is ours"), M)) { return false; } TestEqual(TEXT("walk speed 2.9 m/s"), M->MaxWalkSpeed, static_cast(T::WalkSpeedMps * 100.0), 1e-3f); TestEqual(TEXT("step height 0.35 m"), M->MaxStepHeight, 35.f, 1e-3f); TestEqual(TEXT("walkable floor angle 50"), M->GetWalkableFloorAngle(), 50.f, 1e-3f); TestEqual(TEXT("jump 4.4 m/s"), M->JumpZVelocity, 440.f, 1e-3f); TestEqual(TEXT("gravity 11 m/s2"), M->GravityScale * 9.8f, 11.f, 0.01f); // DESIGN 3.1: what makes the character ride the moving hull TestTrue(TEXT("fast attached move"), M->bFastAttachedMove); TestTrue(TEXT("stay based in the air"), M->bStayBasedInAir); TestEqual(TEXT("stay-based height 300 uu"), M->StayBasedInAirHeight, 300.f, 1e-3f); TestTrue(TEXT("impart base velocity X Y Z"), M->bImpartBaseVelocityX && M->bImpartBaseVelocityY && M->bImpartBaseVelocityZ); TestFalse(TEXT("the character turns with the base"), M->bIgnoreBaseRotation); return true; } IMPLEMENT_SIMPLE_AUTOMATION_TEST(FDescentPlayerClassesTest, "Descent.Player.GameClasses", DESCENT_TEST_FLAGS) bool FDescentPlayerClassesTest::RunTest(const FString& Parameters) { const FDescentGameClassRegistry& Reg = FDescentGameClassRegistry::Get(); TestTrue(TEXT("the pawn slot resolves to the character"), Reg.Resolve(EDescentGameClassSlot::Pawn) == ADescentCharacter::StaticClass()); TestTrue(TEXT("the controller slot resolves to ours"), Reg.Resolve(EDescentGameClassSlot::PlayerController) == ADescentPlayerController::StaticClass()); TestEqual(TEXT("mode names"), FString(DescentModeName(EDescentMode::Title)) + DescentModeName(EDescentMode::Foot), FString(TEXT("TitleFoot"))); return true; } #endif // WITH_DEV_AUTOMATION_TESTS