Marcus von Appen avatar Marcus von Appen committed d75539b

- minor unit test improvements

Comments (0)

Files changed (8)

sdl2/test/keyboard_test.py

 
     @unittest.skip("not implemented")
     def test_SDL_StartTextInput(self):
-        pass
+        keyboard.SDL_StartTextInput()
 
     @unittest.skip("not implemented")
     def test_SDL_StopTextInput(self):
-        pass
+        keyboard.SDL_StopTextInput()
 
 if __name__ == '__main__':
     sys.exit(unittest.main())

sdl2/test/pixels_test.py

         self.assertFalse(isfourcc(pixels.SDL_PIXELFORMAT_ARGB4444))
         self.assertFalse(isfourcc(pixels.SDL_PIXELFORMAT_INDEX8))
 
-    def test_get_pixel_format_name(self):
+    def test_SDL_GetPixelFormatName(self):
         self.assertEqual(pixels.SDL_GetPixelFormatName
                          (pixels.SDL_PIXELFORMAT_INDEX1LSB),
                          b"SDL_PIXELFORMAT_INDEX1LSB")

sdl2/test/platform_test.py

 class SDLPlatformTest(unittest.TestCase):
     __tags__ = ["sdl"]
 
-    def test_get_platform(self):
+    def test_SDL_GetPlatform(self):
         retval = platform.SDL_GetPlatform()
         if sys.platform in ("win32", "cygwin", "cli"):
             self.assertEqual(retval, b"Windows")
         # Do not check others atm, since we are unsure about what Python will
         # return here.
 
+
 if __name__ == '__main__':
     sys.exit(unittest.main())

sdl2/test/render_test.py

 from .. import SDL_Init, SDL_Quit, SDL_INIT_EVERYTHING
 from ..stdinc import Uint8, Uint32, SDL_TRUE, SDL_FALSE
 from .. import render, video, surface, pixels, blendmode, rect
+from ..ext.pixelaccess import PixelView
 
 
 # TODO: mostly positive tests, improve this!
         #self.assertIsInstance(window, video.SDL_Window)
         #self.assertIsInstance(renderer, render.SDL_Renderer)
 
-    def test_create_SDL_DestroyRenderer(self):
+    def test_SDL_CreateDestroyRenderer(self):
         window = video.SDL_CreateWindow(b"Test", 10, 10, 10, 10,
                                      video.SDL_WINDOW_SHOWN)
         self.assertIsInstance(window.contents, video.SDL_Window)
         video.SDL_DestroyWindow(window)
 
     @unittest.skip("not implemented")
-    def test_update_texture(self):
+    def test_SDL_UpdateTexture(self):
         pass
 
     @unittest.skip("not implemented")
-    def test_lock_texture(self):
-        pass
-
-    @unittest.skip("not implemented")
-    def test_unlock_texture(self):
+    def test_SDL_LockUnlockTexture(self):
         pass
 
     def test_SDL_RenderTargetSupported(self):
 #        self.assertRaises((AttributeError, TypeError),
 #                          render.SDL_RenderClear, 123456)
 
-    @unittest.skip("not implemented")
+    @unittest.skipIf(hasattr(sys, "pypy_version_info"),
+                     "PyPy's ctypes can't do byref(value, offset)")
     def test_SDL_RenderDrawPoint(self):
         points = ((-4, -3), (-4, 3), (4, -3),
                   (0, 0), (1, 1), (10, 10), (99, 99),
             ret = render.SDL_RenderDrawPoint(renderer, x, y)
             self.assertEqual(ret, 0)
         render.SDL_RenderPresent(renderer)
-        #view = pvid.PixelView(sf)
-        #for x, y in points:
-        #    npx = max(x + 1, w)
-        #    npy = max(y + 1, h)
-        #    ppx = max(x - 1, 0)
-        #    ppy = max(y - 1, 0)
-        #    if x < 0 or x >= w or y < 0 or y >= h:
-        #        continue
-        #    self.assertEqual(hex(view[y][x]), hex(color))
-        #    if (npx, npy) not in points:
-        #        self.assertNotEqual(hex(view[npy][npx]), hex(color))
-        #    if (ppx, ppy) not in points:
-        #        self.assertNotEqual(hex(view[ppy][ppx]), hex(color))
+        view = PixelView(sf.contents)
+        for x, y in points:
+            npx = max(x + 1, w)
+            npy = max(y + 1, h)
+            ppx = max(x - 1, 0)
+            ppy = max(y - 1, 0)
+            if x < 0 or x >= w or y < 0 or y >= h:
+                continue
+            self.assertEqual(hex(view[y][x]), hex(color))
+            if (npx, npy) not in points:
+                self.assertNotEqual(hex(view[npy][npx]), hex(color))
+            if (ppx, ppy) not in points:
+                self.assertNotEqual(hex(view[ppy][ppx]), hex(color))
         render.SDL_DestroyRenderer(renderer)
-        #del view
+        del view
         surface.SDL_FreeSurface(sf)
 
     @unittest.skip("not implemented")

sdl2/test/sdl2ext_pixelaccess_test.py

                 for col in row:
                     self.assertEqual(col, 0x0)
 
+    @unittest.skip("not implemented")
     @unittest.skipIf(not _HASNUMPY, "numpy module is not supported")
     def test_pixels2d(self):
         factory = sdl2ext.SpriteFactory(sdl2ext.SOFTWARE)
         sprite = factory.create_sprite(size=(5, 10), bpp=32,
                                        masks=(0xFF000000, 0x00FF0000,
                                               0x0000FF00, 0x000000FF))
-        sdl2ext.fill(sprite, 0xAABBCCDD, (2, 2, 2, 2))
+        sdl2ext.fill(sprite, 0x01, (2, 2, 2, 2))
         nparray = sdl2ext.pixels2d(sprite)
 
     @unittest.skipIf(not _HASNUMPY, "numpy module is not supported")
                                               0x0000FF00, 0x000000FF))
         sdl2ext.fill(sprite, 0xAABBCCDD, (1, 2, 3, 4))
         nparray = sdl2ext.pixels3d(sprite)
