testUriScheme.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
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 
9 #include "squid.h"
10 
11 #include <cppunit/TestAssert.h>
12 
13 #include "anyp/UriScheme.h"
14 #include "tests/testUriScheme.h"
15 
16 #include <sstream>
17 
19 
20 #if 0
21 /*
22  * We should be able to make an HttpRequestMethod straight from a string.
23  */
24 void
26 {
27  /* parse an empty string -> METHOD_NONE */
28  CPPUNIT_ASSERT(METHOD_NONE == HttpRequestMethod(NULL));
29  /* parsing a literal should work */
30  CPPUNIT_ASSERT(METHOD_GET == HttpRequestMethod("GET", NULL));
31 }
32 
33 /*
34  * We can also parse precise ranges of characters
35  */
36 void
38 {
39  char const * buffer;
40  /* parse an empty string -> METHOD_NONE */
41  CPPUNIT_ASSERT(METHOD_NONE == HttpRequestMethod(NULL, NULL));
42  /* parsing a literal should work */
43  CPPUNIT_ASSERT(METHOD_GET == HttpRequestMethod("GET", NULL));
44  /* parsing with an explicit end should work */
45  buffer = "POSTPLUS";
46  CPPUNIT_ASSERT(METHOD_POST == HttpRequestMethod(buffer, buffer + 4));
47 }
48 
49 #endif
50 
51 /*
52  * we should be able to assign a protocol_t to a AnyP::UriScheme for ease
53  * of code conversion
54  */
55 void
57 {
58  AnyP::UriScheme empty_scheme;
59  AnyP::UriScheme scheme;
60  scheme = AnyP::PROTO_NONE;
61  CPPUNIT_ASSERT_EQUAL(empty_scheme, scheme);
62 
63  AnyP::UriScheme https_scheme(AnyP::PROTO_HTTPS);
64  scheme = AnyP::PROTO_HTTPS;
65  CPPUNIT_ASSERT_EQUAL(https_scheme, scheme);
66 }
67 
68 /*
69  * We should be able to get a protocol_t from a AnyP::UriScheme for ease
70  * of migration
71  */
72 void
74 {
75  /* explicit cast */
76  AnyP::ProtocolType protocol = static_cast<AnyP::ProtocolType>(AnyP::UriScheme());
77  CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_NONE, protocol);
78  /* and implicit */
80  CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, protocol);
81 }
82 
83 /*
84  * a default constructed AnyP::UriScheme is == AnyP::PROTO_NONE
85  */
86 void
88 {
89  AnyP::UriScheme lhs;
91  CPPUNIT_ASSERT_EQUAL(lhs, rhs);
92 }
93 
94 /*
95  * we should be able to construct a AnyP::UriScheme from the old 'protocol_t' enum.
96  */
97 void
99 {
101  CPPUNIT_ASSERT_EQUAL(lhs_none, rhs_none);
102 
104  CPPUNIT_ASSERT_EQUAL(lhs_cacheobj, rhs_cacheobj);
105  CPPUNIT_ASSERT(lhs_none != rhs_cacheobj);
106 }
107 
108 /*
109  * we should be able to get a char const * version of the method.
110  */
111 void
113 {
114  SBuf lhs("wais");
116  SBuf rhs(wais.image());
117  CPPUNIT_ASSERT_EQUAL(lhs, rhs);
118 }
119 
120 /*
121  * a AnyP::UriScheme replaces protocol_t, so we should be able to test for equality on
122  * either the left or right hand side seamlessly.
123  */
124 void
126 {
127  CPPUNIT_ASSERT(AnyP::UriScheme() == AnyP::PROTO_NONE);
128  CPPUNIT_ASSERT(not (AnyP::UriScheme(AnyP::PROTO_WAIS) == AnyP::PROTO_HTTP));
131 }
132 
133 /*
134  * a AnyP::UriScheme should testable for inequality with a protocol_t.
135  */
136 void
138 {
140  CPPUNIT_ASSERT(not (AnyP::UriScheme(AnyP::PROTO_HTTP) != AnyP::PROTO_HTTP));
142  CPPUNIT_ASSERT(not (AnyP::PROTO_WAIS != AnyP::UriScheme(AnyP::PROTO_WAIS)));
143 }
144 
145 /*
146  * we should be able to send it to a stream and get the normalised version
147  */
148 void
150 {
151  std::ostringstream buffer;
153  SBuf http_str("http");
154  SBuf from_buf(buffer.str());
155  CPPUNIT_ASSERT_EQUAL(http_str, from_buf);
156 }
157 
void testCastToprotocol_t()
void testAssignFromprotocol_t()
Definition: SBuf.h:87
SBuf image() const
Definition: UriScheme.h:50
void testConstructprotocol_t()
CPPUNIT_TEST_SUITE_REGISTRATION(testUriScheme)
void testNotEqualprotocol_t()
ProtocolType
Definition: ProtocolType.h:22
void testEqualprotocol_t()
#define NULL
Definition: types.h:166
void testDefaultConstructor()

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors