#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "base/files/memory_mapped_file.h"
#include <stddef.h>
#include <stdint.h>
#include <utility>
#include "base/containers/heap_array.h"
#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#if BUILDFLAG(IS_WIN)
#include "base/path_service.h"
#endif
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
namespace base {
namespace {
base::HeapArray<uint8_t> CreateTestBuffer(size_t size, size_t offset) { … }
bool CheckBufferContents(span<const uint8_t> bytes, size_t offset) { … }
class MemoryMappedFileTest : public PlatformTest { … };
TEST_F(MemoryMappedFileTest, MapWholeFileByPath) { … }
TEST_F(MemoryMappedFileTest, MapWholeFileByFD) { … }
TEST_F(MemoryMappedFileTest, MapSmallFile) { … }
TEST_F(MemoryMappedFileTest, MapWholeFileUsingRegion) { … }
TEST_F(MemoryMappedFileTest, MapPartialRegionAtBeginning) { … }
TEST_F(MemoryMappedFileTest, MapPartialRegionAtEnd) { … }
TEST_F(MemoryMappedFileTest, MapSmallPartialRegionInTheMiddle) { … }
TEST_F(MemoryMappedFileTest, MapLargePartialRegionInTheMiddle) { … }
TEST_F(MemoryMappedFileTest, WriteableFile) { … }
TEST_F(MemoryMappedFileTest, CopyOnWrite) { … }
TEST_F(MemoryMappedFileTest, ExtendableFile) { … }
#if BUILDFLAG(IS_WIN)
TEST_F(MemoryMappedFileTest, ReadCodeImage) {
base::FilePath exe_path;
base::PathService::Get(base::FILE_EXE, &exe_path);
File file(exe_path,
File::FLAG_OPEN | File::FLAG_READ | File::FLAG_WIN_SHARE_DELETE);
ASSERT_TRUE(file.IsValid());
MemoryMappedFile map;
ASSERT_TRUE(
map.Initialize(std::move(file), MemoryMappedFile::READ_CODE_IMAGE));
}
#endif
}
}