+        for x in range(1, 4):
+            for y in range(2, 6):
+                self.assertTrue(numpy.all([nparray[x, y],
+                                           [0xAA, 0xBB, 0xCC, 0xDD]]))
+        self.assertFalse(numpy.all([nparray[0, 0], [0xAA, 0xBB, 0xCC, 0xDD]]))
+        self.assertFalse(numpy.all([nparray[1, 0], [0xAA, 0xBB, 0xCC, 0xDD]]))
+        self.assertFalse(numpy.all([nparray[0, 1], [0xAA, 0xBB, 0xCC, 0xDD]]))
+        self.assertFalse(numpy.all([nparray[3, 6], [0xAA, 0xBB, 0xCC, 0xDD]]))
+        self.assertFalse(numpy.all([nparray[4, 6], [0xAA, 0xBB, 0xCC, 0xDD]]))
 
 
 if __name__ == '__main__':

sdl2/test/sdl2ext_sprite_test.py

 import sys
 import unittest
-from ctypes import ArgumentError
+from ctypes import ArgumentError, POINTER, byref
 from ..ext.resources import Resources
 from .. import ext as sdl2ext
 from ..surface import SDL_Surface, SDL_CreateRGBSurface, SDL_FreeSurface
+from sdl2.video import SDL_Window, SDL_WINDOW_HIDDEN, SDL_DestroyWindow
+from sdl2.render import SDL_Renderer, SDL_CreateWindowAndRenderer, \
+    SDL_DestroyRenderer, SDL_CreateTexture, SDL_Texture
 
 RESOURCES = Resources(__file__, "resources")
 
         #self.assertRaises(ValueError, factory.create_software_sprite, (10,-5))
         self.assertRaises(TypeError, factory.create_software_sprite, size=None)
         self.assertRaises(sdl2ext.SDLError, factory.create_software_sprite,
-                          bpp=-1)
+                          bpp= -1)
         self.assertRaises(TypeError, factory.create_software_sprite, masks=5)
         self.assertRaises((ArgumentError, TypeError),
                           factory.create_software_sprite,
             self.assertRaises((AttributeError, IOError, sdl2ext.SDLError),
                               factory.from_image, 12345)
 
+    @unittest.skip("not implemented")
     def test_SpriteFactory_from_object(self):
         window = sdl2ext.Window("Test", size=(1, 1))
         renderer = sdl2ext.RenderContext(window)
     @unittest.skip("not implemented")
     def test_TextureSpriteRenderer(self):
         pass
-
+        
     @unittest.skip("not implemented")
     def test_TextureSpriteRenderer_render(self):
         pass
         sprite.position = -22, 99
         self.assertEqual(sprite.area, (-22, 99, -12, 109))
 
-    @unittest.skip("not implemented")
     def test_TextureSprite(self):
-        pass
+        window = POINTER(SDL_Window)()
+        renderer = POINTER(SDL_Renderer)()
+        SDL_CreateWindowAndRenderer(10, 10, SDL_WINDOW_HIDDEN,
+                                    byref(window), byref(renderer))
 
-    @unittest.skip("not implemented")
+        tex = SDL_CreateTexture(renderer, 0, 0, 10, 10)
+        self.assertIsInstance(tex.contents, SDL_Texture)
+        sprite = sdl2ext.TextureSprite(tex.contents)
+        self.assertIsInstance(sprite, sdl2ext.TextureSprite)
+        SDL_DestroyRenderer(renderer)
+        SDL_DestroyWindow(window)
+
     def test_TextureSprite_position_xy(self):
-        pass
+        window = POINTER(SDL_Window)()
+        renderer = POINTER(SDL_Renderer)()
+        SDL_CreateWindowAndRenderer(10, 10, SDL_WINDOW_HIDDEN,
+                                    byref(window), byref(renderer))
+        tex = SDL_CreateTexture(renderer, 0, 0, 10, 10)
+        self.assertIsInstance(tex.contents, SDL_Texture)
+        sprite = sdl2ext.TextureSprite(tex.contents)
+        self.assertIsInstance(sprite, sdl2ext.TextureSprite)
+        self.assertEqual(sprite.position, (0, 0))
+        positions = [(x, y) for x in range(-50, 50) for y in range(-50, 50)]
+        for x, y in positions:
+            sprite.position = x, y
+            self.assertEqual(sprite.position, (x, y))
+            sprite.x = x + 1
+            sprite.y = y + 1
+            self.assertEqual(sprite.position, (x + 1, y + 1))
+        SDL_DestroyRenderer(renderer)
+        SDL_DestroyWindow(window)
 
-    @unittest.skip("not implemented")
     def test_TextureSprite_size(self):
-        pass
+        window = POINTER(SDL_Window)()
+        renderer = POINTER(SDL_Renderer)()
+        SDL_CreateWindowAndRenderer(10, 10, SDL_WINDOW_HIDDEN,
+                                    byref(window), byref(renderer))
+        sizes = [(w, h) for w in range(1, 200) for h in range(1, 200)]
+        for w, h in sizes:
+            tex = SDL_CreateTexture(renderer, 0, 0, w, h)
+            sprite = sdl2ext.TextureSprite(tex.contents)
+            self.assertEqual(sprite.size, (w, h))
+        SDL_DestroyRenderer(renderer)
+        SDL_DestroyWindow(window)
 
-    @unittest.skip("not implemented")
     def test_TextureSprite_area(self):
-        pass
+        window = POINTER(SDL_Window)()
+        renderer = POINTER(SDL_Renderer)()
+        SDL_CreateWindowAndRenderer(10, 10, SDL_WINDOW_HIDDEN,
+                                    byref(window), byref(renderer))
+        tex = SDL_CreateTexture(renderer, 0, 0, 10, 20)
+        sprite = sdl2ext.TextureSprite(tex.contents)
+        self.assertEqual(sprite.area, (0, 0, 10, 20))
+
+        def setarea(s, v):
+            s.area = v
+
+        self.assertRaises(AttributeError, setarea, sprite, (1, 2, 3, 4))
+        sprite.position = 7, 3
+        self.assertEqual(sprite.area, (7, 3, 17, 23))
+        sprite.position = -22, 99
+        self.assertEqual(sprite.area, (-22, 99, -12, 119))
+        SDL_DestroyRenderer(renderer)
+        SDL_DestroyWindow(window)
 
     @unittest.skip("not implemented")
     def test_RenderContext(self):

sdl2/test/surface_test.py

                         self.assertEqual(ret, 0)
                     surface.SDL_FreeSurface(sf)
 
-    def test_fill_rects(self):
+    def test_SDL_FillRects(self):
         rectlist = to_ctypes([rect.SDL_Rect(0, 0, 0, 0),
                               rect.SDL_Rect(0, 0, 10, 10),
                               rect.SDL_Rect(0, 0, -10, 10),

sdl2/test/video_test.py

         video.SDL_DestroyWindow(window)
         video.SDL_GL_UnloadLibrary()
 
-    def test_gl_create_delete_context(self):
+    def test_SDL_GL_CreateDeleteContext(self):
         #self.assertRaises((AttributeError, TypeError),
         #                  video.SDL_GL_CreateContext, None)
         #self.assertRaises((AttributeError, TypeError),
 
         video.SDL_GL_DeleteContext(ctx)
         video.SDL_DestroyWindow(window)
-
         video.SDL_GL_UnloadLibrary()
 
-    @unittest.skip("not implemented")
-    def test_gl_swap_window(self):
-        pass
+    def test_SDL_GL_SwapWindow(self):
+        self.assertEquals(video.SDL_GL_LoadLibrary(None), 0)
+        window = video.SDL_CreateWindow(b"OpenGL", 10, 10, 10, 10,
+                                        video.SDL_WINDOW_OPENGL)
+        ctx = video.SDL_GL_CreateContext(window)
+        video.SDL_GL_MakeCurrent(window, ctx)
+        video.SDL_GL_SwapWindow(window)
+        video.SDL_GL_SwapWindow(window)
+        video.SDL_GL_SwapWindow(window)
+        video.SDL_GL_SwapWindow(window)
+        video.SDL_GL_DeleteContext(ctx)
+        video.SDL_DestroyWindow(window)
+        video.SDL_GL_UnloadLibrary()
 
 
 if __name__ == '__main__':
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.