And implemented testingTimer on Windows.

This commit is contained in:
Pietro Gagliardi 2019-04-23 22:49:28 -04:00
parent 7e631879e7
commit aa49da98ba
2 changed files with 79 additions and 2 deletions

View File

@ -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)

67
test/testing_windows.c Normal file
View File

@ -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 <windows.h>
#include <stdlib.h>
#include <string.h>
#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;
}