Skip to content

Commit

Permalink
[Payment Request] isolate unit tests with a "TestCase" struct
Browse files Browse the repository at this point in the history
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/1180212
Reviewed-by: Rouslan Solomakhin <[email protected]>
Commit-Queue: Rouslan Solomakhin <[email protected]>
Cr-Commit-Position: refs/heads/master@{#584466}
  • Loading branch information
mostynb authored and Commit Bot committed Aug 20, 2018
1 parent 4b176fd commit bfa162f
Showing 1 changed file with 84 additions and 80 deletions.
164 changes: 84 additions & 80 deletions components/payments/core/payment_details_validation_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,28 @@ const bool DO_NOT_REQUIRE_TOTAL = false;
const bool EXPECT_VALID = true;
const bool EXPECT_INVALID = false;

struct TestCase {
TestCase(const char* details, bool require_total, bool expect_valid)
struct PaymentDetailsValidationTestCase {
PaymentDetailsValidationTestCase(const char* details,
bool require_total,
bool expect_valid)
: details(details),
require_total(require_total),
expect_valid(expect_valid) {}
~TestCase() {}
~PaymentDetailsValidationTestCase() {}

const char* const details;
const bool require_total;
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;
return out;
}

class PaymentDetailsValidationTest : public ::testing::TestWithParam<TestCase> {
};
class PaymentDetailsValidationTest
: public ::testing::TestWithParam<PaymentDetailsValidationTestCase> {};

TEST_P(PaymentDetailsValidationTest, Test) {
auto value = base::JSONReader::Read(GetParam().details);
Expand All @@ -53,117 +56,118 @@ TEST_P(PaymentDetailsValidationTest, Test) {
EXPECT_EQ(GetParam().expect_valid, ValidatePaymentDetails(details, &unused));
}

INSTANTIATE_TEST_CASE_P(TestCases,
PaymentDetailsValidationTest,
::testing::Values(TestCase(R"(
INSTANTIATE_TEST_CASE_P(
TestCases,
PaymentDetailsValidationTest,
::testing::Values(PaymentDetailsValidationTestCase(R"(
{
"total": {
"label": "Tots",
"amount": {"currency": "USD", "value": "1.00"}
}
})",
REQUIRE_TOTAL,
EXPECT_VALID),
TestCase(R"(
REQUIRE_TOTAL,
EXPECT_VALID),
PaymentDetailsValidationTestCase(R"(
{
"total": {
"label": "",
"amount": {"currency": "USD", "value": "1.00"}
}
})",
REQUIRE_TOTAL,
EXPECT_VALID),
TestCase(R"(
REQUIRE_TOTAL,
EXPECT_VALID),
PaymentDetailsValidationTestCase(R"(
{
"total": {
"label": "Tots",
"amount": {"currency": "USD", "value": "1"}
}
})",
REQUIRE_TOTAL,
EXPECT_VALID),
TestCase(R"(
REQUIRE_TOTAL,
EXPECT_VALID),
PaymentDetailsValidationTestCase(R"(
{
"total": {
"label": "Tots",
"amount": {"currency": "USD", "value": "100"}
}
})",
REQUIRE_TOTAL,
EXPECT_VALID),
TestCase(R"(
REQUIRE_TOTAL,
EXPECT_VALID),
PaymentDetailsValidationTestCase(R"(
{
"total": {
"label": "Tots",
"amount": {"currency": "USD", "value": ""}
}
})",
REQUIRE_TOTAL,
EXPECT_INVALID),
TestCase(R"(
REQUIRE_TOTAL,
EXPECT_INVALID),
PaymentDetailsValidationTestCase(R"(
{
"total": {
"label": "Tots",
"amount": {"currency": "USD", "value": "-1"}
}
})",
REQUIRE_TOTAL,
EXPECT_INVALID),
TestCase(R"(
REQUIRE_TOTAL,
EXPECT_INVALID),
PaymentDetailsValidationTestCase(R"(
{
"total": {
"label": "Tots",
"amount": {"currency": "USD", "value": "1/3"}
}
})",
REQUIRE_TOTAL,
EXPECT_INVALID),
TestCase(R"(
REQUIRE_TOTAL,
EXPECT_INVALID),
PaymentDetailsValidationTestCase(R"(
{
"total": {
"label": "Tots",
"amount": {"currency": "USD", "value": "1,3"}
}
})",
REQUIRE_TOTAL,
EXPECT_INVALID),
TestCase(R"(
REQUIRE_TOTAL,
EXPECT_INVALID),
PaymentDetailsValidationTestCase(R"(
{
"total": {
"label": "Tots",
"amount": {"currency": "USD", "value": "ABC"}
}
})",
REQUIRE_TOTAL,
EXPECT_INVALID),
TestCase(R"(
REQUIRE_TOTAL,
EXPECT_INVALID),
PaymentDetailsValidationTestCase(R"(
{
"total": {
"label": "Tots",
"amount": {"currency": "", "value": "1.00"}
}
})",
REQUIRE_TOTAL,
EXPECT_INVALID),
TestCase(R"(
REQUIRE_TOTAL,
EXPECT_INVALID),
PaymentDetailsValidationTestCase(R"(
{
"total": {
"label": "Tots",
"amount": {"currency": "usd", "value": "1.00"}
}
})",
REQUIRE_TOTAL,
EXPECT_INVALID),
TestCase(R"(
REQUIRE_TOTAL,
EXPECT_INVALID),
PaymentDetailsValidationTestCase(R"(
{
"total": {
"label": "Tots",
"amount": {"currency": "123", "value": "1.00"}
}
})",
REQUIRE_TOTAL,
EXPECT_INVALID),
TestCase(R"(
REQUIRE_TOTAL,
EXPECT_INVALID),
PaymentDetailsValidationTestCase(R"(
{
"total": {
"label": "Tots",
Expand All @@ -177,9 +181,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
"amount": {"currency": "USD", "value": "0.01"}
}]
})",
REQUIRE_TOTAL,
EXPECT_VALID),
TestCase(R"(
REQUIRE_TOTAL,
EXPECT_VALID),
PaymentDetailsValidationTestCase(R"(
{
"total": {
"label": "",
Expand All @@ -193,9 +197,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
"amount": {"currency": "USD", "value": "0.01"}
}]
})",
REQUIRE_TOTAL,
EXPECT_VALID),
TestCase(R"(
REQUIRE_TOTAL,
EXPECT_VALID),
PaymentDetailsValidationTestCase(R"(
{
"total": {
"label": "Tots",
Expand All @@ -209,9 +213,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
"amount": {"currency": "USD", "value": "0.01"}
}]
})",
REQUIRE_TOTAL,
EXPECT_INVALID),
TestCase(R"(
REQUIRE_TOTAL,
EXPECT_INVALID),
PaymentDetailsValidationTestCase(R"(
{
"total": {
"label": "",
Expand All @@ -225,9 +229,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
"amount": {"currency": "USD", "value": "0.01"}
}]
})",
REQUIRE_TOTAL,
EXPECT_INVALID),
TestCase(R"(
REQUIRE_TOTAL,
EXPECT_INVALID),
PaymentDetailsValidationTestCase(R"(
{
"total": {
"label": "",
Expand All @@ -241,9 +245,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
"amount": {"currency": "USD", "value": "-0.01"}
}]
})",
REQUIRE_TOTAL,
EXPECT_VALID),
TestCase(R"(
REQUIRE_TOTAL,
EXPECT_VALID),
PaymentDetailsValidationTestCase(R"(
{
"displayItems": [{
"label": "Subtotal",
Expand All @@ -253,9 +257,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
"amount": {"currency": "USD", "value": "-0.01"}
}]
})",
DO_NOT_REQUIRE_TOTAL,
EXPECT_VALID),
TestCase(R"(
DO_NOT_REQUIRE_TOTAL,
EXPECT_VALID),
PaymentDetailsValidationTestCase(R"(
{
"displayItems": [{
"label": "Subtotal",
Expand Down Expand Up @@ -292,9 +296,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
}]
}]
})",
DO_NOT_REQUIRE_TOTAL,
EXPECT_VALID),
TestCase(R"(
DO_NOT_REQUIRE_TOTAL,
EXPECT_VALID),
PaymentDetailsValidationTestCase(R"(
{
"displayItems": [{
"label": "Subtotal",
Expand All @@ -318,9 +322,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
}]
}]
})",
DO_NOT_REQUIRE_TOTAL,
EXPECT_INVALID),
TestCase(R"(
DO_NOT_REQUIRE_TOTAL,
EXPECT_INVALID),
PaymentDetailsValidationTestCase(R"(
{
"displayItems": [{
"label": "Subtotal",
Expand All @@ -344,9 +348,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
}]
}]
})",
DO_NOT_REQUIRE_TOTAL,
EXPECT_INVALID),
TestCase(R"(
DO_NOT_REQUIRE_TOTAL,
EXPECT_INVALID),
PaymentDetailsValidationTestCase(R"(
{
"displayItems": [{
"label": "Subtotal",
Expand All @@ -370,9 +374,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
}]
}]
})",
DO_NOT_REQUIRE_TOTAL,
EXPECT_INVALID),
TestCase(R"(
DO_NOT_REQUIRE_TOTAL,
EXPECT_INVALID),
PaymentDetailsValidationTestCase(R"(
{
"displayItems": [{
"label": "Subtotal",
Expand All @@ -396,9 +400,9 @@ INSTANTIATE_TEST_CASE_P(TestCases,
}]
}]
})",
DO_NOT_REQUIRE_TOTAL,
EXPECT_INVALID),
TestCase(R"(
DO_NOT_REQUIRE_TOTAL,
EXPECT_INVALID),
PaymentDetailsValidationTestCase(R"(
{
"displayItems": [{
"label": "Subtotal",
Expand All @@ -422,8 +426,8 @@ INSTANTIATE_TEST_CASE_P(TestCases,
}]
}]
})",
DO_NOT_REQUIRE_TOTAL,
EXPECT_INVALID)));
DO_NOT_REQUIRE_TOTAL,
EXPECT_INVALID)));

} // namespace
} // namespace payments

0 comments on commit bfa162f

Please sign in to comment.