]>
git.ipfire.org Git - thirdparty/squid.git/blob - test-suite/VirtualDeleteOperator.cc
5 * AUTHOR: Robert Collins
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
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.
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.
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.
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.
33 * Copyright (c) 2003 Robert Collins <robertc@squid-cache.org>
49 size_t deletes() const;
51 size_t _news
, _deletes
;
54 CallCounter::CallCounter() : _news(0), _deletes(0) {}
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
;}
64 void *operator new (size_t);
65 void operator delete (void *);
66 virtual ~BaseVirtual();
67 static void DeleteABase(BaseVirtual
*aBase
);
68 static CallCounter Calls
;
71 CallCounter
BaseVirtual::Calls
;
74 BaseVirtual::operator new(size_t byteCount
)
77 return ::operator new (byteCount
);
81 BaseVirtual::operator delete(void *address
)
84 ::operator delete (address
);
88 BaseVirtual::DeleteABase(BaseVirtual
*aBase
)
93 BaseVirtual::~BaseVirtual() {}
95 class ChildVirtual
: public BaseVirtual
98 void *operator new (size_t);
99 void operator delete (void *);
100 virtual ~ChildVirtual();
101 static CallCounter Calls
;
104 CallCounter
ChildVirtual::Calls
;
107 ChildVirtual::operator new(size_t byteCount
)
110 return ::operator new (byteCount
);
114 ChildVirtual::operator delete(void *address
)
116 Calls
.recordDelete();
117 ::operator delete (address
);
120 ChildVirtual::~ChildVirtual() {}
123 main(int argc
, char **argv
)
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);