]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testURLScheme.cc
1 #define SQUID_UNIT_TEST 1
5 #include <cppunit/TestAssert.h>
8 #include "testURLScheme.h"
12 CPPUNIT_TEST_SUITE_REGISTRATION( testURLScheme
);
17 * We should be able to make an HttpRequestMethod straight from a string.
20 testHttpRequestMethod::testConstructCharStart()
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
));
29 * We can also parse precise ranges of characters
32 testHttpRequestMethod::testConstructCharStartEnd()
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 */
41 CPPUNIT_ASSERT(METHOD_POST
== HttpRequestMethod(buffer
, buffer
+ 4));
47 * we should be able to assign a protocol_t to a URLScheme for ease
51 testURLScheme::testAssignFromprotocol_t()
53 URLScheme empty_scheme
;
56 CPPUNIT_ASSERT_EQUAL(empty_scheme
, scheme
);
58 URLScheme
https_scheme(PROTO_HTTPS
);
60 CPPUNIT_ASSERT_EQUAL(https_scheme
, scheme
);
64 * We should be able to get a protocol_t from a URLScheme for ease
68 testURLScheme::testCastToprotocol_t()
71 protocol_t protocol
= (protocol_t
) URLScheme();
72 CPPUNIT_ASSERT_EQUAL(PROTO_NONE
, protocol
);
74 protocol
= URLScheme(PROTO_HTTP
);
75 CPPUNIT_ASSERT_EQUAL(PROTO_HTTP
, protocol
);
79 * a default constructed URLScheme is == PROTO_NONE
82 testURLScheme::testDefaultConstructor()
85 URLScheme
rhs(PROTO_NONE
);
86 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
90 * we should be able to construct a URLScheme from the old 'protocol_t' enum.
93 testURLScheme::testConstructprotocol_t()
95 URLScheme
lhs_none(PROTO_NONE
), rhs_none(PROTO_NONE
);
96 CPPUNIT_ASSERT_EQUAL(lhs_none
, rhs_none
);
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
);
104 * we should be able to get a char const * version of the method.
107 testURLScheme::testConst_str()
110 URLScheme
wais(PROTO_WAIS
);
111 String
rhs(wais
.const_str());
112 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
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.
120 testURLScheme::testEqualprotocol_t()
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
)));
129 * a URLScheme should testable for inequality with a protocol_t.
132 testURLScheme::testNotEqualprotocol_t()
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
)));
141 * we should be able to send it to a stream and get the normalised version
144 testURLScheme::testStream()
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
);