]> git.ipfire.org Git - thirdparty/squid.git/blob - test-suite/syntheticoperators.cc
Author: Francesco Chemolli <kinkie@squid-cache.org>
[thirdparty/squid.git] / test-suite / syntheticoperators.cc
1
2 /*
3 * $Id$
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
41 class HasExplicit
42 {
43 public:
44 HasExplicit();
45 ~HasExplicit();
46 HasExplicit(HasExplicit const &);
47 HasExplicit &operator=(HasExplicit const &);
48 static int const &Instances();
49 static int const &Assignments();
50 static void Assignments(int const &);
51 private:
52 static void AddInstance();
53 static void RemoveInstance();
54 static void Assignment();
55 static int Instances_;
56 static int Assignments_;
57 };
58
59 int HasExplicit::Instances_(0);
60 int HasExplicit::Assignments_(0);
61
62 HasExplicit::HasExplicit()
63 {
64 AddInstance();
65 }
66
67 HasExplicit::~HasExplicit()
68 {
69 RemoveInstance();
70 }
71
72 HasExplicit::HasExplicit(HasExplicit const &)
73 {
74 AddInstance();
75 }
76
77 HasExplicit &
78 HasExplicit::operator= (HasExplicit const &)
79 {
80 Assignment();
81 return *this;
82 }
83
84 void
85 HasExplicit::AddInstance()
86 {
87 ++Instances_;
88 }
89
90 void
91 HasExplicit::RemoveInstance()
92 {
93 --Instances_;
94 }
95
96 void
97 HasExplicit::Assignment()
98 {
99 ++Assignments_;
100 }
101
102 int const &
103 HasExplicit::Instances()
104 {
105 return Instances_;
106 }
107
108 int const &
109 HasExplicit::Assignments()
110 {
111 return Assignments_;
112 }
113
114 void
115 HasExplicit::Assignments(int const &newValue)
116 {
117 Assignments_ = newValue;
118 }
119
120 void
121 CheckHasExplicitWorks()
122 {
123 assert (HasExplicit::Instances() == 0);
124 HasExplicit *one = new HasExplicit;
125 assert (HasExplicit::Instances() == 1);
126 HasExplicit *two = new HasExplicit;
127 assert (HasExplicit::Instances() == 2);
128 *two = *one;
129 assert (HasExplicit::Instances() == 2);
130 assert (HasExplicit::Assignments() == 1);
131 *two = *one;
132 assert (HasExplicit::Instances() == 2);
133 assert (HasExplicit::Assignments() == 2);
134 HasExplicit *three = new HasExplicit(*two);
135 assert (HasExplicit::Instances() == 3);
136 delete three;
137 assert (HasExplicit::Instances() == 2);
138 delete one;
139 assert (HasExplicit::Instances() == 1);
140 delete two;
141 assert (HasExplicit::Instances() == 0);
142 HasExplicit::Assignments(0);
143 assert (HasExplicit::Assignments() == 0);
144 }
145
146 class SyntheticOwnsExplicit
147 {
148 public:
149 HasExplicit aMember;
150 };
151
152 void
153 CheckSyntheticWorks()
154 {
155 assert (HasExplicit::Instances() == 0);
156 assert (HasExplicit::Assignments() == 0);
157 SyntheticOwnsExplicit *one = new SyntheticOwnsExplicit;
158 assert (HasExplicit::Instances() == 1);
159 SyntheticOwnsExplicit *two = new SyntheticOwnsExplicit;
160 assert (HasExplicit::Instances() == 2);
161 *two = *one;
162 assert (HasExplicit::Instances() == 2);
163 assert (HasExplicit::Assignments() == 1);
164 *two = *one;
165 assert (HasExplicit::Instances() == 2);
166 assert (HasExplicit::Assignments() == 2);
167 SyntheticOwnsExplicit *three = new SyntheticOwnsExplicit(*two);
168 assert (HasExplicit::Instances() == 3);
169 delete three;
170 assert (HasExplicit::Instances() == 2);
171 delete one;
172 assert (HasExplicit::Instances() == 1);
173 delete two;
174 assert (HasExplicit::Instances() == 0);
175 HasExplicit::Assignments(0);
176 assert (HasExplicit::Assignments() == 0);
177 }
178
179 int
180 main(int argc, char **argv)
181 {
182 CheckHasExplicitWorks();
183 CheckSyntheticWorks();
184 return 0;
185 }