]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testUriScheme.cc
2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
11 #include <cppunit/TestAssert.h>
13 #include "anyp/UriScheme.h"
14 #include "tests/testUriScheme.h"
18 CPPUNIT_TEST_SUITE_REGISTRATION( testUriScheme
);
22 * We should be able to make an HttpRequestMethod straight from a string.
25 testHttpRequestMethod::testConstructCharStart()
27 /* parse an empty string -> METHOD_NONE */
28 CPPUNIT_ASSERT(METHOD_NONE
== HttpRequestMethod(NULL
));
29 /* parsing a literal should work */
30 CPPUNIT_ASSERT(METHOD_GET
== HttpRequestMethod("GET", NULL
));
34 * We can also parse precise ranges of characters
37 testHttpRequestMethod::testConstructCharStartEnd()
40 /* parse an empty string -> METHOD_NONE */
41 CPPUNIT_ASSERT(METHOD_NONE
== HttpRequestMethod(NULL
, NULL
));
42 /* parsing a literal should work */
43 CPPUNIT_ASSERT(METHOD_GET
== HttpRequestMethod("GET", NULL
));
44 /* parsing with an explicit end should work */
46 CPPUNIT_ASSERT(METHOD_POST
== HttpRequestMethod(buffer
, buffer
+ 4));
52 * we should be able to assign a protocol_t to a AnyP::UriScheme for ease
56 testUriScheme::testAssignFromprotocol_t()
58 AnyP::UriScheme empty_scheme
;
59 AnyP::UriScheme scheme
;
60 scheme
= AnyP::PROTO_NONE
;
61 CPPUNIT_ASSERT_EQUAL(empty_scheme
, scheme
);
63 AnyP::UriScheme
https_scheme(AnyP::PROTO_HTTPS
);
64 scheme
= AnyP::PROTO_HTTPS
;
65 CPPUNIT_ASSERT_EQUAL(https_scheme
, scheme
);
69 * We should be able to get a protocol_t from a AnyP::UriScheme for ease
73 testUriScheme::testCastToprotocol_t()
76 AnyP::ProtocolType protocol
= static_cast<AnyP::ProtocolType
>(AnyP::UriScheme());
77 CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_NONE
, protocol
);
79 protocol
= AnyP::UriScheme(AnyP::PROTO_HTTP
);
80 CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP
, protocol
);
84 * a default constructed AnyP::UriScheme is == AnyP::PROTO_NONE
87 testUriScheme::testDefaultConstructor()
90 AnyP::UriScheme
rhs(AnyP::PROTO_NONE
);
91 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
95 * we should be able to construct a AnyP::UriScheme from the old 'protocol_t' enum.
98 testUriScheme::testConstructprotocol_t()
100 AnyP::UriScheme
lhs_none(AnyP::PROTO_NONE
), rhs_none(AnyP::PROTO_NONE
);
101 CPPUNIT_ASSERT_EQUAL(lhs_none
, rhs_none
);
103 AnyP::UriScheme
lhs_cacheobj(AnyP::PROTO_CACHE_OBJECT
), rhs_cacheobj(AnyP::PROTO_CACHE_OBJECT
);
104 CPPUNIT_ASSERT_EQUAL(lhs_cacheobj
, rhs_cacheobj
);
105 CPPUNIT_ASSERT(lhs_none
!= rhs_cacheobj
);
109 * we should be able to get a char const * version of the method.
112 testUriScheme::testC_str()
115 AnyP::UriScheme
wais(AnyP::PROTO_WAIS
);
116 SBuf
rhs(wais
.image());
117 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
121 * a AnyP::UriScheme replaces protocol_t, so we should be able to test for equality on
122 * either the left or right hand side seamlessly.
125 testUriScheme::testEqualprotocol_t()
127 CPPUNIT_ASSERT(AnyP::UriScheme() == AnyP::PROTO_NONE
);
128 CPPUNIT_ASSERT(not (AnyP::UriScheme(AnyP::PROTO_WAIS
) == AnyP::PROTO_HTTP
));
129 CPPUNIT_ASSERT(AnyP::PROTO_HTTP
== AnyP::UriScheme(AnyP::PROTO_HTTP
));
130 CPPUNIT_ASSERT(not (AnyP::PROTO_CACHE_OBJECT
== AnyP::UriScheme(AnyP::PROTO_HTTP
)));
134 * a AnyP::UriScheme should testable for inequality with a protocol_t.
137 testUriScheme::testNotEqualprotocol_t()
139 CPPUNIT_ASSERT(AnyP::UriScheme(AnyP::PROTO_NONE
) != AnyP::PROTO_HTTP
);
140 CPPUNIT_ASSERT(not (AnyP::UriScheme(AnyP::PROTO_HTTP
) != AnyP::PROTO_HTTP
));
141 CPPUNIT_ASSERT(AnyP::PROTO_NONE
!= AnyP::UriScheme(AnyP::PROTO_HTTP
));
142 CPPUNIT_ASSERT(not (AnyP::PROTO_WAIS
!= AnyP::UriScheme(AnyP::PROTO_WAIS
)));
146 * we should be able to send it to a stream and get the normalised version
149 testUriScheme::testStream()
151 std::ostringstream buffer
;
152 buffer
<< AnyP::UriScheme(AnyP::PROTO_HTTP
);
153 SBuf
http_str("http");
154 SBuf
from_buf(buffer
.str());
155 CPPUNIT_ASSERT_EQUAL(http_str
, from_buf
);