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

Side by Side Diff: base/metrics/persistent_memory_allocator_unittest.cc

Issue 1855373002: Added comments about expected error messages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/metrics/persistent_memory_allocator.h" 5 #include "base/metrics/persistent_memory_allocator.h"
6 6
7 #include "base/files/file.h" 7 #include "base/files/file.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/memory_mapped_file.h" 9 #include "base/files/memory_mapped_file.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 File writer(file_path, File::FLAG_CREATE | File::FLAG_WRITE); 558 File writer(file_path, File::FLAG_CREATE | File::FLAG_WRITE);
559 ASSERT_TRUE(writer.IsValid()); 559 ASSERT_TRUE(writer.IsValid());
560 writer.Write(0, (const char*)local.data(), filesize); 560 writer.Write(0, (const char*)local.data(), filesize);
561 } 561 }
562 ASSERT_TRUE(PathExists(file_path)); 562 ASSERT_TRUE(PathExists(file_path));
563 563
564 mmfile.reset(new MemoryMappedFile()); 564 mmfile.reset(new MemoryMappedFile());
565 mmfile->Initialize(file_path); 565 mmfile->Initialize(file_path);
566 EXPECT_EQ(filesize, mmfile->length()); 566 EXPECT_EQ(filesize, mmfile->length());
567 if (FilePersistentMemoryAllocator::IsFileAcceptable(*mmfile)) { 567 if (FilePersistentMemoryAllocator::IsFileAcceptable(*mmfile)) {
568 // Make sure construction doesn't crash. 568 // Make sure construction doesn't crash. It will, however, cause
569 // error messages warning about about a corrupted memory segment.
569 FilePersistentMemoryAllocator allocator(std::move(mmfile), 0, ""); 570 FilePersistentMemoryAllocator allocator(std::move(mmfile), 0, "");
570 // Also make sure that iteration doesn't crash. 571 // Also make sure that iteration doesn't crash.
571 PersistentMemoryAllocator::Iterator iter; 572 PersistentMemoryAllocator::Iterator iter;
572 allocator.CreateIterator(&iter); 573 allocator.CreateIterator(&iter);
573 for (;;) { 574 for (;;) {
574 Reference ref = allocator.GetNextIterable(&iter, 0); 575 Reference ref = allocator.GetNextIterable(&iter, 0);
575 if (!ref) 576 if (!ref)
576 break; 577 break;
577 const char* data = allocator.GetAsObject<char>(ref, 0); 578 const char* data = allocator.GetAsObject<char>(ref, 0);
578 uint32_t type = allocator.GetType(ref); 579 uint32_t type = allocator.GetType(ref);
(...skipping 19 matching lines...) Expand all
598 File writer(file_path, File::FLAG_CREATE | File::FLAG_WRITE); 599 File writer(file_path, File::FLAG_CREATE | File::FLAG_WRITE);
599 ASSERT_TRUE(writer.IsValid()); 600 ASSERT_TRUE(writer.IsValid());
600 writer.Write(0, (const char*)garbage.get(), filesize); 601 writer.Write(0, (const char*)garbage.get(), filesize);
601 } 602 }
602 ASSERT_TRUE(PathExists(file_path)); 603 ASSERT_TRUE(PathExists(file_path));
603 604
604 mmfile.reset(new MemoryMappedFile()); 605 mmfile.reset(new MemoryMappedFile());
605 mmfile->Initialize(file_path); 606 mmfile->Initialize(file_path);
606 EXPECT_EQ(filesize, mmfile->length()); 607 EXPECT_EQ(filesize, mmfile->length());
607 if (FilePersistentMemoryAllocator::IsFileAcceptable(*mmfile)) { 608 if (FilePersistentMemoryAllocator::IsFileAcceptable(*mmfile)) {
608 // Just need to make sure it doesn't crash. 609 // Make sure construction doesn't crash. It will, however, cause
610 // error messages warning about about a corrupted memory segment.
609 FilePersistentMemoryAllocator allocator(std::move(mmfile), 0, ""); 611 FilePersistentMemoryAllocator allocator(std::move(mmfile), 0, "");
610 EXPECT_TRUE(allocator.IsCorrupt()); // Garbage data so it should be. 612 EXPECT_TRUE(allocator.IsCorrupt()); // Garbage data so it should be.
611 } else { 613 } else {
612 // For filesize >= minsize, the file must be acceptable. This 614 // For filesize >= minsize, the file must be acceptable. This
613 // else clause (file-not-acceptable) should be reached only if 615 // else clause (file-not-acceptable) should be reached only if
614 // filesize < minsize. 616 // filesize < minsize.
615 EXPECT_GT(minsize, filesize); 617 EXPECT_GT(minsize, filesize);
616 } 618 }
617 } 619 }
618 } 620 }
619 621
620 } // namespace base 622 } // namespace base
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