Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <string> | |
| 6 | |
| 7 #include "base/logging.h" | |
|
Ilya Sherman
2012/08/04 01:18:35
nit: What is this include needed for?
kaiwang
2012/08/08 03:59:33
Done.
| |
| 8 #include "base/metrics/sparse_histogram.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace base { | |
|
Ilya Sherman
2012/08/04 01:18:35
nit: Please leave a blank line after this line.
kaiwang
2012/08/08 03:59:33
Done.
| |
| 12 class SparseHistogramTest : public testing::Test { | |
| 13 protected: | |
| 14 SparseHistogram* NewSparseHistogram(const std::string& name) { | |
| 15 return new SparseHistogram(name); | |
|
Ilya Sherman
2012/08/04 01:18:35
Why is the test code using the constructor, rather
kaiwang
2012/08/08 03:59:33
Deleted the newed histogram.
Will test FactoryGet
| |
| 16 } | |
| 17 }; | |
| 18 | |
| 19 TEST_F(SparseHistogramTest, BasicTest) { | |
| 20 SparseHistogram* histogram = NewSparseHistogram("Sparse1"); | |
| 21 SparseHistogram::SampleCounts sample; | |
| 22 histogram->SnapshotSample(&sample); | |
| 23 | |
| 24 ASSERT_EQ(0u, sample.size()); | |
| 25 | |
| 26 histogram->Add(100); | |
| 27 histogram->SnapshotSample(&sample); | |
| 28 ASSERT_EQ(1u, sample.size()); | |
| 29 EXPECT_EQ(1, sample[100]); | |
| 30 | |
| 31 histogram->Add(100); | |
| 32 histogram->Add(101); | |
| 33 histogram->SnapshotSample(&sample); | |
| 34 ASSERT_EQ(2u, sample.size()); | |
| 35 EXPECT_EQ(2, sample[100]); | |
| 36 EXPECT_EQ(1, sample[101]); | |
| 37 } | |
|
Ilya Sherman
2012/08/04 01:18:35
Since the SparseHistogram code uses locks, I would
kaiwang
2012/08/08 03:59:33
What's the common way in chromium code to test loc
Ilya Sherman
2012/08/08 05:00:29
I'm not sure if there's an especially common way;
| |
| 38 | |
| 39 } // namespace base | |
| OLD | NEW |