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/platform_thread.h" | 5 #include "base/platform_thread.h" |
6 #include "base/timer.h" | 6 #include "base/timer.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
9 #include "net/disk_cache/disk_cache_test_base.h" | 9 #include "net/disk_cache/disk_cache_test_base.h" |
10 #include "net/disk_cache/disk_cache_test_util.h" | 10 #include "net/disk_cache/disk_cache_test_util.h" |
11 #include "net/disk_cache/entry_impl.h" | 11 #include "net/disk_cache/entry_impl.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 using base::Time; | 14 using base::Time; |
15 | 15 |
16 extern int g_cache_tests_max_id; | 16 extern int g_cache_tests_max_id; |
17 extern volatile int g_cache_tests_received; | 17 extern volatile int g_cache_tests_received; |
18 extern volatile bool g_cache_tests_error; | 18 extern volatile bool g_cache_tests_error; |
19 | 19 |
20 // Tests that can run with different types of caches. | 20 // Tests that can run with different types of caches. |
21 class DiskCacheEntryTest : public DiskCacheTestWithCache { | 21 class DiskCacheEntryTest : public DiskCacheTestWithCache { |
22 protected: | 22 protected: |
23 void InternalSyncIO(); | 23 void InternalSyncIO(); |
24 void InternalAsyncIO(); | 24 void InternalAsyncIO(); |
25 void ExternalSyncIO(); | 25 void ExternalSyncIO(); |
26 void ExternalAsyncIO(); | 26 void ExternalAsyncIO(); |
27 void StreamAccess(); | |
27 void GetKey(); | 28 void GetKey(); |
28 void GrowData(); | 29 void GrowData(); |
29 void TruncateData(); | 30 void TruncateData(); |
30 void ReuseEntry(int size); | 31 void ReuseEntry(int size); |
31 void InvalidData(); | 32 void InvalidData(); |
32 void DoomEntry(); | 33 void DoomEntry(); |
33 void DoomedEntry(); | 34 void DoomedEntry(); |
34 }; | 35 }; |
35 | 36 |
36 void DiskCacheEntryTest::InternalSyncIO() { | 37 void DiskCacheEntryTest::InternalSyncIO() { |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 InitCache(); | 367 InitCache(); |
367 ExternalAsyncIO(); | 368 ExternalAsyncIO(); |
368 } | 369 } |
369 | 370 |
370 TEST_F(DiskCacheEntryTest, MemoryOnlyExternalAsyncIO) { | 371 TEST_F(DiskCacheEntryTest, MemoryOnlyExternalAsyncIO) { |
371 SetMemoryOnlyMode(); | 372 SetMemoryOnlyMode(); |
372 InitCache(); | 373 InitCache(); |
373 ExternalAsyncIO(); | 374 ExternalAsyncIO(); |
374 } | 375 } |
375 | 376 |
377 // Tests IO on all valid streams. | |
378 void DiskCacheEntryTest::StreamAccess() { | |
379 disk_cache::Entry *entry = NULL; | |
380 ASSERT_TRUE(cache_->CreateEntry("the first key", &entry)); | |
381 ASSERT_TRUE(NULL != entry); | |
382 | |
383 const int kBufferSize = 1024; | |
384 char buffer1[kBufferSize]; | |
385 char buffer2[kBufferSize]; | |
386 | |
387 const int kNumStreams = 3; | |
388 for (int i = 0; i < kNumStreams; i++) { | |
389 CacheTestFillBuffer(buffer1, kBufferSize, false); | |
390 EXPECT_EQ(kBufferSize, entry->WriteData(i, 0, buffer1, kBufferSize, NULL, | |
391 false)); | |
392 memset(buffer2, 0, kBufferSize); | |
393 EXPECT_EQ(kBufferSize, entry->ReadData(i, 0, buffer2, kBufferSize, NULL)); | |
394 EXPECT_EQ(0, memcmp(buffer1, buffer2, kBufferSize)); | |
395 } | |
396 | |
397 EXPECT_EQ(net::ERR_INVALID_ARGUMENT, | |
Nicolas Sylvain
2008/12/04 18:52:28
you comment says : // Tests IO on all valid strea
| |
398 entry->ReadData(kNumStreams, 0, buffer1, kBufferSize, NULL)); | |
399 entry->Close(); | |
400 } | |
401 | |
402 TEST_F(DiskCacheEntryTest, StreamAccess) { | |
403 InitCache(); | |
404 StreamAccess(); | |
405 } | |
406 | |
407 TEST_F(DiskCacheEntryTest, MemoryOnlyStreamAccess) { | |
408 SetMemoryOnlyMode(); | |
409 InitCache(); | |
410 StreamAccess(); | |
411 } | |
412 | |
376 void DiskCacheEntryTest::GetKey() { | 413 void DiskCacheEntryTest::GetKey() { |
377 std::string key1("the first key"); | 414 std::string key1("the first key"); |
378 disk_cache::Entry *entry1; | 415 disk_cache::Entry *entry1; |
379 ASSERT_TRUE(cache_->CreateEntry(key1, &entry1)); | 416 ASSERT_TRUE(cache_->CreateEntry(key1, &entry1)); |
380 EXPECT_EQ(key1, entry1->GetKey()) << "short key"; | 417 EXPECT_EQ(key1, entry1->GetKey()) << "short key"; |
381 entry1->Close(); | 418 entry1->Close(); |
382 | 419 |
383 int seed = static_cast<int>(Time::Now().ToInternalValue()); | 420 int seed = static_cast<int>(Time::Now().ToInternalValue()); |
384 srand(seed); | 421 srand(seed); |
385 char key_buffer[20000]; | 422 char key_buffer[20000]; |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
746 InitCache(); | 783 InitCache(); |
747 DoomEntry(); | 784 DoomEntry(); |
748 } | 785 } |
749 | 786 |
750 TEST_F(DiskCacheEntryTest, MemoryOnlyDoomedEntry) { | 787 TEST_F(DiskCacheEntryTest, MemoryOnlyDoomedEntry) { |
751 SetMemoryOnlyMode(); | 788 SetMemoryOnlyMode(); |
752 InitCache(); | 789 InitCache(); |
753 DoomEntry(); | 790 DoomEntry(); |
754 } | 791 } |
755 | 792 |
OLD | NEW |