]>
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 "http/RequestMethod.h"
8 #include "SquidConfig.h"
9 #include "testHttpRequestMethod.h"
13 CPPUNIT_TEST_SUITE_REGISTRATION( testHttpRequestMethod
);
16 * We should be able to make an HttpRequestMethod straight from a string.
19 testHttpRequestMethod::testConstructCharStart()
21 /* parse an empty string -> Http::METHOD_NONE */
22 CPPUNIT_ASSERT(HttpRequestMethod(NULL
) == Http::METHOD_NONE
);
23 /* parsing a literal should work */
24 CPPUNIT_ASSERT(HttpRequestMethod("GET") == Http::METHOD_GET
);
25 CPPUNIT_ASSERT(HttpRequestMethod("QWERTY") == Http::METHOD_OTHER
);
29 * We can also parse precise ranges of characters
32 testHttpRequestMethod::testConstructCharStartEnd()
35 /* parse an empty string -> Http::METHOD_NONE */
36 CPPUNIT_ASSERT(HttpRequestMethod(NULL
) == Http::METHOD_NONE
);
37 /* parsing a literal should work */
38 CPPUNIT_ASSERT(HttpRequestMethod("GET") == Http::METHOD_GET
);
39 /* parsing with an explicit end should work */
41 CPPUNIT_ASSERT(HttpRequestMethod(SBuf(buffer
, 4)) == Http::METHOD_POST
);
45 * we should be able to assign a Http::MethodType to a HttpRequestMethod
48 testHttpRequestMethod::testAssignFrommethod_t()
50 HttpRequestMethod method
;
51 method
= Http::METHOD_NONE
;
52 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(Http::METHOD_NONE
), method
);
53 method
= Http::METHOD_POST
;
54 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(Http::METHOD_POST
), method
);
58 * a default constructed HttpRequestMethod is == Http::METHOD_NONE
61 testHttpRequestMethod::testDefaultConstructor()
63 HttpRequestMethod lhs
;
64 HttpRequestMethod
rhs(Http::METHOD_NONE
);
65 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
69 * we should be able to construct a HttpRequestMethod from a Http::MethodType
72 testHttpRequestMethod::testConstructmethod_t()
74 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(Http::METHOD_NONE
), HttpRequestMethod(Http::METHOD_NONE
));
75 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(Http::METHOD_POST
), HttpRequestMethod(Http::METHOD_POST
));
76 CPPUNIT_ASSERT(HttpRequestMethod(Http::METHOD_NONE
) != HttpRequestMethod(Http::METHOD_POST
));
80 * we should be able to get a char const * version of the method.
83 testHttpRequestMethod::testImage()
85 // relaxed RFC-compliance parse HTTP methods are upgraded to correct case
86 Config
.onoff
.relaxed_header_parser
= 1;
87 CPPUNIT_ASSERT_EQUAL(SBuf("POST"), HttpRequestMethod("POST").image());
88 CPPUNIT_ASSERT_EQUAL(SBuf("POST"), HttpRequestMethod("pOsT").image());
89 CPPUNIT_ASSERT_EQUAL(SBuf("POST"), HttpRequestMethod("post").image());
91 // strict RFC-compliance parse HTTP methods are case sensitive
92 Config
.onoff
.relaxed_header_parser
= 0;
93 CPPUNIT_ASSERT_EQUAL(SBuf("POST"), HttpRequestMethod("POST").image());
94 CPPUNIT_ASSERT_EQUAL(SBuf("pOsT"), HttpRequestMethod("pOsT").image());
95 CPPUNIT_ASSERT_EQUAL(SBuf("post"), HttpRequestMethod("post").image());
99 * an HttpRequestMethod should be comparable to a Http::MethodType without false
103 testHttpRequestMethod::testEqualmethod_t()
105 CPPUNIT_ASSERT(HttpRequestMethod(Http::METHOD_NONE
) == Http::METHOD_NONE
);
106 CPPUNIT_ASSERT(not (HttpRequestMethod(Http::METHOD_POST
) == Http::METHOD_GET
));
107 CPPUNIT_ASSERT(HttpRequestMethod(Http::METHOD_GET
) == Http::METHOD_GET
);
108 CPPUNIT_ASSERT(not (HttpRequestMethod(Http::METHOD_TRACE
) == Http::METHOD_SEARCH
));
112 * an HttpRequestMethod should testable for inequality without fail maatches
115 testHttpRequestMethod::testNotEqualmethod_t()
117 CPPUNIT_ASSERT(HttpRequestMethod(Http::METHOD_NONE
) != Http::METHOD_GET
);
118 CPPUNIT_ASSERT(not (HttpRequestMethod(Http::METHOD_POST
) != Http::METHOD_POST
));
119 CPPUNIT_ASSERT(HttpRequestMethod(Http::METHOD_GET
) != Http::METHOD_NONE
);
120 CPPUNIT_ASSERT(not (HttpRequestMethod(Http::METHOD_SEARCH
) != Http::METHOD_SEARCH
));
124 * we should be able to send it to a stream and get the normalised version
127 testHttpRequestMethod::testStream()
129 // relaxed RFC-compliance parse HTTP methods are upgraded to correct case
130 Config
.onoff
.relaxed_header_parser
= 1;
131 std::ostringstream buffer
;
132 buffer
<< HttpRequestMethod("get");
133 CPPUNIT_ASSERT_EQUAL(String("GET"), String(buffer
.str().c_str()));
135 // strict RFC-compliance parse HTTP methods are case sensitive
136 Config
.onoff
.relaxed_header_parser
= 0;
137 std::ostringstream buffer2
;
138 buffer2
<< HttpRequestMethod("get");
139 CPPUNIT_ASSERT_EQUAL(String("get"), String(buffer2
.str().c_str()));