#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "base/i18n/file_util_icu.h"
#include <stddef.h>
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
namespace base {
namespace i18n {
class FileUtilICUTest : public PlatformTest { … };
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE)
static const struct GoodBadPairLinux { … } kLinuxIllegalCharacterCases[] = …;
TEST_F(FileUtilICUTest, ReplaceIllegalCharactersInPathLinuxTest) { … }
#endif
static const struct FileUtilICUTestCases { … } kIllegalCharacterCases[] = …;
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_POSIX)
TEST_F(FileUtilICUTest, ReplaceIllegalCharactersInPathTest) { … }
TEST_F(FileUtilICUTest, ReplaceIllegalCharactersInPathWithIllegalEndCharTest) { … }
#endif
TEST_F(FileUtilICUTest, IsFilenameLegalTest) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
static const struct normalize_name_encoding_test_cases {
const char* original_path;
const char* normalized_path;
} kNormalizeFileNameEncodingTestCases[] = {
{ "foo_na\xcc\x88me.foo", "foo_n\xc3\xa4me.foo"},
{ "foo_dir_na\xcc\x88me/foo_na\xcc\x88me.foo",
"foo_dir_na\xcc\x88me/foo_n\xc3\xa4me.foo"},
{ "", ""},
{ "foo_dir_na\xcc\x88me/", "foo_dir_n\xc3\xa4me"}
};
TEST_F(FileUtilICUTest, NormalizeFileNameEncoding) {
for (size_t i = 0; i < std::size(kNormalizeFileNameEncodingTestCases); i++) {
FilePath path(kNormalizeFileNameEncodingTestCases[i].original_path);
NormalizeFileNameEncoding(&path);
EXPECT_EQ(FilePath(kNormalizeFileNameEncodingTestCases[i].normalized_path),
path);
}
}
#endif
}
}