diff --git a/test/meson.build b/test/meson.build index 12386512..3dbc33c3 100644 --- a/test/meson.build +++ b/test/meson.build @@ -6,12 +6,15 @@ libui_test_sources = [ 'testing.c', ] -if libui_OS == 'darwin' +if libui_OS == 'windows' + libui_test_sources += ['testing_windows.c'] +elif libui_OS == 'darwin' libui_test_sources += ['testing_darwin.c'] else libui_test_sources += ['testing_unix.c'] endif +libui_test_deps = [] if libui_OS == 'windows' libui_test_manifest = 'test.manifest' if libui_mode == 'static' @@ -22,12 +25,19 @@ if libui_OS == 'windows' args: libui_manifest_args, depend_files: [libui_test_manifest]), ] + if libui_mode != 'static' + libui_test_deps += [ + # for QueryPerformanceCounter()/QueryPerformanceFrequency() + meson.get_compiler('c').find_library('kernel32', + required: true), + ] + endif endif # TODO once we upgrade to 0.49.0, add pie: true # TODO once we upgrade to 0.50.0, add protocol: 'exitcode' libui_tester = executable('tester', libui_test_sources, - dependencies: libui_binary_deps, + dependencies: libui_binary_deps + libui_test_deps, link_with: libui_libui, gui_app: false, install: false) diff --git a/test/testing_windows.c b/test/testing_windows.c new file mode 100644 index 00000000..cce9803f --- /dev/null +++ b/test/testing_windows.c @@ -0,0 +1,67 @@ +// 23 april 2019 +#define UNICODE +#define _UNICODE +#define STRICT +#define STRICT_TYPED_ITEMIDS +#define WINVER 0x0600 +#define _WIN32_WINNT 0x0600 +#define _WIN32_WINDOWS 0x0600 +#define _WIN32_IE 0x0700 +#define NTDDI_VERSION 0x06000000 +#include +#include +#include +#include "testing.h" + +struct testingTimer { + LARGE_INTEGER start; + LARGE_INTEGER end; +}; + +testingTimer *testingNewTimer(void) +{ + testingTimer *t; + + t = (testingTimer *) malloc(sizeof (testingTimer)); + // TODO handle failure + memset(t, 0, sizeof (testingTimer)); + return t; +} + +void testingFreeTimer(testingTimer *t) +{ + free(t); +} + +void testingTimerStart(testingTimer *t) +{ + QueryPerformanceCounter(&(t->start)); +} + +void testingTimerEnd(testingTimer *t) +{ + QueryPerformanceCounter(&(t->end)); +} + +int64_t testingTimerNsec(testingTimer *t) +{ + LARGE_INTEGER qpf; + int64_t c; + int64_t sec; + int64_t subsec; + double subsecf; + + QueryPerformanceFrequency(&qpf); + c = t->end.QuadPart - t->start.QuadPart; + + sec = c / qpf.QuadPart; + sec *= testingTimerNsecPerSec; + + subsec = c % qpf.QuadPart; + subsecf = (double) subsec; + subsecf /= qpf.QuadPart; + subsecf *= testingTimerNsecPerSec; + subsec = (int64_t) subsecf; + + return sec + subsec; +}