OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/metrics/sample_map.h" | |
8 #include "base/metrics/sparse_histogram.h" | 9 #include "base/metrics/sparse_histogram.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 | 11 |
11 namespace base { | 12 namespace base { |
12 | 13 |
13 class SparseHistogramTest : public testing::Test { | 14 class SparseHistogramTest : public testing::Test { |
14 protected: | 15 protected: |
15 scoped_ptr<SparseHistogram> NewSparseHistogram(const std::string& name) { | 16 scoped_ptr<SparseHistogram> NewSparseHistogram(const std::string& name) { |
16 return scoped_ptr<SparseHistogram>(new SparseHistogram(name)); | 17 return scoped_ptr<SparseHistogram>(new SparseHistogram(name)); |
17 } | 18 } |
18 }; | 19 }; |
19 | 20 |
20 TEST_F(SparseHistogramTest, BasicTest) { | 21 TEST_F(SparseHistogramTest, BasicTest) { |
21 scoped_ptr<SparseHistogram> histogram(NewSparseHistogram("Sparse1")); | 22 scoped_ptr<SparseHistogram> histogram(NewSparseHistogram("Sparse1")); |
22 std::map<HistogramBase::Sample, HistogramBase::Count> sample; | |
23 histogram->SnapshotSample(&sample); | |
24 | |
25 ASSERT_EQ(0u, sample.size()); | |
Ilya Sherman
2012/10/05 03:29:24
nit: Why did you remove the testcase covering an e
kaiwang
2012/10/05 04:02:38
Done.
| |
26 | 23 |
27 histogram->Add(100); | 24 histogram->Add(100); |
28 histogram->SnapshotSample(&sample); | 25 scoped_ptr<SampleMap> snapshot(histogram->SnapshotSamples()); |
29 ASSERT_EQ(1u, sample.size()); | 26 EXPECT_EQ(1, snapshot->TotalCount()); |
30 EXPECT_EQ(1, sample[100]); | 27 EXPECT_EQ(1, snapshot->GetCount(100)); |
31 | 28 |
32 histogram->Add(100); | 29 histogram->Add(100); |
33 histogram->Add(101); | 30 histogram->Add(101); |
34 histogram->SnapshotSample(&sample); | 31 scoped_ptr<SampleMap> snapshot2(histogram->SnapshotSamples()); |
35 ASSERT_EQ(2u, sample.size()); | 32 EXPECT_EQ(3, snapshot2->TotalCount()); |
36 EXPECT_EQ(2, sample[100]); | 33 EXPECT_EQ(2, snapshot2->GetCount(100)); |
37 EXPECT_EQ(1, sample[101]); | 34 EXPECT_EQ(1, snapshot2->GetCount(101)); |
38 } | 35 } |
39 | 36 |
40 } // namespace base | 37 } // namespace base |
OLD | NEW |