Created
January 6, 2020 01:43
-
-
Save thrimbor/7d8515ad443edafc400fc046e414329e to your computer and use it in GitHub Desktop.
Tests for nxdk InitOnce* API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <hal/debug.h> | |
#include <hal/video.h> | |
#include <windows.h> | |
// expected output: | |
// > failing function running | |
// > failing function running | |
// > succeeding function running | |
// > tests done | |
BOOL CALLBACK initOnceFnFailing (PINIT_ONCE initOnce, PVOID Parameter, PVOID *Context) | |
{ | |
debugPrint("failing function running\n"); | |
return FALSE; | |
} | |
BOOL CALLBACK initOnceFnSucceeding (PINIT_ONCE initOnce, PVOID Parameter, PVOID *Context) | |
{ | |
debugPrint("succeeding function running\n"); | |
return TRUE; | |
} | |
int main(void) | |
{ | |
XVideoSetMode(640, 480, 32, REFRESH_DEFAULT); | |
INIT_ONCE initOnce = INIT_ONCE_STATIC_INIT; | |
BOOL ret; | |
// these asserts were written after experiments on Windows 7 + VS 2017 | |
ret = InitOnceExecuteOnce(&initOnce, initOnceFnFailing, NULL, NULL); | |
assert(ret == FALSE); | |
assert(GetLastError() == 0); | |
ret = InitOnceExecuteOnce(&initOnce, initOnceFnFailing, NULL, NULL); | |
assert(ret == FALSE); | |
assert(GetLastError() == 0); | |
ret = InitOnceExecuteOnce(&initOnce, initOnceFnSucceeding, NULL, NULL); | |
assert(ret == TRUE); | |
// It's already initialized, so we get TRUE, but the function doesn't run | |
ret = InitOnceExecuteOnce(&initOnce, initOnceFnSucceeding, NULL, NULL); | |
assert(ret == TRUE); | |
debugPrint("tests done\n"); | |
while(1) { | |
Sleep(2000); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment