]> git.ipfire.org Git - thirdparty/squid.git/blame - test-suite/syntheticoperators.cc
Merged from trunk.
[thirdparty/squid.git] / test-suite / syntheticoperators.cc
CommitLineData
d2d59a68 1
2/*
3 * $Id: syntheticoperators.cc,v 1.1 2003/07/10 01:31:51 robertc Exp $
4 *
5 * AUTHOR: Robert Collins
6 *
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
9 *
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
32 *
33 * Copyright (c) 2003 Robert Collins <robertc@squid-cache.org>
34 */
35
36#include "squid.h"
37#include "stmem.h"
38#include "mem_node.h"
39#include <iostream>
40
41class HasExplicit {
42 public:
43 HasExplicit();
44 ~HasExplicit();
45 HasExplicit(HasExplicit const &);
46 HasExplicit &operator=(HasExplicit const &);
47 static int const &Instances();
48 static int const &Assignments();
49 static void Assignments(int const &);
50 private:
51 static void AddInstance();
52 static void RemoveInstance();
53 static void Assignment();
54 static int Instances_;
55 static int Assignments_;
56};
57
58int HasExplicit::Instances_(0);
59int HasExplicit::Assignments_(0);
60
61HasExplicit::HasExplicit() {
62 AddInstance();
63}
64
65HasExplicit::~HasExplicit() {
66 RemoveInstance();
67}
68
69HasExplicit::HasExplicit(HasExplicit const &) {
70 AddInstance();
71}
72
73HasExplicit &
74HasExplicit::operator= (HasExplicit const &) {
75 Assignment();
76 return *this;
77}
78
79void
80HasExplicit::AddInstance()
81{
82 ++Instances_;
83}
84
85void
86HasExplicit::RemoveInstance()
87{
88 --Instances_;
89}
90
91void
92HasExplicit::Assignment()
93{
94 ++Assignments_;
95}
96
97int const &
98HasExplicit::Instances()
99{
100 return Instances_;
101}
102
103int const &
104HasExplicit::Assignments()
105{
106 return Assignments_;
107}
108
109void
110HasExplicit::Assignments(int const &newValue)
111{
112 Assignments_ = newValue;
113}
114
115void
116CheckHasExplicitWorks()
117{
118 assert (HasExplicit::Instances() == 0);
119 HasExplicit *one = new HasExplicit;
120 assert (HasExplicit::Instances() == 1);
121 HasExplicit *two = new HasExplicit;
122 assert (HasExplicit::Instances() == 2);
123 *two = *one;
124 assert (HasExplicit::Instances() == 2);
125 assert (HasExplicit::Assignments() == 1);
126 *two = *one;
127 assert (HasExplicit::Instances() == 2);
128 assert (HasExplicit::Assignments() == 2);
129 HasExplicit *three = new HasExplicit(*two);
130 assert (HasExplicit::Instances() == 3);
131 delete three;
132 assert (HasExplicit::Instances() == 2);
133 delete one;
134 assert (HasExplicit::Instances() == 1);
135 delete two;
136 assert (HasExplicit::Instances() == 0);
137 HasExplicit::Assignments(0);
138 assert (HasExplicit::Assignments() == 0);
139}
140
141class SyntheticOwnsExplicit {
142 public:
143 HasExplicit aMember;
144};
145
146void
147CheckSyntheticWorks()
148{
149 assert (HasExplicit::Instances() == 0);
150 assert (HasExplicit::Assignments() == 0);
151 SyntheticOwnsExplicit *one = new SyntheticOwnsExplicit;
152 assert (HasExplicit::Instances() == 1);
153 SyntheticOwnsExplicit *two = new SyntheticOwnsExplicit;
154 assert (HasExplicit::Instances() == 2);
155 *two = *one;
156 assert (HasExplicit::Instances() == 2);
157 assert (HasExplicit::Assignments() == 1);
158 *two = *one;
159 assert (HasExplicit::Instances() == 2);
160 assert (HasExplicit::Assignments() == 2);
161 SyntheticOwnsExplicit *three = new SyntheticOwnsExplicit(*two);
162 assert (HasExplicit::Instances() == 3);
163 delete three;
164 assert (HasExplicit::Instances() == 2);
165 delete one;
166 assert (HasExplicit::Instances() == 1);
167 delete two;
168 assert (HasExplicit::Instances() == 0);
169 HasExplicit::Assignments(0);
170 assert (HasExplicit::Assignments() == 0);
171}
172
173int
b610642c 174main(int argc, char **argv)
d2d59a68 175{
176 CheckHasExplicitWorks();
177 CheckSyntheticWorks();
178 return 0;
179}