diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2021-12-21 17:53:52 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-12-21 17:54:09 +0300 |
commit | 8cf19944557452ae7a9c1cb2365d6121f2dfdb4d (patch) | |
tree | 5e72acf407ba4734c8a0b3f72f6b38f8b04839b4 /source/blender/blenlib/tests | |
parent | d66a6525c361d93de2f7878bad27cd78dff2ecfd (diff) |
Fix T93960: Asset Catalogs I/O fails with unicode file paths on Windows
On Windows, encode file paths as UTF-16 before trying to open the file
for reading/writing.
This introduces a new class `blender::fstream`, which wraps
`std::fstream` and provides this UTF-16 encoding. This class should also
be used in other areas, like the Alembic importer/exporter.
Manifest Task: T93960
Reviewed By: JacquesLucke
Differential Revision: https://developer.blender.org/D13633
Diffstat (limited to 'source/blender/blenlib/tests')
-rw-r--r-- | source/blender/blenlib/tests/BLI_fileops_test.cc | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/source/blender/blenlib/tests/BLI_fileops_test.cc b/source/blender/blenlib/tests/BLI_fileops_test.cc new file mode 100644 index 00000000000..e2a792647dc --- /dev/null +++ b/source/blender/blenlib/tests/BLI_fileops_test.cc @@ -0,0 +1,40 @@ +/* Apache License, Version 2.0 */ + +#include "BLI_fileops.hh" + +#include "testing/testing.h" + +namespace blender::tests { + +TEST(fileops, fstream_open_string_filename) +{ + const std::string test_files_dir = blender::tests::flags_test_asset_dir(); + if (test_files_dir.empty()) { + FAIL(); + } + + const std::string filepath = test_files_dir + "/asset_library/новый/blender_assets.cats.txt"; + fstream in(filepath, std::ios_base::in); + ASSERT_TRUE(in.is_open()) << "could not open " << filepath; + in.close(); /* This should not crash. */ + + /* Reading the file not tested here. That's deferred to `std::fstream` anyway. */ +} + +TEST(fileops, fstream_open_charptr_filename) +{ + const std::string test_files_dir = blender::tests::flags_test_asset_dir(); + if (test_files_dir.empty()) { + FAIL(); + } + + const std::string filepath_str = test_files_dir + "/asset_library/новый/blender_assets.cats.txt"; + const char *filepath = filepath_str.c_str(); + fstream in(filepath, std::ios_base::in); + ASSERT_TRUE(in.is_open()) << "could not open " << filepath; + in.close(); /* This should not crash. */ + + /* Reading the file not tested here. That's deferred to `std::fstream` anyway. */ +} + +} // namespace blender::tests |