LCOV - code coverage report
Current view: top level - src/test - rest_tests.cpp (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 22 22 100.0 %
Date: 2022-04-21 14:51:19 Functions: 1 1 100.0 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 0 0 -

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2012-2022 The Bitcoin Core developers
#       2                 :            : // Distributed under the MIT software license, see the accompanying
#       3                 :            : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#       4                 :            : 
#       5                 :            : #include <rest.h>
#       6                 :            : #include <test/util/setup_common.h>
#       7                 :            : 
#       8                 :            : #include <boost/test/unit_test.hpp>
#       9                 :            : 
#      10                 :            : #include <string>
#      11                 :            : 
#      12                 :            : BOOST_FIXTURE_TEST_SUITE(rest_tests, BasicTestingSetup)
#      13                 :            : 
#      14                 :            : BOOST_AUTO_TEST_CASE(test_query_string)
#      15                 :          2 : {
#      16                 :          2 :     std::string param;
#      17                 :          2 :     RESTResponseFormat rf;
#      18                 :            :     // No query string
#      19                 :          2 :     rf = ParseDataFormat(param, "/rest/endpoint/someresource.json");
#      20                 :          2 :     BOOST_CHECK_EQUAL(param, "/rest/endpoint/someresource");
#      21                 :          2 :     BOOST_CHECK_EQUAL(rf, RESTResponseFormat::JSON);
#      22                 :            : 
#      23                 :            :     // Query string with single parameter
#      24                 :          2 :     rf = ParseDataFormat(param, "/rest/endpoint/someresource.bin?p1=v1");
#      25                 :          2 :     BOOST_CHECK_EQUAL(param, "/rest/endpoint/someresource");
#      26                 :          2 :     BOOST_CHECK_EQUAL(rf, RESTResponseFormat::BINARY);
#      27                 :            : 
#      28                 :            :     // Query string with multiple parameters
#      29                 :          2 :     rf = ParseDataFormat(param, "/rest/endpoint/someresource.hex?p1=v1&p2=v2");
#      30                 :          2 :     BOOST_CHECK_EQUAL(param, "/rest/endpoint/someresource");
#      31                 :          2 :     BOOST_CHECK_EQUAL(rf, RESTResponseFormat::HEX);
#      32                 :            : 
#      33                 :            :     // Incorrectly formed query string will not be handled
#      34                 :          2 :     rf = ParseDataFormat(param, "/rest/endpoint/someresource.json&p1=v1");
#      35                 :          2 :     BOOST_CHECK_EQUAL(param, "/rest/endpoint/someresource.json&p1=v1");
#      36                 :          2 :     BOOST_CHECK_EQUAL(rf, RESTResponseFormat::UNDEF);
#      37                 :            : 
#      38                 :            :     // Omitted data format with query string should return UNDEF and hide query string
#      39                 :          2 :     rf = ParseDataFormat(param, "/rest/endpoint/someresource?p1=v1");
#      40                 :          2 :     BOOST_CHECK_EQUAL(param, "/rest/endpoint/someresource");
#      41                 :          2 :     BOOST_CHECK_EQUAL(rf, RESTResponseFormat::UNDEF);
#      42                 :            : 
#      43                 :            :     // Data format specified after query string
#      44                 :          2 :     rf = ParseDataFormat(param, "/rest/endpoint/someresource?p1=v1.json");
#      45                 :          2 :     BOOST_CHECK_EQUAL(param, "/rest/endpoint/someresource");
#      46                 :          2 :     BOOST_CHECK_EQUAL(rf, RESTResponseFormat::UNDEF);
#      47                 :          2 : }
#      48                 :            : BOOST_AUTO_TEST_SUITE_END()

Generated by: LCOV version 0-eol-96201-ge66f56f4af6a