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