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

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

Issue 10809076: Move CachedRanges out and add support for checksum. (Closed) Base URL: svn://svn.chromium.org/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 | « base/metrics/bucket_ranges.cc ('k') | base/metrics/histogram.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/metrics/bucket_ranges.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace base {
10 namespace {
11
12 TEST(BucketRangesTest, NormalSetup) {
13 BucketRanges ranges(5);
14 ASSERT_EQ(5u, ranges.size());
15
16 for (int i = 0; i < 5; i++) {
17 EXPECT_EQ(0, ranges.range(i));
18 }
19 EXPECT_EQ(0u, ranges.checksum());
20
21 ranges.set_range(3, 100);
22 EXPECT_EQ(100, ranges.range(3));
23 }
24
25 TEST(BucketRangesTest, Equals) {
26 // Compare empty ranges.
27 BucketRanges ranges1(3);
28 BucketRanges ranges2(3);
29 BucketRanges ranges3(5);
30
31 EXPECT_TRUE(ranges1.Equals(&ranges2));
32 EXPECT_FALSE(ranges1.Equals(&ranges3));
33 EXPECT_FALSE(ranges2.Equals(&ranges3));
34
35 // Compare full filled ranges.
36 ranges1.set_range(0, 0);
37 ranges1.set_range(1, 1);
38 ranges1.set_range(2, 2);
39 ranges1.set_checksum(100);
40 ranges2.set_range(0, 0);
41 ranges2.set_range(1, 1);
42 ranges2.set_range(2, 2);
43 ranges2.set_checksum(100);
44
45 EXPECT_TRUE(ranges1.Equals(&ranges2));
46
47 // Checksum does not match.
48 ranges1.set_checksum(99);
49 EXPECT_FALSE(ranges1.Equals(&ranges2));
50 ranges1.set_checksum(100);
51
52 // Range does not match.
53 ranges1.set_range(1, 3);
54 EXPECT_FALSE(ranges1.Equals(&ranges2));
55 }
56
57 TEST(BucketRangesTest, Checksum) {
58 BucketRanges ranges(3);
59 ranges.set_range(0, 0);
60 ranges.set_range(1, 1);
61 ranges.set_range(2, 2);
62
63 ranges.ResetChecksum();
64 EXPECT_EQ(289217253u, ranges.checksum());
65
66 ranges.set_range(2, 3);
67 EXPECT_FALSE(ranges.HasValidChecksum());
68
69 ranges.ResetChecksum();
70 EXPECT_EQ(2843835776u, ranges.checksum());
71 EXPECT_TRUE(ranges.HasValidChecksum());
72 }
73
74 } // namespace
75 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/bucket_ranges.cc ('k') | base/metrics/histogram.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698