testUriScheme.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2022 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 /*
21  * we should be able to assign a protocol_t to a AnyP::UriScheme for ease
22  * of code conversion
23  */
24 void
26 {
27  AnyP::UriScheme empty_scheme;
28  AnyP::UriScheme scheme;
29  scheme = AnyP::PROTO_NONE;
30  CPPUNIT_ASSERT_EQUAL(empty_scheme, scheme);
31 
32  AnyP::UriScheme https_scheme(AnyP::PROTO_HTTPS);
33  scheme = AnyP::PROTO_HTTPS;
34  CPPUNIT_ASSERT_EQUAL(https_scheme, scheme);
35 }
36 
37 /*
38  * We should be able to get a protocol_t from a AnyP::UriScheme for ease
39  * of migration
40  */
41 void
43 {
44  /* explicit cast */
45  AnyP::ProtocolType protocol = static_cast<AnyP::ProtocolType>(AnyP::UriScheme());
46  CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_NONE, protocol);
47  /* and implicit */
49  CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, protocol);
50 }
51 
52 /*
53  * a default constructed AnyP::UriScheme is == AnyP::PROTO_NONE
54  */
55 void
57 {
58  AnyP::UriScheme lhs;
60  CPPUNIT_ASSERT_EQUAL(lhs, rhs);
61 }
62 
63 /*
64  * we should be able to construct a AnyP::UriScheme from the old 'protocol_t' enum.
65  */
66 void
68 {
70  CPPUNIT_ASSERT_EQUAL(lhs_none, rhs_none);
71 
73  CPPUNIT_ASSERT_EQUAL(lhs_cacheobj, rhs_cacheobj);
74  CPPUNIT_ASSERT(lhs_none != rhs_cacheobj);
75 }
76 
77 /*
78  * we should be able to get a char const * version of the method.
79  */
80 void
82 {
83  SBuf lhs("wais");
85  SBuf rhs(wais.image());
86  CPPUNIT_ASSERT_EQUAL(lhs, rhs);
87 }
88 
89 /*
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.
92  */
93 void
95 {
96  CPPUNIT_ASSERT(AnyP::UriScheme() == AnyP::PROTO_NONE);
97  CPPUNIT_ASSERT(not (AnyP::UriScheme(AnyP::PROTO_WAIS) == AnyP::PROTO_HTTP));
100 }
101 
102 /*
103  * a AnyP::UriScheme should testable for inequality with a protocol_t.
104  */
105 void
107 {
109  CPPUNIT_ASSERT(not (AnyP::UriScheme(AnyP::PROTO_HTTP) != AnyP::PROTO_HTTP));
111  CPPUNIT_ASSERT(not (AnyP::PROTO_WAIS != AnyP::UriScheme(AnyP::PROTO_WAIS)));
112 }
113 
114 /*
115  * we should be able to send it to a stream and get the normalised version
116  */
117 void
119 {
120  std::ostringstream buffer;
122  SBuf http_str("http");
123  SBuf from_buf(buffer.str());
124  CPPUNIT_ASSERT_EQUAL(http_str, from_buf);
125 }
126 
127 void
129 {
130  Mem::Init();
132 }
133 
@ PROTO_NONE
Definition: ProtocolType.h:24
void testEqualprotocol_t()
Definition: SBuf.h:94
void testConstructprotocol_t()
ProtocolType
Definition: ProtocolType.h:23
CPPUNIT_TEST_SUITE_REGISTRATION(testUriScheme)
static void Init()
initializes down-cased protocol scheme names array
Definition: UriScheme.cc:38
void testDefaultConstructor()
void testNotEqualprotocol_t()
SBuf image() const
Definition: UriScheme.h:50
void testCastToprotocol_t()
@ PROTO_CACHE_OBJECT
Definition: ProtocolType.h:32
@ PROTO_HTTPS
Definition: ProtocolType.h:27
@ PROTO_HTTP
Definition: ProtocolType.h:25
@ PROTO_WAIS
Definition: ProtocolType.h:31
void Init()
Definition: old_api.cc:425
void testAssignFromprotocol_t()

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors