Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: net/disk_cache/entry_unittest.cc

Issue 146005: Disk Cache: Implement GetAvailableRange for the regular disk cache.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/disk_cache/sparse_control.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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/platform_thread.h" 6 #include "base/platform_thread.h"
7 #include "base/timer.h" 7 #include "base/timer.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 19 matching lines...) Expand all
30 void GetKey(); 30 void GetKey();
31 void GrowData(); 31 void GrowData();
32 void TruncateData(); 32 void TruncateData();
33 void ZeroLengthIO(); 33 void ZeroLengthIO();
34 void ReuseEntry(int size); 34 void ReuseEntry(int size);
35 void InvalidData(); 35 void InvalidData();
36 void DoomEntry(); 36 void DoomEntry();
37 void DoomedEntry(); 37 void DoomedEntry();
38 void BasicSparseIO(bool async); 38 void BasicSparseIO(bool async);
39 void HugeSparseIO(bool async); 39 void HugeSparseIO(bool async);
40 void GetAvailableRange();
40 }; 41 };
41 42
42 void DiskCacheEntryTest::InternalSyncIO() { 43 void DiskCacheEntryTest::InternalSyncIO() {
43 disk_cache::Entry *entry1 = NULL; 44 disk_cache::Entry *entry1 = NULL;
44 ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1)); 45 ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1));
45 ASSERT_TRUE(NULL != entry1); 46 ASSERT_TRUE(NULL != entry1);
46 47
47 const int kSize1 = 10; 48 const int kSize1 = 10;
48 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1); 49 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1);
49 CacheTestFillBuffer(buffer1->data(), kSize1, false); 50 CacheTestFillBuffer(buffer1->data(), kSize1, false);
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 std::string key("the first key"); 961 std::string key("the first key");
961 disk_cache::Entry* entry; 962 disk_cache::Entry* entry;
962 ASSERT_TRUE(cache_->CreateEntry(key, &entry)); 963 ASSERT_TRUE(cache_->CreateEntry(key, &entry));
963 964
964 // Write 1.2 MB so that we cover multiple entries. 965 // Write 1.2 MB so that we cover multiple entries.
965 const int kSize = 1200 * 1024; 966 const int kSize = 1200 * 1024;
966 scoped_refptr<net::IOBuffer> buf_1 = new net::IOBuffer(kSize); 967 scoped_refptr<net::IOBuffer> buf_1 = new net::IOBuffer(kSize);
967 scoped_refptr<net::IOBuffer> buf_2 = new net::IOBuffer(kSize); 968 scoped_refptr<net::IOBuffer> buf_2 = new net::IOBuffer(kSize);
968 CacheTestFillBuffer(buf_1->data(), kSize, false); 969 CacheTestFillBuffer(buf_1->data(), kSize, false);
969 970
970 // Write at offset 0x20F0000 (20 MB - 64 KB). 971 // Write at offset 0x20F0000 (33 MB - 64 KB).
971 VerifySparseIO(entry, 0x20F0000, buf_1, kSize, async, buf_2); 972 VerifySparseIO(entry, 0x20F0000, buf_1, kSize, async, buf_2);
972 entry->Close(); 973 entry->Close();
973 974
974 // Check it again. 975 // Check it again.
975 ASSERT_TRUE(cache_->OpenEntry(key, &entry)); 976 ASSERT_TRUE(cache_->OpenEntry(key, &entry));
976 VerifyContentSparseIO(entry, 0x20F0000, buf_1->data(), kSize, async); 977 VerifyContentSparseIO(entry, 0x20F0000, buf_1->data(), kSize, async);
977 entry->Close(); 978 entry->Close();
978 } 979 }
979 980
980 TEST_F(DiskCacheEntryTest, HugeSparseSyncIO) { 981 TEST_F(DiskCacheEntryTest, HugeSparseSyncIO) {
(...skipping 10 matching lines...) Expand all
991 TEST_F(DiskCacheEntryTest, HugeSparseAsyncIO) { 992 TEST_F(DiskCacheEntryTest, HugeSparseAsyncIO) {
992 InitCache(); 993 InitCache();
993 HugeSparseIO(true); 994 HugeSparseIO(true);
994 } 995 }
995 996
996 TEST_F(DiskCacheEntryTest, DISABLED_MemoryOnlyHugeSparseAsyncIO) { 997 TEST_F(DiskCacheEntryTest, DISABLED_MemoryOnlyHugeSparseAsyncIO) {
997 SetMemoryOnlyMode(); 998 SetMemoryOnlyMode();
998 InitCache(); 999 InitCache();
999 HugeSparseIO(true); 1000 HugeSparseIO(true);
1000 } 1001 }
1002
1003 void DiskCacheEntryTest::GetAvailableRange() {
1004 std::string key("the first key");
1005 disk_cache::Entry* entry;
1006 ASSERT_TRUE(cache_->CreateEntry(key, &entry));
1007
1008 const int kSize = 16 * 1024;
1009 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize);
1010 CacheTestFillBuffer(buf->data(), kSize, false);
1011
1012 // Write at offset 0x20F0000 (33 MB - 64 KB), and 0x20F4400 (33 MB - 47 KB).
1013 EXPECT_EQ(kSize, entry->WriteSparseData(0x20F0000, buf, kSize, NULL));
1014 EXPECT_EQ(kSize, entry->WriteSparseData(0x20F4400, buf, kSize, NULL));
1015
1016 // We stop at the first empty block.
1017 int64 start;
1018 EXPECT_EQ(kSize, entry->GetAvailableRange(0x20F0000, kSize * 2, &start));
1019 EXPECT_EQ(0x20F0000, start);
1020
1021 start = 0;
1022 EXPECT_EQ(0, entry->GetAvailableRange(0, kSize, &start));
1023 EXPECT_EQ(0, entry->GetAvailableRange(0x20F0000 - kSize, kSize, &start));
1024 EXPECT_EQ(kSize, entry->GetAvailableRange(0, 0x2100000, &start));
Nicolas Sylvain 2009/06/23 02:49:07 why is this returning kSize? is it not returning a
rvargas (doing something else) 2009/06/23 02:59:24 GetAvailableRange returns the number of bytes stor
1025 EXPECT_EQ(0x20F0000, start);
1026
1027 // We should be able to Read based on the results of GetAvailableRange.
1028 start = -1;
1029 EXPECT_EQ(0, entry->GetAvailableRange(0x2100000, kSize, &start));
1030 EXPECT_EQ(0, entry->ReadSparseData(start, buf, kSize, NULL));
1031
1032 start = 0;
1033 EXPECT_EQ(0x2000, entry->GetAvailableRange(0x20F2000, kSize, &start));
1034 EXPECT_EQ(0x20F2000, start);
1035 EXPECT_EQ(0x2000, entry->ReadSparseData(start, buf, kSize, NULL));
1036
1037 // Make sure that we respect the |len| argument.
1038 start = 0;
1039 EXPECT_EQ(1, entry->GetAvailableRange(0x20F0001 - kSize, kSize, &start));
1040 EXPECT_EQ(0x20F0000, start);
1041
1042 entry->Close();
1043 }
1044
1045 TEST_F(DiskCacheEntryTest, GetAvailableRange) {
1046 InitCache();
1047 GetAvailableRange();
1048 }
1049
1050 TEST_F(DiskCacheEntryTest, DISABLED_MemoryOnlyGetAvailableRange) {
1051 SetMemoryOnlyMode();
1052 InitCache();
1053 GetAvailableRange();
1054 }
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/sparse_control.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698