blob: b8b1f199add674448d18227c6b3deb7e8fc7b6ee (
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
53
54
55
56
57
58
59
60
61
|
// Copyright 2018 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/base_switches.h"
#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/optional.h"
#include "base/test/launcher/unit_test_launcher.h"
#include "base/test/test_suite.h"
#include "build/build_config.h"
#include "mojo/core/mojo_core_unittest.h"
#include "mojo/public/c/system/core.h"
#include "mojo/public/cpp/system/dynamic_library_support.h"
base::FilePath GetMojoCoreLibraryPath() {
#if defined(OS_WIN)
const char kLibraryFilename[] = "mojo_core.dll";
#else
const char kLibraryFilename[] = "libmojo_core.so";
#endif
base::FilePath executable_dir =
base::CommandLine::ForCurrentProcess()->GetProgram().DirName();
if (executable_dir.IsAbsolute())
return executable_dir.AppendASCII(kLibraryFilename);
base::FilePath current_directory;
CHECK(base::GetCurrentDirectory(¤t_directory));
return current_directory.Append(executable_dir).AppendASCII(kLibraryFilename);
}
int main(int argc, char** argv) {
base::TestSuite test_suite(argc, argv);
MojoInitializeFlags flags = MOJO_INITIALIZE_FLAG_NONE;
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
if (!command_line.HasSwitch(switches::kTestChildProcess))
flags |= MOJO_INITIALIZE_FLAG_AS_BROKER;
base::Optional<base::FilePath> library_path;
if (command_line.HasSwitch(switches::kMojoUseExplicitLibraryPath))
library_path = GetMojoCoreLibraryPath();
if (command_line.HasSwitch(switches::kMojoLoadBeforeInit)) {
CHECK_EQ(MOJO_RESULT_OK, mojo::LoadCoreLibrary(library_path));
CHECK_EQ(MOJO_RESULT_OK, mojo::InitializeCoreLibrary(flags));
} else {
CHECK_EQ(MOJO_RESULT_OK,
mojo::LoadAndInitializeCoreLibrary(library_path, flags));
}
int result = base::LaunchUnitTests(
argc, argv,
base::BindOnce(&base::TestSuite::Run, base::Unretained(&test_suite)));
CHECK_EQ(MOJO_RESULT_OK, MojoShutdown(nullptr));
return result;
}
|