3232
3333#include < gtest/gtest.h>
3434#include " ur_client_library/control/script_reader.h"
35+ #include " ur_client_library/ur/version_information.h"
3536
3637#include < fstream>
3738
@@ -165,6 +166,7 @@ TEST_F(ScriptReaderTest, ReplaceVariables)
165166 // By default std::to_string will convert double to 6 decimal places
166167 EXPECT_EQ (script, " movej([value1, 42, 6.280000, 0, 0, 0])\n local is_true = True\n local is_false = False\n This is "
167168 " just a line without any replacement" );
169+ std::remove (existing_script_file);
168170}
169171
170172TEST_F (ScriptReaderTest, VariableNotInDictThrowsError)
@@ -186,6 +188,7 @@ TEST_F(ScriptReaderTest, VariableNotInDictThrowsError)
186188 ofs.close ();
187189
188190 EXPECT_THROW (reader.readScriptFile (existing_script_file, data), urcl::UnknownVariable);
191+ std::remove (existing_script_file);
189192}
190193
191194TEST_F (ScriptReaderTest, ReplaceConditionals)
@@ -235,6 +238,7 @@ Please log in.
235238 data[" is_guest" ] = false ;
236239 script = reader.readScriptFile (existing_script_file, data);
237240 EXPECT_EQ (script, " Please log in." );
241+ std::remove (existing_script_file);
238242}
239243
240244TEST_F (ScriptReaderTest, CheckCondition)
@@ -323,25 +327,6 @@ TEST_F(ScriptReaderTest, CheckCondition)
323327 EXPECT_THROW (reader.evaluateExpression (" X >= True" , data), std::invalid_argument);
324328}
325329
326- TEST_F (ScriptReaderTest, ParseBoolean)
327- {
328- EXPECT_TRUE (ScriptReader::parseBoolean (" true" ));
329- EXPECT_TRUE (ScriptReader::parseBoolean (" True" ));
330- EXPECT_TRUE (ScriptReader::parseBoolean (" TRUE" ));
331- EXPECT_TRUE (ScriptReader::parseBoolean (" on" ));
332- EXPECT_TRUE (ScriptReader::parseBoolean (" On" ));
333- EXPECT_TRUE (ScriptReader::parseBoolean (" ON" ));
334- EXPECT_TRUE (ScriptReader::parseBoolean (" 1" ));
335- EXPECT_FALSE (ScriptReader::parseBoolean (" false" ));
336- EXPECT_FALSE (ScriptReader::parseBoolean (" False" ));
337- EXPECT_FALSE (ScriptReader::parseBoolean (" FALSE" ));
338- EXPECT_FALSE (ScriptReader::parseBoolean (" off" ));
339- EXPECT_FALSE (ScriptReader::parseBoolean (" Off" ));
340- EXPECT_FALSE (ScriptReader::parseBoolean (" OFF" ));
341- EXPECT_FALSE (ScriptReader::parseBoolean (" 0" ));
342- EXPECT_THROW (ScriptReader::parseBoolean (" notabool" ), urcl::UrException);
343- }
344-
345330TEST_F (ScriptReaderTest, DataVariantOperators)
346331{
347332 ScriptReader::DataDict data;
@@ -403,49 +388,21 @@ TEST_F(ScriptReaderTest, DataVariantOperators)
403388 EXPECT_THROW (data[" double1" ] == data[" str1" ], std::invalid_argument);
404389}
405390
406- TEST_F (ScriptReaderTest, ConditionalInclude )
391+ TEST_F (ScriptReaderTest, Example )
407392{
408393 ScriptReader reader;
409-
410- char existing_script_file[] = " main_script.XXXXXX" ;
411- std::ignore = mkstemp (existing_script_file);
412- char existing_include_file[] = " included_script.XXXXXX" ;
413- std::ignore = mkstemp (existing_include_file);
414- std::ofstream ofs (existing_script_file);
415- if (ofs.bad ())
416- {
417- std::cout << " Failed to create temporary files" << std::endl;
418- GTEST_FAIL ();
419- }
420- ofs << " textmsg(\" This is a test script\" )" << std::endl;
421- ofs << " {% if ROBOT_VERSION > 10.7 %}" << std::endl;
422- ofs << " {% include '" << std::string (existing_include_file) << " ' %}" << std::endl;
423- ofs << " {% endif %}" << std::endl;
424- ofs.close ();
425-
426- // Create a temporary included script
427- std::ofstream ofs_included (existing_include_file);
428- if (ofs_included.bad ())
429- {
430- std::cout << " Failed to create temporary files" << std::endl;
431- GTEST_FAIL ();
432- }
433- ofs_included << " movej([1,2,3,4,5,6])" ;
434- ofs_included.close ();
394+ std::string existing_script_file = " resources/example_urscript_main.urscript" ;
435395
436396 ScriptReader::DataDict data;
437- data[" ROBOT_VERSION" ] = 10.8 ; // Set a version greater than 10.7 to include the script
397+ data[" SOFTWARE_VERSION" ] = urcl::VersionInformation::fromString (" 5.9" );
398+ data[" feature_name" ] = " torque control" ;
438399
439400 std::string processed_script = reader.readScriptFile (existing_script_file, data);
440- std::string expected_script = " textmsg(\" This is a test script\" )\n "
441- " movej([1,2,3,4,5,6])" ;
401+ std::string expected_script = " popup(\" The cool new feature is not supported on Software version 5.23.0\" )" ;
442402 EXPECT_EQ (processed_script, expected_script);
443403
444- data[" ROBOT_VERSION " ] = 10.6 ;
404+ data[" SOFTWARE_VERSION " ] = urcl::VersionInformation::fromString ( " 5.23.0 " ) ;
445405 processed_script = reader.readScriptFile (existing_script_file, data);
446- expected_script = " textmsg(\" This is a test script \" )" ;
406+ expected_script = " textmsg(\" torque control is a very cool feature! \" )" ;
447407 EXPECT_EQ (processed_script, expected_script);
448-
449- std::remove (existing_script_file);
450- std::remove (existing_include_file);
451408}
0 commit comments