forked from BabylonJS/BabylonNative
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestUtilsImpl.cpp
More file actions
70 lines (63 loc) · 2.16 KB
/
TestUtilsImpl.cpp
File metadata and controls
70 lines (63 loc) · 2.16 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
#include "../TestUtilsImplData.h"
#define XK_MISCELLANY
#define XK_LATIN1
#include <X11/keysymdef.h>
#include <X11/Xlib.h> // will include X11 which #defines None... Don't mess with order of includes.
#include <X11/Xutil.h>
#include <unistd.h> // syscall
#undef None
#include <filesystem>
namespace Babylon::Plugins::TestUtils
{
int errorCode{};
}
namespace Babylon::Plugins::Internal
{
void TestUtils::Exit(const Napi::CallbackInfo& info)
{
auto window = (Window)m_implData->m_window;
const int32_t exitCode = info[0].As<Napi::Number>().Int32Value();
Plugins::TestUtils::errorCode = exitCode;
auto display = XOpenDisplay(NULL);
XClientMessageEvent dummyEvent;
memset(&dummyEvent, 0, sizeof(XClientMessageEvent));
dummyEvent.type = ClientMessage;
dummyEvent.window = window;
dummyEvent.format = 32;
dummyEvent.data.l[0] = XInternAtom(display, "WM_DELETE_WINDOW", False);;
XSendEvent(display, window, 0, 0, (XEvent*)&dummyEvent);
XFlush(display);
XCloseDisplay(display);
}
void TestUtils::UpdateSize(const Napi::CallbackInfo& /*info*/)
{
}
void TestUtils::SetTitle(const Napi::CallbackInfo& info)
{
const auto title = info[0].As<Napi::String>().Utf8Value();
auto display = XOpenDisplay(NULL);
auto window = (Window)m_implData->m_window;
XStoreName(display, window, title.c_str());
XCloseDisplay(display);
}
Napi::Value TestUtils::GetOutputDirectory(const Napi::CallbackInfo& info)
{
char exe[1024];
int ret = readlink("/proc/self/exe", exe, sizeof(exe) - 1);
if (ret == -1)
{
throw Napi::Error::New(info.Env(), "Unable to get executable location");
}
exe[ret] = 0;
auto path = std::filesystem::path{exe}.parent_path().generic_string();
return Napi::Value::From(info.Env(), path);
}
}
namespace Babylon::Plugins::TestUtils
{
void Initialize(Napi::Env env, Graphics::WindowT window)
{
auto implData{std::make_shared<Internal::TestUtils::ImplData>(window)};
Internal::TestUtils::CreateInstance(env, implData);
}
}