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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
|
import os
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 surface, render
from .conftest import _check_error_msg
sdlgfx = pytest.importorskip("sdl2.sdlgfx")
@pytest.fixture(scope="module")
def with_sdl():
if SDL_Init(SDL_INIT_VIDEO) != 0:
raise RuntimeError("Video subsystem not supported")
yield
SDL_Quit()
@pytest.fixture
def test_surf(with_sdl):
w, h = 480, 320
sf = surface.SDL_CreateRGBSurface(0, w, h, 32, 0, 0, 0, 0)
assert isinstance(sf.contents, surface.SDL_Surface)
yield sf
surface.SDL_FreeSurface(sf)
@pytest.fixture
def software_renderer(with_sdl):
height, width = (480, 320)
sdl2.SDL_ClearError()
# Create a new SDL surface and make it the target of a new renderer
target = surface.SDL_CreateRGBSurface(0, height, width, 32, 0, 0, 0, 0)
assert target, _check_error_msg()
renderer = render.SDL_CreateSoftwareRenderer(target)
assert renderer, _check_error_msg()
# Return the renderer and surface for the test
yield (renderer, target)
# Free memory for the renderer and surface once we're done
sdl2.SDL_DestroyRenderer(renderer)
sdl2.SDL_FreeSurface(target)
RED_U32 = 0xFF0000FF
WHITE_U32 = 0xFFFFFFFF
class TestFramerate(object):
__tags__ = ["sdl", "sdlgfx"]
def test_SDL_initFramerate(self):
manager = sdlgfx.FPSManager()
sdlgfx.SDL_initFramerate(manager)
assert manager.framecount == 0
assert manager.rate == sdlgfx.FPS_DEFAULT
def test_SDL_getsetFramerate(self):
manager = sdlgfx.FPSManager()
sdlgfx.SDL_initFramerate(manager)
ret = sdlgfx.SDL_setFramerate(manager, 24)
fps = sdlgfx.SDL_getFramerate(manager)
assert ret == 0
assert manager.rate == 24
assert fps == 24
def test_SDL_getFramecount(self):
manager = sdlgfx.FPSManager()
sdlgfx.SDL_initFramerate(manager)
assert sdlgfx.SDL_getFramecount(manager) == 0
sdlgfx.SDL_framerateDelay(manager)
assert sdlgfx.SDL_getFramecount(manager) == 1
@pytest.mark.xfail(reason="Timing can be super wonky on CI platforms")
def test_SDL_framerateDelay(self):
manager = sdlgfx.FPSManager()
sdlgfx.SDL_initFramerate(manager)
ret = sdlgfx.SDL_setFramerate(manager, 100)
assert ret == 0
sdlgfx.SDL_framerateDelay(manager)
assert manager.framecount == 1
frametimes = []
for i in range(10):
msec_since_last = sdlgfx.SDL_framerateDelay(manager)
frametimes.append(msec_since_last)
avg_framerate = round(sum(frametimes) / 10)
assert abs(avg_framerate - 10) < 2
assert manager.framecount == 11
class TestDrawing(object):
__tags__ = ["sdl", "sdlgfx"]
def test_pixel(self, software_renderer):
renderer, sf = software_renderer
ret = sdlgfx.pixelColor(renderer, 5, 5, RED_U32)
assert ret == 0
ret = sdlgfx.pixelRGBA(renderer, 5, 5, 255, 255, 255, 255)
assert ret == 0
@pytest.mark.skip("not implemented")
def test_hline(self):
pass
@pytest.mark.skip("not implemented")
def test_vline(self):
pass
@pytest.mark.skip("not implemented")
def test_rectangle(self):
pass
@pytest.mark.skip("not implemented")
def test_roundedRectangle(self):
pass
@pytest.mark.skip("not implemented")
def test_box(self):
pass
@pytest.mark.skip("not implemented")
def test_roundedBox(self):
pass
@pytest.mark.skip("not implemented")
def test_line(self):
pass
@pytest.mark.skip("not implemented")
def test_aaline(self):
pass
@pytest.mark.skip("not implemented")
def test_thickLine(self):
pass
@pytest.mark.skip("not implemented")
def test_circle(self):
pass
@pytest.mark.skip("not implemented")
def test_arc(self):
pass
@pytest.mark.skip("not implemented")
def test_aacircle(self):
pass
@pytest.mark.skip("not implemented")
def test_filledCircle(self):
pass
@pytest.mark.skip("not implemented")
def test_ellipse(self):
pass
@pytest.mark.skip("not implemented")
def test_aaellipse(self):
pass
@pytest.mark.skip("not implemented")
def test_filledEllipse(self):
pass
@pytest.mark.skip("not implemented")
def test_pie(self):
pass
@pytest.mark.skip("not implemented")
def test_filledPie(self):
pass
@pytest.mark.skip("not implemented")
def test_trigon(self):
pass
@pytest.mark.skip("not implemented")
def test_aatrigon(self):
pass
@pytest.mark.skip("not implemented")
def test_filledTrigon(self):
pass
@pytest.mark.skip("not implemented")
def test_polygon(self):
pass
@pytest.mark.skip("not implemented")
def test_aapolygon(self):
pass
@pytest.mark.skip("not implemented")
def test_filledPolygon(self):
pass
@pytest.mark.skip("not implemented")
def test_texturedPolygon(self):
pass
@pytest.mark.skip("not implemented")
def test_bezier(self):
pass
@pytest.mark.skip("not implemented")
def test_gfxPrimitivesSetFont(self):
pass
@pytest.mark.skip("not implemented")
def test_gfxPrimitivesSetFontRotation(self):
pass
@pytest.mark.skip("not implemented")
def test_character(self):
pass
@pytest.mark.skip("not implemented")
def test_string(self):
pass
class TestRotoZoom(object):
__tags__ = ["sdl", "sdlgfx"]
@pytest.mark.skip("not implemented")
def test_rotozoomSurface(self, test_surf):
pass
@pytest.mark.skip("not implemented")
def test_rotozoomSurfaceXY(self, test_surf):
pass
@pytest.mark.skip("not implemented")
def test_rotozoomSurfaceSize(self, test_surf):
pass
@pytest.mark.skip("not implemented")
def test_rotozoomSurfaceSizeXY(self, test_surf):
pass
def test_zoomSurface(self, test_surf):
zoom_sf = sdlgfx.zoomSurface(test_surf, 1.5, 2.0, 0)
assert isinstance(zoom_sf.contents, surface.SDL_Surface)
assert zoom_sf.contents.w == test_surf.contents.w * 1.5
assert zoom_sf.contents.h == test_surf.contents.h * 2.0
surface.SDL_FreeSurface(zoom_sf)
def test_zoomSurfaceSize(self, test_surf):
out_w, out_h = (c_int(0), c_int(0))
w, h = (test_surf.contents.w, test_surf.contents.h)
sdlgfx.zoomSurfaceSize(w, h, 1.5, 2.0, byref(out_w), byref(out_h))
assert out_w.value == w * 1.5
assert out_h.value == h * 2.0
def test_shrinkSurface(self, test_surf):
shrunk_sf = sdlgfx.shrinkSurface(test_surf, 3, 2)
assert isinstance(shrunk_sf.contents, surface.SDL_Surface)
assert shrunk_sf.contents.w == test_surf.contents.w / 3
assert shrunk_sf.contents.h == test_surf.contents.h / 2
surface.SDL_FreeSurface(shrunk_sf)
def test_rotateSurface90Degrees(self, test_surf):
rotsf = sdlgfx.rotateSurface90Degrees(test_surf, 1)
assert isinstance(rotsf.contents, surface.SDL_Surface)
assert rotsf.contents.w == test_surf.contents.h
assert rotsf.contents.h == test_surf.contents.w
surface.SDL_FreeSurface(rotsf)
|