]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testUriScheme.cc
3 #include <cppunit/TestAssert.h>
5 #include "anyp/UriScheme.h"
7 #include "SquidString.h"
8 #include "tests/testUriScheme.h"
12 CPPUNIT_TEST_SUITE_REGISTRATION( testUriScheme
);
16 * We should be able to make an HttpRequestMethod straight from a string.
19 testHttpRequestMethod::testConstructCharStart()
21 /* parse an empty string -> METHOD_NONE */
22 CPPUNIT_ASSERT(METHOD_NONE
== HttpRequestMethod(NULL
));
23 /* parsing a literal should work */
24 CPPUNIT_ASSERT(METHOD_GET
== HttpRequestMethod("GET", NULL
));
28 * We can also parse precise ranges of characters
31 testHttpRequestMethod::testConstructCharStartEnd()
34 /* parse an empty string -> METHOD_NONE */
35 CPPUNIT_ASSERT(METHOD_NONE
== HttpRequestMethod(NULL
, NULL
));
36 /* parsing a literal should work */
37 CPPUNIT_ASSERT(METHOD_GET
== HttpRequestMethod("GET", NULL
));
38 /* parsing with an explicit end should work */
40 CPPUNIT_ASSERT(METHOD_POST
== HttpRequestMethod(buffer
, buffer
+ 4));
46 * we should be able to assign a protocol_t to a AnyP::UriScheme for ease
50 testUriScheme::testAssignFromprotocol_t()
52 AnyP::UriScheme empty_scheme
;
53 AnyP::UriScheme scheme
;
54 scheme
= AnyP::PROTO_NONE
;
55 CPPUNIT_ASSERT_EQUAL(empty_scheme
, scheme
);
57 AnyP::UriScheme
https_scheme(AnyP::PROTO_HTTPS
);
58 scheme
= AnyP::PROTO_HTTPS
;
59 CPPUNIT_ASSERT_EQUAL(https_scheme
, scheme
);
63 * We should be able to get a protocol_t from a AnyP::UriScheme for ease
67 testUriScheme::testCastToprotocol_t()
70 AnyP::ProtocolType protocol
= static_cast<AnyP::ProtocolType
>(AnyP::UriScheme());
71 CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_NONE
, protocol
);
73 protocol
= AnyP::UriScheme(AnyP::PROTO_HTTP
);
74 CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP
, protocol
);
78 * a default constructed AnyP::UriScheme is == AnyP::PROTO_NONE
81 testUriScheme::testDefaultConstructor()
84 AnyP::UriScheme
rhs(AnyP::PROTO_NONE
);
85 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
89 * we should be able to construct a AnyP::UriScheme from the old 'protocol_t' enum.
92 testUriScheme::testConstructprotocol_t()
94 AnyP::UriScheme
lhs_none(AnyP::PROTO_NONE
), rhs_none(AnyP::PROTO_NONE
);
95 CPPUNIT_ASSERT_EQUAL(lhs_none
, rhs_none
);
97 AnyP::UriScheme
lhs_cacheobj(AnyP::PROTO_CACHE_OBJECT
), rhs_cacheobj(AnyP::PROTO_CACHE_OBJECT
);
98 CPPUNIT_ASSERT_EQUAL(lhs_cacheobj
, rhs_cacheobj
);
99 CPPUNIT_ASSERT(lhs_none
!= rhs_cacheobj
);
103 * we should be able to get a char const * version of the method.
106 testUriScheme::testC_str()
109 AnyP::UriScheme
wais(AnyP::PROTO_WAIS
);
110 String
rhs(wais
.c_str());
111 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
115 * a AnyP::UriScheme replaces protocol_t, so we should be able to test for equality on
116 * either the left or right hand side seamlessly.
119 testUriScheme::testEqualprotocol_t()
121 CPPUNIT_ASSERT(AnyP::UriScheme() == AnyP::PROTO_NONE
);
122 CPPUNIT_ASSERT(not (AnyP::UriScheme(AnyP::PROTO_WAIS
) == AnyP::PROTO_HTTP
));
123 CPPUNIT_ASSERT(AnyP::PROTO_HTTP
== AnyP::UriScheme(AnyP::PROTO_HTTP
));
124 CPPUNIT_ASSERT(not (AnyP::PROTO_CACHE_OBJECT
== AnyP::UriScheme(AnyP::PROTO_HTTP
)));
128 * a AnyP::UriScheme should testable for inequality with a protocol_t.
131 testUriScheme::testNotEqualprotocol_t()
133 CPPUNIT_ASSERT(AnyP::UriScheme(AnyP::PROTO_NONE
) != AnyP::PROTO_HTTP
);
134 CPPUNIT_ASSERT(not (AnyP::UriScheme(AnyP::PROTO_HTTP
) != AnyP::PROTO_HTTP
));
135 CPPUNIT_ASSERT(AnyP::PROTO_NONE
!= AnyP::UriScheme(AnyP::PROTO_HTTP
));
136 CPPUNIT_ASSERT(not (AnyP::PROTO_WAIS
!= AnyP::UriScheme(AnyP::PROTO_WAIS
)));
140 * we should be able to send it to a stream and get the normalised version
143 testUriScheme::testStream()
145 std::ostringstream buffer
;
146 buffer
<< AnyP::UriScheme(AnyP::PROTO_HTTP
);
147 String
http_str("http");
148 String
from_buf(buffer
.str().c_str());
149 CPPUNIT_ASSERT_EQUAL(http_str
, from_buf
);