]>
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 "SquidString.h"
9 #include "testURLScheme.h"
10 #include "URLScheme.h"
16 CPPUNIT_TEST_SUITE_REGISTRATION( testURLScheme
);
21 * We should be able to make an HttpRequestMethod straight from a string.
24 testHttpRequestMethod::testConstructCharStart()
26 /* parse an empty string -> METHOD_NONE */
27 CPPUNIT_ASSERT(METHOD_NONE
== HttpRequestMethod(NULL
));
28 /* parsing a literal should work */
29 CPPUNIT_ASSERT(METHOD_GET
== HttpRequestMethod("GET", NULL
));
33 * We can also parse precise ranges of characters
36 testHttpRequestMethod::testConstructCharStartEnd()
39 /* parse an empty string -> METHOD_NONE */
40 CPPUNIT_ASSERT(METHOD_NONE
== HttpRequestMethod(NULL
, NULL
));
41 /* parsing a literal should work */
42 CPPUNIT_ASSERT(METHOD_GET
== HttpRequestMethod("GET", NULL
));
43 /* parsing with an explicit end should work */
45 CPPUNIT_ASSERT(METHOD_POST
== HttpRequestMethod(buffer
, buffer
+ 4));
51 * we should be able to assign a protocol_t to a URLScheme for ease
55 testURLScheme::testAssignFromprotocol_t()
57 URLScheme empty_scheme
;
59 scheme
= AnyP::PROTO_NONE
;
60 CPPUNIT_ASSERT_EQUAL(empty_scheme
, scheme
);
62 URLScheme
https_scheme(AnyP::PROTO_HTTPS
);
63 scheme
= AnyP::PROTO_HTTPS
;
64 CPPUNIT_ASSERT_EQUAL(https_scheme
, scheme
);
68 * We should be able to get a protocol_t from a URLScheme for ease
72 testURLScheme::testCastToprotocol_t()
75 AnyP::ProtocolType protocol
= static_cast<AnyP::ProtocolType
>(URLScheme());
76 CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_NONE
, protocol
);
78 protocol
= URLScheme(AnyP::PROTO_HTTP
);
79 CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP
, protocol
);
83 * a default constructed URLScheme is == AnyP::PROTO_NONE
86 testURLScheme::testDefaultConstructor()
89 URLScheme
rhs(AnyP::PROTO_NONE
);
90 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
94 * we should be able to construct a URLScheme from the old 'protocol_t' enum.
97 testURLScheme::testConstructprotocol_t()
99 URLScheme
lhs_none(AnyP::PROTO_NONE
), rhs_none(AnyP::PROTO_NONE
);
100 CPPUNIT_ASSERT_EQUAL(lhs_none
, rhs_none
);
102 URLScheme
lhs_cacheobj(AnyP::PROTO_CACHE_OBJECT
), rhs_cacheobj(AnyP::PROTO_CACHE_OBJECT
);
103 CPPUNIT_ASSERT_EQUAL(lhs_cacheobj
, rhs_cacheobj
);
104 CPPUNIT_ASSERT(lhs_none
!= rhs_cacheobj
);
108 * we should be able to get a char const * version of the method.
111 testURLScheme::testConst_str()
114 URLScheme
wais(AnyP::PROTO_WAIS
);
115 String
rhs(wais
.const_str());
116 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
120 * a URLScheme replaces protocol_t, so we should be able to test for equality on
121 * either the left or right hand side seamlessly.
124 testURLScheme::testEqualprotocol_t()
126 CPPUNIT_ASSERT(URLScheme() == AnyP::PROTO_NONE
);
127 CPPUNIT_ASSERT(not (URLScheme(AnyP::PROTO_WAIS
) == AnyP::PROTO_HTTP
));
128 CPPUNIT_ASSERT(AnyP::PROTO_HTTP
== URLScheme(AnyP::PROTO_HTTP
));
129 CPPUNIT_ASSERT(not (AnyP::PROTO_CACHE_OBJECT
== URLScheme(AnyP::PROTO_HTTP
)));
133 * a URLScheme should testable for inequality with a protocol_t.
136 testURLScheme::testNotEqualprotocol_t()
138 CPPUNIT_ASSERT(URLScheme(AnyP::PROTO_NONE
) != AnyP::PROTO_HTTP
);
139 CPPUNIT_ASSERT(not (URLScheme(AnyP::PROTO_HTTP
) != AnyP::PROTO_HTTP
));
140 CPPUNIT_ASSERT(AnyP::PROTO_NONE
!= URLScheme(AnyP::PROTO_HTTP
));
141 CPPUNIT_ASSERT(not (AnyP::PROTO_WAIS
!= URLScheme(AnyP::PROTO_WAIS
)));
145 * we should be able to send it to a stream and get the normalised version
148 testURLScheme::testStream()
150 std::ostringstream buffer
;
151 buffer
<< URLScheme(AnyP::PROTO_HTTP
);
152 String
http_str("http");
153 String
from_buf(buffer
.str().c_str());
154 CPPUNIT_ASSERT_EQUAL(http_str
, from_buf
);