]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testUriScheme.cc
1 #define SQUID_UNIT_TEST 1
5 #include <cppunit/TestAssert.h>
7 #include "anyp/UriScheme.h"
9 #include "SquidString.h"
10 #include "tests/testUriScheme.h"
16 CPPUNIT_TEST_SUITE_REGISTRATION( testUriScheme
);
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 AnyP::UriScheme for ease
54 testUriScheme::testAssignFromprotocol_t()
56 AnyP::UriScheme empty_scheme
;
57 AnyP::UriScheme scheme
;
58 scheme
= AnyP::PROTO_NONE
;
59 CPPUNIT_ASSERT_EQUAL(empty_scheme
, scheme
);
61 AnyP::UriScheme
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 AnyP::UriScheme for ease
71 testUriScheme::testCastToprotocol_t()
74 AnyP::ProtocolType protocol
= static_cast<AnyP::ProtocolType
>(AnyP::UriScheme());
75 CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_NONE
, protocol
);
77 protocol
= AnyP::UriScheme(AnyP::PROTO_HTTP
);
78 CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP
, protocol
);
82 * a default constructed AnyP::UriScheme is == AnyP::PROTO_NONE
85 testUriScheme::testDefaultConstructor()
88 AnyP::UriScheme
rhs(AnyP::PROTO_NONE
);
89 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
93 * we should be able to construct a AnyP::UriScheme from the old 'protocol_t' enum.
96 testUriScheme::testConstructprotocol_t()
98 AnyP::UriScheme
lhs_none(AnyP::PROTO_NONE
), rhs_none(AnyP::PROTO_NONE
);
99 CPPUNIT_ASSERT_EQUAL(lhs_none
, rhs_none
);
101 AnyP::UriScheme
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 testUriScheme::testC_str()
113 AnyP::UriScheme
wais(AnyP::PROTO_WAIS
);
114 String
rhs(wais
.c_str());
115 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
119 * a AnyP::UriScheme replaces protocol_t, so we should be able to test for equality on
120 * either the left or right hand side seamlessly.
123 testUriScheme::testEqualprotocol_t()
125 CPPUNIT_ASSERT(AnyP::UriScheme() == AnyP::PROTO_NONE
);
126 CPPUNIT_ASSERT(not (AnyP::UriScheme(AnyP::PROTO_WAIS
) == AnyP::PROTO_HTTP
));
127 CPPUNIT_ASSERT(AnyP::PROTO_HTTP
== AnyP::UriScheme(AnyP::PROTO_HTTP
));
128 CPPUNIT_ASSERT(not (AnyP::PROTO_CACHE_OBJECT
== AnyP::UriScheme(AnyP::PROTO_HTTP
)));
132 * a AnyP::UriScheme should testable for inequality with a protocol_t.
135 testUriScheme::testNotEqualprotocol_t()
137 CPPUNIT_ASSERT(AnyP::UriScheme(AnyP::PROTO_NONE
) != AnyP::PROTO_HTTP
);
138 CPPUNIT_ASSERT(not (AnyP::UriScheme(AnyP::PROTO_HTTP
) != AnyP::PROTO_HTTP
));
139 CPPUNIT_ASSERT(AnyP::PROTO_NONE
!= AnyP::UriScheme(AnyP::PROTO_HTTP
));
140 CPPUNIT_ASSERT(not (AnyP::PROTO_WAIS
!= AnyP::UriScheme(AnyP::PROTO_WAIS
)));
144 * we should be able to send it to a stream and get the normalised version
147 testUriScheme::testStream()
149 std::ostringstream buffer
;
150 buffer
<< AnyP::UriScheme(AnyP::PROTO_HTTP
);
151 String
http_str("http");
152 String
from_buf(buffer
.str().c_str());
153 CPPUNIT_ASSERT_EQUAL(http_str
, from_buf
);