]>
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
);
18 * We should be able to make an HttpRequestMethod straight from a string.
21 testHttpRequestMethod::testConstructCharStart()
23 /* parse an empty string -> METHOD_NONE */
24 CPPUNIT_ASSERT(HttpRequestMethod(NULL
,NULL
) == METHOD_NONE
);
25 /* parsing a literal should work */
26 CPPUNIT_ASSERT(HttpRequestMethod("GET", NULL
) == METHOD_GET
);
27 CPPUNIT_ASSERT(HttpRequestMethod("QWERTY", NULL
) == METHOD_OTHER
);
31 * We can also parse precise ranges of characters
34 testHttpRequestMethod::testConstructCharStartEnd()
37 /* parse an empty string -> METHOD_NONE */
38 CPPUNIT_ASSERT(HttpRequestMethod(NULL
, NULL
) == METHOD_NONE
);
39 /* parsing a literal should work */
40 CPPUNIT_ASSERT(HttpRequestMethod("GET", NULL
) == METHOD_GET
);
41 /* parsing with an explicit end should work */
43 CPPUNIT_ASSERT(HttpRequestMethod(buffer
, buffer
+ 4) == METHOD_POST
);
47 * we should be able to assign a method_t to a HttpRequestMethod
50 testHttpRequestMethod::testAssignFrommethod_t()
52 HttpRequestMethod method
;
54 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(METHOD_NONE
), method
);
56 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(METHOD_POST
), method
);
60 * a default constructed HttpRequestMethod is == METHOD_NONE
63 testHttpRequestMethod::testDefaultConstructor()
65 HttpRequestMethod lhs
;
66 HttpRequestMethod
rhs(METHOD_NONE
);
67 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
71 * we should be able to construct a HttpRequestMethod from a method_t
74 testHttpRequestMethod::testConstructmethod_t()
76 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(METHOD_NONE
), HttpRequestMethod(METHOD_NONE
));
77 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(METHOD_POST
), HttpRequestMethod(METHOD_POST
));
78 CPPUNIT_ASSERT(HttpRequestMethod(METHOD_NONE
) != HttpRequestMethod(METHOD_POST
));
82 * we should be able to get a char const * version of the method.
85 testHttpRequestMethod::testImage()
87 CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("post",NULL
).image()));
91 * an HttpRequestMethod should be comparable to a method_t without false
95 testHttpRequestMethod::testEqualmethod_t()
97 CPPUNIT_ASSERT(HttpRequestMethod(METHOD_NONE
) == METHOD_NONE
);
98 CPPUNIT_ASSERT(not (HttpRequestMethod(METHOD_POST
) == METHOD_GET
));
99 CPPUNIT_ASSERT(HttpRequestMethod(METHOD_GET
) == METHOD_GET
);
100 CPPUNIT_ASSERT(not (HttpRequestMethod(METHOD_TRACE
) == METHOD_SEARCH
));
104 * an HttpRequestMethod should testable for inequality without fail maatches
107 testHttpRequestMethod::testNotEqualmethod_t()
109 CPPUNIT_ASSERT(HttpRequestMethod(METHOD_NONE
) != METHOD_GET
);
110 CPPUNIT_ASSERT(not (HttpRequestMethod(METHOD_POST
) != METHOD_POST
));
111 CPPUNIT_ASSERT(HttpRequestMethod(METHOD_GET
) != METHOD_NONE
);
112 CPPUNIT_ASSERT(not (HttpRequestMethod(METHOD_SEARCH
) != METHOD_SEARCH
));
116 * we should be able to send it to a stream and get the normalised version
119 testHttpRequestMethod::testStream()
121 std::ostringstream buffer
;
122 buffer
<< HttpRequestMethod("get",NULL
);
123 CPPUNIT_ASSERT_EQUAL(String("GET"), String(buffer
.str().c_str()));