]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testUriScheme.cc
2 * Copyright (C) 1996-2017 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 "SquidString.h"
15 #include "tests/testUriScheme.h"
19 CPPUNIT_TEST_SUITE_REGISTRATION( testUriScheme
);
23 * We should be able to make an HttpRequestMethod straight from a string.
26 testHttpRequestMethod::testConstructCharStart()
28 /* parse an empty string -> METHOD_NONE */
29 CPPUNIT_ASSERT(METHOD_NONE
== HttpRequestMethod(NULL
));
30 /* parsing a literal should work */
31 CPPUNIT_ASSERT(METHOD_GET
== HttpRequestMethod("GET", NULL
));
35 * We can also parse precise ranges of characters
38 testHttpRequestMethod::testConstructCharStartEnd()
41 /* parse an empty string -> METHOD_NONE */
42 CPPUNIT_ASSERT(METHOD_NONE
== HttpRequestMethod(NULL
, NULL
));
43 /* parsing a literal should work */
44 CPPUNIT_ASSERT(METHOD_GET
== HttpRequestMethod("GET", NULL
));
45 /* parsing with an explicit end should work */
47 CPPUNIT_ASSERT(METHOD_POST
== HttpRequestMethod(buffer
, buffer
+ 4));
53 * we should be able to assign a protocol_t to a AnyP::UriScheme for ease
57 testUriScheme::testAssignFromprotocol_t()
59 AnyP::UriScheme empty_scheme
;
60 AnyP::UriScheme scheme
;
61 scheme
= AnyP::PROTO_NONE
;
62 CPPUNIT_ASSERT_EQUAL(empty_scheme
, scheme
);
64 AnyP::UriScheme
https_scheme(AnyP::PROTO_HTTPS
);
65 scheme
= AnyP::PROTO_HTTPS
;
66 CPPUNIT_ASSERT_EQUAL(https_scheme
, scheme
);
70 * We should be able to get a protocol_t from a AnyP::UriScheme for ease
74 testUriScheme::testCastToprotocol_t()
77 AnyP::ProtocolType protocol
= static_cast<AnyP::ProtocolType
>(AnyP::UriScheme());
78 CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_NONE
, protocol
);
80 protocol
= AnyP::UriScheme(AnyP::PROTO_HTTP
);
81 CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP
, protocol
);
85 * a default constructed AnyP::UriScheme is == AnyP::PROTO_NONE
88 testUriScheme::testDefaultConstructor()
91 AnyP::UriScheme
rhs(AnyP::PROTO_NONE
);
92 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
96 * we should be able to construct a AnyP::UriScheme from the old 'protocol_t' enum.
99 testUriScheme::testConstructprotocol_t()
101 AnyP::UriScheme
lhs_none(AnyP::PROTO_NONE
), rhs_none(AnyP::PROTO_NONE
);
102 CPPUNIT_ASSERT_EQUAL(lhs_none
, rhs_none
);
104 AnyP::UriScheme
lhs_cacheobj(AnyP::PROTO_CACHE_OBJECT
), rhs_cacheobj(AnyP::PROTO_CACHE_OBJECT
);
105 CPPUNIT_ASSERT_EQUAL(lhs_cacheobj
, rhs_cacheobj
);
106 CPPUNIT_ASSERT(lhs_none
!= rhs_cacheobj
);
110 * we should be able to get a char const * version of the method.
113 testUriScheme::testC_str()
116 AnyP::UriScheme
wais(AnyP::PROTO_WAIS
);
117 SBuf
rhs(wais
.image());
118 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
122 * a AnyP::UriScheme replaces protocol_t, so we should be able to test for equality on
123 * either the left or right hand side seamlessly.
126 testUriScheme::testEqualprotocol_t()
128 CPPUNIT_ASSERT(AnyP::UriScheme() == AnyP::PROTO_NONE
);
129 CPPUNIT_ASSERT(not (AnyP::UriScheme(AnyP::PROTO_WAIS
) == AnyP::PROTO_HTTP
));
130 CPPUNIT_ASSERT(AnyP::PROTO_HTTP
== AnyP::UriScheme(AnyP::PROTO_HTTP
));
131 CPPUNIT_ASSERT(not (AnyP::PROTO_CACHE_OBJECT
== AnyP::UriScheme(AnyP::PROTO_HTTP
)));
135 * a AnyP::UriScheme should testable for inequality with a protocol_t.
138 testUriScheme::testNotEqualprotocol_t()
140 CPPUNIT_ASSERT(AnyP::UriScheme(AnyP::PROTO_NONE
) != AnyP::PROTO_HTTP
);
141 CPPUNIT_ASSERT(not (AnyP::UriScheme(AnyP::PROTO_HTTP
) != AnyP::PROTO_HTTP
));
142 CPPUNIT_ASSERT(AnyP::PROTO_NONE
!= AnyP::UriScheme(AnyP::PROTO_HTTP
));
143 CPPUNIT_ASSERT(not (AnyP::PROTO_WAIS
!= AnyP::UriScheme(AnyP::PROTO_WAIS
)));
147 * we should be able to send it to a stream and get the normalised version
150 testUriScheme::testStream()
152 std::ostringstream buffer
;
153 buffer
<< AnyP::UriScheme(AnyP::PROTO_HTTP
);
154 String
http_str("http");
155 String
from_buf(buffer
.str().c_str());
156 CPPUNIT_ASSERT_EQUAL(http_str
, from_buf
);