Skip to content

Commit 9890ba7

Browse files
authored
Fix DashboardClient load program from subdir (#269)
When loading a program from an absolute path or a subdirectory instead of a file being directly in /programs (or /ursim/programs in the case of URSim) the check "programState" will only return the filename without the path while we compare it against the path that was requested to load. This commit only compares the actual program's filename, as the full path is already checked during the load operation.
1 parent 97ad825 commit 9890ba7

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/ur/dashboard_client.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727
//----------------------------------------------------------------------
2828

29+
#include <filesystem>
2930
#include <iostream>
3031
#include <regex>
3132
#include <thread>
@@ -246,8 +247,12 @@ bool DashboardClient::commandBrakeRelease()
246247
bool DashboardClient::commandLoadProgram(const std::string& program_file_name)
247248
{
248249
assertVersion("5.0.0", "1.4", "load <program>");
250+
// We load the program, which will fail if the program is not found or the requested file does
251+
// not contain a valid program. Afterwards, we wait until the program state is stopped with a
252+
// program named the same as the requested program. We cannot check the full file path here, but
253+
// the important thing is that the program state is stopped.
249254
return sendRequest("load " + program_file_name + "", "(?:Loading program: ).*(?:" + program_file_name + ").*") &&
250-
waitForReply("programState", "STOPPED " + program_file_name);
255+
waitForReply("programState", "STOPPED " + std::filesystem::path{ program_file_name }.filename().string());
251256
}
252257

253258
bool DashboardClient::commandLoadInstallation(const std::string& installation_file_name)

tests/test_dashboard_client.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ TEST_F(DashboardClientTest, connecting_twice_returns_false)
242242
EXPECT_FALSE(dashboard_client_->connect());
243243
}
244244

245+
TEST_F(DashboardClientTest, load_program_in_subdir_works)
246+
{
247+
ASSERT_TRUE(dashboard_client_->connect());
248+
249+
ASSERT_TRUE(dashboard_client_->commandLoadProgram("/ursim/programs/wait_program.urp"));
250+
}
251+
245252
int main(int argc, char* argv[])
246253
{
247254
::testing::InitGoogleTest(&argc, argv);

0 commit comments

Comments
 (0)