]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testHttpRequestMethod.cc
1 #define SQUID_UNIT_TEST 1
4 #include <cppunit/TestAssert.h>
6 #include "HttpRequestMethod.h"
8 #include "SquidConfig.h"
9 #include "testHttpRequestMethod.h"
15 CPPUNIT_TEST_SUITE_REGISTRATION( testHttpRequestMethod
);
18 * We should be able to make an HttpRequestMethod straight from a string.
21 testHttpRequestMethod::testConstructCharStart()
23 /* parse an empty string -> Http::METHOD_NONE */
24 CPPUNIT_ASSERT(HttpRequestMethod(NULL
,NULL
) == Http::METHOD_NONE
);
25 /* parsing a literal should work */
26 CPPUNIT_ASSERT(HttpRequestMethod("GET", NULL
) == Http::METHOD_GET
);
27 CPPUNIT_ASSERT(HttpRequestMethod("QWERTY", NULL
) == Http::METHOD_OTHER
);
31 * We can also parse precise ranges of characters
34 testHttpRequestMethod::testConstructCharStartEnd()
37 /* parse an empty string -> Http::METHOD_NONE */
38 CPPUNIT_ASSERT(HttpRequestMethod(NULL
, NULL
) == Http::METHOD_NONE
);
39 /* parsing a literal should work */
40 CPPUNIT_ASSERT(HttpRequestMethod("GET", NULL
) == Http::METHOD_GET
);
41 /* parsing with an explicit end should work */
43 CPPUNIT_ASSERT(HttpRequestMethod(buffer
, buffer
+ 4) == Http::METHOD_POST
);
47 * we should be able to assign a Http::MethodType to a HttpRequestMethod
50 testHttpRequestMethod::testAssignFrommethod_t()
52 HttpRequestMethod method
;
53 method
= Http::METHOD_NONE
;
54 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(Http::METHOD_NONE
), method
);
55 method
= Http::METHOD_POST
;
56 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(Http::METHOD_POST
), method
);
60 * a default constructed HttpRequestMethod is == Http::METHOD_NONE
63 testHttpRequestMethod::testDefaultConstructor()
65 HttpRequestMethod lhs
;
66 HttpRequestMethod
rhs(Http::METHOD_NONE
);
67 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
71 * we should be able to construct a HttpRequestMethod from a Http::MethodType
74 testHttpRequestMethod::testConstructmethod_t()
76 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(Http::METHOD_NONE
), HttpRequestMethod(Http::METHOD_NONE
));
77 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(Http::METHOD_POST
), HttpRequestMethod(Http::METHOD_POST
));
78 CPPUNIT_ASSERT(HttpRequestMethod(Http::METHOD_NONE
) != HttpRequestMethod(Http::METHOD_POST
));
82 * we should be able to get a char const * version of the method.
85 testHttpRequestMethod::testImage()
87 // relaxed RFC-compliance parse HTTP methods are upgraded to correct case
88 Config
.onoff
.relaxed_header_parser
= 1;
89 CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("POST",NULL
).image()));
90 CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("pOsT",NULL
).image()));
91 CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("post",NULL
).image()));
93 // strict RFC-compliance parse HTTP methods are case sensitive
94 Config
.onoff
.relaxed_header_parser
= 0;
95 CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("POST",NULL
).image()));
96 CPPUNIT_ASSERT_EQUAL(String("pOsT"), String(HttpRequestMethod("pOsT",NULL
).image()));
97 CPPUNIT_ASSERT_EQUAL(String("post"), String(HttpRequestMethod("post",NULL
).image()));
101 * an HttpRequestMethod should be comparable to a Http::MethodType without false
105 testHttpRequestMethod::testEqualmethod_t()
107 CPPUNIT_ASSERT(HttpRequestMethod(Http::METHOD_NONE
) == Http::METHOD_NONE
);
108 CPPUNIT_ASSERT(not (HttpRequestMethod(Http::METHOD_POST
) == Http::METHOD_GET
));
109 CPPUNIT_ASSERT(HttpRequestMethod(Http::METHOD_GET
) == Http::METHOD_GET
);
110 CPPUNIT_ASSERT(not (HttpRequestMethod(Http::METHOD_TRACE
) == Http::METHOD_SEARCH
));
114 * an HttpRequestMethod should testable for inequality without fail maatches
117 testHttpRequestMethod::testNotEqualmethod_t()
119 CPPUNIT_ASSERT(HttpRequestMethod(Http::METHOD_NONE
) != Http::METHOD_GET
);
120 CPPUNIT_ASSERT(not (HttpRequestMethod(Http::METHOD_POST
) != Http::METHOD_POST
));
121 CPPUNIT_ASSERT(HttpRequestMethod(Http::METHOD_GET
) != Http::METHOD_NONE
);
122 CPPUNIT_ASSERT(not (HttpRequestMethod(Http::METHOD_SEARCH
) != Http::METHOD_SEARCH
));
126 * we should be able to send it to a stream and get the normalised version
129 testHttpRequestMethod::testStream()
131 // relaxed RFC-compliance parse HTTP methods are upgraded to correct case
132 Config
.onoff
.relaxed_header_parser
= 1;
133 std::ostringstream buffer
;
134 buffer
<< HttpRequestMethod("get", NULL
);
135 CPPUNIT_ASSERT_EQUAL(String("GET"), String(buffer
.str().c_str()));
137 // strict RFC-compliance parse HTTP methods are case sensitive
138 Config
.onoff
.relaxed_header_parser
= 0;
139 std::ostringstream buffer2
;
140 buffer2
<< HttpRequestMethod("get", NULL
);
141 CPPUNIT_ASSERT_EQUAL(String("get"), String(buffer2
.str().c_str()));