1// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#import <Foundation/Foundation.h>
6#include <stddef.h>
7
8#include "base/stl_util.h"
9#include "base/strings/sys_string_conversions.h"
10#include "testing/gtest/include/gtest/gtest.h"
11#include "testing/platform_test.h"
12#include "ui/base/l10n/l10n_util_mac.h"
13
14typedef PlatformTest L10nUtilMacTest;
15
16TEST_F(L10nUtilMacTest, FixUpWindowsStyleLabel) {
17  struct TestData {
18    NSString* input;
19    NSString* output;
20  };
21
22  TestData data[] = {
23    { @"", @"" },
24    { @"nothing", @"nothing" },
25    { @"foo &bar", @"foo bar" },
26    { @"foo &&bar", @"foo &bar" },
27    { @"foo &&&bar", @"foo &bar" },
28    { @"&foo &&bar", @"foo &bar" },
29    { @"&foo &bar", @"foo bar" },
30    { @"foo bar.", @"foo bar." },
31    { @"foo bar..", @"foo bar.." },
32    { @"foo bar...", @"foo bar\u2026" },
33    { @"foo.bar", @"foo.bar" },
34    { @"foo..bar", @"foo..bar" },
35    { @"foo...bar", @"foo\u2026bar" },
36    { @"foo...bar...", @"foo\u2026bar\u2026" },
37    { @"foo(&b)", @"foo" },
38    { @"foo(&b)...", @"foo\u2026" },
39    { @"(&b)foo", @"foo" },
40  };
41  for (size_t idx = 0; idx < base::size(data); ++idx) {
42    base::string16 input16(base::SysNSStringToUTF16(data[idx].input));
43
44    NSString* result = l10n_util::FixUpWindowsStyleLabel(input16);
45    EXPECT_TRUE(result != nil) << "Fixup Failed, idx = " << idx;
46
47    EXPECT_TRUE([data[idx].output isEqual:result])
48        << "For idx " << idx << ", expected '" << [data[idx].output UTF8String]
49        << "', got '" << [result UTF8String] << "'";
50  }
51}
52
53TEST_F(L10nUtilMacTest, GetDisplayNameForLocale) {
54  // Test documented error cases and return values of GetDisplayNameForLocale.
55  base::string16 result = l10n_util::GetDisplayNameForLocale("xyz", "en");
56  EXPECT_EQ(base::SysNSStringToUTF16(@"xyz"), result);
57
58  result = l10n_util::GetDisplayNameForLocale("Xyz", "en");
59  EXPECT_EQ(base::SysNSStringToUTF16(@"xyz"), result);
60
61  result = l10n_util::GetDisplayNameForLocale("Xyz-Xyz", "en");
62  EXPECT_EQ(base::SysNSStringToUTF16(@"xyz (XYZ)"), result);
63
64  result = l10n_util::GetDisplayNameForLocale("Xyz-", "en");
65  EXPECT_EQ(base::SysNSStringToUTF16(@"xyz"), result);
66
67  result = l10n_util::GetDisplayNameForLocale("xyz-xyz-xyz", "en");
68  EXPECT_EQ(base::SysNSStringToUTF16(@"xyz-xyz (XYZ)"), result);
69
70  result = l10n_util::GetDisplayNameForLocale("", "en");
71  EXPECT_EQ(base::SysNSStringToUTF16(@""), result);
72}
73