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