]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testHttpRequestMethod.cc
1 #define SQUID_UNIT_TEST 1
5 #include <cppunit/TestAssert.h>
8 #include "testHttpRequestMethod.h"
9 #include "HttpRequestMethod.h"
12 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 -> METHOD_NONE */
22 CPPUNIT_ASSERT(HttpRequestMethod(NULL
,NULL
) == METHOD_NONE
);
23 /* parsing a literal should work */
24 CPPUNIT_ASSERT(HttpRequestMethod("GET", NULL
) == METHOD_GET
);
25 CPPUNIT_ASSERT(HttpRequestMethod("QWERTY", NULL
) == METHOD_OTHER
);
29 * We can also parse precise ranges of characters
32 testHttpRequestMethod::testConstructCharStartEnd()
35 /* parse an empty string -> METHOD_NONE */
36 CPPUNIT_ASSERT(HttpRequestMethod(NULL
, NULL
) == METHOD_NONE
);
37 /* parsing a literal should work */
38 CPPUNIT_ASSERT(HttpRequestMethod("GET", NULL
) == METHOD_GET
);
39 /* parsing with an explicit end should work */
41 CPPUNIT_ASSERT(HttpRequestMethod(buffer
, buffer
+ 4) == METHOD_POST
);
45 * we should be able to assign a method_t to a HttpRequestMethod
48 testHttpRequestMethod::testAssignFrommethod_t()
50 HttpRequestMethod method
;
52 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(METHOD_NONE
), method
);
54 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(METHOD_POST
), method
);
58 * a default constructed HttpRequestMethod is == METHOD_NONE
61 testHttpRequestMethod::testDefaultConstructor()
63 HttpRequestMethod lhs
;
64 HttpRequestMethod
rhs(METHOD_NONE
);
65 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
69 * we should be able to construct a HttpRequestMethod from a method_t
72 testHttpRequestMethod::testConstructmethod_t()
74 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(METHOD_NONE
), HttpRequestMethod(METHOD_NONE
));
75 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(METHOD_POST
), HttpRequestMethod(METHOD_POST
));
76 CPPUNIT_ASSERT(HttpRequestMethod(METHOD_NONE
) != HttpRequestMethod(METHOD_POST
));
80 * we should be able to get a char const * version of the method.
83 testHttpRequestMethod::testImage()
85 CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("post",NULL
).image()));
89 * an HttpRequestMethod should be comparable to a method_t without false
93 testHttpRequestMethod::testEqualmethod_t()
95 CPPUNIT_ASSERT(HttpRequestMethod(METHOD_NONE
) == METHOD_NONE
);
96 CPPUNIT_ASSERT(not (HttpRequestMethod(METHOD_POST
) == METHOD_GET
));
97 CPPUNIT_ASSERT(HttpRequestMethod(METHOD_GET
) == METHOD_GET
);
98 CPPUNIT_ASSERT(not (HttpRequestMethod(METHOD_TRACE
) == METHOD_SEARCH
));
102 * an HttpRequestMethod should testable for inequality without fail maatches
105 testHttpRequestMethod::testNotEqualmethod_t()
107 CPPUNIT_ASSERT(HttpRequestMethod(METHOD_NONE
) != METHOD_GET
);
108 CPPUNIT_ASSERT(not (HttpRequestMethod(METHOD_POST
) != METHOD_POST
));
109 CPPUNIT_ASSERT(HttpRequestMethod(METHOD_GET
) != METHOD_NONE
);
110 CPPUNIT_ASSERT(not (HttpRequestMethod(METHOD_SEARCH
) != METHOD_SEARCH
));
114 * we should be able to send it to a stream and get the normalised version
117 testHttpRequestMethod::testStream()
119 std::ostringstream buffer
;
120 buffer
<< HttpRequestMethod("get",NULL
);
121 CPPUNIT_ASSERT_EQUAL(String("GET"), String(buffer
.str().c_str()));