OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/metrics/serialization/serialization_utils.h" | 5 #include "components/metrics/serialization/serialization_utils.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "components/metrics/serialization/metric_sample.h" | 11 #include "components/metrics/serialization/metric_sample.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace metrics { | 14 namespace metrics { |
15 namespace { | 15 namespace { |
16 | 16 |
17 class SerializationUtilsTest : public testing::Test { | 17 class SerializationUtilsTest : public testing::Test { |
18 protected: | 18 protected: |
19 SerializationUtilsTest() { | 19 SerializationUtilsTest() { |
20 bool success = temporary_dir.CreateUniqueTempDir(); | 20 bool success = temporary_dir.CreateUniqueTempDir(); |
21 if (success) { | 21 if (success) { |
22 base::FilePath dir_path = temporary_dir.path(); | 22 base::FilePath dir_path = temporary_dir.path(); |
23 filename = dir_path.value() + "chromeossampletest"; | 23 filename = dir_path.value() + "chromeossampletest"; |
24 filepath = base::FilePath(filename); | 24 filepath = base::FilePath(filename); |
25 } | 25 } |
26 } | 26 } |
27 | 27 |
28 virtual void SetUp() OVERRIDE { | 28 virtual void SetUp() override { |
29 base::DeleteFile(filepath, false); | 29 base::DeleteFile(filepath, false); |
30 } | 30 } |
31 | 31 |
32 void TestSerialization(MetricSample* sample) { | 32 void TestSerialization(MetricSample* sample) { |
33 std::string serialized(sample->ToString()); | 33 std::string serialized(sample->ToString()); |
34 ASSERT_EQ('\0', serialized[serialized.length() - 1]); | 34 ASSERT_EQ('\0', serialized[serialized.length() - 1]); |
35 scoped_ptr<MetricSample> deserialized = | 35 scoped_ptr<MetricSample> deserialized = |
36 SerializationUtils::ParseSample(serialized); | 36 SerializationUtils::ParseSample(serialized); |
37 ASSERT_TRUE(deserialized); | 37 ASSERT_TRUE(deserialized); |
38 EXPECT_TRUE(sample->IsEqual(*deserialized.get())); | 38 EXPECT_TRUE(sample->IsEqual(*deserialized.get())); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 EXPECT_TRUE(shist->IsEqual(*vect[3])); | 161 EXPECT_TRUE(shist->IsEqual(*vect[3])); |
162 EXPECT_TRUE(action->IsEqual(*vect[4])); | 162 EXPECT_TRUE(action->IsEqual(*vect[4])); |
163 | 163 |
164 int64 size = 0; | 164 int64 size = 0; |
165 ASSERT_TRUE(base::GetFileSize(filepath, &size)); | 165 ASSERT_TRUE(base::GetFileSize(filepath, &size)); |
166 ASSERT_EQ(0, size); | 166 ASSERT_EQ(0, size); |
167 } | 167 } |
168 | 168 |
169 } // namespace | 169 } // namespace |
170 } // namespace metrics | 170 } // namespace metrics |
OLD | NEW |