]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testUriScheme.cc
cb2464b3df2eecb0e0ddac533ad4e8ee13017cd6
2 * Copyright (C) 1996-2022 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
);
21 * we should be able to assign a protocol_t to a AnyP::UriScheme for ease
25 testUriScheme::testAssignFromprotocol_t()
27 AnyP::UriScheme empty_scheme
;
28 AnyP::UriScheme scheme
;
29 scheme
= AnyP::PROTO_NONE
;
30 CPPUNIT_ASSERT_EQUAL(empty_scheme
, scheme
);
32 AnyP::UriScheme
https_scheme(AnyP::PROTO_HTTPS
);
33 scheme
= AnyP::PROTO_HTTPS
;
34 CPPUNIT_ASSERT_EQUAL(https_scheme
, scheme
);
38 * We should be able to get a protocol_t from a AnyP::UriScheme for ease
42 testUriScheme::testCastToprotocol_t()
45 AnyP::ProtocolType protocol
= static_cast<AnyP::ProtocolType
>(AnyP::UriScheme());
46 CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_NONE
, protocol
);
48 protocol
= AnyP::UriScheme(AnyP::PROTO_HTTP
);
49 CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP
, protocol
);
53 * a default constructed AnyP::UriScheme is == AnyP::PROTO_NONE
56 testUriScheme::testDefaultConstructor()
59 AnyP::UriScheme
rhs(AnyP::PROTO_NONE
);
60 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
64 * we should be able to construct a AnyP::UriScheme from the old 'protocol_t' enum.
67 testUriScheme::testConstructprotocol_t()
69 AnyP::UriScheme
lhs_none(AnyP::PROTO_NONE
), rhs_none(AnyP::PROTO_NONE
);
70 CPPUNIT_ASSERT_EQUAL(lhs_none
, rhs_none
);
72 AnyP::UriScheme
lhs_cacheobj(AnyP::PROTO_CACHE_OBJECT
), rhs_cacheobj(AnyP::PROTO_CACHE_OBJECT
);
73 CPPUNIT_ASSERT_EQUAL(lhs_cacheobj
, rhs_cacheobj
);
74 CPPUNIT_ASSERT(lhs_none
!= rhs_cacheobj
);
78 * we should be able to get a char const * version of the method.
81 testUriScheme::testC_str()
84 AnyP::UriScheme
wais(AnyP::PROTO_WAIS
);
85 SBuf
rhs(wais
.image());
86 CPPUNIT_ASSERT_EQUAL(lhs
, rhs
);
90 * a AnyP::UriScheme replaces protocol_t, so we should be able to test for equality on
91 * either the left or right hand side seamlessly.
94 testUriScheme::testEqualprotocol_t()
96 CPPUNIT_ASSERT(AnyP::UriScheme() == AnyP::PROTO_NONE
);
97 CPPUNIT_ASSERT(not (AnyP::UriScheme(AnyP::PROTO_WAIS
) == AnyP::PROTO_HTTP
));
98 CPPUNIT_ASSERT(AnyP::PROTO_HTTP
== AnyP::UriScheme(AnyP::PROTO_HTTP
));
99 CPPUNIT_ASSERT(not (AnyP::PROTO_CACHE_OBJECT
== AnyP::UriScheme(AnyP::PROTO_HTTP
)));
103 * a AnyP::UriScheme should testable for inequality with a protocol_t.
106 testUriScheme::testNotEqualprotocol_t()
108 CPPUNIT_ASSERT(AnyP::UriScheme(AnyP::PROTO_NONE
) != AnyP::PROTO_HTTP
);
109 CPPUNIT_ASSERT(not (AnyP::UriScheme(AnyP::PROTO_HTTP
) != AnyP::PROTO_HTTP
));
110 CPPUNIT_ASSERT(AnyP::PROTO_NONE
!= AnyP::UriScheme(AnyP::PROTO_HTTP
));
111 CPPUNIT_ASSERT(not (AnyP::PROTO_WAIS
!= AnyP::UriScheme(AnyP::PROTO_WAIS
)));
115 * we should be able to send it to a stream and get the normalised version
118 testUriScheme::testStream()
120 std::ostringstream buffer
;
121 buffer
<< AnyP::UriScheme(AnyP::PROTO_HTTP
);
122 SBuf
http_str("http");
123 SBuf
from_buf(buffer
.str());
124 CPPUNIT_ASSERT_EQUAL(http_str
, from_buf
);
128 testUriScheme::setUp()
131 AnyP::UriScheme::Init();