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
|
import sys
import ctypes
import pytest
from sdl2 import version, dll, __version__, version_info
class TestSDLVersion(object):
__tags__ = ["sdl"]
def test__version_tuple(self):
# Note that this is not public API.
assert dll._version_tuple_to_int((2, 0, 18)) == 2018
assert dll._version_tuple_to_int((2, 24, 1)) == 2241
# Micro version stops at 9 in this encoding
assert dll._version_tuple_to_int((2, 24, 15)) == 2249
assert dll._version_tuple_to_int((2, 99, 9)) == 2999
# Minor version stops at 99 in this encoding
assert dll._version_tuple_to_int((2, 103, 6)) == 2999
def test_SDL_version(self):
v = version.SDL_version(0, 0, 0)
assert v.major == 0
assert v.minor == 0
assert v.patch == 0
def test_SDL_GetVersion(self):
v = version.SDL_version()
version.SDL_GetVersion(ctypes.byref(v))
assert type(v) == version.SDL_version
assert v.major == 2
assert v.minor >= 0
assert v.patch >= 0
assert (v.major, v.minor, v.patch) >= (2, 0, 5)
assert (v.major, v.minor, v.patch) == dll.version_tuple
def test_SDL_VERSIONNUM(self):
assert version.SDL_VERSIONNUM(1, 2, 3) == 1203
assert version.SDL_VERSIONNUM(4, 5, 6) == 4506
assert version.SDL_VERSIONNUM(2, 0, 0) == 2000
assert version.SDL_VERSIONNUM(17, 42, 3) == 21203
# This is a bit weird now that SDL uses the minor version more often,
# but does sort in the correct order against all versions of SDL 2.
assert version.SDL_VERSIONNUM(2, 23, 0) == 4300
# This is the highest possible SDL 2 version
assert version.SDL_VERSIONNUM(2, 255, 99) == 27599
def test_SDL_VERSION_ATLEAST(self):
assert version.SDL_VERSION_ATLEAST(1, 2, 3)
assert version.SDL_VERSION_ATLEAST(2, 0, 0)
assert version.SDL_VERSION_ATLEAST(2, 0, 1)
assert not version.SDL_VERSION_ATLEAST(2, 0, 100)
def test_SDL_GetRevision(self):
rev = version.SDL_GetRevision()
# If revision not empty string (e.g. Conda), test the prefix
if len(rev):
if dll.version_tuple >= (2, 0, 16):
if rev[0:4] not in (b"http", b"SDL-"):
pytest.xfail("no API guarantee about the format of this string")
else:
assert version.SDL_GetRevision()[0:3] == b"hg-"
def test_SDL_GetRevisionNumber(self):
if sys.platform in ("win32",) or dll.version_tuple >= (2, 0, 16):
# HG tip on Win32 does not set any revision number
assert version.SDL_GetRevisionNumber() >= 0
else:
assert version.SDL_GetRevisionNumber() >= 7000
|