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 ScopedTestCache test_cache; | 64 FilePath filename = GetCacheFilePath().AppendASCII("a_test"); |
65 FilePath filename = test_cache.path().AppendASCII("a_test"); | |
66 | |
67 scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); | 65 scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); |
68 ASSERT_TRUE(CreateCacheTestFile(filename)); | 66 ASSERT_TRUE(CreateCacheTestFile(filename)); |
69 ASSERT_TRUE(file->Init(filename, 8192)); | 67 ASSERT_TRUE(file->Init(filename, 8192)); |
70 | 68 |
71 char buffer1[20]; | 69 char buffer1[20]; |
72 char buffer2[20]; | 70 char buffer2[20]; |
73 CacheTestFillBuffer(buffer1, sizeof(buffer1), false); | 71 CacheTestFillBuffer(buffer1, sizeof(buffer1), false); |
74 base::strlcpy(buffer1, "the data", arraysize(buffer1)); | 72 base::strlcpy(buffer1, "the data", arraysize(buffer1)); |
75 EXPECT_TRUE(file->Write(buffer1, sizeof(buffer1), 8192)); | 73 EXPECT_TRUE(file->Write(buffer1, sizeof(buffer1), 8192)); |
76 EXPECT_TRUE(file->Read(buffer2, sizeof(buffer2), 8192)); | 74 EXPECT_TRUE(file->Read(buffer2, sizeof(buffer2), 8192)); |
77 EXPECT_STREQ(buffer1, buffer2); | 75 EXPECT_STREQ(buffer1, buffer2); |
78 } | 76 } |
79 | 77 |
80 TEST_F(DiskCacheTest, MappedFile_AsyncIO) { | 78 TEST_F(DiskCacheTest, MappedFile_AsyncIO) { |
81 ScopedTestCache test_cache; | 79 FilePath filename = GetCacheFilePath().AppendASCII("a_test"); |
82 FilePath filename = test_cache.path().AppendASCII("a_test"); | |
83 | |
84 scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); | 80 scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); |
85 ASSERT_TRUE(CreateCacheTestFile(filename)); | 81 ASSERT_TRUE(CreateCacheTestFile(filename)); |
86 ASSERT_TRUE(file->Init(filename, 8192)); | 82 ASSERT_TRUE(file->Init(filename, 8192)); |
87 | 83 |
88 FileCallbackTest callback(1); | 84 FileCallbackTest callback(1); |
89 g_cache_tests_error = false; | 85 g_cache_tests_error = false; |
90 g_cache_tests_max_id = 0; | 86 g_cache_tests_max_id = 0; |
91 g_cache_tests_received = 0; | 87 g_cache_tests_received = 0; |
92 | 88 |
93 MessageLoopHelper helper; | 89 MessageLoopHelper helper; |
(...skipping 14 matching lines...) Expand all Loading... |
108 &completed)); | 104 &completed)); |
109 if (!completed) | 105 if (!completed) |
110 expected++; | 106 expected++; |
111 | 107 |
112 helper.WaitUntilCacheIoFinished(expected); | 108 helper.WaitUntilCacheIoFinished(expected); |
113 | 109 |
114 EXPECT_EQ(expected, g_cache_tests_received); | 110 EXPECT_EQ(expected, g_cache_tests_received); |
115 EXPECT_FALSE(g_cache_tests_error); | 111 EXPECT_FALSE(g_cache_tests_error); |
116 EXPECT_STREQ(buffer1, buffer2); | 112 EXPECT_STREQ(buffer1, buffer2); |
117 } | 113 } |
OLD | NEW |