GCC Code Coverage Report


Directory: ./
File: src/validators/base_validator.cpp
Date: 2024-07-09 12:21:25
Exec Total Coverage
Lines: 9 11 81.8%
Functions: 2 3 66.7%
Branches: 4 8 50.0%

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 "validators/base_validator.hpp"
8
9 9 BaseValidator::BaseValidator(ValidationError err_code)
10 9 : code_on_error_(err_code)
11 9 , err_header_(kErrHeaders.at(err_code))
12 {
13 9 }
14
15 945 BaseValidator::BaseValidator(const std::vector<std::string>& ref_keys, ValidationError err_code)
16 945 : code_on_error_(err_code)
17 945 , err_header_(kErrHeaders.at(err_code))
18 {
19
4/8
✓ Branch 1 taken 945 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 945 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 945 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 945 times.
✗ Branch 11 not taken.
945 err_header_ += R"("specRef":")" + JoinReference(ref_keys) + R"(",)";
20 945 }
21
22 std::string BaseValidator::GetErrHeader() const
23 {
24 return err_header_;
25 }
26
27 const std::unordered_map<ValidationError, std::string> BaseValidator::kErrHeaders = {
28 {ValidationError::NONE, "NONE"},
29 {ValidationError::INVALID_METHOD, R"({"errorCode":"INVALID_METHOD","details":{)"},
30 {ValidationError::INVALID_ROUTE, R"({"errorCode":"INVALID_ROUTE","details":{)"},
31 {ValidationError::INVALID_PATH_PARAM, R"({"errorCode":"INVALID_PATH_PARAM","details":{)"},
32 {ValidationError::INVALID_QUERY_PARAM, R"({"errorCode":"INVALID_QUERY_PARAM","details":{)"},
33 {ValidationError::INVALID_HEADER_PARAM, R"({"errorCode":"INVALID_HEADER_PARAM","details":{)"},
34 {ValidationError::INVALID_BODY, R"({"errorCode":"INVALID_BODY","details":{)"},
35 {ValidationError::INVALID_RSP, R"({"errorCode":"INVALID_RSP","details":{)"}};
36