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 "deserializers/array_deserializer.hpp" | ||
8 | #include <gtest/gtest.h> | ||
9 | |||
10 | enum : size_t | ||
11 | { | ||
12 | INPUT, | ||
13 | START_CHAR, | ||
14 | SKIP_NAME, | ||
15 | ITEMS_TYPE, | ||
16 | SEPARATOR, | ||
17 | HAS_RUNNING_NAME, | ||
18 | HAS_20_SEPARATOR, | ||
19 | EXPECTED, | ||
20 | SHOULD_THROW | ||
21 | }; | ||
22 | |||
23 | class ArrayDeserializerTest | ||
24 | : public ::testing::TestWithParam< | ||
25 | std::tuple<std::string, char, bool, PrimitiveType, char, bool, bool, std::string, bool>> | ||
26 | { | ||
27 | protected: | ||
28 | 35 | void SetUp() override | |
29 | { | ||
30 |
2/4✓ Branch 1 taken 35 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 35 times.
✗ Branch 5 not taken.
|
35 | auto params = GetParam(); |
31 |
1/2✓ Branch 2 taken 35 times.
✗ Branch 3 not taken.
|
35 | std::string input = std::get<INPUT>(params); |
32 | 35 | char start_char = std::get<START_CHAR>(params); | |
33 | 35 | bool skip_name = std::get<SKIP_NAME>(params); | |
34 | 35 | PrimitiveType items_type = std::get<ITEMS_TYPE>(params); | |
35 | 35 | char separator = std::get<SEPARATOR>(params); | |
36 | 35 | bool has_running_name = std::get<HAS_RUNNING_NAME>(params); | |
37 | 35 | bool has_20_separator = std::get<HAS_20_SEPARATOR>(params); | |
38 |
1/2✓ Branch 2 taken 35 times.
✗ Branch 3 not taken.
|
35 | std::string expected = std::get<EXPECTED>(params); |
39 | 35 | bool should_throw = std::get<SHOULD_THROW>(params); | |
40 | |||
41 |
1/2✓ Branch 1 taken 35 times.
✗ Branch 2 not taken.
|
70 | deserializer_ = std::make_unique<ArrayDeserializer>("test", start_char, skip_name, items_type, separator, |
42 | 35 | has_running_name, has_20_separator); | |
43 |
1/2✓ Branch 1 taken 35 times.
✗ Branch 2 not taken.
|
35 | input_ = input; |
44 |
1/2✓ Branch 1 taken 35 times.
✗ Branch 2 not taken.
|
35 | expected_ = expected; |
45 | 35 | expect_throw_ = should_throw; | |
46 | 35 | } | |
47 | |||
48 | std::unique_ptr<ArrayDeserializer> deserializer_; | ||
49 | std::string input_; | ||
50 | std::string expected_; | ||
51 | bool expect_throw_; | ||
52 | }; | ||
53 |
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.
|
142 | TEST_P(ArrayDeserializerTest, Deserialize) |
54 | { | ||
55 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 31 times.
|
70 | if (expect_throw_) { |
56 |
7/39✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 4 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 4 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✓ Branch 34 taken 4 times.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 39 taken 4 times.
✗ Branch 40 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
|
8 | EXPECT_THROW({ deserializer_->Deserialize(input_.c_str(), input_.c_str() + input_.size()); }, |
57 | 8 | DeserializationException); | |
58 | } else { | ||
59 |
1/2✓ Branch 5 taken 31 times.
✗ Branch 6 not taken.
|
62 | std::string result = deserializer_->Deserialize(input_.c_str(), input_.c_str() + input_.size()); |
60 |
2/10✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 31 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.
|
62 | EXPECT_EQ(result, expected_); |
61 | 62 | } | |
62 | 70 | } | |
63 | |||
64 |
38/112✓ Branch 1 taken 1 times.
✓ Branch 2 taken 35 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 113 not taken.
✗ Branch 114 not taken.
|
74 | INSTANTIATE_TEST_SUITE_P( |
65 | ArrayDeserializerTests, ArrayDeserializerTest, | ||
66 | ::testing::Values( | ||
67 | std::make_tuple("true,false", '\0', false, PrimitiveType::BOOLEAN, ',', false, false, "[true,false]", false), | ||
68 | std::make_tuple("1,2,3", '\0', false, PrimitiveType::INTEGER, ',', false, false, "[1,2,3]", false), | ||
69 | std::make_tuple("1.1,2.2,3.3", '\0', false, PrimitiveType::NUMBER, ',', false, false, "[1.1,2.2,3.3]", false), | ||
70 | std::make_tuple("abc,def,ghi", '\0', false, PrimitiveType::STRING, ',', false, false, | ||
71 | "[\"abc\",\"def\",\"ghi\"]", false), | ||
72 | std::make_tuple("test=true,false", '\0', true, PrimitiveType::BOOLEAN, ',', false, false, "[true,false]", | ||
73 | false), | ||
74 | std::make_tuple("test=1,2,3", '\0', true, PrimitiveType::INTEGER, ',', false, false, "[1,2,3]", false), | ||
75 | std::make_tuple("test=1.1,2.2,3.3", '\0', true, PrimitiveType::NUMBER, ',', false, false, "[1.1,2.2,3.3]", | ||
76 | false), | ||
77 | std::make_tuple("test=abc,def,ghi", '\0', true, PrimitiveType::STRING, ',', false, false, | ||
78 | "[\"abc\",\"def\",\"ghi\"]", false), | ||
79 | std::make_tuple(".true,false", '.', false, PrimitiveType::BOOLEAN, ',', false, false, "[true,false]", false), | ||
80 | std::make_tuple(".1,2,3", '.', false, PrimitiveType::INTEGER, ',', false, false, "[1,2,3]", false), | ||
81 | std::make_tuple(".1.1,2.2,3.3", '.', false, PrimitiveType::NUMBER, ',', false, false, "[1.1,2.2,3.3]", false), | ||
82 | std::make_tuple(".abc,def,ghi", '.', false, PrimitiveType::STRING, ',', false, false, | ||
83 | "[\"abc\",\"def\",\"ghi\"]", false), | ||
84 | std::make_tuple(".true.false", '.', false, PrimitiveType::BOOLEAN, '.', false, false, "[true,false]", false), | ||
85 | std::make_tuple(".1.2.3", '.', false, PrimitiveType::INTEGER, '.', false, false, "[1,2,3]", false), | ||
86 | // std::make_tuple(".1.1.2.2.3.3", '.', false, PrimitiveType::NUMBER, '.', false, false, "[1.1,2.2,3.3]", | ||
87 | // false), // NOT a valid serialization | ||
88 | std::make_tuple(".abc.def.ghi", '.', false, PrimitiveType::STRING, '.', false, false, | ||
89 | "[\"abc\",\"def\",\"ghi\"]", false), | ||
90 | std::make_tuple(";test=true,false", ';', true, PrimitiveType::BOOLEAN, ',', false, false, "[true,false]", | ||
91 | false), | ||
92 | std::make_tuple(";test=1,2,3", ';', true, PrimitiveType::INTEGER, ',', false, false, "[1,2,3]", false), | ||
93 | std::make_tuple(";test=1.1,2.2,3.3", ';', true, PrimitiveType::NUMBER, ',', false, false, "[1.1,2.2,3.3]", | ||
94 | false), | ||
95 | std::make_tuple(";test=abc,def,ghi", ';', true, PrimitiveType::STRING, ',', false, false, | ||
96 | "[\"abc\",\"def\",\"ghi\"]", false), | ||
97 | std::make_tuple(";test=true;test=false", ';', true, PrimitiveType::BOOLEAN, ';', true, false, "[true,false]", | ||
98 | false), | ||
99 | std::make_tuple(";test=1;test=2", ';', true, PrimitiveType::INTEGER, ';', true, false, "[1,2]", false), | ||
100 | std::make_tuple(";test=1.1;test=2.2", ';', true, PrimitiveType::NUMBER, ';', true, false, "[1.1,2.2]", false), | ||
101 | std::make_tuple(";test=abc;test=def", ';', true, PrimitiveType::STRING, ';', true, false, "[\"abc\",\"def\"]", | ||
102 | false), | ||
103 | std::make_tuple("?test=true&test=false", '?', true, PrimitiveType::BOOLEAN, '&', true, false, "[true,false]", | ||
104 | false), | ||
105 | std::make_tuple("?test=1&test=2", '?', true, PrimitiveType::INTEGER, '&', true, false, "[1,2]", false), | ||
106 | std::make_tuple("?test=1.1&test=2.2", '?', true, PrimitiveType::NUMBER, '&', true, false, "[1.1,2.2]", false), | ||
107 | std::make_tuple("?test=abc&test=def", '?', true, PrimitiveType::STRING, '&', true, false, "[\"abc\",\"def\"]", | ||
108 | false), | ||
109 | std::make_tuple("?test=true%20false", '?', true, PrimitiveType::BOOLEAN, '%', false, true, "[true,false]", | ||
110 | false), | ||
111 | std::make_tuple("?test=1%202", '?', true, PrimitiveType::INTEGER, '%', false, true, "[1,2]", false), | ||
112 | std::make_tuple("?test=1.1%202.2", '?', true, PrimitiveType::NUMBER, '%', false, true, "[1.1,2.2]", false), | ||
113 | std::make_tuple("?test=abc%20def", '?', true, PrimitiveType::STRING, '%', false, true, "[\"abc\",\"def\"]", | ||
114 | false), | ||
115 | std::make_tuple("true-false", '\0', false, PrimitiveType::BOOLEAN, ',', false, false, "[true,false]", true), | ||
116 | std::make_tuple("abc-true-5.3", '\0', false, PrimitiveType::INTEGER, ',', false, false, "[1,2,3]", true), | ||
117 | std::make_tuple("abc-true-5.3", '\0', false, PrimitiveType::NUMBER, ',', false, false, "[1.1,2.2,3.3]", true), | ||
118 | std::make_tuple("abc%true-5.3", '\0', false, PrimitiveType::STRING, ',', false, false, | ||
119 | "[\"abc\",\"def\",\"ghi\"]", true))); | ||
120 |