summaryrefslogtreecommitdiffhomepage
path: root/src/CompilerKit/test/Linkers/DynamicLinker64+MachO.test.cpp
blob: 8f3ff6b77cffa9d083008fe22ab6ca851b4499f6 (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
52
// SPDX-License-Identifier: Apache-2.0
// Copyright 2025-2026, Amlal El Mahrouss (amlal@nekernel.org)
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// Official repository: https://github.com/ne-foss-org/nectar

/// @author Amlal El Mahrouss

#include <CompilerKit/Detail/Config.h>
#include <CompilerKit/ErrorID.h>
#include <CompilerKit/Utilities/Compiler.h>
#include <CompilerKit/Utilities/DLL.h>

#include <gtest/gtest.h>

static Int32  argc{};
static char** argv{};

Int32 main(Int32 _argc, char** _argv) {
  ::testing::InitGoogleTest(&_argc, _argv);

  argc = _argc;
  argv = _argv;

  return RUN_ALL_TESTS();
}

#ifdef __APPLE__
static auto kPath = "/usr/local/lib/libCompilerKit.dylib";
#else
static auto kPath = "/usr/lib/libCompilerKit.so";
#endif

static auto kSymbol = "DynamicLinker64MachO";

TEST(LinkerRunMachO, LinkerExitsCorrectly) {
  CompilerKit::ModuleLoader dylib;
  dylib(kPath, kSymbol);

  CompilerKit::ModuleLoader::EntryT entrypoint_cxx =
      reinterpret_cast<CompilerKit::ModuleLoader::EntryT>(dylib.fEntrypoint);

  if (!entrypoint_cxx) {
    kStdOut;
    std::printf("error: Could not find entrypoint in %s: %s\n", kPath, dlerror());

    return;
  }

  auto ret =(entrypoint_cxx(argc, const_cast<const char**>(argv)) == NECTAR_SUCCESS) ? EXIT_SUCCESS : EXIT_FAILURE;
  EXPECT_TRUE(ret == EXIT_SUCCESS);
}