| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/test/gtest_util.h" | 9 #include "base/test/gtest_util.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 TEST(SampleMapIteratorTest, IterateTest) { | 74 TEST(SampleMapIteratorTest, IterateTest) { |
| 75 SampleMap samples(1); | 75 SampleMap samples(1); |
| 76 samples.Accumulate(1, 100); | 76 samples.Accumulate(1, 100); |
| 77 samples.Accumulate(2, 200); | 77 samples.Accumulate(2, 200); |
| 78 samples.Accumulate(4, -300); | 78 samples.Accumulate(4, -300); |
| 79 samples.Accumulate(5, 0); | 79 samples.Accumulate(5, 0); |
| 80 | 80 |
| 81 std::unique_ptr<SampleCountIterator> it = samples.Iterator(); | 81 std::unique_ptr<SampleCountIterator> it = samples.Iterator(); |
| 82 | 82 |
| 83 HistogramBase::Sample min; | 83 HistogramBase::Sample min; |
| 84 HistogramBase::Sample max; | 84 int64_t max; |
| 85 HistogramBase::Count count; | 85 HistogramBase::Count count; |
| 86 | 86 |
| 87 it->Get(&min, &max, &count); | 87 it->Get(&min, &max, &count); |
| 88 EXPECT_EQ(1, min); | 88 EXPECT_EQ(1, min); |
| 89 EXPECT_EQ(2, max); | 89 EXPECT_EQ(2, max); |
| 90 EXPECT_EQ(100, count); | 90 EXPECT_EQ(100, count); |
| 91 EXPECT_FALSE(it->GetBucketIndex(NULL)); | 91 EXPECT_FALSE(it->GetBucketIndex(NULL)); |
| 92 | 92 |
| 93 it->Next(); | 93 it->Next(); |
| 94 it->Get(&min, &max, &count); | 94 it->Get(&min, &max, &count); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 118 samples2.Accumulate(5, 1); | 118 samples2.Accumulate(5, 1); |
| 119 samples2.Accumulate(20, 4); | 119 samples2.Accumulate(20, 4); |
| 120 samples2.Accumulate(25, 5); | 120 samples2.Accumulate(25, 5); |
| 121 | 121 |
| 122 samples.Subtract(samples2); | 122 samples.Subtract(samples2); |
| 123 | 123 |
| 124 std::unique_ptr<SampleCountIterator> it = samples.Iterator(); | 124 std::unique_ptr<SampleCountIterator> it = samples.Iterator(); |
| 125 EXPECT_FALSE(it->Done()); | 125 EXPECT_FALSE(it->Done()); |
| 126 | 126 |
| 127 HistogramBase::Sample min; | 127 HistogramBase::Sample min; |
| 128 HistogramBase::Sample max; | 128 int64_t max; |
| 129 HistogramBase::Count count; | 129 HistogramBase::Count count; |
| 130 | 130 |
| 131 it->Get(&min, &max, &count); | 131 it->Get(&min, &max, &count); |
| 132 EXPECT_EQ(10, min); | 132 EXPECT_EQ(10, min); |
| 133 EXPECT_EQ(11, max); | 133 EXPECT_EQ(11, max); |
| 134 EXPECT_EQ(2, count); | 134 EXPECT_EQ(2, count); |
| 135 | 135 |
| 136 it->Next(); | 136 it->Next(); |
| 137 EXPECT_FALSE(it->Done()); | 137 EXPECT_FALSE(it->Done()); |
| 138 | 138 |
| 139 it->Get(&min, &max, &count); | 139 it->Get(&min, &max, &count); |
| 140 EXPECT_EQ(15, min); | 140 EXPECT_EQ(15, min); |
| 141 EXPECT_EQ(16, max); | 141 EXPECT_EQ(16, max); |
| 142 EXPECT_EQ(3, count); | 142 EXPECT_EQ(3, count); |
| 143 | 143 |
| 144 it->Next(); | 144 it->Next(); |
| 145 EXPECT_TRUE(it->Done()); | 145 EXPECT_TRUE(it->Done()); |
| 146 } | 146 } |
| 147 | 147 |
| 148 TEST(SampleMapIteratorDeathTest, IterateDoneTest) { | 148 TEST(SampleMapIteratorDeathTest, IterateDoneTest) { |
| 149 SampleMap samples(1); | 149 SampleMap samples(1); |
| 150 | 150 |
| 151 std::unique_ptr<SampleCountIterator> it = samples.Iterator(); | 151 std::unique_ptr<SampleCountIterator> it = samples.Iterator(); |
| 152 | 152 |
| 153 EXPECT_TRUE(it->Done()); | 153 EXPECT_TRUE(it->Done()); |
| 154 | 154 |
| 155 HistogramBase::Sample min; | 155 HistogramBase::Sample min; |
| 156 HistogramBase::Sample max; | 156 int64_t max; |
| 157 HistogramBase::Count count; | 157 HistogramBase::Count count; |
| 158 EXPECT_DCHECK_DEATH(it->Get(&min, &max, &count)); | 158 EXPECT_DCHECK_DEATH(it->Get(&min, &max, &count)); |
| 159 | 159 |
| 160 EXPECT_DCHECK_DEATH(it->Next()); | 160 EXPECT_DCHECK_DEATH(it->Next()); |
| 161 | 161 |
| 162 samples.Accumulate(1, 100); | 162 samples.Accumulate(1, 100); |
| 163 it = samples.Iterator(); | 163 it = samples.Iterator(); |
| 164 EXPECT_FALSE(it->Done()); | 164 EXPECT_FALSE(it->Done()); |
| 165 } | 165 } |
| 166 | 166 |
| 167 } // namespace | 167 } // namespace |
| 168 } // namespace base | 168 } // namespace base |
| OLD | NEW |