@@ -39,7 +39,6 @@ const std::string OUTPUT_RECIPE = "resources/rtde_output_recipe.txt";
3939const std::string INPUT_RECIPE = " resources/rtde_input_recipe.txt" ;
4040std::string g_ROBOT_IP = " 192.168.56.101" ;
4141bool g_HEADLESS = true ;
42- char g_modified_script[] = " urscript.XXXXXX" ;
4342
4443std::unique_ptr<ExampleRobotWrapper> g_my_robot;
4544
@@ -58,40 +57,42 @@ class ExternalControlProgramTest : public ::testing::Test
5857protected:
5958 void SetUp () override
6059 {
61- extendScript ();
62- std::string script_file = " ../resources/external_control.urscript" ;
60+ std::string modified_script_path = extendScript (SCRIPT_FILE );
6361
6462 g_my_robot = std::make_unique<ExampleRobotWrapper>(g_ROBOT_IP, OUTPUT_RECIPE , INPUT_RECIPE , g_HEADLESS,
65- " external_control.urp" , g_modified_script );
63+ " external_control.urp" , modified_script_path );
6664 if (!g_my_robot->isHealthy ())
6765 {
6866 ASSERT_TRUE (g_my_robot->resendRobotProgram ());
6967 ASSERT_TRUE (g_my_robot->waitForProgramRunning (500 ));
7068 }
7169 }
7270
73- void extendScript ()
71+ std::string extendScript (const std::string& script_path )
7472 {
73+ char modified_script_path[] = " urscript.XXXXXX" ;
7574#ifdef _WIN32
7675# define mkstemp _mktemp_s
7776#endif
78- std::ignore = mkstemp (g_modified_script );
77+ std::ignore = mkstemp (modified_script_path );
7978
80- std::ofstream ofs (g_modified_script );
79+ std::ofstream ofs (modified_script_path );
8180 if (ofs.bad ())
8281 {
8382 std::cout << " Failed to create temporary files" << std::endl;
84- GTEST_FAIL ( );
83+ throw std::runtime_error ( " Failed to create temporary files " );
8584 }
86- std::ifstream in_file (SCRIPT_FILE );
85+ std::ifstream in_file (script_path );
8786 std::string prog ((std::istreambuf_iterator<char >(in_file)), (std::istreambuf_iterator<char >()));
8887 prog += " \n socket_open(\" {{SERVER_IP_REPLACE}}\" , 60005, \" test_socket\" )\n " ;
8988 prog += " \n sleep(0.6)\n " ;
9089 prog += " \n textmsg(\" sleeping done.\" )\n " ;
9190 std::ofstream out_file;
92- out_file.open (g_modified_script );
91+ out_file.open (modified_script_path );
9392 out_file << prog;
9493 out_file.close ();
94+
95+ return modified_script_path;
9596 }
9697
9798 bool waitForConnectionCallback (int milliseconds = 100 )
@@ -146,13 +147,13 @@ int main(int argc, char* argv[])
146147 if (std::string (argv[i]) == " --robot_ip" && i + 1 < argc)
147148 {
148149 g_ROBOT_IP = argv[i + 1 ];
149- break ;
150+ ++i ;
150151 }
151152 if (std::string (argv[i]) == " --headless" && i + 1 < argc)
152153 {
153154 std::string headless = argv[i + 1 ];
154155 g_HEADLESS = headless == " true" || headless == " 1" || headless == " True" || headless == " TRUE" ;
155- break ;
156+ ++i ;
156157 }
157158 }
158159
0 commit comments