Commit bfa162fc authored by Mostyn Bramley-Moore's avatar Mostyn Bramley-Moore Committed by Commit Bot

[Payment Request] isolate unit tests with a "TestCase" struct

These two files both define a TestCase struct in the anonymous namespace:
payment_details_validation_unittest.cc
payments_validators_unittest.cc

These can conflict in jumbo builds.  Let's isolate one of them by using
a file-specific namespace instead of the anonymous namespace.

Change-Id: Ic8e3fa255dde091311c02f73273a244782c4d2c3
Reviewed-on: https://chromium-review.googlesource.com/1180212Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584466}
parent 4b176fda
...@@ -20,25 +20,28 @@ const bool DO_NOT_REQUIRE_TOTAL = false; ...@@ -20,25 +20,28 @@ const bool DO_NOT_REQUIRE_TOTAL = false;
const bool EXPECT_VALID = true; const bool EXPECT_VALID = true;
const bool EXPECT_INVALID = false; const bool EXPECT_INVALID = false;
struct TestCase { struct PaymentDetailsValidationTestCase {
TestCase(const char* details, bool require_total, bool expect_valid) PaymentDetailsValidationTestCase(const char* details,
bool require_total,
bool expect_valid)
: details(details), : details(details),
require_total(require_total), require_total(require_total),
expect_valid(expect_valid) {} expect_valid(expect_valid) {}
~TestCase() {} ~PaymentDetailsValidationTestCase() {}
const char* const details; const char* const details;
const bool require_total; const bool require_total;
const bool expect_valid; const bool expect_valid;
}; };
std::ostream& operator<<(std::ostream& out, const TestCase& test_case) { std::ostream& operator<<(std::ostream& out,
const PaymentDetailsValidationTestCase& test_case) {
out << test_case.details; out << test_case.details;
return out; return out;
} }
class PaymentDetailsValidationTest : public ::testing::TestWithParam<TestCase> { class PaymentDetailsValidationTest
}; : public ::testing::TestWithParam<PaymentDetailsValidationTestCase> {};
TEST_P(PaymentDetailsValidationTest, Test) { TEST_P(PaymentDetailsValidationTest, Test) {
auto value = base::JSONReader::Read(GetParam().details); auto value = base::JSONReader::Read(GetParam().details);
...@@ -53,117 +56,118 @@ TEST_P(PaymentDetailsValidationTest, Test) { ...@@ -53,117 +56,118 @@ TEST_P(PaymentDetailsValidationTest, Test) {
EXPECT_EQ(GetParam().expect_valid, ValidatePaymentDetails(details, &unused)); EXPECT_EQ(GetParam().expect_valid, ValidatePaymentDetails(details, &unused));
} }
INSTANTIATE_TEST_CASE_P(TestCases, INSTANTIATE_TEST_CASE_P(
PaymentDetailsValidationTest, TestCases,
::testing::Values(TestCase(R"( PaymentDetailsValidationTest,
::testing::Values(PaymentDetailsValidationTestCase(R"(
{ {
"total": { "total": {
"label": "Tots", "label": "Tots",
"amount": {"currency": "USD", "value": "1.00"} "amount": {"currency": "USD", "value": "1.00"}
} }
})", })",
REQUIRE_TOTAL, REQUIRE_TOTAL,
EXPECT_VALID), EXPECT_VALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"total": { "total": {
"label": "", "label": "",
"amount": {"currency": "USD", "value": "1.00"} "amount": {"currency": "USD", "value": "1.00"}
} }
})", })",
REQUIRE_TOTAL, REQUIRE_TOTAL,
EXPECT_VALID), EXPECT_VALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"total": { "total": {
"label": "Tots", "label": "Tots",
"amount": {"currency": "USD", "value": "1"} "amount": {"currency": "USD", "value": "1"}
} }
})", })",
REQUIRE_TOTAL, REQUIRE_TOTAL,
EXPECT_VALID), EXPECT_VALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"total": { "total": {
"label": "Tots", "label": "Tots",
"amount": {"currency": "USD", "value": "100"} "amount": {"currency": "USD", "value": "100"}
} }
})", })",
REQUIRE_TOTAL, REQUIRE_TOTAL,
EXPECT_VALID), EXPECT_VALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"total": { "total": {
"label": "Tots", "label": "Tots",
"amount": {"currency": "USD", "value": ""} "amount": {"currency": "USD", "value": ""}
} }
})", })",
REQUIRE_TOTAL, REQUIRE_TOTAL,
EXPECT_INVALID), EXPECT_INVALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"total": { "total": {
"label": "Tots", "label": "Tots",
"amount": {"currency": "USD", "value": "-1"} "amount": {"currency": "USD", "value": "-1"}
} }
})", })",
REQUIRE_TOTAL, REQUIRE_TOTAL,
EXPECT_INVALID), EXPECT_INVALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"total": { "total": {
"label": "Tots", "label": "Tots",
"amount": {"currency": "USD", "value": "1/3"} "amount": {"currency": "USD", "value": "1/3"}
} }
})", })",
REQUIRE_TOTAL, REQUIRE_TOTAL,
EXPECT_INVALID), EXPECT_INVALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"total": { "total": {
"label": "Tots", "label": "Tots",
"amount": {"currency": "USD", "value": "1,3"} "amount": {"currency": "USD", "value": "1,3"}
} }
})", })",
REQUIRE_TOTAL, REQUIRE_TOTAL,
EXPECT_INVALID), EXPECT_INVALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"total": { "total": {
"label": "Tots", "label": "Tots",
"amount": {"currency": "USD", "value": "ABC"} "amount": {"currency": "USD", "value": "ABC"}
} }
})", })",
REQUIRE_TOTAL, REQUIRE_TOTAL,
EXPECT_INVALID), EXPECT_INVALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"total": { "total": {
"label": "Tots", "label": "Tots",
"amount": {"currency": "", "value": "1.00"} "amount": {"currency": "", "value": "1.00"}
} }
})", })",
REQUIRE_TOTAL, REQUIRE_TOTAL,
EXPECT_INVALID), EXPECT_INVALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"total": { "total": {
"label": "Tots", "label": "Tots",
"amount": {"currency": "usd", "value": "1.00"} "amount": {"currency": "usd", "value": "1.00"}
} }
})", })",
REQUIRE_TOTAL, REQUIRE_TOTAL,
EXPECT_INVALID), EXPECT_INVALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"total": { "total": {
"label": "Tots", "label": "Tots",
"amount": {"currency": "123", "value": "1.00"} "amount": {"currency": "123", "value": "1.00"}
} }
})", })",
REQUIRE_TOTAL, REQUIRE_TOTAL,
EXPECT_INVALID), EXPECT_INVALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"total": { "total": {
"label": "Tots", "label": "Tots",
...@@ -177,9 +181,9 @@ INSTANTIATE_TEST_CASE_P(TestCases, ...@@ -177,9 +181,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
"amount": {"currency": "USD", "value": "0.01"} "amount": {"currency": "USD", "value": "0.01"}
}] }]
})", })",
REQUIRE_TOTAL, REQUIRE_TOTAL,
EXPECT_VALID), EXPECT_VALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"total": { "total": {
"label": "", "label": "",
...@@ -193,9 +197,9 @@ INSTANTIATE_TEST_CASE_P(TestCases, ...@@ -193,9 +197,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
"amount": {"currency": "USD", "value": "0.01"} "amount": {"currency": "USD", "value": "0.01"}
}] }]
})", })",
REQUIRE_TOTAL, REQUIRE_TOTAL,
EXPECT_VALID), EXPECT_VALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"total": { "total": {
"label": "Tots", "label": "Tots",
...@@ -209,9 +213,9 @@ INSTANTIATE_TEST_CASE_P(TestCases, ...@@ -209,9 +213,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
"amount": {"currency": "USD", "value": "0.01"} "amount": {"currency": "USD", "value": "0.01"}
}] }]
})", })",
REQUIRE_TOTAL, REQUIRE_TOTAL,
EXPECT_INVALID), EXPECT_INVALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"total": { "total": {
"label": "", "label": "",
...@@ -225,9 +229,9 @@ INSTANTIATE_TEST_CASE_P(TestCases, ...@@ -225,9 +229,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
"amount": {"currency": "USD", "value": "0.01"} "amount": {"currency": "USD", "value": "0.01"}
}] }]
})", })",
REQUIRE_TOTAL, REQUIRE_TOTAL,
EXPECT_INVALID), EXPECT_INVALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"total": { "total": {
"label": "", "label": "",
...@@ -241,9 +245,9 @@ INSTANTIATE_TEST_CASE_P(TestCases, ...@@ -241,9 +245,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
"amount": {"currency": "USD", "value": "-0.01"} "amount": {"currency": "USD", "value": "-0.01"}
}] }]
})", })",
REQUIRE_TOTAL, REQUIRE_TOTAL,
EXPECT_VALID), EXPECT_VALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"displayItems": [{ "displayItems": [{
"label": "Subtotal", "label": "Subtotal",
...@@ -253,9 +257,9 @@ INSTANTIATE_TEST_CASE_P(TestCases, ...@@ -253,9 +257,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
"amount": {"currency": "USD", "value": "-0.01"} "amount": {"currency": "USD", "value": "-0.01"}
}] }]
})", })",
DO_NOT_REQUIRE_TOTAL, DO_NOT_REQUIRE_TOTAL,
EXPECT_VALID), EXPECT_VALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"displayItems": [{ "displayItems": [{
"label": "Subtotal", "label": "Subtotal",
...@@ -292,9 +296,9 @@ INSTANTIATE_TEST_CASE_P(TestCases, ...@@ -292,9 +296,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
}] }]
}] }]
})", })",
DO_NOT_REQUIRE_TOTAL, DO_NOT_REQUIRE_TOTAL,
EXPECT_VALID), EXPECT_VALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"displayItems": [{ "displayItems": [{
"label": "Subtotal", "label": "Subtotal",
...@@ -318,9 +322,9 @@ INSTANTIATE_TEST_CASE_P(TestCases, ...@@ -318,9 +322,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
}] }]
}] }]
})", })",
DO_NOT_REQUIRE_TOTAL, DO_NOT_REQUIRE_TOTAL,
EXPECT_INVALID), EXPECT_INVALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"displayItems": [{ "displayItems": [{
"label": "Subtotal", "label": "Subtotal",
...@@ -344,9 +348,9 @@ INSTANTIATE_TEST_CASE_P(TestCases, ...@@ -344,9 +348,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
}] }]
}] }]
})", })",
DO_NOT_REQUIRE_TOTAL, DO_NOT_REQUIRE_TOTAL,
EXPECT_INVALID), EXPECT_INVALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"displayItems": [{ "displayItems": [{
"label": "Subtotal", "label": "Subtotal",
...@@ -370,9 +374,9 @@ INSTANTIATE_TEST_CASE_P(TestCases, ...@@ -370,9 +374,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
}] }]
}] }]
})", })",
DO_NOT_REQUIRE_TOTAL, DO_NOT_REQUIRE_TOTAL,
EXPECT_INVALID), EXPECT_INVALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"displayItems": [{ "displayItems": [{
"label": "Subtotal", "label": "Subtotal",
...@@ -396,9 +400,9 @@ INSTANTIATE_TEST_CASE_P(TestCases, ...@@ -396,9 +400,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
}] }]
}] }]
})", })",
DO_NOT_REQUIRE_TOTAL, DO_NOT_REQUIRE_TOTAL,
EXPECT_INVALID), EXPECT_INVALID),
TestCase(R"( PaymentDetailsValidationTestCase(R"(
{ {
"displayItems": [{ "displayItems": [{
"label": "Subtotal", "label": "Subtotal",
...@@ -422,8 +426,8 @@ INSTANTIATE_TEST_CASE_P(TestCases, ...@@ -422,8 +426,8 @@ INSTANTIATE_TEST_CASE_P(TestCases,
}] }]
}] }]
})", })",
DO_NOT_REQUIRE_TOTAL, DO_NOT_REQUIRE_TOTAL,
EXPECT_INVALID))); EXPECT_INVALID)));
} // namespace } // namespace
} // namespace payments } // namespace payments
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment