Commits

Marcus von Appen committed c1c58d2

- added unit tests for sdl2.ext.Renderer, sdl2.ext.Renderer.color,
sdl2.ext.Renderer.clear(), sdl2.SDL_RWread(), sdl2.SDL_RWwrite()
- added missing documentation for sdl2.ext.compat.unicode()

Comments (0)

Files changed (3)

doc/modules/sdl2ext_compat.rst

 
       Only defined for Python 3.x, for which it is the same as :func:`chr()`.
 
+.. function:: unicode(string[, encoding[, errors]])
+
+   .. note::
+
+      Only defined for Python 3.x, for which it is the same as :func:`str()`.
+
 .. function:: callable(x) -> bool
 
    .. note::

sdl2/test/rwops_test.py

         pos = rwops.SDL_RWseek(rw, 12, rwops.RW_SEEK_END)
         self.assertTrue(pos == buf.tell() == len(data) + 12)
 
-    @unittest.skip("not implemented")
     def test_SDL_RWread(self):
-        pass
+        data = byteify("A Teststring of length 25", "utf-8")
+        buf = BytesIO(data)
+        rw = rwops.rw_from_object(buf)
+        self.assertIsInstance(rw, rwops.SDL_RWops)
+        
+        readbuf = ctypes.create_string_buffer(2)
+        
+        read = rwops.SDL_RWread(rw, readbuf, 1, 2)
+        self.assertEqual(read, 2)
+        self.assertEqual(readbuf.raw, b"A ")
+        readbuf = ctypes.create_string_buffer(10)
+        read = rwops.SDL_RWread(rw, readbuf, 1, 10)
+        self.assertEqual(read, 10)
+        self.assertEqual(readbuf.raw, b"Teststring")
 
-    @unittest.skip("not implemented")
     def test_SDL_RWwrite(self):
-        pass
+        data = byteify("A Teststring of length 25", "utf-8")
+        buf = BytesIO(data)
+        rw = rwops.rw_from_object(buf)
+        self.assertIsInstance(rw, rwops.SDL_RWops)
 
+        writebuf = ctypes.create_string_buffer(b"XQ")
+        written = rwops.SDL_RWwrite(rw, writebuf, 1, 2)
+        self.assertEqual(written, 2)
+        self.assertEqual(buf.getvalue(), b"XQTeststring of length 25")
+        
+        writebuf = ctypes.create_string_buffer(b"banana")
+        rwops.SDL_RWseek(rw, 14, rwops.RW_SEEK_CUR)
+        written = rwops.SDL_RWwrite(rw, writebuf, 1, 6)
+        self.assertEqual(written, 6)
+        self.assertEqual(buf.getvalue(), b"XQTeststring of banana 25")
+       
     def test_SDL_RWclose(self):
         data = byteify("A Teststring", "utf-8")
         buf = BytesIO(data)

sdl2/test/sdl2ext_sprite_test.py

         SDL_DestroyRenderer(renderer)
         SDL_DestroyWindow(window)
 
-    @unittest.skip("not implemented")
     def test_Renderer(self):
-        pass
+        sf = SDL_CreateRGBSurface(0, 10, 10, 32, 0, 0, 0, 0).contents
+        
+        renderer = sdl2ext.Renderer(sf)
+        self.assertEqual(renderer.rendertarget, sf)
+        self.assertIsInstance(renderer.renderer.contents, SDL_Renderer)
+        del renderer
+        
+        sprite = sdl2ext.SoftwareSprite(sf, True)
+        renderer = sdl2ext.Renderer(sprite)
+        self.assertEqual(renderer.rendertarget, sprite.surface)
+        self.assertEqual(renderer.rendertarget, sf)
+        self.assertIsInstance(renderer.renderer.contents, SDL_Renderer)
+        del renderer
+        
+        window = sdl2ext.Window("Test", size=(1, 1))
+        renderer = sdl2ext.Renderer(window)
+        self.assertEqual(renderer.rendertarget, window.window)
+        self.assertIsInstance(renderer.renderer.contents, SDL_Renderer)
+        del renderer
+        
+        sdlwindow = window.window
+        renderer = sdl2ext.Renderer(sdlwindow)
+        self.assertEqual(renderer.rendertarget, sdlwindow)
+        self.assertEqual(renderer.rendertarget, window.window)
+        self.assertIsInstance(renderer.renderer.contents, SDL_Renderer)
+        del renderer
+        del window
+        
+        self.assertRaises(TypeError, sdl2ext.Renderer, None)
+        self.assertRaises(TypeError, sdl2ext.Renderer, 1234)
+        self.assertRaises(TypeError, sdl2ext.Renderer, "test")
 
-    @unittest.skip("not implemented")
     def test_Renderer_color(self):
-        pass
+        sf = SDL_CreateRGBSurface(0, 10, 10, 32,
+                                  0xFF000000,
+                                  0x00FF0000,
+                                  0x0000FF00,
+                                  0x000000FF)
+        renderer = sdl2ext.Renderer(sf.contents)
+        self.assertIsInstance(renderer.color, sdl2ext.Color)
+        self.assertEqual(renderer.color, sdl2ext.Color(0, 0, 0 ,0))
+        renderer.color = 0x00FF0000
+        self.assertEqual(renderer.color, sdl2ext.Color(0xFF, 0, 0, 0))
+        renderer.clear()
+        view = sdl2ext.PixelView(sf.contents)
+        self.check_areas(view, 10, 10, [[0, 0, 10, 10]], 0xFF000000, (0x0,))
+        del view
+        renderer.color = 0xAABBCCDD
+        self.assertEqual(renderer.color, sdl2ext.Color(0xBB, 0xCC, 0xDD, 0xAA))
+        renderer.clear()
+        view = sdl2ext.PixelView(sf.contents)
+        self.check_areas(view, 10, 10, [[0, 0, 10, 10]], 0xBBCCDDAA, (0x0,))
+        del view
+        del renderer
+        SDL_FreeSurface(sf)
 
     @unittest.skip("not implemented")
     def test_Renderer_blendmode(self):
         pass
 
-    @unittest.skip("not implemented")
     def test_Renderer_clear(self):
-        pass
+        sf = SDL_CreateRGBSurface(0, 10, 10, 32,
+                                  0xFF000000,
+                                  0x00FF0000,
+                                  0x0000FF00,
+                                  0x000000FF)
+        renderer = sdl2ext.Renderer(sf.contents)
+        self.assertIsInstance(renderer.color, sdl2ext.Color)
+        self.assertEqual(renderer.color, sdl2ext.Color(0, 0, 0 ,0))
+        renderer.color = 0x00FF0000
+        self.assertEqual(renderer.color, sdl2ext.Color(0xFF, 0, 0, 0))
+        renderer.clear()
+        view = sdl2ext.PixelView(sf.contents)
+        self.check_areas(view, 10, 10, [[0, 0, 10, 10]], 0xFF000000, (0x0,))
+        del view
+        renderer.clear(0xAABBCCDD)
+        self.assertEqual(renderer.color, sdl2ext.Color(0xFF, 0, 0, 0))
+        view = sdl2ext.PixelView(sf.contents)
+        self.check_areas(view, 10, 10, [[0, 0, 10, 10]], 0xBBCCDDAA, (0x0,))
+        del view
+        del renderer
+        SDL_FreeSurface(sf)
 
     @unittest.skipIf(_ISPYPY, "PyPy's ctypes can't do byref(value, offset)")
     def test_Renderer_copy(self):