summaryrefslogtreecommitdiff
path: root/chromium/base/mac/mach_o_unittest.cc
blob: 1703b35e90f1cb1ad77901daf7e8ef444e739efd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/mac/mach_o.h"

#include "base/base_paths.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace base {
namespace {

TEST(MachO, GetMachOArchitectures) {
  FilePath exe_path;
  ASSERT_TRUE(PathService::Get(FILE_EXE, &exe_path));
#if defined(ARCH_CPU_X86_64)
  constexpr MachOArchitectures kSelfArchitecture = MachOArchitectures::kX86_64;
#elif defined(ARCH_CPU_ARM64)
  constexpr MachOArchitectures kSelfArchitecture = MachOArchitectures::kARM64;
#endif
  EXPECT_EQ(GetMachOArchitectures(exe_path) & kSelfArchitecture,
            kSelfArchitecture);

  FilePath data_dir;
  ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &data_dir));
  data_dir = data_dir.AppendASCII("mac");

  EXPECT_EQ(GetMachOArchitectures(data_dir.AppendASCII("x86_64")),
            MachOArchitectures::kX86_64);

  EXPECT_EQ(GetMachOArchitectures(data_dir.AppendASCII("arm64")),
            MachOArchitectures::kARM64);

  EXPECT_EQ(GetMachOArchitectures(data_dir.AppendASCII("universal")),
            MachOArchitectures::kX86_64 | MachOArchitectures::kARM64);

  EXPECT_EQ(GetMachOArchitectures(data_dir.AppendASCII("x86")),
            MachOArchitectures::kUnknownArchitecture);

  EXPECT_EQ(GetMachOArchitectures(data_dir.AppendASCII("elf")),
            MachOArchitectures::kInvalidFormat);

  EXPECT_EQ(GetMachOArchitectures(data_dir.AppendASCII("enoent")),
            MachOArchitectures::kFileError);
}

}  // namespace
}  // namespace base