Skip to content

Commit 5483ca4

Browse files
committed
Update tests.
1 parent 6e8ef19 commit 5483ca4

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

tests/TEST_init.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1-
from .__init__ import sdl3, TEST_RegisterFunction, TEST_PassFunction
1+
from .__init__ import sdl3, ctypes, TEST_RegisterFunction
22

33
@TEST_RegisterFunction(["Linux", "Darwin", "Windows"])
4-
def TEST_SDL_Init():
5-
assert sdl3.SDL_Init(0), sdl3.SDL_GetError().decode()
4+
def TEST_SDL_Init() -> None:
5+
assert sdl3.SDL_Init(sdl3.SDL_INIT_EVENTS), sdl3.SDL_GetError().decode()
6+
assert sdl3.SDL_WasInit(0) & sdl3.SDL_INIT_EVENTS, "Failed to initialize subsystem."
67
assert (error := sdl3.SDL_GetError()) == "".encode(), error.decode()
78
sdl3.SDL_Quit()
89

9-
@TEST_RegisterFunction(["Darwin", "Windows"])
10-
def TEST_SDL_CreateWindow():
11-
assert sdl3.SDL_Init(sdl3.SDL_INIT_VIDEO), sdl3.SDL_GetError().decode()
12-
assert (window := sdl3.SDL_CreateWindow("Test".encode(), 1600, 900, sdl3.SDL_WINDOW_RESIZABLE)), sdl3.SDL_GetError().decode()
10+
@TEST_RegisterFunction(["Linux", "Darwin", "Windows"])
11+
def TEST_SDL_InitSubSystem() -> None:
12+
assert sdl3.SDL_Init(sdl3.SDL_INIT_AUDIO), sdl3.SDL_GetError().decode()
13+
assert sdl3.SDL_InitSubSystem(sdl3.SDL_INIT_EVENTS), sdl3.SDL_GetError().decode()
1314
assert (error := sdl3.SDL_GetError()) == "".encode(), error.decode()
14-
sdl3.SDL_DestroyWindow(window)
15-
sdl3.SDL_Quit()
15+
assert sdl3.SDL_WasInit(0) & sdl3.SDL_INIT_EVENTS, "Failed to initialize subsystem."
16+
assert sdl3.SDL_WasInit(0) & sdl3.SDL_INIT_AUDIO, "Failed to initialize subsystem."
17+
sdl3.SDL_QuitSubSystem(sdl3.SDL_INIT_EVENTS)
18+
sdl3.SDL_Quit()
19+
20+
@TEST_RegisterFunction(["Linux", "Darwin", "Windows"])
21+
def TEST_SDL_IsMainThread() -> None:
22+
assert sdl3.SDL_IsMainThread(), sdl3.SDL_GetError().decode()
23+
24+
@sdl3.SDL_MainThreadCallback
25+
def callback(data: ctypes.c_void_p) -> None:
26+
ctypes.cast(data, ctypes.POINTER(ctypes.c_bool))[0] = True
27+
28+
@TEST_RegisterFunction(["Linux", "Darwin", "Windows"])
29+
def TEST_SDL_RunOnMainThread() -> None:
30+
data = ctypes.pointer(ctypes.c_bool(False))
31+
assert sdl3.SDL_RunOnMainThread(callback, ctypes.cast(data, ctypes.c_void_p), True), sdl3.SDL_GetError().decode()
32+
assert data[0], "Failed to run on main thread."

tests/TEST_video.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from .__init__ import sdl3, TEST_RegisterFunction
2+
3+
@TEST_RegisterFunction(["Darwin", "Windows"])
4+
def TEST_SDL_CreateWindow() -> None:
5+
assert sdl3.SDL_Init(sdl3.SDL_INIT_VIDEO), sdl3.SDL_GetError().decode()
6+
assert (window := sdl3.SDL_CreateWindow("Test".encode(), 1600, 900, sdl3.SDL_WINDOW_RESIZABLE)), sdl3.SDL_GetError().decode()
7+
assert (error := sdl3.SDL_GetError()) == "".encode(), error.decode()
8+
sdl3.SDL_DestroyWindow(window)
9+
sdl3.SDL_Quit()

tests/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1-
import os, sys, atexit
1+
import os, sys, atexit, typing
22

33
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
44

5-
import sdl3
5+
import sdl3, ctypes
66

77
functions = {}
88

9-
def TEST_RegisterFunction(systems):
9+
def TEST_RegisterFunction(systems: typing.List[str]) -> typing.Callable:
1010
return lambda func: functions.update({func: systems})
1111

1212
class TEST_PassFunction(Exception):
1313
...
1414

1515
from tests.TEST_init import *
16+
from tests.TEST_video import *
1617

1718
@atexit.register
18-
def TEST_RunAllTests():
19+
def TEST_RunAllTests() -> None:
1920
if not functions: return
2021
passed, failed = 0, 0
2122

2223
for func, systems in functions.items():
2324
try:
25+
sdl3.SDL_ClearError()
2426
if sdl3.SDL_SYSTEM in systems: func()
2527
else: raise TEST_PassFunction()
2628
print("\33[32m", f"Test '{func.__name__}' passed.", "\33[0m", sep = "", flush = True)

0 commit comments

Comments
 (0)