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