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

Side by Side Diff: net/disk_cache/blockfile/bitmap_unittest.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "net/disk_cache/blockfile/bitmap.h" 5 #include "net/disk_cache/blockfile/bitmap.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 7
8 TEST(BitmapTest, OverAllocate) { 8 TEST(BitmapTest, OverAllocate) {
9 // Test that we don't over allocate on boundaries. 9 // Test that we don't over allocate on boundaries.
10 disk_cache::Bitmap map32(32, false); 10 disk_cache::Bitmap map32(32, false);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 for (int i = 0; i < kMapSize; i++) { 98 for (int i = 0; i < kMapSize; i++) {
99 if (i % 2) 99 if (i % 2)
100 EXPECT_TRUE(bitmap.Get(i * 8)); 100 EXPECT_TRUE(bitmap.Get(i * 8));
101 else 101 else
102 EXPECT_FALSE(bitmap.Get(i * 8)); 102 EXPECT_FALSE(bitmap.Get(i * 8));
103 } 103 }
104 104
105 EXPECT_EQ(0, memcmp(local_map, bitmap.GetMap(), kMapSize)); 105 EXPECT_EQ(0, memcmp(local_map, bitmap.GetMap(), kMapSize));
106 106
107 // Now let's create a bitmap that shares local_map as storage. 107 // Now let's create a bitmap that shares local_map as storage.
108 disk_cache::Bitmap bitmap2(reinterpret_cast<uint32*>(local_map), 108 disk_cache::Bitmap bitmap2(
109 kMapSize * 8, kMapSize / 4); 109 reinterpret_cast<uint32*>(local_map), kMapSize * 8, kMapSize / 4);
110 EXPECT_EQ(0, memcmp(local_map, bitmap2.GetMap(), kMapSize)); 110 EXPECT_EQ(0, memcmp(local_map, bitmap2.GetMap(), kMapSize));
111 111
112 local_map[kMapSize / 2] = 'a'; 112 local_map[kMapSize / 2] = 'a';
113 EXPECT_EQ(0, memcmp(local_map, bitmap2.GetMap(), kMapSize)); 113 EXPECT_EQ(0, memcmp(local_map, bitmap2.GetMap(), kMapSize));
114 EXPECT_NE(0, memcmp(local_map, bitmap.GetMap(), kMapSize)); 114 EXPECT_NE(0, memcmp(local_map, bitmap.GetMap(), kMapSize));
115 } 115 }
116 116
117 TEST(BitmapTest, SetAll) { 117 TEST(BitmapTest, SetAll) {
118 // Tests SetAll and Clear. 118 // Tests SetAll and Clear.
119 const int kMapSize = 80; 119 const int kMapSize = 80;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 176 }
177 177
178 TEST(BitmapTest, FindNextSetBitBeforeLimit) { 178 TEST(BitmapTest, FindNextSetBitBeforeLimit) {
179 // Test FindNextSetBitBeforeLimit. Only check bits from 111 to 277 (limit 179 // Test FindNextSetBitBeforeLimit. Only check bits from 111 to 277 (limit
180 // bit == 278). Should find all multiples of 27 in that range. 180 // bit == 278). Should find all multiples of 27 in that range.
181 disk_cache::Bitmap map(500, true); 181 disk_cache::Bitmap map(500, true);
182 for (int i = 0; i < 500; i++) 182 for (int i = 0; i < 500; i++)
183 map.Set(i, (i % 27) == 0); 183 map.Set(i, (i % 27) == 0);
184 184
185 int find_me = 135; // First one expected. 185 int find_me = 135; // First one expected.
186 for (int index = 111; map.FindNextSetBitBeforeLimit(&index, 278); 186 for (int index = 111; map.FindNextSetBitBeforeLimit(&index, 278); ++index) {
187 ++index) {
188 EXPECT_EQ(index, find_me); 187 EXPECT_EQ(index, find_me);
189 find_me += 27; 188 find_me += 27;
190 } 189 }
191 EXPECT_EQ(find_me, 297); // The next find_me after 278. 190 EXPECT_EQ(find_me, 297); // The next find_me after 278.
192 } 191 }
193 192
194 TEST(BitmapTest, FindNextSetBitBeforeLimitAligned) { 193 TEST(BitmapTest, FindNextSetBitBeforeLimitAligned) {
195 // Test FindNextSetBitBeforeLimit on aligned scans. 194 // Test FindNextSetBitBeforeLimit on aligned scans.
196 disk_cache::Bitmap map(256, true); 195 disk_cache::Bitmap map(256, true);
197 for (int i = 0; i < 256; i++) 196 for (int i = 0; i < 256; i++)
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 bitmap.SetMapElement(11, 0xff); 283 bitmap.SetMapElement(11, 0xff);
285 284
286 index = 0; 285 index = 0;
287 EXPECT_EQ(16, bitmap.FindBits(&index, 500, true)); 286 EXPECT_EQ(16, bitmap.FindBits(&index, 500, true));
288 EXPECT_EQ(344, index); 287 EXPECT_EQ(344, index);
289 288
290 index = 0; 289 index = 0;
291 EXPECT_EQ(4, bitmap.FindBits(&index, 348, true)); 290 EXPECT_EQ(4, bitmap.FindBits(&index, 348, true));
292 EXPECT_EQ(344, index); 291 EXPECT_EQ(344, index);
293 } 292 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698