diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2017-04-26 15:19:20 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2017-04-26 15:22:46 +0300 |
commit | ccfe7bafafbca43b94cf3d1c75144f51d57a5386 (patch) | |
tree | c2673e26a3035fd395a158257064596c301de49c /src | |
parent | b4a7abf366b0b05a8a468d48f37b4eeb86130772 (diff) | |
download | libmicrohttpd-ccfe7bafafbca43b94cf3d1c75144f51d57a5386.tar.gz libmicrohttpd-ccfe7bafafbca43b94cf3d1c75144f51d57a5386.zip |
reason_phrase.c: Fixed shift in HTTP reasons strings.
Added test for HTTP reasons strings.
Diffstat (limited to 'src')
-rw-r--r-- | src/microhttpd/Makefile.am | 5 | ||||
-rw-r--r-- | src/microhttpd/reason_phrase.c | 1 | ||||
-rw-r--r-- | src/microhttpd/test_http_reasons.c | 131 |
3 files changed, 136 insertions, 1 deletions
diff --git a/src/microhttpd/Makefile.am b/src/microhttpd/Makefile.am index 7573fa7a..8cffd29d 100644 --- a/src/microhttpd/Makefile.am +++ b/src/microhttpd/Makefile.am | |||
@@ -142,6 +142,7 @@ endif | |||
142 | check_PROGRAMS = \ | 142 | check_PROGRAMS = \ |
143 | test_str_compare \ | 143 | test_str_compare \ |
144 | test_str_to_value \ | 144 | test_str_to_value \ |
145 | test_http_reasons \ | ||
145 | test_shutdown_select \ | 146 | test_shutdown_select \ |
146 | test_shutdown_poll \ | 147 | test_shutdown_poll \ |
147 | test_daemon | 148 | test_daemon |
@@ -249,3 +250,7 @@ test_str_compare_SOURCES = \ | |||
249 | 250 | ||
250 | test_str_to_value_SOURCES = \ | 251 | test_str_to_value_SOURCES = \ |
251 | test_str.c test_helpers.h mhd_str.c | 252 | test_str.c test_helpers.h mhd_str.c |
253 | |||
254 | test_http_reasons_SOURCES = \ | ||
255 | test_http_reasons.c \ | ||
256 | reason_phrase.c microhttpd.h mhd_str.c mhd_str.h | ||
diff --git a/src/microhttpd/reason_phrase.c b/src/microhttpd/reason_phrase.c index d2cd152f..a6ffc75f 100644 --- a/src/microhttpd/reason_phrase.c +++ b/src/microhttpd/reason_phrase.c | |||
@@ -74,7 +74,6 @@ static const char *const two_hundred[] = { | |||
74 | static const char *const three_hundred[] = { | 74 | static const char *const three_hundred[] = { |
75 | "Multiple Choices", | 75 | "Multiple Choices", |
76 | "Moved Permanently", | 76 | "Moved Permanently", |
77 | "Moved Temporarily", | ||
78 | "Found", | 77 | "Found", |
79 | "See Other", | 78 | "See Other", |
80 | "Not Modified", | 79 | "Not Modified", |
diff --git a/src/microhttpd/test_http_reasons.c b/src/microhttpd/test_http_reasons.c new file mode 100644 index 00000000..1a78e2c6 --- /dev/null +++ b/src/microhttpd/test_http_reasons.c | |||
@@ -0,0 +1,131 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | Copyright (C) 2017 Karlson2k (Evgeny Grin) | ||
4 | |||
5 | This test tool is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU General Public License as | ||
7 | published by the Free Software Foundation; either version 2, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This test tool is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | */ | ||
19 | |||
20 | /** | ||
21 | * @file microhttpd/test_http_reasons.c | ||
22 | * @brief Unit tests for MHD_get_reason_phrase_for() function | ||
23 | * @author Karlson2k (Evgeny Grin) | ||
24 | */ | ||
25 | |||
26 | #include "mhd_options.h" | ||
27 | #include <stdio.h> | ||
28 | #include "microhttpd.h" | ||
29 | #include "mhd_str.h" | ||
30 | |||
31 | static int expect_result(int code, const char* expected) | ||
32 | { | ||
33 | const char* const reason = MHD_get_reason_phrase_for(code); | ||
34 | if (MHD_str_equal_caseless_(reason, expected)) | ||
35 | return 0; | ||
36 | fprintf(stderr, "Incorrect reason returned for code %d:\n Returned: \"%s\" \tExpected: \"%s\"\n", | ||
37 | code, reason, expected); | ||
38 | return 1; | ||
39 | } | ||
40 | |||
41 | static int expect_absent(int code) | ||
42 | { | ||
43 | return expect_result(code, "unknown"); | ||
44 | } | ||
45 | |||
46 | static int test_absent_codes(void) | ||
47 | { | ||
48 | int errcount = 0; | ||
49 | errcount += expect_absent(0); | ||
50 | errcount += expect_absent(1); | ||
51 | errcount += expect_absent(50); | ||
52 | errcount += expect_absent(99); | ||
53 | errcount += expect_absent(600); | ||
54 | errcount += expect_absent(601); | ||
55 | errcount += expect_absent(900); | ||
56 | errcount += expect_absent(10000); | ||
57 | return errcount; | ||
58 | } | ||
59 | |||
60 | static int test_1xx(void) | ||
61 | { | ||
62 | int errcount = 0; | ||
63 | errcount += expect_result(MHD_HTTP_CONTINUE, "continue"); | ||
64 | errcount += expect_result(MHD_HTTP_PROCESSING, "processing"); | ||
65 | errcount += expect_absent(110); | ||
66 | errcount += expect_absent(190); | ||
67 | return errcount; | ||
68 | } | ||
69 | |||
70 | static int test_2xx(void) | ||
71 | { | ||
72 | int errcount = 0; | ||
73 | errcount += expect_result(MHD_HTTP_OK, "ok"); | ||
74 | errcount += expect_result(MHD_HTTP_ALREADY_REPORTED, "already reported"); | ||
75 | errcount += expect_absent(217); | ||
76 | errcount += expect_result(MHD_HTTP_IM_USED, "im used"); | ||
77 | errcount += expect_absent(230); | ||
78 | errcount += expect_absent(295); | ||
79 | return errcount; | ||
80 | } | ||
81 | |||
82 | static int test_3xx(void) | ||
83 | { | ||
84 | int errcount = 0; | ||
85 | errcount += expect_result(MHD_HTTP_MULTIPLE_CHOICES, "multiple choices"); | ||
86 | errcount += expect_result(MHD_HTTP_SEE_OTHER, "see other"); | ||
87 | errcount += expect_result(MHD_HTTP_PERMANENT_REDIRECT, "permanent redirect"); | ||
88 | errcount += expect_absent(311); | ||
89 | errcount += expect_absent(399); | ||
90 | return errcount; | ||
91 | } | ||
92 | |||
93 | static int test_4xx(void) | ||
94 | { | ||
95 | int errcount = 0; | ||
96 | errcount += expect_result(MHD_HTTP_BAD_REQUEST, "bad request"); | ||
97 | errcount += expect_result(MHD_HTTP_NOT_FOUND, "not found"); | ||
98 | errcount += expect_result(MHD_HTTP_URI_TOO_LONG, "uri too long"); | ||
99 | errcount += expect_result(MHD_HTTP_EXPECTATION_FAILED, "expectation failed"); | ||
100 | errcount += expect_result(MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE, "request header fields too large"); | ||
101 | errcount += expect_absent(441); | ||
102 | errcount += expect_result(MHD_HTTP_NO_RESPONSE, "no response"); | ||
103 | errcount += expect_result(MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS, "unavailable for legal reasons"); | ||
104 | errcount += expect_absent(470); | ||
105 | errcount += expect_absent(493); | ||
106 | return errcount; | ||
107 | } | ||
108 | |||
109 | static int test_5xx(void) | ||
110 | { | ||
111 | int errcount = 0; | ||
112 | errcount += expect_result(MHD_HTTP_INTERNAL_SERVER_ERROR, "internal server error"); | ||
113 | errcount += expect_result(MHD_HTTP_BAD_GATEWAY, "bad gateway"); | ||
114 | errcount += expect_result(MHD_HTTP_HTTP_VERSION_NOT_SUPPORTED, "http version not supported"); | ||
115 | errcount += expect_result(MHD_HTTP_NETWORK_AUTHENTICATION_REQUIRED, "network authentication required"); | ||
116 | errcount += expect_absent(520); | ||
117 | errcount += expect_absent(597); | ||
118 | return errcount; | ||
119 | } | ||
120 | |||
121 | int main(int argc, char * argv[]) | ||
122 | { | ||
123 | int errcount = 0; | ||
124 | errcount += test_absent_codes(); | ||
125 | errcount += test_1xx(); | ||
126 | errcount += test_2xx(); | ||
127 | errcount += test_3xx(); | ||
128 | errcount += test_4xx(); | ||
129 | errcount += test_5xx(); | ||
130 | return errcount == 0 ? 0 : 1; | ||
131 | } | ||