Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(902)

Side by Side Diff: base/i18n/number_formatting_unittest.cc

Issue 656033009: Convert ARRAYSIZE_UNSAFE -> arraysize in base/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/i18n/icu_string_conversions_unittest.cc ('k') | base/i18n/rtl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <limits> 5 #include <limits>
6 6
7 #include "base/i18n/number_formatting.h" 7 #include "base/i18n/number_formatting.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace base { 12 namespace base {
13 namespace { 13 namespace {
14 14
15 TEST(NumberFormattingTest, FormatNumber) { 15 TEST(NumberFormattingTest, FormatNumber) {
16 static const struct { 16 static const struct {
17 int64 number; 17 int64 number;
18 const char* expected_english; 18 const char* expected_english;
19 const char* expected_german; 19 const char* expected_german;
20 } cases[] = { 20 } cases[] = {
21 {0, "0", "0"}, 21 {0, "0", "0"},
22 {1024, "1,024", "1.024"}, 22 {1024, "1,024", "1.024"},
23 {std::numeric_limits<int64>::max(), 23 {std::numeric_limits<int64>::max(),
24 "9,223,372,036,854,775,807", "9.223.372.036.854.775.807"}, 24 "9,223,372,036,854,775,807", "9.223.372.036.854.775.807"},
25 {std::numeric_limits<int64>::min(), 25 {std::numeric_limits<int64>::min(),
26 "-9,223,372,036,854,775,808", "-9.223.372.036.854.775.808"}, 26 "-9,223,372,036,854,775,808", "-9.223.372.036.854.775.808"},
27 {-42, "-42", "-42"}, 27 {-42, "-42", "-42"},
28 }; 28 };
29 29
30 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 30 for (size_t i = 0; i < arraysize(cases); ++i) {
31 i18n::SetICUDefaultLocale("en"); 31 i18n::SetICUDefaultLocale("en");
32 testing::ResetFormatters(); 32 testing::ResetFormatters();
33 EXPECT_EQ(cases[i].expected_english, 33 EXPECT_EQ(cases[i].expected_english,
34 UTF16ToUTF8(FormatNumber(cases[i].number))); 34 UTF16ToUTF8(FormatNumber(cases[i].number)));
35 i18n::SetICUDefaultLocale("de"); 35 i18n::SetICUDefaultLocale("de");
36 testing::ResetFormatters(); 36 testing::ResetFormatters();
37 EXPECT_EQ(cases[i].expected_german, 37 EXPECT_EQ(cases[i].expected_german,
38 UTF16ToUTF8(FormatNumber(cases[i].number))); 38 UTF16ToUTF8(FormatNumber(cases[i].number)));
39 } 39 }
40 } 40 }
(...skipping 24 matching lines...) Expand all
65 "000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000." 65 "000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000."
66 "000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000." 66 "000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000."
67 "000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000." 67 "000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000."
68 "000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000." 68 "000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000."
69 "000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000." 69 "000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000."
70 "000,000000"}, 70 "000,000000"},
71 {std::numeric_limits<double>::min(), 2, "0.00", "0,00"}, 71 {std::numeric_limits<double>::min(), 2, "0.00", "0,00"},
72 {-42.7, 3, "-42.700", "-42,700"}, 72 {-42.7, 3, "-42.700", "-42,700"},
73 }; 73 };
74 74
75 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 75 for (size_t i = 0; i < arraysize(cases); ++i) {
76 i18n::SetICUDefaultLocale("en"); 76 i18n::SetICUDefaultLocale("en");
77 testing::ResetFormatters(); 77 testing::ResetFormatters();
78 EXPECT_EQ(cases[i].expected_english, 78 EXPECT_EQ(cases[i].expected_english,
79 UTF16ToUTF8(FormatDouble(cases[i].number, cases[i].frac_digits))); 79 UTF16ToUTF8(FormatDouble(cases[i].number, cases[i].frac_digits)));
80 i18n::SetICUDefaultLocale("de"); 80 i18n::SetICUDefaultLocale("de");
81 testing::ResetFormatters(); 81 testing::ResetFormatters();
82 EXPECT_EQ(cases[i].expected_german, 82 EXPECT_EQ(cases[i].expected_german,
83 UTF16ToUTF8(FormatDouble(cases[i].number, cases[i].frac_digits))); 83 UTF16ToUTF8(FormatDouble(cases[i].number, cases[i].frac_digits)));
84 } 84 }
85 } 85 }
86 86
87 } // namespace 87 } // namespace
88 } // namespace base 88 } // namespace base
OLDNEW
« no previous file with comments | « base/i18n/icu_string_conversions_unittest.cc ('k') | base/i18n/rtl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698