]>
Commit | Line | Data |
---|---|---|
4e0938ef | 1 | /* |
4ac4a490 | 2 | * Copyright (C) 1996-2017 The Squid Software Foundation and contributors |
4e0938ef AJ |
3 | * |
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. | |
7 | */ | |
8 | ||
582c2af2 | 9 | #include "squid.h" |
27e059d4 | 10 | |
985c86bc | 11 | #include <cppunit/TestAssert.h> |
12 | ||
1ca54a54 | 13 | #include "anyp/UriScheme.h" |
582c2af2 | 14 | #include "SquidString.h" |
1ca54a54 | 15 | #include "tests/testUriScheme.h" |
985c86bc | 16 | |
27e059d4 | 17 | #include <sstream> |
985c86bc | 18 | |
1ca54a54 | 19 | CPPUNIT_TEST_SUITE_REGISTRATION( testUriScheme ); |
985c86bc | 20 | |
985c86bc | 21 | #if 0 |
22 | /* | |
23 | * We should be able to make an HttpRequestMethod straight from a string. | |
24 | */ | |
25 | void | |
26 | testHttpRequestMethod::testConstructCharStart() | |
27 | { | |
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)); | |
32 | } | |
33 | ||
34 | /* | |
26ac0430 | 35 | * We can also parse precise ranges of characters |
985c86bc | 36 | */ |
37 | void | |
38 | testHttpRequestMethod::testConstructCharStartEnd() | |
39 | { | |
40 | char const * buffer; | |
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 */ | |
46 | buffer = "POSTPLUS"; | |
47 | CPPUNIT_ASSERT(METHOD_POST == HttpRequestMethod(buffer, buffer + 4)); | |
48 | } | |
49 | ||
50 | #endif | |
51 | ||
52 | /* | |
1ca54a54 | 53 | * we should be able to assign a protocol_t to a AnyP::UriScheme for ease |
985c86bc | 54 | * of code conversion |
55 | */ | |
56 | void | |
1ca54a54 | 57 | testUriScheme::testAssignFromprotocol_t() |
985c86bc | 58 | { |
1ca54a54 AJ |
59 | AnyP::UriScheme empty_scheme; |
60 | AnyP::UriScheme scheme; | |
0c3d3f65 | 61 | scheme = AnyP::PROTO_NONE; |
41030a36 | 62 | CPPUNIT_ASSERT_EQUAL(empty_scheme, scheme); |
63 | ||
1ca54a54 | 64 | AnyP::UriScheme https_scheme(AnyP::PROTO_HTTPS); |
0c3d3f65 | 65 | scheme = AnyP::PROTO_HTTPS; |
41030a36 | 66 | CPPUNIT_ASSERT_EQUAL(https_scheme, scheme); |
985c86bc | 67 | } |
68 | ||
69 | /* | |
1ca54a54 | 70 | * We should be able to get a protocol_t from a AnyP::UriScheme for ease |
985c86bc | 71 | * of migration |
72 | */ | |
73 | void | |
1ca54a54 | 74 | testUriScheme::testCastToprotocol_t() |
985c86bc | 75 | { |
76 | /* explicit cast */ | |
1ca54a54 | 77 | AnyP::ProtocolType protocol = static_cast<AnyP::ProtocolType>(AnyP::UriScheme()); |
0c3d3f65 | 78 | CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_NONE, protocol); |
985c86bc | 79 | /* and implicit */ |
1ca54a54 | 80 | protocol = AnyP::UriScheme(AnyP::PROTO_HTTP); |
0c3d3f65 | 81 | CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, protocol); |
985c86bc | 82 | } |
83 | ||
84 | /* | |
1ca54a54 | 85 | * a default constructed AnyP::UriScheme is == AnyP::PROTO_NONE |
985c86bc | 86 | */ |
87 | void | |
1ca54a54 | 88 | testUriScheme::testDefaultConstructor() |
985c86bc | 89 | { |
1ca54a54 AJ |
90 | AnyP::UriScheme lhs; |
91 | AnyP::UriScheme rhs(AnyP::PROTO_NONE); | |
41030a36 | 92 | CPPUNIT_ASSERT_EQUAL(lhs, rhs); |
985c86bc | 93 | } |
94 | ||
95 | /* | |
1ca54a54 | 96 | * we should be able to construct a AnyP::UriScheme from the old 'protocol_t' enum. |
985c86bc | 97 | */ |
98 | void | |
1ca54a54 | 99 | testUriScheme::testConstructprotocol_t() |
985c86bc | 100 | { |
1ca54a54 | 101 | AnyP::UriScheme lhs_none(AnyP::PROTO_NONE), rhs_none(AnyP::PROTO_NONE); |
41030a36 | 102 | CPPUNIT_ASSERT_EQUAL(lhs_none, rhs_none); |
103 | ||
1ca54a54 | 104 | AnyP::UriScheme lhs_cacheobj(AnyP::PROTO_CACHE_OBJECT), rhs_cacheobj(AnyP::PROTO_CACHE_OBJECT); |
41030a36 | 105 | CPPUNIT_ASSERT_EQUAL(lhs_cacheobj, rhs_cacheobj); |
106 | CPPUNIT_ASSERT(lhs_none != rhs_cacheobj); | |
985c86bc | 107 | } |
108 | ||
109 | /* | |
110 | * we should be able to get a char const * version of the method. | |
111 | */ | |
112 | void | |
1ca54a54 | 113 | testUriScheme::testC_str() |
985c86bc | 114 | { |
d31d59d8 | 115 | SBuf lhs("wais"); |
1ca54a54 | 116 | AnyP::UriScheme wais(AnyP::PROTO_WAIS); |
d31d59d8 | 117 | SBuf rhs(wais.image()); |
41030a36 | 118 | CPPUNIT_ASSERT_EQUAL(lhs, rhs); |
985c86bc | 119 | } |
120 | ||
121 | /* | |
1ca54a54 | 122 | * a AnyP::UriScheme replaces protocol_t, so we should be able to test for equality on |
985c86bc | 123 | * either the left or right hand side seamlessly. |
124 | */ | |
125 | void | |
1ca54a54 | 126 | testUriScheme::testEqualprotocol_t() |
985c86bc | 127 | { |
1ca54a54 AJ |
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))); | |
985c86bc | 132 | } |
133 | ||
134 | /* | |
1ca54a54 | 135 | * a AnyP::UriScheme should testable for inequality with a protocol_t. |
985c86bc | 136 | */ |
137 | void | |
1ca54a54 | 138 | testUriScheme::testNotEqualprotocol_t() |
985c86bc | 139 | { |
1ca54a54 AJ |
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))); | |
985c86bc | 144 | } |
145 | ||
146 | /* | |
147 | * we should be able to send it to a stream and get the normalised version | |
148 | */ | |
149 | void | |
1ca54a54 | 150 | testUriScheme::testStream() |
985c86bc | 151 | { |
152 | std::ostringstream buffer; | |
1ca54a54 | 153 | buffer << AnyP::UriScheme(AnyP::PROTO_HTTP); |
30abd221 | 154 | String http_str("http"); |
155 | String from_buf(buffer.str().c_str()); | |
41030a36 | 156 | CPPUNIT_ASSERT_EQUAL(http_str, from_buf); |
985c86bc | 157 | } |
f53969cc | 158 |