]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testHttpRequestMethod.cc
1 #define SQUID_UNIT_TEST 1
4 #include <cppunit/TestAssert.h>
7 #include "testHttpRequestMethod.h"
8 #include "HttpRequestMethod.h"
14 CPPUNIT_TEST_SUITE_REGISTRATION( testHttpRequestMethod
);
17 * We should be able to make an HttpRequestMethod straight from a string.
20 testHttpRequestMethod::testConstructCharStart()
22 /* parse an empty string -> Http::METHOD_NONE */
23 CPPUNIT_ASSERT(HttpRequestMethod(NULL
,NULL
) == Http::METHOD_NONE
);
24 /* parsing a literal should work */
25 CPPUNIT_ASSERT(HttpRequestMethod("GET", NULL
) == Http::METHOD_GET
);
26 CPPUNIT_ASSERT(HttpRequestMethod("QWERTY", NULL
) == Http::METHOD_OTHER
);
30 * We can also parse precise ranges of characters
33 testHttpRequestMethod::testConstructCharStartEnd()
36 /* parse an empty string -> Http::METHOD_NONE */
37 CPPUNIT_ASSERT(HttpRequestMethod(NULL
, NULL
) == Http::METHOD_NONE
);
38 /* parsing a literal should work */
39 CPPUNIT_ASSERT(HttpRequestMethod("GET", NULL
) == Http::METHOD_GET
);
40 /* parsing with an explicit end should work */
42 CPPUNIT_ASSERT(HttpRequestMethod(buffer
, buffer
+ 4) == Http::METHOD_POST
);
46 * we should be able to assign a Http::MethodType to a HttpRequestMethod
49 testHttpRequestMethod::testAssignFrommethod_t()
51 HttpRequestMethod method
;
52 method
= Http::METHOD_NONE
;
53 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(Http::METHOD_NONE
), method
);
54 method
= Http::METHOD_POST
;
55 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(Http::METHOD_POST
), method
);
59 * a default constructed HttpRequestMethod is == Http::METHOD_NONE
62 testHttpRequestMethod::testDefaultConstructor()
64 HttpRequestMethod lhs
;
65 HttpRequestMethod
rhs(Http::METHOD_NONE
);
66 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
70 * we should be able to construct a HttpRequestMethod from a Http::MethodType
73 testHttpRequestMethod::testConstructmethod_t()
75 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(Http::METHOD_NONE
), HttpRequestMethod(Http::METHOD_NONE
));
76 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(Http::METHOD_POST
), HttpRequestMethod(Http::METHOD_POST
));
77 CPPUNIT_ASSERT(HttpRequestMethod(Http::METHOD_NONE
) != HttpRequestMethod(Http::METHOD_POST
));
81 * we should be able to get a char const * version of the method.
84 testHttpRequestMethod::testImage()
86 CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("post",NULL
).image()));
90 * an HttpRequestMethod should be comparable to a Http::MethodType without false
94 testHttpRequestMethod::testEqualmethod_t()
96 CPPUNIT_ASSERT(HttpRequestMethod(Http::METHOD_NONE
) == Http::METHOD_NONE
);
97 CPPUNIT_ASSERT(not (HttpRequestMethod(Http::METHOD_POST
) == Http::METHOD_GET
));
98 CPPUNIT_ASSERT(HttpRequestMethod(Http::METHOD_GET
) == Http::METHOD_GET
);
99 CPPUNIT_ASSERT(not (HttpRequestMethod(Http::METHOD_TRACE
) == Http::METHOD_SEARCH
));
103 * an HttpRequestMethod should testable for inequality without fail maatches
106 testHttpRequestMethod::testNotEqualmethod_t()
108 CPPUNIT_ASSERT(HttpRequestMethod(Http::METHOD_NONE
) != Http::METHOD_GET
);
109 CPPUNIT_ASSERT(not (HttpRequestMethod(Http::METHOD_POST
) != Http::METHOD_POST
));
110 CPPUNIT_ASSERT(HttpRequestMethod(Http::METHOD_GET
) != Http::METHOD_NONE
);
111 CPPUNIT_ASSERT(not (HttpRequestMethod(Http::METHOD_SEARCH
) != Http::METHOD_SEARCH
));
115 * we should be able to send it to a stream and get the normalised version
118 testHttpRequestMethod::testStream()
120 std::ostringstream buffer
;
121 buffer
<< HttpRequestMethod("get",NULL
);
122 CPPUNIT_ASSERT_EQUAL(String("GET"), String(buffer
.str().c_str()));