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

Side by Side Diff: base/metrics/histogram_unittest.cc

Issue 10779040: Initialize StatisticsRecorder in Child Process to hold (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/metrics/statistics_recorder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Test of Histogram class 5 // Test of Histogram class
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/metrics/statistics_recorder.h" 13 #include "base/metrics/statistics_recorder.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace base { 17 namespace base {
18 namespace {
19 18
20 class HistogramTest : public testing::Test { 19 class HistogramTest : public testing::Test {
21 }; 20 };
22 21
23 // Check for basic syntax and use. 22 // Check for basic syntax and use.
24 TEST(HistogramTest, StartupShutdownTest) { 23 TEST(HistogramTest, StartupShutdownTest) {
25 // Try basic construction 24 // Try basic construction
26 Histogram* histogram(Histogram::FactoryGet( 25 Histogram* histogram(Histogram::FactoryGet(
27 "TestHistogram", 1, 1000, 10, Histogram::kNoFlags)); 26 "TestHistogram", 1, 1000, 10, Histogram::kNoFlags));
28 EXPECT_NE(reinterpret_cast<Histogram*>(NULL), histogram); 27 EXPECT_NE(reinterpret_cast<Histogram*>(NULL), histogram);
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 // Leave overflow bucket empty. 341 // Leave overflow bucket empty.
343 342
344 // Check to see that the bucket counts reflect our additions. 343 // Check to see that the bucket counts reflect our additions.
345 Histogram::SampleSet sample; 344 Histogram::SampleSet sample;
346 histogram->SnapshotSample(&sample); 345 histogram->SnapshotSample(&sample);
347 EXPECT_EQ(INT_MAX, histogram->ranges(8)); 346 EXPECT_EQ(INT_MAX, histogram->ranges(8));
348 for (int i = 0; i < 8; i++) 347 for (int i = 0; i < 8; i++)
349 EXPECT_EQ(i + 1, sample.counts(i)); 348 EXPECT_EQ(i + 1, sample.counts(i));
350 } 349 }
351 350
352 } // namespace
353
354 //------------------------------------------------------------------------------
355 // We can't be an an anonymous namespace while being friends, so we pop back
356 // out to the base namespace here. We need to be friends to corrupt the
357 // internals of the histogram and/or sampleset.
358 TEST(HistogramTest, CorruptSampleCounts) { 351 TEST(HistogramTest, CorruptSampleCounts) {
359 Histogram* histogram(Histogram::FactoryGet( 352 Histogram* histogram(Histogram::FactoryGet(
360 "Histogram", 1, 64, 8, Histogram::kNoFlags)); // As per header file. 353 "Histogram", 1, 64, 8, Histogram::kNoFlags)); // As per header file.
361 354
362 EXPECT_EQ(0, histogram->sample_.redundant_count()); 355 EXPECT_EQ(0, histogram->sample_.redundant_count());
363 histogram->Add(20); // Add some samples. 356 histogram->Add(20); // Add some samples.
364 histogram->Add(40); 357 histogram->Add(40);
365 EXPECT_EQ(2, histogram->sample_.redundant_count()); 358 EXPECT_EQ(2, histogram->sample_.redundant_count());
366 359
367 Histogram::SampleSet snapshot; 360 Histogram::SampleSet snapshot;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 "Histogram3", 1, 64, 16, Histogram::kNoFlags)); 439 "Histogram3", 1, 64, 16, Histogram::kNoFlags));
447 440
448 CachedRanges* cached_ranges1 = histogram1->cached_ranges(); 441 CachedRanges* cached_ranges1 = histogram1->cached_ranges();
449 CachedRanges* cached_ranges2 = histogram2->cached_ranges(); 442 CachedRanges* cached_ranges2 = histogram2->cached_ranges();
450 CachedRanges* cached_ranges3 = histogram3->cached_ranges(); 443 CachedRanges* cached_ranges3 = histogram3->cached_ranges();
451 EXPECT_TRUE(cached_ranges1->Equals(cached_ranges2)); 444 EXPECT_TRUE(cached_ranges1->Equals(cached_ranges2));
452 EXPECT_FALSE(cached_ranges1->Equals(cached_ranges3)); 445 EXPECT_FALSE(cached_ranges1->Equals(cached_ranges3));
453 } 446 }
454 447
455 } // namespace base 448 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/metrics/statistics_recorder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698