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

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

Issue 21284: Fix some purify warnings. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 10 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 | no next file » | 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-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/path_service.h" 7 #include "base/path_service.h"
8 #include "base/platform_thread.h" 8 #include "base/platform_thread.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 TEST_F(DiskCacheBackendTest, ValidEntry) { 335 TEST_F(DiskCacheBackendTest, ValidEntry) {
336 SetDirectMode(); 336 SetDirectMode();
337 InitCache(); 337 InitCache();
338 338
339 std::string key("Some key"); 339 std::string key("Some key");
340 disk_cache::Entry* entry1; 340 disk_cache::Entry* entry1;
341 ASSERT_TRUE(cache_->CreateEntry(key, &entry1)); 341 ASSERT_TRUE(cache_->CreateEntry(key, &entry1));
342 342
343 const int kSize = 50; 343 const int kSize = 50;
344 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); 344 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize);
345 memset(buffer1->data(), 0, kSize);
345 base::strlcpy(buffer1->data(), "And the data to save", kSize); 346 base::strlcpy(buffer1->data(), "And the data to save", kSize);
346 EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false)); 347 EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false));
347 entry1->Close(); 348 entry1->Close();
348 SimulateCrash(); 349 SimulateCrash();
349 350
350 ASSERT_TRUE(cache_->OpenEntry(key, &entry1)); 351 ASSERT_TRUE(cache_->OpenEntry(key, &entry1));
351 352
352 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize); 353 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize);
353 memset(buffer2->data(), 0, kSize); 354 memset(buffer2->data(), 0, kSize);
354 EXPECT_EQ(kSize, entry1->ReadData(0, 0, buffer2, kSize, NULL)); 355 EXPECT_EQ(kSize, entry1->ReadData(0, 0, buffer2, kSize, NULL));
355 entry1->Close(); 356 entry1->Close();
356 EXPECT_STREQ(buffer1->data(), buffer2->data()); 357 EXPECT_STREQ(buffer1->data(), buffer2->data());
357 } 358 }
358 359
359 // The same logic of the previous test (ValidEntry), but this time force the 360 // The same logic of the previous test (ValidEntry), but this time force the
360 // entry to be invalid, simulating a crash in the middle. 361 // entry to be invalid, simulating a crash in the middle.
361 // We'll be leaking memory from this test. 362 // We'll be leaking memory from this test.
362 TEST_F(DiskCacheBackendTest, InvalidEntry) { 363 TEST_F(DiskCacheBackendTest, InvalidEntry) {
363 // Use the implementation directly... we need to simulate a crash. 364 // Use the implementation directly... we need to simulate a crash.
364 SetDirectMode(); 365 SetDirectMode();
365 InitCache(); 366 InitCache();
366 367
367 std::string key("Some key"); 368 std::string key("Some key");
368 disk_cache::Entry* entry1; 369 disk_cache::Entry* entry1;
369 ASSERT_TRUE(cache_->CreateEntry(key, &entry1)); 370 ASSERT_TRUE(cache_->CreateEntry(key, &entry1));
370 371
371 const int kSize = 50; 372 const int kSize = 50;
372 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); 373 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize);
374 memset(buffer1->data(), 0, kSize);
373 base::strlcpy(buffer1->data(), "And the data to save", kSize); 375 base::strlcpy(buffer1->data(), "And the data to save", kSize);
374 EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false)); 376 EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false));
375 SimulateCrash(); 377 SimulateCrash();
376 378
377 EXPECT_FALSE(cache_->OpenEntry(key, &entry1)); 379 EXPECT_FALSE(cache_->OpenEntry(key, &entry1));
378 EXPECT_EQ(0, cache_->GetEntryCount()); 380 EXPECT_EQ(0, cache_->GetEntryCount());
379 } 381 }
380 382
381 // Almost the same test, but this time crash the cache after reading an entry. 383 // Almost the same test, but this time crash the cache after reading an entry.
382 // We'll be leaking memory from this test. 384 // We'll be leaking memory from this test.
383 TEST_F(DiskCacheBackendTest, InvalidEntryRead) { 385 TEST_F(DiskCacheBackendTest, InvalidEntryRead) {
384 // Use the implementation directly... we need to simulate a crash. 386 // Use the implementation directly... we need to simulate a crash.
385 SetDirectMode(); 387 SetDirectMode();
386 InitCache(); 388 InitCache();
387 389
388 std::string key("Some key"); 390 std::string key("Some key");
389 disk_cache::Entry* entry1; 391 disk_cache::Entry* entry1;
390 ASSERT_TRUE(cache_->CreateEntry(key, &entry1)); 392 ASSERT_TRUE(cache_->CreateEntry(key, &entry1));
391 393
392 const int kSize = 50; 394 const int kSize = 50;
393 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); 395 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize);
396 memset(buffer1->data(), 0, kSize);
394 base::strlcpy(buffer1->data(), "And the data to save", kSize); 397 base::strlcpy(buffer1->data(), "And the data to save", kSize);
395 EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false)); 398 EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false));
396 entry1->Close(); 399 entry1->Close();
397 ASSERT_TRUE(cache_->OpenEntry(key, &entry1)); 400 ASSERT_TRUE(cache_->OpenEntry(key, &entry1));
398 EXPECT_EQ(kSize, entry1->ReadData(0, 0, buffer1, kSize, NULL)); 401 EXPECT_EQ(kSize, entry1->ReadData(0, 0, buffer1, kSize, NULL));
399 402
400 SimulateCrash(); 403 SimulateCrash();
401 404
402 EXPECT_FALSE(cache_->OpenEntry(key, &entry1)); 405 EXPECT_FALSE(cache_->OpenEntry(key, &entry1));
403 EXPECT_EQ(0, cache_->GetEntryCount()); 406 EXPECT_EQ(0, cache_->GetEntryCount());
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 // Use the implementation directly... we need to simulate a crash. 552 // Use the implementation directly... we need to simulate a crash.
550 SetDirectMode(); 553 SetDirectMode();
551 InitCache(); 554 InitCache();
552 555
553 std::string key("Some key"); 556 std::string key("Some key");
554 disk_cache::Entry *entry, *entry1, *entry2; 557 disk_cache::Entry *entry, *entry1, *entry2;
555 ASSERT_TRUE(cache_->CreateEntry(key, &entry1)); 558 ASSERT_TRUE(cache_->CreateEntry(key, &entry1));
556 559
557 const int kSize = 50; 560 const int kSize = 50;
558 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); 561 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize);
562 memset(buffer1->data(), 0, kSize);
559 base::strlcpy(buffer1->data(), "And the data to save", kSize); 563 base::strlcpy(buffer1->data(), "And the data to save", kSize);
560 EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false)); 564 EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false));
561 entry1->Close(); 565 entry1->Close();
562 ASSERT_TRUE(cache_->OpenEntry(key, &entry1)); 566 ASSERT_TRUE(cache_->OpenEntry(key, &entry1));
563 EXPECT_EQ(kSize, entry1->ReadData(0, 0, buffer1, kSize, NULL)); 567 EXPECT_EQ(kSize, entry1->ReadData(0, 0, buffer1, kSize, NULL));
564 568
565 std::string key2("Another key"); 569 std::string key2("Another key");
566 ASSERT_TRUE(cache_->CreateEntry(key2, &entry2)); 570 ASSERT_TRUE(cache_->CreateEntry(key2, &entry2));
567 entry2->Close(); 571 entry2->Close();
568 ASSERT_EQ(2, cache_->GetEntryCount()); 572 ASSERT_EQ(2, cache_->GetEntryCount());
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 InitCache(); 980 InitCache();
977 BackendDoomAll(); 981 BackendDoomAll();
978 } 982 }
979 983
980 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) { 984 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) {
981 SetMemoryOnlyMode(); 985 SetMemoryOnlyMode();
982 InitCache(); 986 InitCache();
983 BackendDoomAll(); 987 BackendDoomAll();
984 } 988 }
985 989
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698