blob: 14a0ebbae672d6e7a99f084bfc3b214113c84b14 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Implementation of instance count mixin base class.
#include "ceee/testing/utils/instance_count_mixin.h"
#include "base/logging.h"
#include "gtest/gtest.h"
namespace {
// Set of existing instances.
testing::InstanceCountMixinBase::InstanceSet instances;
};
namespace testing {
Lock InstanceCountMixinBase::lock_;
InstanceCountMixinBase::InstanceCountMixinBase() {
base::AutoLock lock(lock_);
instances.insert(this);
}
InstanceCountMixinBase::~InstanceCountMixinBase() {
base::AutoLock lock(lock_);
EXPECT_EQ(1, instances.erase(this));
}
void InstanceCountMixinBase::GetDescription(std::string* description) const {
*description = "Override GetDescription in your test classes\n"
"to get useful information about the leaked objects.";
}
void InstanceCountMixinBase::LogLeakedInstances() {
base::AutoLock lock(lock_);
InstanceSet::const_iterator it(instances.begin());
InstanceSet::const_iterator end(instances.end());
for (; it != end; ++it) {
std::string description;
(*it)->GetDescription(&description);
LOG(ERROR) << "Leaked: " << description.c_str();
}
}
typedef InstanceCountMixinBase::InstanceSet InstanceSet;
size_t InstanceCountMixinBase::all_instance_count() {
base::AutoLock lock(lock_);
return instances.size();
}
InstanceSet::const_iterator InstanceCountMixinBase::begin() {
return instances.begin();
}
InstanceSet::const_iterator InstanceCountMixinBase::end() {
return instances.end();
}
} // namespace testing
|