-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathHost.cpp
More file actions
116 lines (86 loc) · 3.36 KB
/
Copy pathHost.cpp
File metadata and controls
116 lines (86 loc) · 3.36 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Host.cpp : Diese Datei enthält die Funktion "main". Hier beginnt und endet die Ausführung des Programms.
//
#include <iostream>
#include <fstream>
# define DOTNET_RUNTIME_VERSION "6.0.0"
#include "Common.h"
#include "Test_ManagedEntryPoint.h"
#include "Test_NativeFunctionPointer.h"
#include "Test_ManagedFunctionPointer.h"
#include "Test_DllImport.h"
#include "Test_NativeExport.h"
#include "Test_NativeArray.h"
#include "Test_NativeString.h"
#include "Test_ManagedString.h"
#include "Test_ManagedUnsafe.h"
#include "Test_NativeVTable.h"
#define RUN_TEST(TESTNAME) \
try { \
bool result = TESTNAME::Run(lib); \
std::wcout << (result ? "OK" : "ERR"); \
std::wcout << L"\t" << #TESTNAME << std::endl; \
success &= result;\
} catch (const std::exception& e) { \
std::wcout << "Exception during " << #TESTNAME << " '" << e.what() << "'\n"; \
}
inline bool exists (string_t name) {
std::ifstream f(name.c_str());
return f.good();
}
#if defined(_WIN32)
int __cdecl wmain(int argc, wchar_t *argv[])
#else
int main(int argc, char *argv[])
#endif
{
for(int i = 0; i < argc; i++)
std::wcout << "argv[" << i << "] = " << argv[i] << std::endl;
string_t root_repo =
argc > 1 ?
argv[1] :
STR("/Users/kevingliewe/Documents/prog/dotnet/dotnet_runtime_test/");
string_t root_path = root_repo + STR("dotnet_runtime") DIR_SEPARATOR;
//string_t hostfxr_path = L"C:\\Program Files\\dotnet\\host\\fxr\\6.0.0\\hostfxr.dll";//root_path + DOTNET_RUNTIME_PATH_HOSTFXR;
string_t hostfxr_path = root_path + DOTNET_RUNTIME_PATH_HOSTFXR;
string_t lib_path = root_repo +
DIR_SEPARATOR
STR("bin")
DIR_SEPARATOR
STR("Lib")
DIR_SEPARATOR
STR("net6.0")
DIR_SEPARATOR;
string_t libDll_path = lib_path + STR("Lib.dll");
string_t libRuntimeconfig_path = lib_path + STR("Lib.runtimeconfig.json");
std::wcout << "root_path = " << root_path.c_str() << std::endl;
std::wcout << "hostfxr_path = " << hostfxr_path.c_str() << std::endl;
std::wcout << "lib_path = " << lib_path.c_str() << std::endl;
std::wcout << "libDll_path = " << libDll_path.c_str() << std::endl;
std::wcout << "libRuntimeconfig_path = " << libRuntimeconfig_path.c_str() << std::endl;
assert(exists(hostfxr_path));
assert(exists(libDll_path));
assert(exists(libRuntimeconfig_path));
void* host_handle = dotnet_runtime::get_host_handle();
std::wcout << "host_handle = " << host_handle << std::endl;
// begin-snippet: InitRuntimeAndLib
// Init runtime and lib
auto runtime = dotnet_runtime::Runtime(hostfxr_path, libRuntimeconfig_path);
auto lib = dotnet_runtime::Library(&runtime, libDll_path, STR("Lib"));
// end-snippet
g_pRuntime = &runtime;
g_pLib = &lib;
// Running tests
bool success = true;
RUN_TEST(Test_ManagedEntryPoint);
RUN_TEST(Test_NativeFunctionPointer);
RUN_TEST(Test_ManagedFunctionPointer);
RUN_TEST(Test_NativeArray);
RUN_TEST(Test_NativeString);
RUN_TEST(Test_ManagedString);
RUN_TEST(Test_ManagedUnsafe);
RUN_TEST(Test_DllImport);
RUN_TEST(Test_NativeExport);
RUN_TEST(Test_NativeVTable);
std::wcout << "Success: " << (success ? "true" : "false") << std::endl;
return success ? EXIT_SUCCESS : EXIT_FAILURE;
}