chromium/base/i18n/file_util_icu_unittest.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
#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 {

// file_util winds up using autoreleased objects on the Mac, so this needs
// to be a PlatformTest
class FileUtilICUTest : public PlatformTest {};

#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE)

// On linux, file path is parsed and filtered as UTF-8.
static const struct GoodBadPairLinux {} kLinuxIllegalCharacterCases[] =;

TEST_F(FileUtilICUTest, ReplaceIllegalCharactersInPathLinuxTest) {}

#endif

// For Mac & Windows, which both do Unicode validation on filenames. These
// characters are given as UTF-16 strings since its more convenient to specify
// unicode characters. For Mac they should be converted to UTF-8, for Windows to
// wide.
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

}  // namespace i18n
}  // namespace base