]> git.ipfire.org Git - thirdparty/squid.git/blob - test-suite/VirtualDeleteOperator.cc
Removed squid-old.h
[thirdparty/squid.git] / test-suite / VirtualDeleteOperator.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
38 #if HAVE_IOSTREAM
39 #include <iostream>
40 #endif
41
42 class CallCounter
43 {
44 public:
45 CallCounter();
46 void recordNew();
47 void recordDelete();
48 size_t news() const;
49 size_t deletes() const;
50 private:
51 size_t _news, _deletes;
52 };
53
54 CallCounter::CallCounter() : _news(0), _deletes(0) {}
55
56 void CallCounter::recordNew() { ++_news;}
57 void CallCounter::recordDelete() { ++_deletes;}
58 size_t CallCounter::news() const {return _news;}
59 size_t CallCounter::deletes() const {return _deletes;}
60
61 class BaseVirtual
62 {
63 public:
64 void *operator new (size_t);
65 void operator delete (void *);
66 virtual ~BaseVirtual();
67 static void DeleteABase(BaseVirtual *aBase);
68 static CallCounter Calls;
69 };
70
71 CallCounter BaseVirtual::Calls;
72
73 void *
74 BaseVirtual::operator new(size_t byteCount)
75 {
76 Calls.recordNew();
77 return ::operator new (byteCount);
78 }
79
80 void
81 BaseVirtual::operator delete(void *address)
82 {
83 Calls.recordDelete();
84 ::operator delete (address);
85 }
86
87 void
88 BaseVirtual::DeleteABase(BaseVirtual *aBase)
89 {
90 delete aBase;
91 }
92
93 BaseVirtual::~BaseVirtual() {}
94
95 class ChildVirtual : public BaseVirtual
96 {
97 public:
98 void *operator new (size_t);
99 void operator delete (void *);
100 virtual ~ChildVirtual();
101 static CallCounter Calls;
102 };
103
104 CallCounter ChildVirtual::Calls;
105
106 void *
107 ChildVirtual::operator new(size_t byteCount)
108 {
109 Calls.recordNew();
110 return ::operator new (byteCount);
111 }
112
113 void
114 ChildVirtual::operator delete(void *address)
115 {
116 Calls.recordDelete();
117 ::operator delete (address);
118 }
119
120 ChildVirtual::~ChildVirtual() {}
121
122 int
123 main(int argc, char **argv)
124 {
125 assert (BaseVirtual::Calls.news() == 0);
126 assert (BaseVirtual::Calls.deletes() == 0);
127 assert (ChildVirtual::Calls.news() == 0);
128 assert (ChildVirtual::Calls.deletes() == 0);
129 BaseVirtual *aBase = new ChildVirtual;
130 assert (BaseVirtual::Calls.news() == 0);
131 assert (BaseVirtual::Calls.deletes() == 0);
132 assert (ChildVirtual::Calls.news() == 1);
133 assert (ChildVirtual::Calls.deletes() == 0);
134 BaseVirtual::DeleteABase(aBase);
135 assert (BaseVirtual::Calls.news() == 0);
136 assert (BaseVirtual::Calls.deletes() == 0);
137 assert (ChildVirtual::Calls.news() == 1);
138 assert (ChildVirtual::Calls.deletes() == 1);
139 // deleting NULL works.
140 BaseVirtual::DeleteABase(NULL);
141 assert (BaseVirtual::Calls.news() == 0);
142 assert (BaseVirtual::Calls.deletes() == 0);
143 assert (ChildVirtual::Calls.news() == 1);
144 assert (ChildVirtual::Calls.deletes() == 1);
145 return 0;
146 }