Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / net / disk_cache / simple / simple_test_util.h
blobec9b64434c0db0985571f3372a4d286f9b77943e
1 // Copyright 2013 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.
5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_TEST_UTIL_H_
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_TEST_UTIL_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
13 namespace base {
14 class FilePath;
17 namespace disk_cache {
18 namespace simple_util {
20 // Immutable array with compile-time bound-checking.
21 template <typename T, size_t Size>
22 class ImmutableArray {
23 public:
24 static const size_t size = Size;
26 ImmutableArray(const base::Callback<T (size_t index)>& initializer) {
27 for (size_t i = 0; i < size; ++i)
28 data_[i] = initializer.Run(i);
31 template <size_t Index>
32 const T& at() const {
33 static_assert(Index < size, "array out of bounds");
34 return data_[Index];
37 private:
38 T data_[size];
41 // Creates a corrupt file to be used in tests.
42 bool CreateCorruptFileForTests(const std::string& key,
43 const base::FilePath& cache_path);
45 } // namespace simple_backend
46 } // namespace disk_cache
48 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_TEST_UTIL_H_