]>
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"
15 CPPUNIT_TEST_SUITE_REGISTRATION( testURLScheme
);
20 * We should be able to make an HttpRequestMethod straight from a string.
23 testHttpRequestMethod::testConstructCharStart()
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
));
32 * We can also parse precise ranges of characters
35 testHttpRequestMethod::testConstructCharStartEnd()
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 */
44 CPPUNIT_ASSERT(METHOD_POST
== HttpRequestMethod(buffer
, buffer
+ 4));
50 * we should be able to assign a protocol_t to a URLScheme for ease
54 testURLScheme::testAssignFromprotocol_t()
56 URLScheme empty_scheme
;
58 scheme
= AnyP::PROTO_NONE
;
59 CPPUNIT_ASSERT_EQUAL(empty_scheme
, scheme
);
61 URLScheme
https_scheme(AnyP::PROTO_HTTPS
);
62 scheme
= AnyP::PROTO_HTTPS
;
63 CPPUNIT_ASSERT_EQUAL(https_scheme
, scheme
);
67 * We should be able to get a protocol_t from a URLScheme for ease
71 testURLScheme::testCastToprotocol_t()
74 AnyP::ProtocolType protocol
= static_cast<AnyP::ProtocolType
>(URLScheme());
75 CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_NONE
, protocol
);
77 protocol
= URLScheme(AnyP::PROTO_HTTP
);
78 CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP
, protocol
);
82 * a default constructed URLScheme is == AnyP::PROTO_NONE
85 testURLScheme::testDefaultConstructor()
88 URLScheme
rhs(AnyP::PROTO_NONE
);
89 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
93 * we should be able to construct a URLScheme from the old 'protocol_t' enum.
96 testURLScheme::testConstructprotocol_t()
98 URLScheme
lhs_none(AnyP::PROTO_NONE
), rhs_none(AnyP::PROTO_NONE
);
99 CPPUNIT_ASSERT_EQUAL(lhs_none
, rhs_none
);
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
);
107 * we should be able to get a char const * version of the method.
110 testURLScheme::testConst_str()
113 URLScheme
wais(AnyP::PROTO_WAIS
);
114 String
rhs(wais
.const_str());
115 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
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.
123 testURLScheme::testEqualprotocol_t()
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
)));
132 * a URLScheme should testable for inequality with a protocol_t.
135 testURLScheme::testNotEqualprotocol_t()
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
)));
144 * we should be able to send it to a stream and get the normalised version
147 testURLScheme::testStream()
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
);