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/content_deserializer.hpp" | ||
8 | #include <gtest/gtest.h> | ||
9 | |||
10 | enum : size_t | ||
11 | { | ||
12 | INPUT, | ||
13 | START_CHAR, | ||
14 | SKIP_NAME, | ||
15 | SHOULD_THROW | ||
16 | }; | ||
17 | |||
18 | static const std::string EXPECTED = | ||
19 | R"({"boolTrue":true,"boolFalse":false,"int":123,"number":123.456,"string":"abc xyz"})"; | ||
20 | |||
21 | class ContentDeserializerTest: public ::testing::TestWithParam<std::tuple<std::string, char, bool, bool>> | ||
22 | { | ||
23 | protected: | ||
24 | 4 | void SetUp() override | |
25 | { | ||
26 |
2/4✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
|
4 | auto params = GetParam(); |
27 |
1/2✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | std::string input = std::get<INPUT>(params); |
28 | 4 | char start_char = std::get<START_CHAR>(params); | |
29 | 4 | bool skip_name = std::get<SKIP_NAME>(params); | |
30 | 4 | bool should_throw = std::get<SHOULD_THROW>(params); | |
31 | |||
32 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | deserializer_ = std::make_unique<ContentDeserializer>("test", start_char, skip_name); |
33 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | input_ = input; |
34 | 4 | expect_throw_ = should_throw; | |
35 | 4 | } | |
36 | |||
37 | std::unique_ptr<ContentDeserializer> deserializer_; | ||
38 | std::string input_; | ||
39 | bool expect_throw_; | ||
40 | }; | ||
41 | |||
42 |
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.
|
18 | TEST_P(ContentDeserializerTest, Deserialize) |
43 | { | ||
44 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
|
8 | if (expect_throw_) { |
45 |
7/39✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 1 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 1 times.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 39 taken 1 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.
|
2 | EXPECT_THROW({ deserializer_->Deserialize(input_.c_str(), input_.c_str() + input_.size()); }, |
46 | 2 | DeserializationException); | |
47 | } else { | ||
48 |
1/2✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
|
6 | std::string result = deserializer_->Deserialize(input_.c_str(), input_.c_str() + input_.size()); |
49 |
2/10✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 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.
|
6 | EXPECT_EQ(result, EXPECTED); |
50 | 6 | } | |
51 | 8 | } | |
52 | |||
53 |
7/19✓ Branch 1 taken 1 times.
✓ Branch 2 taken 4 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 20 not taken.
✗ Branch 21 not taken.
|
12 | INSTANTIATE_TEST_SUITE_P( |
54 | ContentDeserializerTests, ContentDeserializerTest, | ||
55 | ::testing::Values(std::make_tuple("%7B%22boolTrue%22%3Atrue%2C%22boolFalse%22%3Afalse%2C%22int%22%3A123%2C%" | ||
56 | "22number%22%3A123.456%2C%22string%22%3A%22abc%20xyz%22%7D", | ||
57 | '\0', false, false), | ||
58 | std::make_tuple("test=%7B%22boolTrue%22%3Atrue%2C%22boolFalse%22%3Afalse%2C%22int%22%3A123%2C%" | ||
59 | "22number%22%3A123.456%2C%22string%22%3A%22abc%20xyz%22%7D", | ||
60 | '\0', true, false), | ||
61 | std::make_tuple("?test=%7B%22boolTrue%22%3Atrue%2C%22boolFalse%22%3Afalse%2C%22int%22%3A123%2C%" | ||
62 | "22number%22%3A123.456%2C%22string%22%3A%22abc%20xyz%22%7D", | ||
63 | '?', true, false), | ||
64 | std::make_tuple("test%7B%22boolTrue%22%3Atrue%2C%22boolFalse%22%3Afalse%2C%22int%22%3A123%2C%" | ||
65 | "22number%22%3A123.456%2C%22string%22%3A%22abc%" | ||
66 | "20xyz%22%7D&test2=123", | ||
67 | '\0', true, true))); | ||
68 |