| 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 "base/metrics/sample_map.h" | 5 #include "base/metrics/sample_map.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include <memory> |
| 8 |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 10 |
| 10 namespace base { | 11 namespace base { |
| 11 namespace { | 12 namespace { |
| 12 | 13 |
| 13 TEST(SampleMapTest, AccumulateTest) { | 14 TEST(SampleMapTest, AccumulateTest) { |
| 14 SampleMap samples(1); | 15 SampleMap samples(1); |
| 15 | 16 |
| 16 samples.Accumulate(1, 100); | 17 samples.Accumulate(1, 100); |
| 17 samples.Accumulate(2, 200); | 18 samples.Accumulate(2, 200); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 EXPECT_EQ(samples1.redundant_count(), samples1.TotalCount()); | 70 EXPECT_EQ(samples1.redundant_count(), samples1.TotalCount()); |
| 70 } | 71 } |
| 71 | 72 |
| 72 TEST(SampleMapIteratorTest, IterateTest) { | 73 TEST(SampleMapIteratorTest, IterateTest) { |
| 73 SampleMap samples(1); | 74 SampleMap samples(1); |
| 74 samples.Accumulate(1, 100); | 75 samples.Accumulate(1, 100); |
| 75 samples.Accumulate(2, 200); | 76 samples.Accumulate(2, 200); |
| 76 samples.Accumulate(4, -300); | 77 samples.Accumulate(4, -300); |
| 77 samples.Accumulate(5, 0); | 78 samples.Accumulate(5, 0); |
| 78 | 79 |
| 79 scoped_ptr<SampleCountIterator> it = samples.Iterator(); | 80 std::unique_ptr<SampleCountIterator> it = samples.Iterator(); |
| 80 | 81 |
| 81 HistogramBase::Sample min; | 82 HistogramBase::Sample min; |
| 82 HistogramBase::Sample max; | 83 HistogramBase::Sample max; |
| 83 HistogramBase::Count count; | 84 HistogramBase::Count count; |
| 84 | 85 |
| 85 it->Get(&min, &max, &count); | 86 it->Get(&min, &max, &count); |
| 86 EXPECT_EQ(1, min); | 87 EXPECT_EQ(1, min); |
| 87 EXPECT_EQ(2, max); | 88 EXPECT_EQ(2, max); |
| 88 EXPECT_EQ(100, count); | 89 EXPECT_EQ(100, count); |
| 89 EXPECT_FALSE(it->GetBucketIndex(NULL)); | 90 EXPECT_FALSE(it->GetBucketIndex(NULL)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 112 samples.Accumulate(20, 4); | 113 samples.Accumulate(20, 4); |
| 113 samples.Accumulate(25, 5); | 114 samples.Accumulate(25, 5); |
| 114 | 115 |
| 115 SampleMap samples2(2); | 116 SampleMap samples2(2); |
| 116 samples2.Accumulate(5, 1); | 117 samples2.Accumulate(5, 1); |
| 117 samples2.Accumulate(20, 4); | 118 samples2.Accumulate(20, 4); |
| 118 samples2.Accumulate(25, 5); | 119 samples2.Accumulate(25, 5); |
| 119 | 120 |
| 120 samples.Subtract(samples2); | 121 samples.Subtract(samples2); |
| 121 | 122 |
| 122 scoped_ptr<SampleCountIterator> it = samples.Iterator(); | 123 std::unique_ptr<SampleCountIterator> it = samples.Iterator(); |
| 123 EXPECT_FALSE(it->Done()); | 124 EXPECT_FALSE(it->Done()); |
| 124 | 125 |
| 125 HistogramBase::Sample min; | 126 HistogramBase::Sample min; |
| 126 HistogramBase::Sample max; | 127 HistogramBase::Sample max; |
| 127 HistogramBase::Count count; | 128 HistogramBase::Count count; |
| 128 | 129 |
| 129 it->Get(&min, &max, &count); | 130 it->Get(&min, &max, &count); |
| 130 EXPECT_EQ(10, min); | 131 EXPECT_EQ(10, min); |
| 131 EXPECT_EQ(11, max); | 132 EXPECT_EQ(11, max); |
| 132 EXPECT_EQ(2, count); | 133 EXPECT_EQ(2, count); |
| 133 | 134 |
| 134 it->Next(); | 135 it->Next(); |
| 135 EXPECT_FALSE(it->Done()); | 136 EXPECT_FALSE(it->Done()); |
| 136 | 137 |
| 137 it->Get(&min, &max, &count); | 138 it->Get(&min, &max, &count); |
| 138 EXPECT_EQ(15, min); | 139 EXPECT_EQ(15, min); |
| 139 EXPECT_EQ(16, max); | 140 EXPECT_EQ(16, max); |
| 140 EXPECT_EQ(3, count); | 141 EXPECT_EQ(3, count); |
| 141 | 142 |
| 142 it->Next(); | 143 it->Next(); |
| 143 EXPECT_TRUE(it->Done()); | 144 EXPECT_TRUE(it->Done()); |
| 144 } | 145 } |
| 145 | 146 |
| 146 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST | 147 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST |
| 147 | 148 |
| 148 TEST(SampleMapIteratorDeathTest, IterateDoneTest) { | 149 TEST(SampleMapIteratorDeathTest, IterateDoneTest) { |
| 149 SampleMap samples(1); | 150 SampleMap samples(1); |
| 150 | 151 |
| 151 scoped_ptr<SampleCountIterator> it = samples.Iterator(); | 152 std::unique_ptr<SampleCountIterator> it = samples.Iterator(); |
| 152 | 153 |
| 153 EXPECT_TRUE(it->Done()); | 154 EXPECT_TRUE(it->Done()); |
| 154 | 155 |
| 155 HistogramBase::Sample min; | 156 HistogramBase::Sample min; |
| 156 HistogramBase::Sample max; | 157 HistogramBase::Sample max; |
| 157 HistogramBase::Count count; | 158 HistogramBase::Count count; |
| 158 EXPECT_DEATH(it->Get(&min, &max, &count), ""); | 159 EXPECT_DEATH(it->Get(&min, &max, &count), ""); |
| 159 | 160 |
| 160 EXPECT_DEATH(it->Next(), ""); | 161 EXPECT_DEATH(it->Next(), ""); |
| 161 | 162 |
| 162 samples.Accumulate(1, 100); | 163 samples.Accumulate(1, 100); |
| 163 it = samples.Iterator(); | 164 it = samples.Iterator(); |
| 164 EXPECT_FALSE(it->Done()); | 165 EXPECT_FALSE(it->Done()); |
| 165 } | 166 } |
| 166 | 167 |
| 167 #endif | 168 #endif |
| 168 // (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST | 169 // (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST |
| 169 | 170 |
| 170 } // namespace | 171 } // namespace |
| 171 } // namespace base | 172 } // namespace base |
| OLD | NEW |