Chromium Code Reviews| Index: base/metrics/sparse_histogram_unittest.cc |
| =================================================================== |
| --- base/metrics/sparse_histogram_unittest.cc (revision 0) |
| +++ base/metrics/sparse_histogram_unittest.cc (revision 0) |
| @@ -0,0 +1,39 @@ |
| +// Copyright (c) 2012 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. |
| + |
| +#include <string> |
| + |
| +#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.
|
| +#include "base/metrics/sparse_histogram.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +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.
|
| +class SparseHistogramTest : public testing::Test { |
| + protected: |
| + SparseHistogram* NewSparseHistogram(const std::string& name) { |
| + 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
|
| + } |
| +}; |
| + |
| +TEST_F(SparseHistogramTest, BasicTest) { |
| + SparseHistogram* histogram = NewSparseHistogram("Sparse1"); |
| + SparseHistogram::SampleCounts sample; |
| + histogram->SnapshotSample(&sample); |
| + |
| + ASSERT_EQ(0u, sample.size()); |
| + |
| + histogram->Add(100); |
| + histogram->SnapshotSample(&sample); |
| + ASSERT_EQ(1u, sample.size()); |
| + EXPECT_EQ(1, sample[100]); |
| + |
| + histogram->Add(100); |
| + histogram->Add(101); |
| + histogram->SnapshotSample(&sample); |
| + ASSERT_EQ(2u, sample.size()); |
| + EXPECT_EQ(2, sample[100]); |
| + EXPECT_EQ(1, sample[101]); |
| +} |
|
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;
|
| + |
| +} // namespace base |
| Property changes on: base/metrics/sparse_histogram_unittest.cc |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |