diff --git a/csdl/tests/test_video.py b/csdl/tests/test_video.py new file mode 100644 index 0000000..f837722 --- /dev/null +++ b/csdl/tests/test_video.py @@ -0,0 +1,84 @@ +from csdl import init, InitFlags, quit +from csdl import video +from nose.tools import with_setup + +def video_setup(): + init(InitFlags.VIDEO) + +def test_get_render_drivers(): + driver_list = video.get_render_drivers() + assert driver_list + + software = None + for drv in driver_list: + if drv.name == 'software': + software = drv + + # software renderer should always be available + assert software + # texture formats should be non-zero + assert all(software.texture_formats[0:software.num_texture_formats]) + + assert repr(software) == "" + +def test_rect_basics(): + r1 = video.Rect(0,0,10,10) + r2 = video.Rect(0,0,10,10) + + # __eq__ + assert r1 == r2 + + # is_empty + assert video.Rect(1,2,3,0).is_empty() + assert video.Rect(1,2,0,4).is_empty() + assert not video.Rect(1,2,3,4).is_empty() + + # __repr__ + assert repr(r1) == 'Rect(0, 0, 10, 10)' + + +@with_setup(video_setup, quit) +def test_window_title(): + w = video.Window("window_title_test", 10, 10, 50, 50) + assert w.title == "window_title_test" + w.title = "something completely different" + assert w.title == "something completely different" + w.destroy() + +@with_setup(video_setup, quit) +def test_window_size(): + w = video.Window("window_size_test", 10, 10, 50, 50) + assert w.size == (50, 50) + w.resize(100, 120) + assert w.size == (100, 120) + w.destroy() + +@with_setup(video_setup, quit) +def test_window_position(): + w = video.Window('window_position_test', 10, 10, 50, 50) + assert w.position == (10, 10) + w.move(100, 110) + assert w.position == (100, 110) + w.destroy() + +@with_setup(video_setup, quit) +def test_screensaver(): + enabled = video.is_screensaver_enabled() + + if enabled: + video.disable_screensaver() + assert not video.is_screensaver_enabled() + video.enable_screensaver() + assert video.is_screensaver_enabled() + else: + video.enable_screensaver() + assert video.is_screensaver_enabled() + video.disable_screensaver() + assert not video.is_screensaver_enabled() + + +@with_setup(video_setup, quit) +def test_video_info(): + # make sure both aren't blank + assert video.get_num_video_displays() + assert video.get_current_video_driver() diff --git a/csdl/video.py b/csdl/video.py index 291c192..1ed1b3e 100644 --- a/csdl/video.py +++ b/csdl/video.py @@ -67,7 +67,7 @@ class Renderer(object): errcheck(_SDL.SDL_GetRenderDrawColor(self._renderer, ctypes.byref(r), ctypes.byref(g), ctypes.byref(b), ctypes.byref(a))) - return (r,g,b,a) + return (r.value, g.value, b.value, a.value) @property def viewport(self): @@ -192,7 +192,7 @@ class Window(object): h = ctypes.c_int() _SDL.SDL_GetWindowSize(self._handle, ctypes.byref(w), ctypes.byref(h)) - return w,h + return w.value, h.value def resize(self, w, h): _SDL.SDL_SetWindowSize(self._handle, w, h) @@ -235,7 +235,7 @@ def is_screensaver_enabled(): def get_current_display_mode(display): mode = DisplayMode() errcheck(_SDL.SDL_GetCurrentDisplayMode(display, ctypes.byref(mode))) - return mode + return mode.value _SDL.SDL_GetPixelFormatName.restype = ctypes.c_char_p def get_pixel_format_name(format): @@ -265,13 +265,13 @@ def get_display_modes(display_index): for i in xrange(num): mode = DisplayMode() _SDL.SDL_GetDisplayMode(display_index, i, ctypes.byref(mode)) - _display_mode_list[display_index].append(mode) + _display_mode_list[display_index].append(mode.value) return _display_mode_list[display_index] def get_desktop_display_mode(display_index): mode = DisplayMode() errcheck(_SDL.SDL_GetDesktopDisplayMode(display_index, ctypes.byref(mode))) - return mode + return mode.value class Rect(ctypes.Structure): _fields_ = ( @@ -295,7 +295,7 @@ class Rect(ctypes.Structure): if _SDL.SDL_EnclosePoints(_sdl_points, len(points), ctypes.pointer(clip) if clip else None, ctypes.byref(result)): - return result + return result.value def intersects(self, other): return _SDL.SDL_HasIntersection(ctypes.pointer(self), @@ -307,13 +307,13 @@ class Rect(ctypes.Structure): # returns True if an intersection is found if _SDL.SDL_IntersectRect(ctypes.pointer(self), ctypes.pointer(other), ctypes.byref(result)): - return result + return result.value def union(self, other): result = Rect() _SDL.SDL_UnionRect(ctypes.pointer(self), ctypes.pointer(other), ctypes.byref(result)) - return result + return result.value def intersects_line(self, x1, y1, x2, y2): return _SDL.SDL_IntersectRectAndLine(ctypes.pointer(self), @@ -341,4 +341,4 @@ class Point(ctypes.Structure): def get_display_bounds(display_index): rect = Rect() errcheck(_SDL.SDL_GetDisplayBounds(display_index, ctypes.byref(rect))) - return rect + return rect.value