]> git.ipfire.org Git - thirdparty/squid.git/blame - src/tests/testURLScheme.cc
Bug 3610: peername_regex ACL
[thirdparty/squid.git] / src / tests / testURLScheme.cc
CommitLineData
ec94e362
AJ
1#define SQUID_UNIT_TEST 1
2
f7f3304a 3#include "squid-old.h"
27e059d4 4
985c86bc 5#include <cppunit/TestAssert.h>
6
7#include "Mem.h"
8#include "testURLScheme.h"
9#include "URLScheme.h"
10
27e059d4
AJ
11#if HAVE_SSTREAM
12#include <sstream>
13#endif
985c86bc 14
15CPPUNIT_TEST_SUITE_REGISTRATION( testURLScheme );
16
17
18#if 0
19/*
20 * We should be able to make an HttpRequestMethod straight from a string.
21 */
22void
23testHttpRequestMethod::testConstructCharStart()
24{
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));
29}
30
31/*
26ac0430 32 * We can also parse precise ranges of characters
985c86bc 33 */
34void
35testHttpRequestMethod::testConstructCharStartEnd()
36{
37 char const * buffer;
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 */
43 buffer = "POSTPLUS";
44 CPPUNIT_ASSERT(METHOD_POST == HttpRequestMethod(buffer, buffer + 4));
45}
46
47#endif
48
49/*
50 * we should be able to assign a protocol_t to a URLScheme for ease
51 * of code conversion
52 */
53void
54testURLScheme::testAssignFromprotocol_t()
55{
41030a36 56 URLScheme empty_scheme;
985c86bc 57 URLScheme scheme;
0c3d3f65 58 scheme = AnyP::PROTO_NONE;
41030a36 59 CPPUNIT_ASSERT_EQUAL(empty_scheme, scheme);
60
0c3d3f65
AJ
61 URLScheme https_scheme(AnyP::PROTO_HTTPS);
62 scheme = AnyP::PROTO_HTTPS;
41030a36 63 CPPUNIT_ASSERT_EQUAL(https_scheme, scheme);
985c86bc 64}
65
66/*
67 * We should be able to get a protocol_t from a URLScheme for ease
68 * of migration
69 */
70void
71testURLScheme::testCastToprotocol_t()
72{
73 /* explicit cast */
0c3d3f65
AJ
74 AnyP::ProtocolType protocol = static_cast<AnyP::ProtocolType>(URLScheme());
75 CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_NONE, protocol);
985c86bc 76 /* and implicit */
0c3d3f65
AJ
77 protocol = URLScheme(AnyP::PROTO_HTTP);
78 CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, protocol);
985c86bc 79}
80
81/*
0c3d3f65 82 * a default constructed URLScheme is == AnyP::PROTO_NONE
985c86bc 83 */
84void
85testURLScheme::testDefaultConstructor()
86{
41030a36 87 URLScheme lhs;
0c3d3f65 88 URLScheme rhs(AnyP::PROTO_NONE);
41030a36 89 CPPUNIT_ASSERT_EQUAL(lhs, rhs);
985c86bc 90}
91
92/*
93 * we should be able to construct a URLScheme from the old 'protocol_t' enum.
94 */
95void
96testURLScheme::testConstructprotocol_t()
97{
0c3d3f65 98 URLScheme lhs_none(AnyP::PROTO_NONE), rhs_none(AnyP::PROTO_NONE);
41030a36 99 CPPUNIT_ASSERT_EQUAL(lhs_none, rhs_none);
100
39a19cb7 101 URLScheme lhs_cacheobj(AnyP::PROTO_CACHE_OBJECT), rhs_cacheobj(AnyP::PROTO_CACHE_OBJECT);
41030a36 102 CPPUNIT_ASSERT_EQUAL(lhs_cacheobj, rhs_cacheobj);
103 CPPUNIT_ASSERT(lhs_none != rhs_cacheobj);
985c86bc 104}
105
106/*
107 * we should be able to get a char const * version of the method.
108 */
109void
110testURLScheme::testConst_str()
111{
30abd221 112 String lhs("wais");
0c3d3f65 113 URLScheme wais(AnyP::PROTO_WAIS);
30abd221 114 String rhs(wais.const_str());
41030a36 115 CPPUNIT_ASSERT_EQUAL(lhs, rhs);
985c86bc 116}
117
118/*
26ac0430 119 * a URLScheme replaces protocol_t, so we should be able to test for equality on
985c86bc 120 * either the left or right hand side seamlessly.
121 */
122void
123testURLScheme::testEqualprotocol_t()
124{
0c3d3f65
AJ
125 CPPUNIT_ASSERT(URLScheme() == AnyP::PROTO_NONE);
126 CPPUNIT_ASSERT(not (URLScheme(AnyP::PROTO_WAIS) == AnyP::PROTO_HTTP));
127 CPPUNIT_ASSERT(AnyP::PROTO_HTTP == URLScheme(AnyP::PROTO_HTTP));
39a19cb7 128 CPPUNIT_ASSERT(not (AnyP::PROTO_CACHE_OBJECT == URLScheme(AnyP::PROTO_HTTP)));
985c86bc 129}
130
131/*
132 * a URLScheme should testable for inequality with a protocol_t.
133 */
134void
135testURLScheme::testNotEqualprotocol_t()
136{
0c3d3f65
AJ
137 CPPUNIT_ASSERT(URLScheme(AnyP::PROTO_NONE) != AnyP::PROTO_HTTP);
138 CPPUNIT_ASSERT(not (URLScheme(AnyP::PROTO_HTTP) != AnyP::PROTO_HTTP));
139 CPPUNIT_ASSERT(AnyP::PROTO_NONE != URLScheme(AnyP::PROTO_HTTP));
140 CPPUNIT_ASSERT(not (AnyP::PROTO_WAIS != URLScheme(AnyP::PROTO_WAIS)));
985c86bc 141}
142
143/*
144 * we should be able to send it to a stream and get the normalised version
145 */
146void
147testURLScheme::testStream()
148{
149 std::ostringstream buffer;
0c3d3f65 150 buffer << URLScheme(AnyP::PROTO_HTTP);
30abd221 151 String http_str("http");
152 String from_buf(buffer.str().c_str());
41030a36 153 CPPUNIT_ASSERT_EQUAL(http_str, from_buf);
985c86bc 154}