3333
3434#include < fstream>
3535
36+ #ifdef _WIN32
37+ # define mkstemp _mktemp_s
38+ #endif
39+
3640using namespace urcl ::control;
3741
3842class ScriptReaderTest : public ::testing::Test
@@ -51,9 +55,6 @@ class ScriptReaderTest : public ::testing::Test
5155 invalid_script_path_ = " test_resources/non_existent_script.urscript" ;
5256 empty_script_path_ = " resources/empty.txt" ;
5357 char existing_script_file[] = " urscript.XXXXXX" ;
54- #ifdef _WIN32
55- # define mkstemp _mktemp_s
56- #endif
5758 std::ignore = mkstemp (existing_script_file);
5859 std::ofstream ofs (existing_script_file);
5960 if (ofs.bad ())
@@ -65,7 +66,7 @@ class ScriptReaderTest : public ::testing::Test
6566
6667 valid_script_path_ = existing_script_file;
6768
68- simple_script_ << " movej([0,0,0,0,0,0])" ;
69+ simple_script_ << " movej([0,0,0,0,0,0])\n " ;
6970
7071 // Create test resources
7172 std::ofstream valid_script (valid_script_path_);
@@ -89,7 +90,7 @@ TEST_F(ScriptReaderTest, ReadValidScript)
8990{
9091 ScriptReader reader (robot_info_);
9192 std::string content = reader.readScriptFile (valid_script_path_);
92- EXPECT_EQ (content, " movej([0,0,0,0,0,0]) " );
93+ EXPECT_EQ (content, simple_script_. str () );
9394}
9495
9596TEST_F (ScriptReaderTest, ReadEmptyScript)
@@ -103,4 +104,39 @@ TEST_F(ScriptReaderTest, ReadNonExistentScript)
103104{
104105 ScriptReader reader (robot_info_);
105106 EXPECT_THROW (reader.readScriptFile (invalid_script_path_), std::runtime_error);
106- }
107+ }
108+
109+ TEST_F (ScriptReaderTest, ReplaceIncludes)
110+ {
111+ ScriptReader reader (robot_info_);
112+
113+ char existing_script_file[] = " main_script.XXXXXX" ;
114+ std::ignore = mkstemp (existing_script_file);
115+ char existing_include_file[] = " included_script.XXXXXX" ;
116+ std::ignore = mkstemp (existing_include_file);
117+ std::ofstream ofs (existing_script_file);
118+ if (ofs.bad ())
119+ {
120+ std::cout << " Failed to create temporary files" << std::endl;
121+ GTEST_FAIL ();
122+ }
123+ std::string script_with_include = " {% include '" + std::string (existing_include_file) + " ' %}" ;
124+ ofs << script_with_include;
125+ ofs.close ();
126+
127+ // Create a temporary included script
128+ std::ofstream ofs_included (existing_include_file);
129+ if (ofs_included.bad ())
130+ {
131+ std::cout << " Failed to create temporary files" << std::endl;
132+ GTEST_FAIL ();
133+ }
134+ ofs_included << " movej([1,2,3,4,5,6])" ;
135+ ofs_included.close ();
136+
137+ std::string processed_script = reader.readScriptFile (existing_script_file);
138+ EXPECT_EQ (processed_script, " movej([1,2,3,4,5,6])\n " );
139+
140+ std::remove (existing_script_file);
141+ std::remove (existing_include_file);
142+ }
0 commit comments