Bitcoin Core 28.99.0
P2P Digital Currency
rest_tests.cpp
Go to the documentation of this file.
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>
7
8#include <boost/test/unit_test.hpp>
9
10#include <string>
11
13
14BOOST_AUTO_TEST_CASE(test_query_string)
15{
16 std::string param;
18 // No query string
19 rf = ParseDataFormat(param, "/rest/endpoint/someresource.json");
20 BOOST_CHECK_EQUAL(param, "/rest/endpoint/someresource");
22
23 // Query string with single parameter
24 rf = ParseDataFormat(param, "/rest/endpoint/someresource.bin?p1=v1");
25 BOOST_CHECK_EQUAL(param, "/rest/endpoint/someresource");
27
28 // Query string with multiple parameters
29 rf = ParseDataFormat(param, "/rest/endpoint/someresource.hex?p1=v1&p2=v2");
30 BOOST_CHECK_EQUAL(param, "/rest/endpoint/someresource");
32
33 // Incorrectly formed query string will not be handled
34 rf = ParseDataFormat(param, "/rest/endpoint/someresource.json&p1=v1");
35 BOOST_CHECK_EQUAL(param, "/rest/endpoint/someresource.json&p1=v1");
37
38 // Omitted data format with query string should return UNDEF and hide query string
39 rf = ParseDataFormat(param, "/rest/endpoint/someresource?p1=v1");
40 BOOST_CHECK_EQUAL(param, "/rest/endpoint/someresource");
42
43 // Data format specified after query string
44 rf = ParseDataFormat(param, "/rest/endpoint/someresource?p1=v1.json");
45 BOOST_CHECK_EQUAL(param, "/rest/endpoint/someresource");
47}
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
RESTResponseFormat rf
Definition: rest.cpp:48
RESTResponseFormat ParseDataFormat(std::string &param, const std::string &strReq)
Parse a URI to get the data format and URI without data format and query string.
Definition: rest.cpp:137
RESTResponseFormat
Definition: rest.h:10
BOOST_AUTO_TEST_CASE(test_query_string)
Definition: rest_tests.cpp:14
Basic testing setup.
Definition: setup_common.h:63