Skip to content

Commit dc01cbc

Browse files
hebastovasild
andcommitted
test: Add fs_tests/rename unit test
Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
1 parent d4999d4 commit dc01cbc

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/test/fs_tests.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,38 @@ BOOST_AUTO_TEST_CASE(fsbridge_fstream)
118118
}
119119
}
120120

121-
BOOST_AUTO_TEST_SUITE_END()
121+
BOOST_AUTO_TEST_CASE(rename)
122+
{
123+
const fs::path tmpfolder{m_args.GetDataDirBase()};
124+
125+
const fs::path path1{GetUniquePath(tmpfolder)};
126+
const fs::path path2{GetUniquePath(tmpfolder)};
127+
128+
const std::string path1_contents{"1111"};
129+
const std::string path2_contents{"2222"};
130+
131+
{
132+
std::ofstream file{path1};
133+
file << path1_contents;
134+
}
135+
136+
{
137+
std::ofstream file{path2};
138+
file << path2_contents;
139+
}
140+
141+
// Rename path1 -> path2.
142+
BOOST_CHECK(RenameOver(path1, path2));
143+
144+
BOOST_CHECK(!fs::exists(path1));
145+
146+
{
147+
std::ifstream file{path2};
148+
std::string contents;
149+
file >> contents;
150+
BOOST_CHECK_EQUAL(contents, path1_contents);
151+
}
152+
fs::remove(path2);
153+
}
154+
155+
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)