GCC Code Coverage Report


Directory: ./
File: src/deserializers/primitive_deserializer.cpp
Date: 2024-07-09 12:21:25
Exec Total Coverage
Lines: 29 31 93.5%
Functions: 2 2 100.0%
Branches: 23 33 69.7%

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
9 377 PrimitiveDeserializer::PrimitiveDeserializer(const std::string& param_name, char start, bool skip_name,
10 377 PrimitiveType param_type)
11 : BaseDeserializer(param_name, start, skip_name)
12 377 , param_type_(param_type)
13 {
14 377 }
15 128 std::string PrimitiveDeserializer::Deserialize(const char* beg, const char* const end)
16 {
17 128 const char* cursor = beg;
18
19
2/2
✓ Branch 1 taken 124 times.
✓ Branch 2 taken 4 times.
128 CheckNSkipStart(cursor);
20
21
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 66 times.
124 if (skip_name_) {
22
2/2
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 2 times.
58 CheckNSkipName(cursor, end);
23
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 CheckNSkipChar(cursor, end, '=');
24 }
25
26
1/2
✓ Branch 1 taken 122 times.
✗ Branch 2 not taken.
122 CheckData(cursor, end);
27
28 122 std::string ret;
29
1/2
✓ Branch 1 taken 122 times.
✗ Branch 2 not taken.
122 ret.reserve(static_cast<size_t>(end - beg + 2));
30
31
4/5
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 47 times.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 29 times.
✗ Branch 4 not taken.
122 switch (param_type_) {
32 29 case PrimitiveType::BOOLEAN:
33
2/2
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 7 times.
29 DeserializeBoolean(cursor, end, ret);
34 22 break;
35
36 47 case PrimitiveType::INTEGER:
37
2/2
✓ Branch 1 taken 44 times.
✓ Branch 2 taken 3 times.
47 DeserializeInteger(cursor, end, ret);
38 44 break;
39
40 17 case PrimitiveType::NUMBER:
41
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 5 times.
17 DeserializeNumber(cursor, end, ret);
42 12 break;
43
44 29 case PrimitiveType::STRING:
45
2/2
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 7 times.
29 DeserializeString(cursor, end, ret);
46 22 break;
47 default:
48 throw DeserializationException("Invalid primitive type for '" + param_name_ + "'");
49 }
50
51
2/2
✓ Branch 1 taken 90 times.
✓ Branch 2 taken 10 times.
100 CheckEnd(cursor, end);
52
53 180 return ret;
54 32 }
55