diff options
Diffstat (limited to 'src/microhttpd/test_http_reasons.c')
-rw-r--r-- | src/microhttpd/test_http_reasons.c | 124 |
1 files changed, 65 insertions, 59 deletions
diff --git a/src/microhttpd/test_http_reasons.c b/src/microhttpd/test_http_reasons.c index 62721439..4d0484ad 100644 --- a/src/microhttpd/test_http_reasons.c +++ b/src/microhttpd/test_http_reasons.c | |||
@@ -28,105 +28,111 @@ | |||
28 | #include "microhttpd.h" | 28 | #include "microhttpd.h" |
29 | #include "mhd_str.h" | 29 | #include "mhd_str.h" |
30 | 30 | ||
31 | static int expect_result(int code, const char* expected) | 31 | static int expect_result (int code, const char*expected) |
32 | { | 32 | { |
33 | const char* const reason = MHD_get_reason_phrase_for(code); | 33 | const char*const reason = MHD_get_reason_phrase_for (code); |
34 | if (MHD_str_equal_caseless_(reason, expected)) | 34 | if (MHD_str_equal_caseless_ (reason, expected)) |
35 | return 0; | 35 | return 0; |
36 | fprintf(stderr, "Incorrect reason returned for code %d:\n Returned: \"%s\" \tExpected: \"%s\"\n", | 36 | fprintf (stderr, |
37 | code, reason, expected); | 37 | "Incorrect reason returned for code %d:\n Returned: \"%s\" \tExpected: \"%s\"\n", |
38 | code, reason, expected); | ||
38 | return 1; | 39 | return 1; |
39 | } | 40 | } |
40 | 41 | ||
41 | static int expect_absent(int code) | 42 | static int expect_absent (int code) |
42 | { | 43 | { |
43 | return expect_result(code, "unknown"); | 44 | return expect_result (code, "unknown"); |
44 | } | 45 | } |
45 | 46 | ||
46 | static int test_absent_codes(void) | 47 | static int test_absent_codes (void) |
47 | { | 48 | { |
48 | int errcount = 0; | 49 | int errcount = 0; |
49 | errcount += expect_absent(0); | 50 | errcount += expect_absent (0); |
50 | errcount += expect_absent(1); | 51 | errcount += expect_absent (1); |
51 | errcount += expect_absent(50); | 52 | errcount += expect_absent (50); |
52 | errcount += expect_absent(99); | 53 | errcount += expect_absent (99); |
53 | errcount += expect_absent(600); | 54 | errcount += expect_absent (600); |
54 | errcount += expect_absent(601); | 55 | errcount += expect_absent (601); |
55 | errcount += expect_absent(900); | 56 | errcount += expect_absent (900); |
56 | errcount += expect_absent(10000); | 57 | errcount += expect_absent (10000); |
57 | return errcount; | 58 | return errcount; |
58 | } | 59 | } |
59 | 60 | ||
60 | static int test_1xx(void) | 61 | static int test_1xx (void) |
61 | { | 62 | { |
62 | int errcount = 0; | 63 | int errcount = 0; |
63 | errcount += expect_result(MHD_HTTP_CONTINUE, "continue"); | 64 | errcount += expect_result (MHD_HTTP_CONTINUE, "continue"); |
64 | errcount += expect_result(MHD_HTTP_PROCESSING, "processing"); | 65 | errcount += expect_result (MHD_HTTP_PROCESSING, "processing"); |
65 | errcount += expect_absent(110); | 66 | errcount += expect_absent (110); |
66 | errcount += expect_absent(190); | 67 | errcount += expect_absent (190); |
67 | return errcount; | 68 | return errcount; |
68 | } | 69 | } |
69 | 70 | ||
70 | static int test_2xx(void) | 71 | static int test_2xx (void) |
71 | { | 72 | { |
72 | int errcount = 0; | 73 | int errcount = 0; |
73 | errcount += expect_result(MHD_HTTP_OK, "ok"); | 74 | errcount += expect_result (MHD_HTTP_OK, "ok"); |
74 | errcount += expect_result(MHD_HTTP_ALREADY_REPORTED, "already reported"); | 75 | errcount += expect_result (MHD_HTTP_ALREADY_REPORTED, "already reported"); |
75 | errcount += expect_absent(217); | 76 | errcount += expect_absent (217); |
76 | errcount += expect_result(MHD_HTTP_IM_USED, "im used"); | 77 | errcount += expect_result (MHD_HTTP_IM_USED, "im used"); |
77 | errcount += expect_absent(230); | 78 | errcount += expect_absent (230); |
78 | errcount += expect_absent(295); | 79 | errcount += expect_absent (295); |
79 | return errcount; | 80 | return errcount; |
80 | } | 81 | } |
81 | 82 | ||
82 | static int test_3xx(void) | 83 | static int test_3xx (void) |
83 | { | 84 | { |
84 | int errcount = 0; | 85 | int errcount = 0; |
85 | errcount += expect_result(MHD_HTTP_MULTIPLE_CHOICES, "multiple choices"); | 86 | 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_SEE_OTHER, "see other"); |
87 | errcount += expect_result(MHD_HTTP_PERMANENT_REDIRECT, "permanent redirect"); | 88 | errcount += expect_result (MHD_HTTP_PERMANENT_REDIRECT, "permanent redirect"); |
88 | errcount += expect_absent(311); | 89 | errcount += expect_absent (311); |
89 | errcount += expect_absent(399); | 90 | errcount += expect_absent (399); |
90 | return errcount; | 91 | return errcount; |
91 | } | 92 | } |
92 | 93 | ||
93 | static int test_4xx(void) | 94 | static int test_4xx (void) |
94 | { | 95 | { |
95 | int errcount = 0; | 96 | int errcount = 0; |
96 | errcount += expect_result(MHD_HTTP_BAD_REQUEST, "bad request"); | 97 | 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_NOT_FOUND, "not found"); |
98 | errcount += expect_result(MHD_HTTP_URI_TOO_LONG, "uri too long"); | 99 | 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_EXPECTATION_FAILED, "expectation failed"); |
100 | errcount += expect_result(MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE, "request header fields too large"); | 101 | errcount += expect_result (MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE, |
101 | errcount += expect_absent(441); | 102 | "request header fields too large"); |
102 | errcount += expect_result(MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS, "unavailable for legal reasons"); | 103 | errcount += expect_absent (441); |
103 | errcount += expect_absent(470); | 104 | errcount += expect_result (MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS, |
104 | errcount += expect_absent(493); | 105 | "unavailable for legal reasons"); |
106 | errcount += expect_absent (470); | ||
107 | errcount += expect_absent (493); | ||
105 | return errcount; | 108 | return errcount; |
106 | } | 109 | } |
107 | 110 | ||
108 | static int test_5xx(void) | 111 | static int test_5xx (void) |
109 | { | 112 | { |
110 | int errcount = 0; | 113 | int errcount = 0; |
111 | errcount += expect_result(MHD_HTTP_INTERNAL_SERVER_ERROR, "internal server error"); | 114 | errcount += expect_result (MHD_HTTP_INTERNAL_SERVER_ERROR, |
112 | errcount += expect_result(MHD_HTTP_BAD_GATEWAY, "bad gateway"); | 115 | "internal server error"); |
113 | errcount += expect_result(MHD_HTTP_HTTP_VERSION_NOT_SUPPORTED, "http version not supported"); | 116 | errcount += expect_result (MHD_HTTP_BAD_GATEWAY, "bad gateway"); |
114 | errcount += expect_result(MHD_HTTP_NETWORK_AUTHENTICATION_REQUIRED, "network authentication required"); | 117 | errcount += expect_result (MHD_HTTP_HTTP_VERSION_NOT_SUPPORTED, |
115 | errcount += expect_absent(520); | 118 | "http version not supported"); |
116 | errcount += expect_absent(597); | 119 | errcount += expect_result (MHD_HTTP_NETWORK_AUTHENTICATION_REQUIRED, |
120 | "network authentication required"); | ||
121 | errcount += expect_absent (520); | ||
122 | errcount += expect_absent (597); | ||
117 | return errcount; | 123 | return errcount; |
118 | } | 124 | } |
119 | 125 | ||
120 | int main(int argc, char * argv[]) | 126 | int main (int argc, char *argv[]) |
121 | { | 127 | { |
122 | int errcount = 0; | 128 | int errcount = 0; |
123 | (void)argc; (void)argv; /* Unused. Silent compiler warning. */ | 129 | (void) argc; (void) argv; /* Unused. Silent compiler warning. */ |
124 | 130 | ||
125 | errcount += test_absent_codes(); | 131 | errcount += test_absent_codes (); |
126 | errcount += test_1xx(); | 132 | errcount += test_1xx (); |
127 | errcount += test_2xx(); | 133 | errcount += test_2xx (); |
128 | errcount += test_3xx(); | 134 | errcount += test_3xx (); |
129 | errcount += test_4xx(); | 135 | errcount += test_4xx (); |
130 | errcount += test_5xx(); | 136 | errcount += test_5xx (); |
131 | return errcount == 0 ? 0 : 1; | 137 | return errcount == 0 ? 0 : 1; |
132 | } | 138 | } |