]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testURLScheme.cc
Merged from trunk
[thirdparty/squid.git] / src / tests / testURLScheme.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 "testURLScheme.h"
9 #include "URLScheme.h"
10
11
12 CPPUNIT_TEST_SUITE_REGISTRATION( testURLScheme );
13
14
15 #if 0
16 /*
17 * We should be able to make an HttpRequestMethod straight from a string.
18 */
19 void
20 testHttpRequestMethod::testConstructCharStart()
21 {
22 /* parse an empty string -> METHOD_NONE */
23 CPPUNIT_ASSERT(METHOD_NONE == HttpRequestMethod(NULL));
24 /* parsing a literal should work */
25 CPPUNIT_ASSERT(METHOD_GET == HttpRequestMethod("GET", NULL));
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(METHOD_NONE == HttpRequestMethod(NULL, NULL));
37 /* parsing a literal should work */
38 CPPUNIT_ASSERT(METHOD_GET == HttpRequestMethod("GET", NULL));
39 /* parsing with an explicit end should work */
40 buffer = "POSTPLUS";
41 CPPUNIT_ASSERT(METHOD_POST == HttpRequestMethod(buffer, buffer + 4));
42 }
43
44 #endif
45
46 /*
47 * we should be able to assign a protocol_t to a URLScheme for ease
48 * of code conversion
49 */
50 void
51 testURLScheme::testAssignFromprotocol_t()
52 {
53 URLScheme empty_scheme;
54 URLScheme scheme;
55 scheme = PROTO_NONE;
56 CPPUNIT_ASSERT_EQUAL(empty_scheme, scheme);
57
58 URLScheme https_scheme(PROTO_HTTPS);
59 scheme = PROTO_HTTPS;
60 CPPUNIT_ASSERT_EQUAL(https_scheme, scheme);
61 }
62
63 /*
64 * We should be able to get a protocol_t from a URLScheme for ease
65 * of migration
66 */
67 void
68 testURLScheme::testCastToprotocol_t()
69 {
70 /* explicit cast */
71 protocol_t protocol = (protocol_t) URLScheme();
72 CPPUNIT_ASSERT_EQUAL(PROTO_NONE, protocol);
73 /* and implicit */
74 protocol = URLScheme(PROTO_HTTP);
75 CPPUNIT_ASSERT_EQUAL(PROTO_HTTP, protocol);
76 }
77
78 /*
79 * a default constructed URLScheme is == PROTO_NONE
80 */
81 void
82 testURLScheme::testDefaultConstructor()
83 {
84 URLScheme lhs;
85 URLScheme rhs(PROTO_NONE);
86 CPPUNIT_ASSERT_EQUAL(lhs, rhs);
87 }
88
89 /*
90 * we should be able to construct a URLScheme from the old 'protocol_t' enum.
91 */
92 void
93 testURLScheme::testConstructprotocol_t()
94 {
95 URLScheme lhs_none(PROTO_NONE), rhs_none(PROTO_NONE);
96 CPPUNIT_ASSERT_EQUAL(lhs_none, rhs_none);
97
98 URLScheme lhs_cacheobj(PROTO_CACHEOBJ), rhs_cacheobj(PROTO_CACHEOBJ);
99 CPPUNIT_ASSERT_EQUAL(lhs_cacheobj, rhs_cacheobj);
100 CPPUNIT_ASSERT(lhs_none != rhs_cacheobj);
101 }
102
103 /*
104 * we should be able to get a char const * version of the method.
105 */
106 void
107 testURLScheme::testConst_str()
108 {
109 String lhs("wais");
110 URLScheme wais(PROTO_WAIS);
111 String rhs(wais.const_str());
112 CPPUNIT_ASSERT_EQUAL(lhs, rhs);
113 }
114
115 /*
116 * a URLScheme replaces protocol_t, so we should be able to test for equality on
117 * either the left or right hand side seamlessly.
118 */
119 void
120 testURLScheme::testEqualprotocol_t()
121 {
122 CPPUNIT_ASSERT(URLScheme() == PROTO_NONE);
123 CPPUNIT_ASSERT(not (URLScheme(PROTO_WAIS) == PROTO_HTTP));
124 CPPUNIT_ASSERT(PROTO_HTTP == URLScheme(PROTO_HTTP));
125 CPPUNIT_ASSERT(not (PROTO_CACHEOBJ == URLScheme(PROTO_HTTP)));
126 }
127
128 /*
129 * a URLScheme should testable for inequality with a protocol_t.
130 */
131 void
132 testURLScheme::testNotEqualprotocol_t()
133 {
134 CPPUNIT_ASSERT(URLScheme(PROTO_NONE) != PROTO_HTTP);
135 CPPUNIT_ASSERT(not (URLScheme(PROTO_HTTP) != PROTO_HTTP));
136 CPPUNIT_ASSERT(PROTO_NONE != URLScheme(PROTO_HTTP));
137 CPPUNIT_ASSERT(not (PROTO_WAIS != URLScheme(PROTO_WAIS)));
138 }
139
140 /*
141 * we should be able to send it to a stream and get the normalised version
142 */
143 void
144 testURLScheme::testStream()
145 {
146 std::ostringstream buffer;
147 buffer << URLScheme(PROTO_HTTP);
148 String http_str("http");
149 String from_buf(buffer.str().c_str());
150 CPPUNIT_ASSERT_EQUAL(http_str, from_buf);
151 }