]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testHttpRequestMethod.cc
2 #include <cppunit/TestAssert.h>
4 #include "HttpRequestMethod.h"
6 #include "SquidConfig.h"
7 #include "testHttpRequestMethod.h"
11 CPPUNIT_TEST_SUITE_REGISTRATION( testHttpRequestMethod
);
14 * We should be able to make an HttpRequestMethod straight from a string.
17 testHttpRequestMethod::testConstructCharStart()
19 /* parse an empty string -> Http::METHOD_NONE */
20 CPPUNIT_ASSERT(HttpRequestMethod(NULL
,NULL
) == Http::METHOD_NONE
);
21 /* parsing a literal should work */
22 CPPUNIT_ASSERT(HttpRequestMethod("GET", NULL
) == Http::METHOD_GET
);
23 CPPUNIT_ASSERT(HttpRequestMethod("QWERTY", NULL
) == Http::METHOD_OTHER
);
27 * We can also parse precise ranges of characters
30 testHttpRequestMethod::testConstructCharStartEnd()
33 /* parse an empty string -> Http::METHOD_NONE */
34 CPPUNIT_ASSERT(HttpRequestMethod(NULL
, NULL
) == Http::METHOD_NONE
);
35 /* parsing a literal should work */
36 CPPUNIT_ASSERT(HttpRequestMethod("GET", NULL
) == Http::METHOD_GET
);
37 /* parsing with an explicit end should work */
39 CPPUNIT_ASSERT(HttpRequestMethod(buffer
, buffer
+ 4) == Http::METHOD_POST
);
43 * we should be able to assign a Http::MethodType to a HttpRequestMethod
46 testHttpRequestMethod::testAssignFrommethod_t()
48 HttpRequestMethod method
;
49 method
= Http::METHOD_NONE
;
50 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(Http::METHOD_NONE
), method
);
51 method
= Http::METHOD_POST
;
52 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(Http::METHOD_POST
), method
);
56 * a default constructed HttpRequestMethod is == Http::METHOD_NONE
59 testHttpRequestMethod::testDefaultConstructor()
61 HttpRequestMethod lhs
;
62 HttpRequestMethod
rhs(Http::METHOD_NONE
);
63 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
67 * we should be able to construct a HttpRequestMethod from a Http::MethodType
70 testHttpRequestMethod::testConstructmethod_t()
72 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(Http::METHOD_NONE
), HttpRequestMethod(Http::METHOD_NONE
));
73 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(Http::METHOD_POST
), HttpRequestMethod(Http::METHOD_POST
));
74 CPPUNIT_ASSERT(HttpRequestMethod(Http::METHOD_NONE
) != HttpRequestMethod(Http::METHOD_POST
));
78 * we should be able to get a char const * version of the method.
81 testHttpRequestMethod::testImage()
83 // relaxed RFC-compliance parse HTTP methods are upgraded to correct case
84 Config
.onoff
.relaxed_header_parser
= 1;
85 CPPUNIT_ASSERT_EQUAL(SBuf("POST"), HttpRequestMethod("POST",NULL
).image());
86 CPPUNIT_ASSERT_EQUAL(SBuf("POST"), HttpRequestMethod("pOsT",NULL
).image());
87 CPPUNIT_ASSERT_EQUAL(SBuf("POST"), HttpRequestMethod("post",NULL
).image());
89 // strict RFC-compliance parse HTTP methods are case sensitive
90 Config
.onoff
.relaxed_header_parser
= 0;
91 CPPUNIT_ASSERT_EQUAL(SBuf("POST"), HttpRequestMethod("POST",NULL
).image());
92 CPPUNIT_ASSERT_EQUAL(SBuf("pOsT"), HttpRequestMethod("pOsT",NULL
).image());
93 CPPUNIT_ASSERT_EQUAL(SBuf("post"), HttpRequestMethod("post",NULL
).image());
97 * an HttpRequestMethod should be comparable to a Http::MethodType without false
101 testHttpRequestMethod::testEqualmethod_t()
103 CPPUNIT_ASSERT(HttpRequestMethod(Http::METHOD_NONE
) == Http::METHOD_NONE
);
104 CPPUNIT_ASSERT(not (HttpRequestMethod(Http::METHOD_POST
) == Http::METHOD_GET
));
105 CPPUNIT_ASSERT(HttpRequestMethod(Http::METHOD_GET
) == Http::METHOD_GET
);
106 CPPUNIT_ASSERT(not (HttpRequestMethod(Http::METHOD_TRACE
) == Http::METHOD_SEARCH
));
110 * an HttpRequestMethod should testable for inequality without fail maatches
113 testHttpRequestMethod::testNotEqualmethod_t()
115 CPPUNIT_ASSERT(HttpRequestMethod(Http::METHOD_NONE
) != Http::METHOD_GET
);
116 CPPUNIT_ASSERT(not (HttpRequestMethod(Http::METHOD_POST
) != Http::METHOD_POST
));
117 CPPUNIT_ASSERT(HttpRequestMethod(Http::METHOD_GET
) != Http::METHOD_NONE
);
118 CPPUNIT_ASSERT(not (HttpRequestMethod(Http::METHOD_SEARCH
) != Http::METHOD_SEARCH
));
122 * we should be able to send it to a stream and get the normalised version
125 testHttpRequestMethod::testStream()
127 // relaxed RFC-compliance parse HTTP methods are upgraded to correct case
128 Config
.onoff
.relaxed_header_parser
= 1;
129 std::ostringstream buffer
;
130 buffer
<< HttpRequestMethod("get", NULL
);
131 CPPUNIT_ASSERT_EQUAL(String("GET"), String(buffer
.str().c_str()));
133 // strict RFC-compliance parse HTTP methods are case sensitive
134 Config
.onoff
.relaxed_header_parser
= 0;
135 std::ostringstream buffer2
;
136 buffer2
<< HttpRequestMethod("get", NULL
);
137 CPPUNIT_ASSERT_EQUAL(String("get"), String(buffer2
.str().c_str()));