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

Method RunTest

Source/URLabEditor/Private/Tests/MjStepServerTests.cpp:61–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59IMPLEMENT_SIMPLE_AUTOMATION_TEST(FMjStepServerNoManagerGuard,
60 "URLab.StepServer.NoManagerGuard",
61 EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter)
62
63bool FMjStepServerNoManagerGuard::RunTest(const FString& Parameters)
64{
65 UURLabBridgeServer* Server = NewObject<UURLabBridgeServer>();
66 Server->AddToRoot();
67 Server->Start(TEXT("")); // skip ZMQ bind — test only exercises Dispatch()
68 FURLabRpcDispatcher* Disp = Server->GetDispatcher();
69 if (!Disp)
70 {
71 AddError(TEXT("Server has no dispatcher"));
72 Server->RemoveFromRoot();
73 return false;
74 }
75
76 // Plant a session id so subsequent ops reach the manager guard rather
77 // than the session check.
78 Disp->SetActiveSessionIdForTest(TEXT("test-session"));
79
80 // The dispatcher validates RequiredFields BEFORE the manager guard
81 // so malformed requests fail with `missing_field` regardless of PIE
82 // state. To exercise the no-manager path, the request has to be
83 // otherwise well-formed — supply the required fields per op when
84 // probing.
85 auto MakeReq = [](const FString& Op) -> TSharedPtr<FJsonObject> {
86 TSharedPtr<FJsonObject> R = MakeShared<FJsonObject>();
87 R->SetStringField(TEXT("op"), Op);
88 R->SetStringField(TEXT("session_id"), TEXT("test-session"));
89 // Declarative-required fields per op.
90 if (Op == TEXT("set_paused"))
91 R->SetBoolField(TEXT("paused"), true);
92 if (Op == TEXT("set_sim_speed"))
93 R->SetNumberField(TEXT("percent"), 100.0);
94 if (Op == TEXT("configure_controller"))
95 {
96 R->SetStringField(TEXT("articulation"), TEXT("ignored"));
97 R->SetObjectField(TEXT("params"), MakeShared<FJsonObject>());
98 }
99 if (Op == TEXT("set_qpos"))
100 {
101 R->SetStringField(TEXT("target"), TEXT("ignored"));
102 TArray<TSharedPtr<FJsonValue>> EmptyQpos;
103 R->SetArrayField(TEXT("qpos"), EmptyQpos);
104 }
105 if (Op == TEXT("set_mocap_pose") || Op == TEXT("read_mocap_pose"))
106 {
107 R->SetStringField(TEXT("body"), TEXT("ignored"));
108 }
109 return R;
110 };
111
112 auto AssertNoManager = [this, Disp, &MakeReq](const FString& Op) {
113 TSharedPtr<FJsonObject> Reply = Disp->Dispatch(MakeReq(Op));
114 FString Code;
115 Reply->TryGetStringField(TEXT("code"), Code);
116 TestEqual(*FString::Printf(TEXT("op %s -> no_active_manager"), *Op),
117 Code, FString(TEXT("no_active_manager")));
118 };

Callers

nothing calls this directly

Calls 15

RegisterHandlerFunction · 0.85
UnregisterHandlerFunction · 0.85
StartMethod · 0.80
DispatchMethod · 0.80
SetActiveStepModeMethod · 0.80
GetConfigSchemaMethod · 0.80
ApplyConfigMethod · 0.80
GetCurrentConfigMethod · 0.80
GetModelMethod · 0.80
GetDataMethod · 0.80
GetActuatorsMethod · 0.80

Tested by

no test coverage detected