| OLD | NEW |
| 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/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "unicode/locid.h" | 10 #include "unicode/locid.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } | 48 } |
| 49 | 49 |
| 50 TEST(NumberFormattingTest, FormatDouble) { | 50 TEST(NumberFormattingTest, FormatDouble) { |
| 51 static const struct { | 51 static const struct { |
| 52 double number; | 52 double number; |
| 53 int frac_digits; | 53 int frac_digits; |
| 54 const char* expected_english; | 54 const char* expected_english; |
| 55 const char* expected_german; | 55 const char* expected_german; |
| 56 } cases[] = { | 56 } cases[] = { |
| 57 {0.0, 0, "0", "0"}, | 57 {0.0, 0, "0", "0"}, |
| 58 #if !defined(OS_ANDROID) |
| 59 // Bionic can't printf negative zero correctly. |
| 58 {-0.0, 4, "-0.0000", "-0,0000"}, | 60 {-0.0, 4, "-0.0000", "-0,0000"}, |
| 61 #endif |
| 59 {1024.2, 0, "1,024", "1.024"}, | 62 {1024.2, 0, "1,024", "1.024"}, |
| 60 {-1024.223, 2, "-1,024.22", "-1.024,22"}, | 63 {-1024.223, 2, "-1,024.22", "-1.024,22"}, |
| 61 {std::numeric_limits<double>::max(), 6, | 64 {std::numeric_limits<double>::max(), 6, |
| 62 "179,769,313,486,232,000,000,000,000,000,000,000,000,000,000,000,000," | 65 "179,769,313,486,232,000,000,000,000,000,000,000,000,000,000,000,000," |
| 63 "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," |
| 64 "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," |
| 65 "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," |
| 66 "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," |
| 67 "000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000," | 70 "000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000," |
| 68 "000.000000", | 71 "000.000000", |
| (...skipping 14 matching lines...) Expand all Loading... |
| 83 EXPECT_EQ(cases[i].expected_english, | 86 EXPECT_EQ(cases[i].expected_english, |
| 84 UTF16ToUTF8(base::FormatDouble(cases[i].number, | 87 UTF16ToUTF8(base::FormatDouble(cases[i].number, |
| 85 cases[i].frac_digits))); | 88 cases[i].frac_digits))); |
| 86 SetICUDefaultLocale("de"); | 89 SetICUDefaultLocale("de"); |
| 87 base::testing::ResetFormatters(); | 90 base::testing::ResetFormatters(); |
| 88 EXPECT_EQ(cases[i].expected_german, | 91 EXPECT_EQ(cases[i].expected_german, |
| 89 UTF16ToUTF8(base::FormatDouble(cases[i].number, | 92 UTF16ToUTF8(base::FormatDouble(cases[i].number, |
| 90 cases[i].frac_digits))); | 93 cases[i].frac_digits))); |
| 91 } | 94 } |
| 92 } | 95 } |
| OLD | NEW |