| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2024 Muhammad Nawaz | ||
| 3 | * Licensed under the MIT License. See LICENSE file for more information. | ||
| 4 | */ | ||
| 5 | // [ END OF LICENSE c6bd0f49d040fca8d8a9cb05868e66aa63f0e2e0 ] | ||
| 6 | |||
| 7 | #include "validators/param_validators.hpp" | ||
| 8 | #include <gtest/gtest.h> | ||
| 9 | #include <tuple> | ||
| 10 | |||
| 11 | enum : size_t | ||
| 12 | { | ||
| 13 | INPUT, | ||
| 14 | STYLE, | ||
| 15 | EXPLODE, | ||
| 16 | TYPE, | ||
| 17 | EXPECTED_ERROR | ||
| 18 | }; | ||
| 19 | |||
| 20 | // Create a parameterized fixture class using the struct | ||
| 21 | class PathPrimitiveParam | ||
| 22 | : public ::testing::TestWithParam<std::tuple<std::string, std::string, bool, std::string, ValidationError>> | ||
| 23 | { | ||
| 24 | protected: | ||
| 25 | 36 | void SetUp() override | |
| 26 | { | ||
| 27 |
2/4✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 36 times.
✗ Branch 5 not taken.
|
36 | auto params = GetParam(); |
| 28 |
2/4✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 36 times.
✗ Branch 6 not taken.
|
36 | input_ = "/pets/" + std::get<INPUT>(params) + "/xyz"; |
| 29 |
1/2✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
|
36 | std::string style = std::get<STYLE>(params); |
| 30 | 36 | bool explode = std::get<EXPLODE>(params); | |
| 31 |
1/2✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
|
36 | std::string type = std::get<TYPE>(params); |
| 32 | 36 | expected_error_ = std::get<EXPECTED_ERROR>(params); | |
| 33 | |||
| 34 | std::string json = R"({ | ||
| 35 | "name": "param", | ||
| 36 | "in": "path", | ||
| 37 | "required": true, | ||
| 38 |
2/4✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 36 times.
✗ Branch 5 not taken.
|
72 | "style": ")" + style + |
| 39 | R"(", | ||
| 40 |
4/6✓ Branch 0 taken 14 times.
✓ Branch 1 taken 22 times.
✓ Branch 3 taken 36 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 36 times.
✗ Branch 7 not taken.
|
108 | "explode": )" + (explode ? "true" : "false") + |
| 41 | R"(, | ||
| 42 | "schema": { | ||
| 43 |
1/2✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
|
72 | "type": ")" + |
| 44 |
1/2✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
|
36 | type + R"(" |
| 45 | } | ||
| 46 | })"; | ||
| 47 |
1/2✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
|
36 | doc_.Parse(json.c_str()); |
| 48 | |||
| 49 |
1/2✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
|
36 | validator_ = std::make_unique<PathParamValidator>(doc_, keys_); |
| 50 | 36 | } | |
| 51 | |||
| 52 | std::unique_ptr<PathParamValidator> validator_; | ||
| 53 | std::string input_; | ||
| 54 | rapidjson::Document doc_; | ||
| 55 | std::vector<std::string> keys_{"paths", "/pets/{param}/xyz", "get", "parameters", "param"}; | ||
| 56 | std::string error_msg_; | ||
| 57 | ValidationError expected_error_; | ||
| 58 | }; | ||
| 59 | |||
| 60 |
6/12✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
✓ Branch 24 taken 1 times.
✗ Branch 25 not taken.
|
146 | TEST_P(PathPrimitiveParam, ValidateParam) |
| 61 | { | ||
| 62 |
1/2✓ Branch 3 taken 36 times.
✗ Branch 4 not taken.
|
72 | const char* beg = input_.c_str() + std::string("/pets/").size(); |
| 63 |
1/2✓ Branch 4 taken 36 times.
✗ Branch 5 not taken.
|
72 | const char* end = input_.c_str() + input_.size() - std::string("/xyz").size(); |
| 64 |
1/2✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
|
72 | auto result = validator_->ValidateParam(beg, end, error_msg_); |
| 65 |
2/10✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 36 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
72 | EXPECT_EQ(result, expected_error_); |
| 66 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 28 times.
|
72 | if (result != ValidationError::NONE) { |
| 67 |
1/10✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
16 | EXPECT_FALSE(error_msg_.empty()); |
| 68 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
32 | rapidjson::Document doc; |
| 69 |
1/2✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
|
16 | doc.Parse(error_msg_.c_str()); |
| 70 |
1/10✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
16 | EXPECT_FALSE(doc.HasParseError()); |
| 71 | } | ||
| 72 | 72 | } | |
| 73 | |||
| 74 |
39/115✓ Branch 1 taken 1 times.
✓ Branch 2 taken 36 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✓ Branch 34 taken 1 times.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 37 taken 1 times.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✓ Branch 40 taken 1 times.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✓ Branch 43 taken 1 times.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✓ Branch 46 taken 1 times.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✓ Branch 49 taken 1 times.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✓ Branch 64 taken 1 times.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✓ Branch 67 taken 1 times.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✓ Branch 76 taken 1 times.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✓ Branch 79 taken 1 times.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✓ Branch 82 taken 1 times.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✓ Branch 85 taken 1 times.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
✓ Branch 88 taken 1 times.
✗ Branch 89 not taken.
✗ Branch 90 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✗ Branch 93 not taken.
✓ Branch 94 taken 1 times.
✗ Branch 95 not taken.
✗ Branch 96 not taken.
✓ Branch 97 taken 1 times.
✗ Branch 98 not taken.
✗ Branch 99 not taken.
✓ Branch 100 taken 1 times.
✗ Branch 101 not taken.
✗ Branch 102 not taken.
✓ Branch 103 taken 1 times.
✗ Branch 104 not taken.
✗ Branch 105 not taken.
✓ Branch 106 taken 1 times.
✗ Branch 107 not taken.
✗ Branch 108 not taken.
✓ Branch 109 taken 1 times.
✗ Branch 110 not taken.
✗ Branch 111 not taken.
✓ Branch 112 taken 1 times.
✗ Branch 113 not taken.
✗ Branch 114 not taken.
✗ Branch 116 not taken.
✗ Branch 117 not taken.
|
76 | INSTANTIATE_TEST_SUITE_P( |
| 75 | PathParamValidatorTests, PathPrimitiveParam, | ||
| 76 | ::testing::Values(std::make_tuple("true", "simple", false, "boolean", ValidationError::NONE), | ||
| 77 | std::make_tuple("true", "simple", true, "boolean", ValidationError::NONE), | ||
| 78 | std::make_tuple("false", "simple", false, "boolean", ValidationError::NONE), | ||
| 79 | std::make_tuple("false", "simple", true, "boolean", ValidationError::NONE), | ||
| 80 | std::make_tuple("123", "simple", false, "boolean", ValidationError::INVALID_PATH_PARAM), | ||
| 81 | std::make_tuple("123", "simple", false, "integer", ValidationError::NONE), | ||
| 82 | std::make_tuple("123", "simple", true, "integer", ValidationError::NONE), | ||
| 83 | std::make_tuple("123.0", "simple", false, "integer", ValidationError::INVALID_PATH_PARAM), | ||
| 84 | std::make_tuple("123.0", "simple", false, "number", ValidationError::NONE), | ||
| 85 | std::make_tuple("123.0", "simple", true, "number", ValidationError::NONE), | ||
| 86 | std::make_tuple("abc", "simple", false, "number", ValidationError::INVALID_PATH_PARAM), | ||
| 87 | std::make_tuple("abc%20xyz", "simple", false, "string", ValidationError::NONE), | ||
| 88 | std::make_tuple("abc%20xyz", "simple", true, "string", ValidationError::NONE), | ||
| 89 | std::make_tuple(".true", "label", false, "boolean", ValidationError::NONE), | ||
| 90 | std::make_tuple(".true", "label", true, "boolean", ValidationError::NONE), | ||
| 91 | std::make_tuple(".false", "label", false, "boolean", ValidationError::NONE), | ||
| 92 | std::make_tuple(".false", "label", true, "boolean", ValidationError::NONE), | ||
| 93 | std::make_tuple(".123", "label", false, "boolean", ValidationError::INVALID_PATH_PARAM), | ||
| 94 | std::make_tuple(".123", "label", false, "integer", ValidationError::NONE), | ||
| 95 | std::make_tuple(".123", "label", true, "integer", ValidationError::NONE), | ||
| 96 | std::make_tuple(".123.0", "label", false, "integer", ValidationError::INVALID_PATH_PARAM), | ||
| 97 | std::make_tuple(".abc%20xyz", "label", false, "string", ValidationError::NONE), | ||
| 98 | std::make_tuple(".abc%20xyz", "label", true, "string", ValidationError::NONE), | ||
| 99 | std::make_tuple(";param=true", "matrix", false, "boolean", ValidationError::NONE), | ||
| 100 | std::make_tuple(";param=true", "matrix", true, "boolean", ValidationError::NONE), | ||
| 101 | std::make_tuple(";param=false", "matrix", false, "boolean", ValidationError::NONE), | ||
| 102 | std::make_tuple(";param=false", "matrix", true, "boolean", ValidationError::NONE), | ||
| 103 | std::make_tuple(";param=123", "matrix", false, "boolean", ValidationError::INVALID_PATH_PARAM), | ||
| 104 | std::make_tuple(";param=123", "matrix", false, "integer", ValidationError::NONE), | ||
| 105 | std::make_tuple(";param=123", "matrix", true, "integer", ValidationError::NONE), | ||
| 106 | std::make_tuple(";param=123.0", "matrix", false, "integer", ValidationError::INVALID_PATH_PARAM), | ||
| 107 | std::make_tuple(";param=123.0", "matrix", false, "number", ValidationError::NONE), | ||
| 108 | std::make_tuple(";param=123.0", "matrix", true, "number", ValidationError::NONE), | ||
| 109 | std::make_tuple(";param=abc", "matrix", false, "number", ValidationError::INVALID_PATH_PARAM), | ||
| 110 | std::make_tuple(";param=abc%20xyz", "matrix", false, "string", ValidationError::NONE), | ||
| 111 | std::make_tuple(";param=abc%20xyz", "matrix", true, "string", ValidationError::NONE))); | ||
| 112 | |||
| 113 | class PathArrayParam | ||
| 114 | : public ::testing::TestWithParam<std::tuple<std::string, std::string, bool, std::string, ValidationError>> | ||
| 115 | { | ||
| 116 | protected: | ||
| 117 | 34 | void SetUp() override | |
| 118 | { | ||
| 119 |
2/4✓ Branch 1 taken 34 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 34 times.
✗ Branch 5 not taken.
|
34 | auto params = GetParam(); |
| 120 |
2/4✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 34 times.
✗ Branch 6 not taken.
|
34 | input_ = "/pets/" + std::get<INPUT>(params) + "/xyz"; |
| 121 |
1/2✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
|
34 | std::string style = std::get<STYLE>(params); |
| 122 | 34 | bool explode = std::get<EXPLODE>(params); | |
| 123 |
1/2✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
|
34 | std::string type = std::get<TYPE>(params); |
| 124 | 34 | expected_error_ = std::get<EXPECTED_ERROR>(params); | |
| 125 | |||
| 126 | std::string json = R"({ | ||
| 127 | "name": "param", | ||
| 128 | "in": "path", | ||
| 129 | "required": true, | ||
| 130 |
2/4✓ Branch 1 taken 34 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 34 times.
✗ Branch 5 not taken.
|
68 | "style": ")" + style + |
| 131 | R"(", | ||
| 132 |
4/6✓ Branch 0 taken 14 times.
✓ Branch 1 taken 20 times.
✓ Branch 3 taken 34 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 34 times.
✗ Branch 7 not taken.
|
102 | "explode": )" + (explode ? "true" : "false") + |
| 133 | R"(, | ||
| 134 | "schema": { | ||
| 135 | "type": "array", | ||
| 136 | "items": { | ||
| 137 |
1/2✓ Branch 1 taken 34 times.
✗ Branch 2 not taken.
|
68 | "type": ")" + |
| 138 |
1/2✓ Branch 1 taken 34 times.
✗ Branch 2 not taken.
|
34 | type + R"(" |
| 139 | } | ||
| 140 | } | ||
| 141 | })"; | ||
| 142 |
1/2✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
|
34 | doc_.Parse(json.c_str()); |
| 143 | |||
| 144 |
1/2✓ Branch 1 taken 34 times.
✗ Branch 2 not taken.
|
34 | validator_ = std::make_unique<PathParamValidator>(doc_, keys_); |
| 145 | 34 | } | |
| 146 | |||
| 147 | std::unique_ptr<PathParamValidator> validator_; | ||
| 148 | std::string input_; | ||
| 149 | rapidjson::Document doc_; | ||
| 150 | std::vector<std::string> keys_{"paths", "/pets/{param}/xyz", "get", "parameters", "0"}; | ||
| 151 | std::string error_msg_; | ||
| 152 | ValidationError expected_error_; | ||
| 153 | }; | ||
| 154 | |||
| 155 |
6/12✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
✓ Branch 24 taken 1 times.
✗ Branch 25 not taken.
|
138 | TEST_P(PathArrayParam, ValidateParam) |
| 156 | { | ||
| 157 |
1/2✓ Branch 3 taken 34 times.
✗ Branch 4 not taken.
|
68 | const char* beg = input_.c_str() + std::string("/pets/").size(); |
| 158 |
1/2✓ Branch 4 taken 34 times.
✗ Branch 5 not taken.
|
68 | const char* end = input_.c_str() + input_.size() - std::string("/xyz").size(); |
| 159 |
1/2✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
|
68 | auto result = validator_->ValidateParam(beg, end, error_msg_); |
| 160 |
2/10✓ Branch 1 taken 34 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 34 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
68 | EXPECT_EQ(result, expected_error_); |
| 161 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 26 times.
|
68 | if (result != ValidationError::NONE) { |
| 162 |
1/10✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
16 | EXPECT_FALSE(error_msg_.empty()); |
| 163 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
32 | rapidjson::Document doc; |
| 164 |
1/2✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
|
16 | doc.Parse(error_msg_.c_str()); |
| 165 |
1/10✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
16 | EXPECT_FALSE(doc.HasParseError()); |
| 166 | } | ||
| 167 | 68 | } | |
| 168 | |||
| 169 |
37/109✓ Branch 1 taken 1 times.
✓ Branch 2 taken 34 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✓ Branch 34 taken 1 times.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 37 taken 1 times.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✓ Branch 40 taken 1 times.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✓ Branch 43 taken 1 times.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✓ Branch 46 taken 1 times.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✓ Branch 49 taken 1 times.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✓ Branch 64 taken 1 times.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✓ Branch 67 taken 1 times.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✓ Branch 76 taken 1 times.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✓ Branch 79 taken 1 times.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✓ Branch 82 taken 1 times.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✓ Branch 85 taken 1 times.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
✓ Branch 88 taken 1 times.
✗ Branch 89 not taken.
✗ Branch 90 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✗ Branch 93 not taken.
✓ Branch 94 taken 1 times.
✗ Branch 95 not taken.
✗ Branch 96 not taken.
✓ Branch 97 taken 1 times.
✗ Branch 98 not taken.
✗ Branch 99 not taken.
✓ Branch 100 taken 1 times.
✗ Branch 101 not taken.
✗ Branch 102 not taken.
✓ Branch 103 taken 1 times.
✗ Branch 104 not taken.
✗ Branch 105 not taken.
✓ Branch 106 taken 1 times.
✗ Branch 107 not taken.
✗ Branch 108 not taken.
✗ Branch 110 not taken.
✗ Branch 111 not taken.
|
72 | INSTANTIATE_TEST_SUITE_P( |
| 170 | PathParamValidatorTests, PathArrayParam, | ||
| 171 | ::testing::Values( | ||
| 172 | std::make_tuple("true,false", "simple", false, "boolean", ValidationError::NONE), | ||
| 173 | std::make_tuple("true,false", "simple", true, "boolean", ValidationError::NONE), | ||
| 174 | std::make_tuple("false,true", "simple", false, "boolean", ValidationError::NONE), | ||
| 175 | std::make_tuple("false,true", "simple", true, "boolean", ValidationError::NONE), | ||
| 176 | std::make_tuple("123,456", "simple", false, "boolean", ValidationError::INVALID_PATH_PARAM), | ||
| 177 | std::make_tuple("123,456", "simple", false, "integer", ValidationError::NONE), | ||
| 178 | std::make_tuple("123,456", "simple", true, "integer", ValidationError::NONE), | ||
| 179 | std::make_tuple("123.0,456.0", "simple", false, "integer", ValidationError::INVALID_PATH_PARAM), | ||
| 180 | std::make_tuple("123.0,456.0", "simple", false, "number", ValidationError::NONE), | ||
| 181 | std::make_tuple("123.0,456.0", "simple", true, "number", ValidationError::NONE), | ||
| 182 | std::make_tuple("abc,xyz", "simple", false, "number", ValidationError::INVALID_PATH_PARAM), | ||
| 183 | std::make_tuple("abc%20xyz,def%20ghi", "simple", false, "string", ValidationError::NONE), | ||
| 184 | std::make_tuple("abc%20xyz,def%20ghi", "simple", true, "string", ValidationError::NONE), | ||
| 185 | std::make_tuple(".true,false", "label", false, "boolean", ValidationError::NONE), | ||
| 186 | std::make_tuple(".true.false", "label", true, "boolean", ValidationError::NONE), | ||
| 187 | std::make_tuple(".false,true", "label", false, "boolean", ValidationError::NONE), | ||
| 188 | std::make_tuple(".false.true", "label", true, "boolean", ValidationError::NONE), | ||
| 189 | std::make_tuple(".123,456", "label", false, "boolean", ValidationError::INVALID_PATH_PARAM), | ||
| 190 | std::make_tuple(".123,456", "label", false, "integer", ValidationError::NONE), | ||
| 191 | std::make_tuple(".123.456", "label", true, "integer", ValidationError::NONE), | ||
| 192 | std::make_tuple(".123.0,456.0", "label", false, "integer", ValidationError::INVALID_PATH_PARAM), | ||
| 193 | std::make_tuple(".abc%20xyz,def%20ghi", "label", false, "string", ValidationError::NONE), | ||
| 194 | std::make_tuple(".abc%20xyz.def%20ghi", "label", true, "string", ValidationError::NONE), | ||
| 195 | std::make_tuple(";param=true,false", "matrix", false, "boolean", ValidationError::NONE), | ||
| 196 | std::make_tuple(";param=true;param=false", "matrix", true, "boolean", ValidationError::NONE), | ||
| 197 | std::make_tuple(";param=false,true", "matrix", false, "boolean", ValidationError::NONE), | ||
| 198 | std::make_tuple(";param=false;param=true", "matrix", true, "boolean", ValidationError::NONE), | ||
| 199 | std::make_tuple(";param=123,456", "matrix", false, "boolean", ValidationError::INVALID_PATH_PARAM), | ||
| 200 | std::make_tuple(";param=123;param=456", "matrix", true, "integer", ValidationError::NONE), | ||
| 201 | std::make_tuple(";param=123.0,456.0", "matrix", false, "integer", ValidationError::INVALID_PATH_PARAM), | ||
| 202 | std::make_tuple(";param=123.0;param=456.0", "matrix", true, "number", ValidationError::NONE), | ||
| 203 | std::make_tuple(";param=abc,xyz", "matrix", false, "number", ValidationError::INVALID_PATH_PARAM), | ||
| 204 | std::make_tuple(";param=abc%20xyz,def%20ghi", "matrix", false, "string", ValidationError::NONE), | ||
| 205 | std::make_tuple(";param=abc%20xyz;param=def%20ghi", "matrix", true, "string", ValidationError::NONE))); | ||
| 206 | |||
| 207 | class PathObjectParam: public ::testing::TestWithParam<std::tuple<std::string, std::string, bool, ValidationError>> | ||
| 208 | { | ||
| 209 | protected: | ||
| 210 | 9 | void SetUp() override | |
| 211 | { | ||
| 212 |
2/4✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
|
9 | auto params = GetParam(); |
| 213 |
2/4✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
|
9 | input_ = "/pets/" + std::get<0>(params) + "/xyz"; |
| 214 |
1/2✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
|
9 | std::string style = std::get<1>(params); |
| 215 | 9 | bool explode = std::get<2>(params); | |
| 216 | 9 | expected_error_ = std::get<3>(params); | |
| 217 | |||
| 218 | std::string json = R"({ | ||
| 219 | "name": "param", | ||
| 220 | "in": "path", | ||
| 221 | "required": true, | ||
| 222 |
2/4✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
|
18 | "style": ")" + style + |
| 223 | R"(", | ||
| 224 |
3/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✓ Branch 3 taken 9 times.
✗ Branch 4 not taken.
|
27 | "explode": )" + (explode ? "true" : "false") + |
| 225 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
9 | R"(, |
| 226 | "schema": { | ||
| 227 | "type": "object", | ||
| 228 | "properties": { | ||
| 229 | "boolTrue": { | ||
| 230 | "type": "boolean" | ||
| 231 | }, | ||
| 232 | "boolFalse": { | ||
| 233 | "type": "boolean" | ||
| 234 | }, | ||
| 235 | "int": { | ||
| 236 | "type": "integer", | ||
| 237 | "format": "int64" | ||
| 238 | }, | ||
| 239 | "number": { | ||
| 240 | "type": "number", | ||
| 241 | "format": "double" | ||
| 242 | }, | ||
| 243 | "string": { | ||
| 244 | "type": "string" | ||
| 245 | } | ||
| 246 | } | ||
| 247 | } | ||
| 248 | })"; | ||
| 249 |
1/2✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
|
9 | doc_.Parse(json.c_str()); |
| 250 | |||
| 251 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
9 | validator_ = std::make_unique<PathParamValidator>(doc_, keys_); |
| 252 | 9 | } | |
| 253 | |||
| 254 | std::unique_ptr<PathParamValidator> validator_; | ||
| 255 | std::string input_; | ||
| 256 | rapidjson::Document doc_; | ||
| 257 | std::vector<std::string> keys_{"paths", "/pets/{param}/xyz", "get", "parameters", "0"}; | ||
| 258 | std::string error_msg_; | ||
| 259 | ValidationError expected_error_; | ||
| 260 | }; | ||
| 261 | |||
| 262 |
6/12✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
✓ Branch 24 taken 1 times.
✗ Branch 25 not taken.
|
38 | TEST_P(PathObjectParam, ValidateParam) |
| 263 | { | ||
| 264 |
1/2✓ Branch 3 taken 9 times.
✗ Branch 4 not taken.
|
18 | const char* beg = input_.c_str() + std::string("/pets/").size(); |
| 265 |
1/2✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
|
18 | const char* end = input_.c_str() + input_.size() - std::string("/xyz").size(); |
| 266 |
1/2✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
|
18 | auto result = validator_->ValidateParam(beg, end, error_msg_); |
| 267 |
2/10✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
18 | EXPECT_EQ(result, expected_error_); |
| 268 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 5 times.
|
18 | if (result != ValidationError::NONE) { |
| 269 |
1/10✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
8 | EXPECT_FALSE(error_msg_.empty()); |
| 270 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
16 | rapidjson::Document doc; |
| 271 |
1/2✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
8 | doc.Parse(error_msg_.c_str()); |
| 272 |
1/10✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
8 | EXPECT_FALSE(doc.HasParseError()); |
| 273 | } | ||
| 274 | 18 | } | |
| 275 | |||
| 276 |
12/34✓ Branch 1 taken 1 times.
✓ Branch 2 taken 9 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
|
22 | INSTANTIATE_TEST_SUITE_P( |
| 277 | PathParamValidatorTests, PathObjectParam, | ||
| 278 | ::testing::Values(std::make_tuple("boolTrue,true,boolFalse,false,int,123,number,123.456,string,abc%20xyz", "simple", | ||
| 279 | false, ValidationError::NONE), | ||
| 280 | std::make_tuple("boolTrue=true,boolFalse=false,int=123,number=123.456,string=abc%20xyz", "simple", | ||
| 281 | true, ValidationError::NONE), | ||
| 282 | std::make_tuple(".boolTrue,true,boolFalse,false,int,123,number,123.456,string,abc%20xyz", "label", | ||
| 283 | false, ValidationError::NONE), | ||
| 284 | std::make_tuple(";param=boolTrue,true,boolFalse,false,int,123,number,123.456,string,abc%20xyz", | ||
| 285 | "matrix", false, ValidationError::NONE), | ||
| 286 | std::make_tuple(";boolTrue=true;boolFalse=false;int=123;number=123.456;string=abc%20xyz", | ||
| 287 | "matrix", true, ValidationError::NONE), | ||
| 288 | std::make_tuple("boolTrue,ture,boolFalse,false,int,123,number,123.456,string,abc%20xyz", "simple", | ||
| 289 | false, ValidationError::INVALID_PATH_PARAM), | ||
| 290 | std::make_tuple("boolTrue=true,boolFalse=false,int=1.23,number=123.456,string=abc%20xyz", | ||
| 291 | "simple", false, ValidationError::INVALID_PATH_PARAM), | ||
| 292 | std::make_tuple("boolTrue=true,boolFalse=false,int=123,number=123.456,string=abc%2xyz", "simple", | ||
| 293 | false, ValidationError::INVALID_PATH_PARAM), | ||
| 294 | std::make_tuple(".boolTrue,true,boolFalse,false,int,123,number,123.456,string,abc%20xyz", "label", | ||
| 295 | true, ValidationError::INVALID_PATH_PARAM))); | ||
| 296 |