Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "modules/payments/PaymentsValidators.h" | 5 #include "modules/payments/PaymentsValidators.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "wtf/text/WTFString.h" | 8 #include "wtf/text/WTFString.h" |
| 9 #include <ostream> // NOLINT | 9 #include <ostream> // NOLINT |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 | 25 |
| 26 std::ostream& operator<<(std::ostream& out, const TestCase& testCase) | 26 std::ostream& operator<<(std::ostream& out, const TestCase& testCase) |
| 27 { | 27 { |
| 28 out << "'" << testCase.input << "' is expected to be " << (testCase.expected Valid ? "valid" : "invalid"); | 28 out << "'" << testCase.input << "' is expected to be " << (testCase.expected Valid ? "valid" : "invalid"); |
| 29 return out; | 29 return out; |
| 30 } | 30 } |
| 31 | 31 |
| 32 class PaymentsCurrencyValidatorTest : public testing::TestWithParam<TestCase> { | 32 class PaymentsCurrencyValidatorTest : public testing::TestWithParam<TestCase> { |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 const char* longString2048() | |
| 36 { | |
| 37 static char longString[2049]; | |
| 38 for (int i = 0; i < 2049; i++) | |
|
please use gerrit instead
2016/08/25 16:47:38
i < 2048
pals
2016/08/26 07:20:26
One extra space for '\0'. strlen() does not includ
please use gerrit instead
2016/08/26 17:01:37
In the current state, the last value if "i" is "20
pals
2016/08/27 11:16:31
I'm sorry. You are correct. Rectified the issue.
| |
| 39 longString[i] = 'a'; | |
| 40 longString[2048] = '\0'; | |
| 41 return longString; | |
| 42 } | |
| 43 | |
| 44 const char* longString2049() | |
| 45 { | |
| 46 static char longString[2050]; | |
| 47 for (int i = 0; i < 2050; i++) | |
|
please use gerrit instead
2016/08/25 16:47:38
i < 2049
pals
2016/08/26 07:20:26
Same reason.
| |
| 48 longString[i] = 'a'; | |
| 49 longString[2049] = '\0'; | |
| 50 return longString; | |
| 51 } | |
| 52 | |
| 35 TEST_P(PaymentsCurrencyValidatorTest, IsValidCurrencyCodeFormat) | 53 TEST_P(PaymentsCurrencyValidatorTest, IsValidCurrencyCodeFormat) |
| 36 { | 54 { |
| 37 String errorMessage; | 55 String errorMessage; |
| 38 EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidCurrencyCodeF ormat(GetParam().input, &errorMessage)) << errorMessage; | 56 EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidCurrencyCodeF ormat(GetParam().input, &errorMessage)) << errorMessage; |
| 39 EXPECT_EQ(GetParam().expectedValid, errorMessage.isEmpty()) << errorMessage; | 57 EXPECT_EQ(GetParam().expectedValid, errorMessage.isEmpty()) << errorMessage; |
| 40 | 58 |
| 41 EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidCurrencyCodeF ormat(GetParam().input, nullptr)); | 59 EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidCurrencyCodeF ormat(GetParam().input, nullptr)); |
| 42 } | 60 } |
| 43 | 61 |
| 44 INSTANTIATE_TEST_CASE_P(CurrencyCodes, | 62 INSTANTIATE_TEST_CASE_P(CurrencyCodes, |
| 45 PaymentsCurrencyValidatorTest, | 63 PaymentsCurrencyValidatorTest, |
| 46 testing::Values( | 64 testing::Values( |
| 65 // Any string can be a currency code | |
| 47 TestCase("USD", true), | 66 TestCase("USD", true), |
| 48 // Invalid currency code formats | 67 TestCase("US1", true), |
| 49 TestCase("US1", false), | 68 TestCase("US", true), |
| 50 TestCase("US", false), | 69 TestCase("USDO", true), |
| 51 TestCase("USDO", false), | 70 TestCase("usd", true), |
| 52 TestCase("usd", false), | 71 TestCase("ANYSTRING", true), |
| 53 TestCase("", false))); | 72 TestCase("", true), |
| 73 TestCase(longString2048(), true), | |
| 74 TestCase(longString2049(), false))); | |
| 54 | 75 |
| 55 class PaymentsAmountValidatorTest : public testing::TestWithParam<TestCase> { | 76 class PaymentsAmountValidatorTest : public testing::TestWithParam<TestCase> { |
| 56 }; | 77 }; |
| 57 | 78 |
| 58 TEST_P(PaymentsAmountValidatorTest, IsValidAmountFormat) | 79 TEST_P(PaymentsAmountValidatorTest, IsValidAmountFormat) |
| 59 { | 80 { |
| 60 String errorMessage; | 81 String errorMessage; |
| 61 EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidAmountFormat( GetParam().input, &errorMessage)) << errorMessage; | 82 EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidAmountFormat( GetParam().input, &errorMessage)) << errorMessage; |
| 62 EXPECT_EQ(GetParam().expectedValid, errorMessage.isEmpty()) << errorMessage; | 83 EXPECT_EQ(GetParam().expectedValid, errorMessage.isEmpty()) << errorMessage; |
| 63 | 84 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 ShippingAddressTestCase("US", "", "", true), | 229 ShippingAddressTestCase("US", "", "", true), |
| 209 // Invalid shipping addresses | 230 // Invalid shipping addresses |
| 210 ShippingAddressTestCase("", "", "", false), | 231 ShippingAddressTestCase("", "", "", false), |
| 211 ShippingAddressTestCase("InvalidCountryCode", "", "", false), | 232 ShippingAddressTestCase("InvalidCountryCode", "", "", false), |
| 212 ShippingAddressTestCase("US", "InvalidLanguageCode", "", false), | 233 ShippingAddressTestCase("US", "InvalidLanguageCode", "", false), |
| 213 ShippingAddressTestCase("US", "en", "InvalidScriptCode", false), | 234 ShippingAddressTestCase("US", "en", "InvalidScriptCode", false), |
| 214 ShippingAddressTestCase("US", "", "Latn", false))); | 235 ShippingAddressTestCase("US", "", "Latn", false))); |
| 215 | 236 |
| 216 } // namespace | 237 } // namespace |
| 217 } // namespace blink | 238 } // namespace blink |
| OLD | NEW |