This source file includes following definitions.
- TEST
#include "net/disk_cache/blockfile/addr.h"
#include "net/disk_cache/blockfile/block_bitmaps_v3.h"
#include "net/disk_cache/blockfile/block_files.h"
#include "net/disk_cache/blockfile/disk_format_base.h"
#include "testing/gtest/include/gtest/gtest.h"
TEST(DiskCacheBlockBitmaps, V3AllocationMap) {
disk_cache::BlockBitmaps block_bitmaps;
disk_cache::BlockFilesBitmaps bitmaps;
const int kNumHeaders = 10;
disk_cache::BlockFileHeader headers[kNumHeaders];
for (int i = 0; i < kNumHeaders; i++) {
memset(&headers[i], 0, sizeof(headers[i]));
headers[i].magic = disk_cache::kBlockMagic;
headers[i].version = disk_cache::kBlockCurrentVersion;
headers[i].this_file = static_cast<int16>(i);
headers[i].empty[3] = 200;
headers[i].max_entries = 800;
bitmaps.push_back(disk_cache::BlockHeader(&headers[i]));
}
block_bitmaps.Init(bitmaps);
const int kSize = 100;
disk_cache::Addr address[kSize];
for (int i = 0; i < kSize; i++) {
SCOPED_TRACE(i);
int block_size = i % 4 + 1;
ASSERT_TRUE(block_bitmaps.CreateBlock(disk_cache::BLOCK_1K, block_size,
&address[i]));
EXPECT_EQ(disk_cache::BLOCK_1K, address[i].file_type());
EXPECT_EQ(block_size, address[i].num_blocks());
int start = address[i].start_block();
EXPECT_EQ(start / 4, (start + block_size - 1) / 4);
}
for (int i = 0; i < kSize; i++) {
SCOPED_TRACE(i);
EXPECT_TRUE(block_bitmaps.IsValid(address[i]));
}
uint8* buffer = reinterpret_cast<uint8*>(&headers[2].allocation_map);
for (int i = 0; i < 29; i++) {
SCOPED_TRACE(i);
EXPECT_EQ(0xff, buffer[i]);
}
for (int i = 0; i < kSize; i++) {
SCOPED_TRACE(i);
block_bitmaps.DeleteBlock(address[i]);
}
for (int i =0; i < 50; i++) {
SCOPED_TRACE(i);
EXPECT_EQ(0, buffer[i]);
}
}