OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "base/metrics/histogram.h" | 5 #include "base/metrics/histogram.h" |
6 | 6 |
| 7 #include <limits.h> |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
| 11 #include <algorithm> |
7 #include <climits> | 12 #include <climits> |
8 #include <algorithm> | |
9 #include <vector> | 13 #include <vector> |
10 | 14 |
11 #include "base/logging.h" | 15 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
13 #include "base/metrics/bucket_ranges.h" | 17 #include "base/metrics/bucket_ranges.h" |
14 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
15 #include "base/metrics/sample_vector.h" | 19 #include "base/metrics/sample_vector.h" |
16 #include "base/metrics/statistics_recorder.h" | 20 #include "base/metrics/statistics_recorder.h" |
17 #include "base/pickle.h" | 21 #include "base/pickle.h" |
18 #include "base/time/time.h" | 22 #include "base/time/time.h" |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 EXPECT_EQ(HistogramBase::kIPCSerializationSourceFlag, flag); | 411 EXPECT_EQ(HistogramBase::kIPCSerializationSourceFlag, flag); |
408 | 412 |
409 int min; | 413 int min; |
410 EXPECT_TRUE(iter.ReadInt(&min)); | 414 EXPECT_TRUE(iter.ReadInt(&min)); |
411 EXPECT_EQ(1, min); | 415 EXPECT_EQ(1, min); |
412 | 416 |
413 int max; | 417 int max; |
414 EXPECT_TRUE(iter.ReadInt(&max)); | 418 EXPECT_TRUE(iter.ReadInt(&max)); |
415 EXPECT_EQ(64, max); | 419 EXPECT_EQ(64, max); |
416 | 420 |
417 int64 bucket_count; | 421 int64_t bucket_count; |
418 EXPECT_TRUE(iter.ReadInt64(&bucket_count)); | 422 EXPECT_TRUE(iter.ReadInt64(&bucket_count)); |
419 EXPECT_EQ(8, bucket_count); | 423 EXPECT_EQ(8, bucket_count); |
420 | 424 |
421 uint32 checksum; | 425 uint32_t checksum; |
422 EXPECT_TRUE(iter.ReadUInt32(&checksum)); | 426 EXPECT_TRUE(iter.ReadUInt32(&checksum)); |
423 EXPECT_EQ(histogram->bucket_ranges()->checksum(), checksum); | 427 EXPECT_EQ(histogram->bucket_ranges()->checksum(), checksum); |
424 | 428 |
425 // No more data in the pickle. | 429 // No more data in the pickle. |
426 EXPECT_FALSE(iter.SkipBytes(1)); | 430 EXPECT_FALSE(iter.SkipBytes(1)); |
427 } | 431 } |
428 | 432 |
429 TEST_F(HistogramTest, CustomHistogramSerializeInfo) { | 433 TEST_F(HistogramTest, CustomHistogramSerializeInfo) { |
430 std::vector<int> custom_ranges; | 434 std::vector<int> custom_ranges; |
431 custom_ranges.push_back(10); | 435 custom_ranges.push_back(10); |
432 custom_ranges.push_back(100); | 436 custom_ranges.push_back(100); |
433 | 437 |
434 HistogramBase* custom_histogram = CustomHistogram::FactoryGet( | 438 HistogramBase* custom_histogram = CustomHistogram::FactoryGet( |
435 "TestCustomRangeBoundedHistogram", | 439 "TestCustomRangeBoundedHistogram", |
436 custom_ranges, | 440 custom_ranges, |
437 HistogramBase::kNoFlags); | 441 HistogramBase::kNoFlags); |
438 Pickle pickle; | 442 Pickle pickle; |
439 custom_histogram->SerializeInfo(&pickle); | 443 custom_histogram->SerializeInfo(&pickle); |
440 | 444 |
441 // Validate the pickle. | 445 // Validate the pickle. |
442 PickleIterator iter(pickle); | 446 PickleIterator iter(pickle); |
443 | 447 |
444 int i; | 448 int i; |
445 std::string s; | 449 std::string s; |
446 int64 bucket_count; | 450 int64_t bucket_count; |
447 uint32 ui32; | 451 uint32_t ui32; |
448 EXPECT_TRUE(iter.ReadInt(&i) && iter.ReadString(&s) && iter.ReadInt(&i) && | 452 EXPECT_TRUE(iter.ReadInt(&i) && iter.ReadString(&s) && iter.ReadInt(&i) && |
449 iter.ReadInt(&i) && iter.ReadInt(&i) && | 453 iter.ReadInt(&i) && iter.ReadInt(&i) && |
450 iter.ReadInt64(&bucket_count) && iter.ReadUInt32(&ui32)); | 454 iter.ReadInt64(&bucket_count) && iter.ReadUInt32(&ui32)); |
451 EXPECT_EQ(3, bucket_count); | 455 EXPECT_EQ(3, bucket_count); |
452 | 456 |
453 int range; | 457 int range; |
454 EXPECT_TRUE(iter.ReadInt(&range)); | 458 EXPECT_TRUE(iter.ReadInt(&range)); |
455 EXPECT_EQ(10, range); | 459 EXPECT_EQ(10, range); |
456 EXPECT_TRUE(iter.ReadInt(&range)); | 460 EXPECT_TRUE(iter.ReadInt(&range)); |
457 EXPECT_EQ(100, range); | 461 EXPECT_EQ(100, range); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 // CustomHistogram needs at least 1 valid range. | 531 // CustomHistogram needs at least 1 valid range. |
528 custom_ranges.clear(); | 532 custom_ranges.clear(); |
529 custom_ranges.push_back(0); | 533 custom_ranges.push_back(0); |
530 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, | 534 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, |
531 HistogramBase::kNoFlags), | 535 HistogramBase::kNoFlags), |
532 ""); | 536 ""); |
533 } | 537 } |
534 #endif | 538 #endif |
535 | 539 |
536 } // namespace base | 540 } // namespace base |
OLD | NEW |