test: Correctly decode UTF-8 literal string paths

Call fs::u8path to convert some UTF-8 string literals to paths, instead
of relying on implicit conversions. The implicit conversions incorrectly
decode const char* paths using the current windows codepage, instead of
treating them as UTF-8. This could cause test failures depending what
environment windows tests are run in.

Issue was reported by MarcoFalke <falke.marco@gmail.com> in
https://github.com/bitcoin/bitcoin/pull/24306#discussion_r818566106
This commit is contained in:
Ryan Ofsky 2022-03-03 14:12:07 -05:00
parent 08bcfa2767
commit 2f5fd3cf92

View file

@ -46,8 +46,8 @@ BOOST_AUTO_TEST_CASE(fsbridge_fstream)
{
fs::path tmpfolder = m_args.GetDataDirBase();
// tmpfile1 should be the same as tmpfile2
fs::path tmpfile1 = tmpfolder / "fs_tests_₿_🏃";
fs::path tmpfile2 = tmpfolder / "fs_tests_₿_🏃";
fs::path tmpfile1 = tmpfolder / fs::u8path("fs_tests_₿_🏃");
fs::path tmpfile2 = tmpfolder / fs::u8path("fs_tests_₿_🏃");
{
std::ofstream file{tmpfile1};
file << "bitcoin";
@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(fsbridge_fstream)
}
{
// Join an absolute path and a relative path.
fs::path p = fsbridge::AbsPathJoin(tmpfolder, "fs_tests_₿_🏃");
fs::path p = fsbridge::AbsPathJoin(tmpfolder, fs::u8path("fs_tests_₿_🏃"));
BOOST_CHECK(p.is_absolute());
BOOST_CHECK_EQUAL(tmpfile1, p);
}