Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(558)

Unified Diff: base/metrics/sparse_histogram_unittest.cc

Issue 11682003: Serialize/Deserialize support in HistogramBase (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/metrics/sparse_histogram_unittest.cc
diff --git a/base/metrics/sparse_histogram_unittest.cc b/base/metrics/sparse_histogram_unittest.cc
index b4eb8fddba71379cc004fc214fd39bb702f2c958..1b52b6cafb4a82c8df7ee4032e68ad6b14800a4e 100644
--- a/base/metrics/sparse_histogram_unittest.cc
+++ b/base/metrics/sparse_histogram_unittest.cc
@@ -5,8 +5,10 @@
#include <string>
#include "base/memory/scoped_ptr.h"
+#include "base/metrics/histogram_base.h"
#include "base/metrics/sample_map.h"
#include "base/metrics/sparse_histogram.h"
+#include "base/pickle.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
@@ -19,7 +21,7 @@ class SparseHistogramTest : public testing::Test {
};
TEST_F(SparseHistogramTest, BasicTest) {
- scoped_ptr<SparseHistogram> histogram(NewSparseHistogram("Sparse1"));
+ scoped_ptr<SparseHistogram> histogram(NewSparseHistogram("Sparse"));
scoped_ptr<HistogramSamples> snapshot(histogram->SnapshotSamples());
EXPECT_EQ(0, snapshot->TotalCount());
EXPECT_EQ(0, snapshot->sum());
@@ -37,4 +39,29 @@ TEST_F(SparseHistogramTest, BasicTest) {
EXPECT_EQ(1, snapshot2->GetCount(101));
}
+TEST_F(SparseHistogramTest, Serialize) {
+ scoped_ptr<SparseHistogram> histogram(NewSparseHistogram("Sparse"));
+ histogram->SetFlags(HistogramBase::kIPCSerializationSourceFlag);
+
+ Pickle pickle;
+ histogram->SerializeInfo(&pickle);
+
+ PickleIterator iter(pickle);
+
+ int type;
+ EXPECT_TRUE(iter.ReadInt(&type));
+ EXPECT_EQ(SPARSE_HISTOGRAM, type);
+
+ std::string name;
+ EXPECT_TRUE(iter.ReadString(&name));
+ EXPECT_EQ("Sparse", name);
+
+ int flag;
+ EXPECT_TRUE(iter.ReadInt(&flag));
+ EXPECT_EQ(HistogramBase::kIPCSerializationSourceFlag, flag);
+
+ // No more data in the pickle.
+ EXPECT_FALSE(iter.SkipBytes(1));
+}
Ilya Sherman 2012/12/29 00:17:30 It seems like a more fruitful test would be to tes
kaiwang 2013/01/08 00:51:40 All deserializing tests are in histogram_base_unit
+
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698