]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testHttpRequestMethod.cc
Merge from trunk
[thirdparty/squid.git] / src / tests / testHttpRequestMethod.cc
1 #define SQUID_UNIT_TEST 1
2
3 #include "squid.h"
4 #include <sstream>
5 #include <cppunit/TestAssert.h>
6
7 #include "Mem.h"
8 #include "testHttpRequestMethod.h"
9 #include "HttpRequestMethod.h"
10
11
12 CPPUNIT_TEST_SUITE_REGISTRATION( testHttpRequestMethod );
13
14
15 /*
16 * We should be able to make an HttpRequestMethod straight from a string.
17 */
18 void
19 testHttpRequestMethod::testConstructCharStart()
20 {
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);
26 }
27
28 /*
29 * We can also parse precise ranges of characters
30 */
31 void
32 testHttpRequestMethod::testConstructCharStartEnd()
33 {
34 char const * buffer;
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 */
40 buffer = "POSTPLUS";
41 CPPUNIT_ASSERT(HttpRequestMethod(buffer, buffer + 4) == METHOD_POST);
42 }
43
44 /*
45 * we should be able to assign a method_t to a HttpRequestMethod
46 */
47 void
48 testHttpRequestMethod::testAssignFrommethod_t()
49 {
50 HttpRequestMethod method;
51 method = METHOD_NONE;
52 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(METHOD_NONE), method);
53 method = METHOD_POST;
54 CPPUNIT_ASSERT_EQUAL(HttpRequestMethod(METHOD_POST), method);
55 }
56
57 /*
58 * a default constructed HttpRequestMethod is == METHOD_NONE
59 */
60 void
61 testHttpRequestMethod::testDefaultConstructor()
62 {
63 HttpRequestMethod lhs;
64 HttpRequestMethod rhs(METHOD_NONE);
65 CPPUNIT_ASSERT_EQUAL(lhs, rhs);
66 }
67
68 /*
69 * we should be able to construct a HttpRequestMethod from a method_t
70 */
71 void
72 testHttpRequestMethod::testConstructmethod_t()
73 {
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));
77 }
78
79 /*
80 * we should be able to get a char const * version of the method.
81 */
82 void
83 testHttpRequestMethod::testImage()
84 {
85 CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("post",NULL).image()));
86 }
87
88 /*
89 * an HttpRequestMethod should be comparable to a method_t without false
90 * matches
91 */
92 void
93 testHttpRequestMethod::testEqualmethod_t()
94 {
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));
99 }
100
101 /*
102 * an HttpRequestMethod should testable for inequality without fail maatches
103 */
104 void
105 testHttpRequestMethod::testNotEqualmethod_t()
106 {
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));
111 }
112
113 /*
114 * we should be able to send it to a stream and get the normalised version
115 */
116 void
117 testHttpRequestMethod::testStream()
118 {
119 std::ostringstream buffer;
120 buffer << HttpRequestMethod("get",NULL);
121 CPPUNIT_ASSERT_EQUAL(String("GET"), String(buffer.str().c_str()));
122 }