chromium/base/files/memory_mapped_file_unittest.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
#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  // BUILDFLAG(IS_WIN)
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"

namespace base {

namespace {

// Create a temporary buffer and fill it with a watermark sequence.
base::HeapArray<uint8_t> CreateTestBuffer(size_t size, size_t offset) {}

// Check that the watermark sequence is consistent with the |offset| provided.
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  // BUILDFLAG(IS_WIN)

}  // namespace

}  // namespace base