GCC Code Coverage Report


Directory: ./
File: test/unittest/src/deserializers/primitive_deserializer.cpp
Date: 2024-07-09 12:21:25
Exec Total Coverage
Lines: 22 22 100.0%
Functions: 6 6 100.0%
Branches: 48 146 32.9%

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/primitive_deserializer.hpp"
8 #include <gtest/gtest.h>
9 #include <memory>
10 #include <string>
11 #include <tuple>
12
13 enum : size_t
14 {
15 INPUT,
16 TYPE,
17 EXPECTED,
18 START_CHAR,
19 SKIP_NAME,
20 SHOULD_THROW
21 };
22
23 class PrimitiveDeserializerTest
24 : public ::testing::TestWithParam<std::tuple<std::string, PrimitiveType, std::string, char, bool, bool>>
25 {
26 protected:
27 20 void SetUp() override
28 {
29
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 auto params = GetParam();
30
1/2
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
20 std::string input = std::get<INPUT>(params);
31 20 PrimitiveType type = std::get<TYPE>(params);
32
1/2
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
20 std::string expected = std::get<EXPECTED>(params);
33 20 char start_char = std::get<START_CHAR>(params);
34 20 bool skip_name = std::get<SKIP_NAME>(params);
35 20 bool should_throw = std::get<SHOULD_THROW>(params);
36
37
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 deserializer_ = std::make_unique<PrimitiveDeserializer>("test", start_char, skip_name, type);
38
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 input_ = input;
39
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 expected_ = expected;
40 20 expect_throw_ = should_throw;
41 20 }
42
43 std::unique_ptr<PrimitiveDeserializer> deserializer_;
44 std::string input_;
45 std::string expected_;
46 bool expect_throw_;
47 };
48
49
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.
82 TEST_P(PrimitiveDeserializerTest, Deserialize)
50 {
51
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 16 times.
40 if (expect_throw_) {
52
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()); },
53 8 DeserializationException);
54 } else {
55
1/2
✓ Branch 5 taken 16 times.
✗ Branch 6 not taken.
32 std::string result = deserializer_->Deserialize(input_.c_str(), input_.c_str() + input_.size());
56
2/10
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 16 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.
32 EXPECT_EQ(result, expected_);
57 32 }
58 40 }
59
60
23/67
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 20 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 68 not taken.
✗ Branch 69 not taken.
44 INSTANTIATE_TEST_SUITE_P(
61 PrimitiveDeserializerTests, PrimitiveDeserializerTest,
62 ::testing::Values(std::make_tuple("true", PrimitiveType::BOOLEAN, "true", '\0', false, false),
63 std::make_tuple("123", PrimitiveType::INTEGER, "123", '\0', false, false),
64 std::make_tuple("123.456", PrimitiveType::NUMBER, "123.456", '\0', false, false),
65 std::make_tuple("abc", PrimitiveType::STRING, "\"abc\"", '\0', false, false),
66 std::make_tuple("test=true", PrimitiveType::BOOLEAN, "true", '\0', true, false),
67 std::make_tuple("test=123", PrimitiveType::INTEGER, "123", '\0', true, false),
68 std::make_tuple("test=123.456", PrimitiveType::NUMBER, "123.456", '\0', true, false),
69 std::make_tuple("test=abc%20xyz", PrimitiveType::STRING, "\"abc xyz\"", '\0', true, false),
70 std::make_tuple(".true", PrimitiveType::BOOLEAN, "true", '.', false, false),
71 std::make_tuple(".123", PrimitiveType::INTEGER, "123", '.', false, false),
72 std::make_tuple(".123.456", PrimitiveType::NUMBER, "123.456", '.', false, false),
73 std::make_tuple(".abc", PrimitiveType::STRING, "\"abc\"", '.', false, false),
74 std::make_tuple(";test=true", PrimitiveType::BOOLEAN, "true", ';', true, false),
75 std::make_tuple(";test=123", PrimitiveType::INTEGER, "123", ';', true, false),
76 std::make_tuple(";test=123.456", PrimitiveType::NUMBER, "123.456", ';', true, false),
77 std::make_tuple(";test=abc", PrimitiveType::STRING, "\"abc\"", ';', true, false),
78 std::make_tuple("invalid", PrimitiveType::BOOLEAN, "invalid", '\0', false, true),
79 std::make_tuple("invalid", PrimitiveType::INTEGER, "invalid", '\0', false, true),
80 std::make_tuple("invalid", PrimitiveType::NUMBER, "invalid", '\0', false, true),
81 std::make_tuple("inva%lid", PrimitiveType::STRING, "invalid", '\0', false, true)));
82