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
30#include <wtf/FastMalloc.h>
31
32struct CopyMoveCounter {
33 static unsigned constructionCount;
34 static unsigned copyCount;
35 static unsigned moveCount;
36
37 struct TestingScope {
38 TestingScope()
39 {
40 constructionCount = 0;
41 copyCount = 0;
42 moveCount = 0;
43 }
44 };
45
46 CopyMoveCounter() { constructionCount++; }
47 CopyMoveCounter(const CopyMoveCounter&) { copyCount++; }
48 CopyMoveCounter& operator=(const CopyMoveCounter&) { copyCount++; return *this; }
49 CopyMoveCounter(CopyMoveCounter&&) { moveCount++; }
50 CopyMoveCounter& operator=(CopyMoveCounter&&) { moveCount++; return *this; }
51};
52
53
54struct ConstructorDestructorCounter {
55 WTF_MAKE_STRUCT_FAST_ALLOCATED;
56 static unsigned constructionCount;
57 static unsigned destructionCount;
58
59 struct TestingScope {
60 TestingScope()
61 {
62 constructionCount = 0;
63 destructionCount = 0;
64 }
65 };
66
67 ConstructorDestructorCounter() { constructionCount++; }
68 ~ConstructorDestructorCounter() { destructionCount++; }
69};
70
71#if COMPILER(CLANG)
72#if __has_warning("-Wundefined-var-template")
73#pragma clang diagnostic push
74#pragma clang diagnostic ignored "-Wundefined-var-template"
75#endif
76#endif
77template<typename T>
78struct DeleterCounter {
79 static unsigned m_deleterCount;
80
81 static unsigned deleterCount() { return m_deleterCount; }
82
83 struct TestingScope {
84 TestingScope()
85 {
86 m_deleterCount = 0;
87 }
88 };
89
90 void operator()(T* p) const
91 {
92 m_deleterCount++;
93 delete p;
94 }
95};
96#if COMPILER(CLANG)
97#if __has_warning("-Wundefined-var-template")
98#pragma clang diagnostic pop
99#endif
100#endif
101
102#endif // Counters_h
103