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

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

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 years 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
« no previous file with comments | « net/disk_cache/blockfile/bitmap.cc ('k') | net/disk_cache/blockfile/block_bitmaps_v3.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) 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);
11 EXPECT_EQ(1, map32.ArraySize()); 11 EXPECT_EQ(1, map32.ArraySize());
12 12
13 disk_cache::Bitmap map64(64, false); 13 disk_cache::Bitmap map64(64, false);
14 EXPECT_EQ(2, map64.ArraySize()); 14 EXPECT_EQ(2, map64.ArraySize());
15 } 15 }
16 16
17 TEST(BitmapTest, DefaultConstructor) { 17 TEST(BitmapTest, DefaultConstructor) {
18 // Verify that the default constructor doesn't allocate a bitmap. 18 // Verify that the default constructor doesn't allocate a bitmap.
19 disk_cache::Bitmap map; 19 disk_cache::Bitmap map;
20 EXPECT_EQ(0, map.Size()); 20 EXPECT_EQ(0, map.Size());
21 EXPECT_EQ(0, map.ArraySize()); 21 EXPECT_EQ(0, map.ArraySize());
22 EXPECT_TRUE(NULL == map.GetMap()); 22 EXPECT_TRUE(NULL == map.GetMap());
23 } 23 }
24 24
25 TEST(BitmapTest, Basics) { 25 TEST(BitmapTest, Basics) {
26 disk_cache::Bitmap bitmap(80, true); 26 disk_cache::Bitmap bitmap(80, true);
27 const uint32 kValue = 0x74f10060; 27 const uint32_t kValue = 0x74f10060;
28 28
29 // Test proper allocation size. 29 // Test proper allocation size.
30 EXPECT_EQ(80, bitmap.Size()); 30 EXPECT_EQ(80, bitmap.Size());
31 EXPECT_EQ(3, bitmap.ArraySize()); 31 EXPECT_EQ(3, bitmap.ArraySize());
32 32
33 // Test Set/GetMapElement. 33 // Test Set/GetMapElement.
34 EXPECT_EQ(0U, bitmap.GetMapElement(1)); 34 EXPECT_EQ(0U, bitmap.GetMapElement(1));
35 bitmap.SetMapElement(1, kValue); 35 bitmap.SetMapElement(1, kValue);
36 EXPECT_EQ(kValue, bitmap.GetMapElement(1)); 36 EXPECT_EQ(kValue, bitmap.GetMapElement(1));
37 37
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 87 }
88 88
89 TEST(BitmapTest, Map) { 89 TEST(BitmapTest, Map) {
90 // Tests Set/GetMap and the constructor that takes an array. 90 // Tests Set/GetMap and the constructor that takes an array.
91 const int kMapSize = 80; 91 const int kMapSize = 80;
92 char local_map[kMapSize]; 92 char local_map[kMapSize];
93 for (int i = 0; i < kMapSize; i++) 93 for (int i = 0; i < kMapSize; i++)
94 local_map[i] = static_cast<char>(i); 94 local_map[i] = static_cast<char>(i);
95 95
96 disk_cache::Bitmap bitmap(kMapSize * 8, false); 96 disk_cache::Bitmap bitmap(kMapSize * 8, false);
97 bitmap.SetMap(reinterpret_cast<uint32*>(local_map), kMapSize / 4); 97 bitmap.SetMap(reinterpret_cast<uint32_t*>(local_map), kMapSize / 4);
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(reinterpret_cast<uint32_t*>(local_map),
109 kMapSize * 8, kMapSize / 4); 109 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.
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 bitmap.SetMapElement(11, 0xff); 284 bitmap.SetMapElement(11, 0xff);
285 285
286 index = 0; 286 index = 0;
287 EXPECT_EQ(16, bitmap.FindBits(&index, 500, true)); 287 EXPECT_EQ(16, bitmap.FindBits(&index, 500, true));
288 EXPECT_EQ(344, index); 288 EXPECT_EQ(344, index);
289 289
290 index = 0; 290 index = 0;
291 EXPECT_EQ(4, bitmap.FindBits(&index, 348, true)); 291 EXPECT_EQ(4, bitmap.FindBits(&index, 348, true));
292 EXPECT_EQ(344, index); 292 EXPECT_EQ(344, index);
293 } 293 }
OLDNEW
« no previous file with comments | « net/disk_cache/blockfile/bitmap.cc ('k') | net/disk_cache/blockfile/block_bitmaps_v3.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698