testUriScheme.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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 */
24void
26{
27 AnyP::UriScheme empty_scheme;
28 AnyP::UriScheme scheme;
29 scheme = AnyP::PROTO_NONE;
30 CPPUNIT_ASSERT_EQUAL(empty_scheme, scheme);
31
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 */
41void
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 */
55void
57{
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 */
66void
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 */
80void
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 */
93void
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 */
105void
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 */
117void
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
127void
129{
130 Mem::Init();
132}
133
static void Init()
initializes down-cased protocol scheme names array
Definition: UriScheme.cc:38
SBuf image() const
Definition: UriScheme.h:57
Definition: SBuf.h:94
void testEqualprotocol_t()
void testConstructprotocol_t()
void testNotEqualprotocol_t()
void testCastToprotocol_t()
void testDefaultConstructor()
void testAssignFromprotocol_t()
void setUp() override
ProtocolType
Definition: ProtocolType.h:23
@ PROTO_NONE
Definition: ProtocolType.h:24
@ PROTO_HTTPS
Definition: ProtocolType.h:27
@ PROTO_HTTP
Definition: ProtocolType.h:25
@ PROTO_CACHE_OBJECT
Definition: ProtocolType.h:31
@ PROTO_WAIS
Definition: ProtocolType.h:30
void Init()
Definition: old_api.cc:425
CPPUNIT_TEST_SUITE_REGISTRATION(TestUriScheme)

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors