1/*
2 * Copyright (C) 2014 Igalia S.L.
3 * Copyright (C) 2014, 2016 Apple Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#ifndef Counters_h
28#define Counters_h
29
30struct CopyMoveCounter {
31 static unsigned constructionCount;
32 static unsigned copyCount;
33 static unsigned moveCount;
34
35 struct TestingScope {
36 TestingScope()
37 {
38 constructionCount = 0;
39 copyCount = 0;
40 moveCount = 0;
41 }
42 };
43
44 CopyMoveCounter() { constructionCount++; }
45 CopyMoveCounter(const CopyMoveCounter&) { copyCount++; }
46 CopyMoveCounter& operator=(const CopyMoveCounter&) { copyCount++; return *this; }
47 CopyMoveCounter(CopyMoveCounter&&) { moveCount++; }
48 CopyMoveCounter& operator=(CopyMoveCounter&&) { moveCount++; return *this; }
49};
50
51
52struct ConstructorDestructorCounter {
53 static unsigned constructionCount;
54 static unsigned destructionCount;
55
56 struct TestingScope {
57 TestingScope()
58 {
59 constructionCount = 0;
60 destructionCount = 0;
61 }
62 };
63
64 ConstructorDestructorCounter() { constructionCount++; }
65 ~ConstructorDestructorCounter() { destructionCount++; }
66};
67
68#if COMPILER(CLANG)
69#if __has_warning("-Wundefined-var-template")
70#pragma clang diagnostic push
71#pragma clang diagnostic ignored "-Wundefined-var-template"
72#endif
73#endif
74template<typename T>
75struct DeleterCounter {
76 static unsigned m_deleterCount;
77
78 static unsigned deleterCount() { return m_deleterCount; }
79
80 struct TestingScope {
81 TestingScope()
82 {
83 m_deleterCount = 0;
84 }
85 };
86
87 void operator()(T* p) const
88 {
89 m_deleterCount++;
90 delete p;
91 }
92};
93#if COMPILER(CLANG)
94#if __has_warning("-Wundefined-var-template")
95#pragma clang diagnostic pop
96#endif
97#endif
98
99#endif // Counters_h
100