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/object_deserializer.hpp" | ||
8 | #include <gtest/gtest.h> | ||
9 | |||
10 | enum : size_t | ||
11 | { | ||
12 | INPUT, | ||
13 | START_CHAR, | ||
14 | SKIP_NAME, | ||
15 | KV_SEPARATOR, | ||
16 | VK_SEPARATOR, | ||
17 | IS_DEEP_OBJ, | ||
18 | SHOULD_THROW | ||
19 | }; | ||
20 | |||
21 | static const ObjKTMap KT_MAP = {{"\"boolTrue\"", PrimitiveType::BOOLEAN}, | ||
22 | {"\"boolFalse\"", PrimitiveType::BOOLEAN}, | ||
23 | {"\"int\"", PrimitiveType::INTEGER}, | ||
24 | {"\"number\"", PrimitiveType::NUMBER}, | ||
25 | {"\"string\"", PrimitiveType::STRING}}; | ||
26 | |||
27 | static const std::string EXPECTED = | ||
28 | R"({"boolTrue":true,"boolFalse":false,"int":123,"number":123.456,"string":"abc xyz"})"; | ||
29 | |||
30 | class ObjectDeserializerTest | ||
31 | : public ::testing::TestWithParam<std::tuple<std::string, char, bool, char, char, bool, bool>> | ||
32 | { | ||
33 | protected: | ||
34 | 15 | void SetUp() override | |
35 | { | ||
36 |
2/4✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
|
15 | auto params = GetParam(); |
37 |
1/2✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
|
15 | std::string input = std::get<INPUT>(params); |
38 | 15 | char start_char = std::get<START_CHAR>(params); | |
39 | 15 | bool skip_name = std::get<SKIP_NAME>(params); | |
40 | 15 | char kv_separator = std::get<KV_SEPARATOR>(params); | |
41 | 15 | char vk_separator = std::get<VK_SEPARATOR>(params); | |
42 | 15 | bool is_deep_obj = std::get<IS_DEEP_OBJ>(params); | |
43 | 15 | bool should_throw = std::get<SHOULD_THROW>(params); | |
44 | |||
45 |
1/2✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
|
30 | deserializer_ = std::make_unique<ObjectDeserializer>("test", start_char, skip_name, kv_separator, vk_separator, |
46 | 15 | is_deep_obj, KT_MAP); | |
47 |
1/2✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
|
15 | input_ = input; |
48 | 15 | expect_throw_ = should_throw; | |
49 | 15 | } | |
50 | |||
51 | std::unique_ptr<ObjectDeserializer> deserializer_; | ||
52 | std::string input_; | ||
53 | bool expect_throw_; | ||
54 | }; | ||
55 | |||
56 |
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.
|
62 | TEST_P(ObjectDeserializerTest, Deserialize) |
57 | { | ||
58 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 9 times.
|
30 | if (expect_throw_) { |
59 |
7/39✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 6 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 6 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 6 times.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 39 taken 6 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.
|
12 | EXPECT_THROW({ deserializer_->Deserialize(input_.c_str(), input_.c_str() + input_.size()); }, |
60 | 12 | DeserializationException); | |
61 | } else { | ||
62 |
1/2✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
|
18 | std::string result = deserializer_->Deserialize(input_.c_str(), input_.c_str() + input_.size()); |
63 |
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); |
64 | 18 | } | |
65 | 30 | } | |
66 | |||
67 |
18/52✓ Branch 1 taken 1 times.
✓ Branch 2 taken 15 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 53 not taken.
✗ Branch 54 not taken.
|
34 | INSTANTIATE_TEST_SUITE_P( |
68 | ObjectDeserializerTests, ObjectDeserializerTest, | ||
69 | ::testing::Values( | ||
70 | std::make_tuple("boolTrue,true,boolFalse,false,int,123,number,123.456,string,abc%20xyz", '\0', false, ',', ',', | ||
71 | false, false), | ||
72 | std::make_tuple("boolTrue=true,boolFalse=false,int=123,number=123.456,string=abc%20xyz", '\0', false, '=', ',', | ||
73 | false, false), | ||
74 | std::make_tuple(".boolTrue,true,boolFalse,false,int,123,number,123.456,string,abc%20xyz", '.', false, ',', ',', | ||
75 | false, false), | ||
76 | std::make_tuple(".boolTrue=true,boolFalse=false,int=123,number=123.456,string=abc%20xyz", '.', false, '=', ',', | ||
77 | false, false), | ||
78 | std::make_tuple(";test=boolTrue,true,boolFalse,false,int,123,number,123.456,string,abc%20xyz", ';', true, ',', | ||
79 | ',', false, false), | ||
80 | std::make_tuple(";boolTrue=true;boolFalse=false;int=123;number=123.456;string=abc%20xyz", ';', false, '=', ';', | ||
81 | false, false), | ||
82 | std::make_tuple("?boolTrue=true&boolFalse=false&int=123&number=123.456&string=abc%20xyz", '?', false, '=', '&', | ||
83 | false, false), | ||
84 | std::make_tuple("?test=boolTrue,true,boolFalse,false,int,123,number,123.456,string,abc%20xyz", '?', true, ',', | ||
85 | ',', false, false), | ||
86 | std::make_tuple( | ||
87 | "?test[boolTrue]=true&test[boolFalse]=false&test[int]=123&test[number]=123.456&test[string]=abc%20xyz", '?', | ||
88 | true, '=', '&', true, false), | ||
89 | std::make_tuple("boolTrue,true,boolFalse,false,int,str,number,123.456,string,abc%20xyz", '\0', false, ',', ',', | ||
90 | false, true), | ||
91 | std::make_tuple("boolTrue=true,boolFalse=false,int=123,number=123.456,string=abc%2xyz", '\0', false, '=', ',', | ||
92 | false, true), | ||
93 | std::make_tuple(".boolTrue,true,boolFalse,false,int,123,number,1.23.456,string,abc%20xyz", '.', false, ',', ',', | ||
94 | false, true), | ||
95 | std::make_tuple(".boolTrue;true,boolFalse=false,int=123,number=123.456,string=abc%20xyz", '.', false, '=', ',', | ||
96 | false, true), | ||
97 | std::make_tuple("test=boolTrue,true,boolFalse,false,int,123,number,123.456,string,abc%20xyz", ';', true, ',', | ||
98 | ',', false, true), | ||
99 | std::make_tuple(";boolTrue,true;boolFalse=false;int=123;number=123.456;string=abc%20xyz", ';', false, '=', ';', | ||
100 | false, true))); | ||
101 |