OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "net/disk_cache/disk_cache_test_base.h" | 8 #include "net/disk_cache/disk_cache_test_base.h" |
9 #include "net/disk_cache/disk_cache_test_util.h" | 9 #include "net/disk_cache/disk_cache_test_util.h" |
10 #include "net/disk_cache/mapped_file.h" | 10 #include "net/disk_cache/mapped_file.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 iterations = 0; | 54 iterations = 0; |
55 } | 55 } |
56 #elif defined(OS_POSIX) | 56 #elif defined(OS_POSIX) |
57 // TODO(rvargas): Do something when async IO is implemented. | 57 // TODO(rvargas): Do something when async IO is implemented. |
58 #endif | 58 #endif |
59 } | 59 } |
60 | 60 |
61 } // namespace | 61 } // namespace |
62 | 62 |
63 TEST_F(DiskCacheTest, MappedFile_SyncIO) { | 63 TEST_F(DiskCacheTest, MappedFile_SyncIO) { |
64 FilePath filename = GetCacheFilePath().AppendASCII("a_test"); | 64 ScopedTestCache test_cache; |
| 65 FilePath filename = test_cache.path().AppendASCII("a_test"); |
| 66 |
65 scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); | 67 scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); |
66 ASSERT_TRUE(CreateCacheTestFile(filename)); | 68 ASSERT_TRUE(CreateCacheTestFile(filename)); |
67 ASSERT_TRUE(file->Init(filename, 8192)); | 69 ASSERT_TRUE(file->Init(filename, 8192)); |
68 | 70 |
69 char buffer1[20]; | 71 char buffer1[20]; |
70 char buffer2[20]; | 72 char buffer2[20]; |
71 CacheTestFillBuffer(buffer1, sizeof(buffer1), false); | 73 CacheTestFillBuffer(buffer1, sizeof(buffer1), false); |
72 base::strlcpy(buffer1, "the data", arraysize(buffer1)); | 74 base::strlcpy(buffer1, "the data", arraysize(buffer1)); |
73 EXPECT_TRUE(file->Write(buffer1, sizeof(buffer1), 8192)); | 75 EXPECT_TRUE(file->Write(buffer1, sizeof(buffer1), 8192)); |
74 EXPECT_TRUE(file->Read(buffer2, sizeof(buffer2), 8192)); | 76 EXPECT_TRUE(file->Read(buffer2, sizeof(buffer2), 8192)); |
75 EXPECT_STREQ(buffer1, buffer2); | 77 EXPECT_STREQ(buffer1, buffer2); |
76 } | 78 } |
77 | 79 |
78 TEST_F(DiskCacheTest, MappedFile_AsyncIO) { | 80 TEST_F(DiskCacheTest, MappedFile_AsyncIO) { |
79 FilePath filename = GetCacheFilePath().AppendASCII("a_test"); | 81 ScopedTestCache test_cache; |
| 82 FilePath filename = test_cache.path().AppendASCII("a_test"); |
| 83 |
80 scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); | 84 scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); |
81 ASSERT_TRUE(CreateCacheTestFile(filename)); | 85 ASSERT_TRUE(CreateCacheTestFile(filename)); |
82 ASSERT_TRUE(file->Init(filename, 8192)); | 86 ASSERT_TRUE(file->Init(filename, 8192)); |
83 | 87 |
84 FileCallbackTest callback(1); | 88 FileCallbackTest callback(1); |
85 g_cache_tests_error = false; | 89 g_cache_tests_error = false; |
86 g_cache_tests_max_id = 0; | 90 g_cache_tests_max_id = 0; |
87 g_cache_tests_received = 0; | 91 g_cache_tests_received = 0; |
88 | 92 |
89 MessageLoopHelper helper; | 93 MessageLoopHelper helper; |
(...skipping 14 matching lines...) Expand all Loading... |
104 &completed)); | 108 &completed)); |
105 if (!completed) | 109 if (!completed) |
106 expected++; | 110 expected++; |
107 | 111 |
108 helper.WaitUntilCacheIoFinished(expected); | 112 helper.WaitUntilCacheIoFinished(expected); |
109 | 113 |
110 EXPECT_EQ(expected, g_cache_tests_received); | 114 EXPECT_EQ(expected, g_cache_tests_received); |
111 EXPECT_FALSE(g_cache_tests_error); | 115 EXPECT_FALSE(g_cache_tests_error); |
112 EXPECT_STREQ(buffer1, buffer2); | 116 EXPECT_STREQ(buffer1, buffer2); |
113 } | 117 } |
OLD | NEW |