Line data Source code
1 : // Copyright (c) 2011-2026 Made to Order Software Corp. All Rights Reserved
2 : //
3 : // https://snapwebsites.org/project/edhttp
4 : // contact@m2osw.com
5 : //
6 : // This program is free software: you can redistribute it and/or modify
7 : // it under the terms of the GNU General Public License as published by
8 : // the Free Software Foundation, either version 3 of the License, or
9 : // (at your option) any later version.
10 : //
11 : // This program is distributed in the hope that it will be useful,
12 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : // GNU General Public License for more details.
15 : //
16 : // You should have received a copy of the GNU General Public License
17 : // along with this program. If not, see <https://www.gnu.org/licenses/>.
18 :
19 : /** \file
20 : * \brief Verify the token class and functions.
21 : *
22 : * This file implements tests to verify that the token class functions
23 : * properly. It also includes tests for the standalone functions.
24 : */
25 :
26 : // edhttp
27 : //
28 : #include <edhttp/utils.h>
29 :
30 : #include <edhttp/exception.h>
31 :
32 :
33 : // self
34 : //
35 : #include "catch_main.h"
36 :
37 :
38 : // snaplogger
39 : //
40 : #include <snaplogger/message.h>
41 :
42 :
43 :
44 1 : CATCH_TEST_CASE("utils", "[string]")
45 : {
46 1 : CATCH_START_SECTION("utils: decode percents")
47 : {
48 : struct in_out_t
49 : {
50 : std::string f_in = std::string();
51 : std::string f_out = std::string();
52 : };
53 1 : in_out_t in_out[]
54 : {
55 : {
56 : .f_in = "test",
57 : .f_out = "test",
58 : },
59 : {
60 : .f_in = "tab%09",
61 : .f_out = "tab\t",
62 : },
63 : {
64 : .f_in = "%283%20+%201%29%20*%205",
65 : .f_out = "(3 + 1) * 5",
66 : },
67 6 : };
68 4 : for(auto const & io : in_out)
69 : {
70 3 : std::string out;
71 3 : CATCH_REQUIRE(edhttp::decode_percents(io.f_in, out));
72 3 : CATCH_REQUIRE(io.f_out == out);
73 3 : }
74 4 : }
75 2 : CATCH_END_SECTION()
76 1 : }
77 :
78 :
79 1 : CATCH_TEST_CASE("utils_error", "[string][error]")
80 : {
81 1 : CATCH_START_SECTION("utils_error: invalid percent decoding")
82 : {
83 1 : std::string out;
84 3 : CATCH_REQUIRE_FALSE(edhttp::decode_percents("%error", out));
85 3 : CATCH_REQUIRE_FALSE(edhttp::decode_percents("%ff", out));
86 3 : CATCH_REQUIRE_FALSE(edhttp::decode_percents("%0f", out));
87 1 : }
88 2 : CATCH_END_SECTION()
89 1 : }
90 :
91 :
92 :
93 : // vim: ts=4 sw=4 et
|