LCOV - code coverage report
Current view: top level - model - GlobalVariable.cpp (source / functions) Coverage Total Hit
Test: final-coverage.info Lines: 100.0 % 19 19
Test Date: 2025-12-16 15:55:14 Functions: 100.0 % 5 5

            Line data    Source code
       1              : /*
       2              :  ___________________________________________
       3              : |    _     ___                        _     |
       4              : |   | |   |__ \                      | |    |
       5              : |   | |__    ) |__ _  __ _  ___ _ __ | |_   |
       6              : |   | '_ \  / // _` |/ _` |/ _ \ '_ \| __|  |  HTTP/2 AGENT FOR MOCK TESTING
       7              : |   | | | |/ /| (_| | (_| |  __/ | | | |_   |  Version 0.0.z
       8              : |   |_| |_|____\__,_|\__, |\___|_| |_|\__|  |  https://github.com/testillano/h2agent
       9              : |                     __/ |                 |
      10              : |                    |___/                  |
      11              : |___________________________________________|
      12              : 
      13              : Licensed under the MIT License <http://opensource.org/licenses/MIT>.
      14              : SPDX-License-Identifier: MIT
      15              : Copyright (c) 2021 Eduardo Ramos
      16              : 
      17              : Permission is hereby  granted, free of charge, to any  person obtaining a copy
      18              : of this software and associated  documentation files (the "Software"), to deal
      19              : in the Software  without restriction, including without  limitation the rights
      20              : to  use, copy,  modify, merge,  publish, distribute,  sublicense, and/or  sell
      21              : copies  of  the Software,  and  to  permit persons  to  whom  the Software  is
      22              : furnished to do so, subject to the following conditions:
      23              : 
      24              : The above copyright notice and this permission notice shall be included in all
      25              : copies or substantial portions of the Software.
      26              : 
      27              : THE SOFTWARE  IS PROVIDED "AS  IS", WITHOUT WARRANTY  OF ANY KIND,  EXPRESS OR
      28              : IMPLIED,  INCLUDING BUT  NOT  LIMITED TO  THE  WARRANTIES OF  MERCHANTABILITY,
      29              : FITNESS FOR  A PARTICULAR PURPOSE AND  NONINFRINGEMENT. IN NO EVENT  SHALL THE
      30              : AUTHORS  OR COPYRIGHT  HOLDERS  BE  LIABLE FOR  ANY  CLAIM,  DAMAGES OR  OTHER
      31              : LIABILITY, WHETHER IN AN ACTION OF  CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      32              : OUT OF OR IN CONNECTION WITH THE SOFTWARE  OR THE USE OR OTHER DEALINGS IN THE
      33              : SOFTWARE.
      34              : */
      35              : 
      36              : #include <string>
      37              : 
      38              : #include <ert/tracing/Logger.hpp>
      39              : 
      40              : #include <GlobalVariable.hpp>
      41              : #include <AdminSchemas.hpp>
      42              : 
      43              : namespace h2agent
      44              : {
      45              : namespace model
      46              : {
      47              : 
      48          170 : GlobalVariable::GlobalVariable() {
      49          170 :     global_variable_schema_.setJson(h2agent::adminSchemas::global_variable); // won't fail
      50          170 : }
      51              : 
      52          115 : void GlobalVariable::load(const std::string &variable, const std::string &value) {
      53          115 :     std::string currentValue{};
      54          115 :     bool exists = tryGet(variable, currentValue);
      55          115 :     add(variable, currentValue + value);
      56          115 : }
      57              : 
      58           10 : bool GlobalVariable::loadJson(const nlohmann::json &j) {
      59              : 
      60           10 :     std::string error{};
      61           10 :     if (!global_variable_schema_.validate(j, error)) {
      62            5 :         return false;
      63              :     }
      64              : 
      65            5 :     add(j);
      66              : 
      67            5 :     return true;
      68           10 : }
      69              : 
      70            5 : std::string GlobalVariable::asJsonString() const {
      71              : 
      72           11 :     return ((size() != 0) ? getJson().dump() : "{}"); // server data is shown as an object
      73              : }
      74              : 
      75            3 : nlohmann::json GlobalVariable::getJson() const {
      76            3 :     return Map::getJson();
      77              : }
      78              : 
      79              : }
      80              : }
      81              : 
        

Generated by: LCOV version 2.0-1