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,40 @@ |
+// 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/memory/scoped_ptr.h" |
+#include "base/metrics/sparse_histogram.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace base { |
+ |
+class SparseHistogramTest : public testing::Test { |
+ protected: |
+ SparseHistogram* NewSparseHistogram(const std::string& name) { |
Ilya Sherman
2012/08/08 05:00:30
nit: I think you can return a scoped_ptr<SparseHis
kaiwang
2012/08/08 22:17:08
IMHO, the name of the function indicates allocatin
Ilya Sherman
2012/08/08 22:49:40
If at all possible, for Chromium code we prefer to
kaiwang
2012/08/08 23:03:37
Done.
|
+ return new SparseHistogram(name); |
+ } |
+}; |
+ |
+TEST_F(SparseHistogramTest, BasicTest) { |
+ scoped_ptr<SparseHistogram> histogram(NewSparseHistogram("Sparse1")); |
+ std::map<HistogramBase::Sample, HistogramBase::Count> 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]); |
+} |
+ |
+} // namespace base |
Property changes on: base/metrics/sparse_histogram_unittest.cc |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |