File: metal_test.py

package info (click to toggle)
pysdl2 0.9.9%2Bdfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,276 kB
  • sloc: python: 18,592; makefile: 148; sh: 40
file content (65 lines) | stat: -rw-r--r-- 2,636 bytes parent folder | download
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
import sys
from ctypes import c_int, byref
import pytest
import sdl2
from sdl2 import SDL_Init, SDL_Quit, SDL_INIT_VIDEO
from sdl2 import metal, video, error

macos = sys.platform == "darwin"

# TODO: Add more complete tests with pyobjc


class TestSDLMetal(object):
    __tags__ = ["sdl"]

    @classmethod
    def setup_class(cls):
        if SDL_Init(SDL_INIT_VIDEO) != 0:
            raise pytest.skip('Video subsystem not supported')

    @classmethod
    def teardown_class(cls):
        SDL_Quit()

    @pytest.mark.xfail(reason="Metal not supported on all macs")
    @pytest.mark.skipif(sdl2.dll.version < 2012 or not macos, reason="not available")
    def test_SDL_Metal_CreateDestroyView(self):
        error.SDL_ClearError()
        flags = video.SDL_WINDOW_HIDDEN | video.SDL_WINDOW_METAL
        window = video.SDL_CreateWindow(b"Test", 10, 10, 10, 10, flags)
        assert isinstance(window.contents, video.SDL_Window)
        view = metal.SDL_Metal_CreateView(window)
        err = error.SDL_GetError()
        if len(err):
            print("Metal Error: '{0}'".format(err.decode('utf-8')))
        assert view  # Verify pointer is not null
        metal.SDL_Metal_DestroyView(view)
        video.SDL_DestroyWindow(window)

    @pytest.mark.xfail(reason="Metal not supported on all macs")
    @pytest.mark.skipif(sdl2.dll.version < 2014 or not macos, reason="not available")
    def test_SDL_Metal_GetLayer(self):
        flags = video.SDL_WINDOW_HIDDEN | video.SDL_WINDOW_METAL
        window = video.SDL_CreateWindow(b"Test", 10, 10, 10, 10, flags)
        assert isinstance(window.contents, video.SDL_Window)
        view = metal.SDL_Metal_CreateView(window)
        assert view  # Verify pointer is not null
        layer = metal.SDL_Metal_GetLayer(view)
        assert layer  # Verify pointer is not null
        metal.SDL_Metal_DestroyView(view)
        video.SDL_DestroyWindow(window)

    @pytest.mark.xfail(reason="Metal not supported on all macs")
    @pytest.mark.skipif(sdl2.dll.version < 2014 or not macos, reason="not available")
    def test_SDL_Metal_GetDrawableSize(self):
        flags = video.SDL_WINDOW_HIDDEN | video.SDL_WINDOW_METAL
        window = video.SDL_CreateWindow(b"Test", 10, 10, 10, 10, flags)
        assert isinstance(window.contents, video.SDL_Window)
        view = metal.SDL_Metal_CreateView(window)
        assert view  # Verify pointer is not null
        w, h = c_int(0), c_int(0)
        metal.SDL_Metal_GetDrawableSize(window, byref(w), byref(h))
        assert w.value == 10 and h.value == 10
        metal.SDL_Metal_DestroyView(view)
        video.SDL_DestroyWindow(window)