MCPcopy Create free account
hub / github.com/URLab-Sim/UnrealRoboticsLab / RunTest

Method RunTest

Source/URLabEditor/Private/Tests/MjBindingTest.cpp:39–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37IMPLEMENT_SIMPLE_AUTOMATION_TEST(FMjBindingIntegrationTest, "URLab.MuJoCo.Binding.Integration", EAutomationTestFlags::EditorContext | EAutomationTestFlags::ProductFilter)
38
39bool FMjBindingIntegrationTest::RunTest(const FString& Parameters)
40{
41 // 1. Create a Temporary World
42 UWorld* World = UWorld::CreateWorld(EWorldType::Game, false);
43 if (!World)
44 {
45 AddError(TEXT("Failed to create temporary world."));
46 return false;
47 }
48 FWorldContext& WorldContext = GEngine->CreateNewWorldContext(EWorldType::Game);
49 WorldContext.SetCurrentWorld(World);
50
51 // 2. Spawn Articulation (Robot)
52 FActorSpawnParameters SpawnParams;
53 AMjArticulation* Robot = World->SpawnActor<AMjArticulation>(SpawnParams);
54 if (!Robot)
55 {
56 AddError(TEXT("Failed to spawn AMjArticulation."));
57 World->DestroyWorld(false);
58 GEngine->DestroyWorldContext(World);
59 return false;
60 }
61
62 // 3. Construct Component Hierarchy: WorldBody -> Body -> { Geom, Joint }
63 // AMjArticulation::Setup() requires a UMjWorldBody as root, with UMjBody children.
64 UMjWorldBody* WorldBody = NewObject<UMjWorldBody>(Robot, TEXT("WorldBody"));
65 Robot->SetRootComponent(WorldBody);
66 WorldBody->RegisterComponent();
67
68 UMjBody* RootBody = NewObject<UMjBody>(Robot, TEXT("RootBody"));
69 RootBody->RegisterComponent();
70 RootBody->AttachToComponent(WorldBody, FAttachmentTransformRules::KeepRelativeTransform);
71
72 UMjGeom* Geom = NewObject<UMjGeom>(Robot, TEXT("TestGeom"));
73 Geom->size = {0.1f, 0.1f, 0.1f}; // Sphere radius 0.1m — must be non-zero for MuJoCo to accept
74 Geom->bOverride_size = true; // ExportTo only writes size when this is true
75 Geom->RegisterComponent();
76 Geom->AttachToComponent(RootBody, FAttachmentTransformRules::KeepRelativeTransform);
77
78 UMjJoint* Joint = NewObject<UMjJoint>(Robot, TEXT("TestJoint"));
79 Joint->RegisterComponent();
80 Joint->AttachToComponent(RootBody, FAttachmentTransformRules::KeepRelativeTransform);
81
82 // 4. Spawn Manager — World->BeginPlay() does not propagate AActor::BeginPlay()
83 // without a GameMode, so we drive compilation directly.
84 AAMjManager* Manager = World->SpawnActor<AAMjManager>(SpawnParams);
85 if (!Manager)
86 {
87 AddError(TEXT("Failed to spawn AAMjManager."));
88 World->DestroyWorld(false);
89 GEngine->DestroyWorldContext(World);
90 return false;
91 }
92
93 // 5. Drive compilation directly — bypasses the BeginPlay dispatch issue in test worlds
94 Manager->Compile();
95
96 // 6. Verify Manager State

Callers

nothing calls this directly

Calls 3

CompileMethod · 0.45
IsInitializedMethod · 0.45
SetFrictionMethod · 0.45

Tested by

no test coverage detected