]>
Commit | Line | Data |
---|---|---|
26ac0430 | 1 | #define SQUID_UNIT_TEST 1 |
ec94e362 | 2 | |
582c2af2 | 3 | #include "squid.h" |
985c86bc | 4 | #include <cppunit/TestAssert.h> |
5 | ||
602d9612 | 6 | #include "HttpRequestMethod.h" |
985c86bc | 7 | #include "Mem.h" |
8 | #include "testHttpRequestMethod.h" | |
985c86bc | 9 | |
27e059d4 AJ |
10 | #if HAVE_SSTREAM |
11 | #include <sstream> | |
12 | #endif | |
985c86bc | 13 | |
14 | CPPUNIT_TEST_SUITE_REGISTRATION( testHttpRequestMethod ); | |
15 | ||
985c86bc | 16 | /* |
17 | * We should be able to make an HttpRequestMethod straight from a string. | |
18 | */ | |
19 | void | |
20 | testHttpRequestMethod::testConstructCharStart() | |
21 | { | |
c2a7cefd AJ |
22 | /* parse an empty string -> Http::METHOD_NONE */ |
23 | CPPUNIT_ASSERT(HttpRequestMethod(NULL,NULL) == Http::METHOD_NONE); | |
985c86bc | 24 | /* parsing a literal should work */ |
c2a7cefd AJ |
25 | CPPUNIT_ASSERT(HttpRequestMethod("GET", NULL) == Http::METHOD_GET); |
26 | CPPUNIT_ASSERT(HttpRequestMethod("QWERTY", NULL) == Http::METHOD_OTHER); | |
985c86bc | 27 | } |
28 | ||
29 | /* | |
26ac0430 | 30 | * We can also parse precise ranges of characters |
985c86bc | 31 | */ |
32 | void | |
33 | testHttpRequestMethod::testConstructCharStartEnd() | |
34 | { | |
35 | char const * buffer; | |
c2a7cefd AJ |
36 | /* parse an empty string -> Http::METHOD_NONE */ |
37 | CPPUNIT_ASSERT(HttpRequestMethod(NULL, NULL) == Http::METHOD_NONE); | |
985c86bc | 38 | /* parsing a literal should work */ |
c2a7cefd | 39 | CPPUNIT_ASSERT(HttpRequestMethod("GET", NULL) == Http::METHOD_GET); |
985c86bc | 40 | /* parsing with an explicit end should work */ |
41 | buffer = "POSTPLUS"; | |
c2a7cefd | 42 | CPPUNIT_ASSERT(HttpRequestMethod(buffer, buffer + 4) == Http::METHOD_POST); |
985c86bc | 43 | } |
44 | ||
45 | /* | |
c2a7cefd | 46 | * we should be able to assign a Http::MethodType to a HttpRequestMethod |
985c86bc | 47 | */ |
48 | void | |
49 | testHttpRequestMethod::testAssignFrommethod_t() | |
50 | { | |
51 | HttpRequestMethod method; | |
c2a7cefd AJ |
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); | |
985c86bc | 56 | } |
57 | ||
58 | /* | |
c2a7cefd | 59 | * a default constructed HttpRequestMethod is == Http::METHOD_NONE |
985c86bc | 60 | */ |
61 | void | |
62 | testHttpRequestMethod::testDefaultConstructor() | |
63 | { | |
41030a36 | 64 | HttpRequestMethod lhs; |
c2a7cefd | 65 | HttpRequestMethod rhs(Http::METHOD_NONE); |
41030a36 | 66 | CPPUNIT_ASSERT_EQUAL(lhs, rhs); |
985c86bc | 67 | } |
68 | ||
69 | /* | |
c2a7cefd | 70 | * we should be able to construct a HttpRequestMethod from a Http::MethodType |
985c86bc | 71 | */ |
72 | void | |
73 | testHttpRequestMethod::testConstructmethod_t() | |
74 | { | |
c2a7cefd AJ |
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)); | |
985c86bc | 78 | } |
79 | ||
80 | /* | |
81 | * we should be able to get a char const * version of the method. | |
82 | */ | |
83 | void | |
914b89a2 | 84 | testHttpRequestMethod::testImage() |
985c86bc | 85 | { |
914b89a2 | 86 | CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("post",NULL).image())); |
985c86bc | 87 | } |
88 | ||
89 | /* | |
c2a7cefd | 90 | * an HttpRequestMethod should be comparable to a Http::MethodType without false |
985c86bc | 91 | * matches |
92 | */ | |
93 | void | |
94 | testHttpRequestMethod::testEqualmethod_t() | |
95 | { | |
c2a7cefd AJ |
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)); | |
985c86bc | 100 | } |
101 | ||
102 | /* | |
103 | * an HttpRequestMethod should testable for inequality without fail maatches | |
104 | */ | |
105 | void | |
106 | testHttpRequestMethod::testNotEqualmethod_t() | |
107 | { | |
c2a7cefd AJ |
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)); | |
985c86bc | 112 | } |
113 | ||
114 | /* | |
115 | * we should be able to send it to a stream and get the normalised version | |
116 | */ | |
117 | void | |
118 | testHttpRequestMethod::testStream() | |
119 | { | |
120 | std::ostringstream buffer; | |
914b89a2 | 121 | buffer << HttpRequestMethod("get",NULL); |
30abd221 | 122 | CPPUNIT_ASSERT_EQUAL(String("GET"), String(buffer.str().c_str())); |
985c86bc | 123 | } |