summaryrefslogtreecommitdiffstats
path: root/net/disk_cache/flash/flash_cache_test_base.cc
blob: 0123e16d9ba2fdbaca7bd5a0ca38453e99fb4d56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/disk_cache/flash/flash_cache_test_base.h"

#include "base/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/time.h"
#include "net/disk_cache/flash/format.h"
#include "net/disk_cache/flash/log_structured_store.h"
#include "net/disk_cache/flash/storage.h"

namespace {

const int32 kSegmentCount = 10;
const FilePath::StringType kCachePath = FILE_PATH_LITERAL("cache");

}  // namespace

FlashCacheTest::FlashCacheTest() : num_segments_in_storage_(kSegmentCount) {
  int seed = static_cast<int>(base::Time::Now().ToInternalValue());
  srand(seed);
}

FlashCacheTest::~FlashCacheTest() {
}

void FlashCacheTest::SetUp() {
  ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
  const FilePath path(temp_dir_.path().Append(kCachePath));

  int32 storage_size = num_segments_in_storage_ * disk_cache::kFlashSegmentSize;
  storage_.reset(new disk_cache::Storage(path, storage_size));
  ASSERT_TRUE(storage_->Init());

  log_structured_store_.reset(
      new disk_cache::LogStructuredStore(storage_.get()));
  ASSERT_TRUE(log_structured_store_->Init());
}

void FlashCacheTest::TearDown() {
  ASSERT_TRUE(log_structured_store_->Close());
  log_structured_store_.reset();
  storage_.reset();
}