Пример #1
0
 def test_SDL_SetError(self):
     assert error.SDL_GetError() == b""
     error.SDL_SetError(b"A Unit Test Error Message")
     assert error.SDL_GetError() == b"A Unit Test Error Message"
     error.SDL_ClearError()
     error.SDL_SetError(b"A Unit Test Error Message")
     assert error.SDL_GetError() == b"A Unit Test Error Message"
     assert error.SDL_GetError() == b"A Unit Test Error Message"
     error.SDL_ClearError()
     error.SDL_SetError(b"123456789")
     assert error.SDL_GetError() == b"123456789"
Пример #2
0
 def test_SDL_SetError(self):
     self.assertEqual(error.SDL_GetError(), b"")
     error.SDL_SetError(b"A Unit Test Error Message")
     self.assertEqual(error.SDL_GetError(), b"A Unit Test Error Message")
     error.SDL_ClearError()
     error.SDL_SetError(b"A Unit Test Error Message")
     self.assertEqual(error.SDL_GetError(), b"A Unit Test Error Message")
     self.assertEqual(error.SDL_GetError(), b"A Unit Test Error Message")
     error.SDL_ClearError()
     error.SDL_SetError(b"123456789")
     self.assertEqual(error.SDL_GetError(), b"123456789")
Пример #3
0
 def test_SDL_ConvertSurfaceFormat(self):
     tenbit = [
         pixels.SDL_PACKEDLAYOUT_2101010, pixels.SDL_PACKEDLAYOUT_1010102
     ]
     for pfmt in pixels.ALL_PIXELFORMATS:
         for fmt in pixels.ALL_PIXELFORMATS:
             # SDL2 doesn't support converting fancier formats (e.g YUV, 10bit)
             if pixels.SDL_ISPIXELFORMAT_FOURCC(
                     pfmt) or pixels.SDL_PIXELLAYOUT(pfmt) in tenbit:
                 continue
             if pixels.SDL_ISPIXELFORMAT_FOURCC(
                     fmt) or pixels.SDL_PIXELLAYOUT(fmt) in tenbit:
                 continue
             # SDL2 doesn't support converting to formats w/ less than 8 bpp
             if pixels.SDL_BITSPERPIXEL(pfmt) < 8:
                 continue
             # SDL2 doesn't support converting from indexed formats w/ 4 bpp
             if pixels.SDL_PIXELTYPE(fmt) == pixels.SDL_PIXELTYPE_INDEX4:
                 continue
             bpp = c_int()
             rmask, gmask, bmask, amask = Uint32(), Uint32(), Uint32(
             ), Uint32()
             ret = pixels.SDL_PixelFormatEnumToMasks(
                 fmt, byref(bpp), byref(rmask), byref(gmask), byref(bmask),
                 byref(amask))
             assert ret == SDL_TRUE
             sf = surface.SDL_CreateRGBSurface(0, 10, 20, bpp, rmask, gmask,
                                               bmask, amask)
             assert isinstance(sf.contents, surface.SDL_Surface)
             csf = surface.SDL_ConvertSurfaceFormat(sf, pfmt, 0)
             assert csf, error.SDL_GetError()
             assert isinstance(csf.contents, surface.SDL_Surface)
             surface.SDL_FreeSurface(sf)
             surface.SDL_FreeSurface(csf)
Пример #4
0
    def test_SDL_ConvertSurface(self):
        bad_combos = []
        good_combos = []
        tenbit = [
            pixels.SDL_PACKEDLAYOUT_2101010, pixels.SDL_PACKEDLAYOUT_1010102
        ]
        for idx in pixels.ALL_PIXELFORMATS:
            pfmt = pixels.SDL_AllocFormat(idx)
            for fmt in pixels.ALL_PIXELFORMATS:
                idx_name = pixels.SDL_GetPixelFormatName(idx).decode('utf-8')
                fmt_name = pixels.SDL_GetPixelFormatName(fmt).decode('utf-8')
                # SDL2 doesn't support converting fancier formats (e.g YUV, 10bit)
                if pixels.SDL_ISPIXELFORMAT_FOURCC(
                        idx) or pixels.SDL_PIXELLAYOUT(idx) in tenbit:
                    continue
                if pixels.SDL_ISPIXELFORMAT_FOURCC(
                        fmt) or pixels.SDL_PIXELLAYOUT(fmt) in tenbit:
                    continue
                # SDL2 doesn't support converting to formats w/ less than 8 bpp
                if pixels.SDL_BITSPERPIXEL(idx) < 8:
                    continue
                # SDL2 doesn't support converting from indexed formats w/ 4 bpp
                if pixels.SDL_PIXELTYPE(fmt) == pixels.SDL_PIXELTYPE_INDEX4:
                    continue
                bpp = c_int()
                rmask, gmask, bmask, amask = Uint32(), Uint32(), Uint32(
                ), Uint32()
                ret = pixels.SDL_PixelFormatEnumToMasks(
                    fmt, byref(bpp), byref(rmask), byref(gmask), byref(bmask),
                    byref(amask))
                self.assertEqual(ret, SDL_TRUE)
                sf = surface.SDL_CreateRGBSurface(0, 10, 20, bpp, rmask, gmask,
                                                  bmask, amask)
                self.assertIsInstance(sf.contents, surface.SDL_Surface)
                csf = surface.SDL_ConvertSurface(sf, pfmt, 0)
                self.assertTrue(csf)
                if error.SDL_GetError() == b'Blit combination not supported':
                    bad_combos.append('{0} -> {1}'.format(fmt_name, idx_name))
                    error.SDL_ClearError()
                else:
                    good_combos.append('{0} -> {1}'.format(fmt_name, idx_name))
                    self.assertIsInstance(csf.contents, surface.SDL_Surface)
                surface.SDL_FreeSurface(sf)
                surface.SDL_FreeSurface(csf)
            pixels.SDL_FreeFormat(pfmt)

        self.assertEqual(len(bad_combos), 0)
Пример #5
0
 def test_SDL_ConvertSurfaceFormat(self):
     for pfmt in pixels.ALL_PIXELFORMATS:
         if pixels.SDL_ISPIXELFORMAT_FOURCC(pfmt):
             continue
         for fmt in pixels.ALL_PIXELFORMATS:
             if pixels.SDL_ISPIXELFORMAT_FOURCC(fmt):
                 continue
             bpp = c_int()
             rmask, gmask, bmask, amask = Uint32(), Uint32(), Uint32(
             ), Uint32()
             ret = pixels.SDL_PixelFormatEnumToMasks(
                 fmt, byref(bpp), byref(rmask), byref(gmask), byref(bmask),
                 byref(amask))
             self.assertEqual(ret, SDL_TRUE)
             sf = surface.SDL_CreateRGBSurface(0, 10, 20, bpp, rmask, gmask,
                                               bmask, amask)
             self.assertIsInstance(sf.contents, surface.SDL_Surface)
             csf = surface.SDL_ConvertSurfaceFormat(sf, pfmt, 0)
             self.assertTrue(csf, error.SDL_GetError())
             self.assertIsInstance(csf.contents, surface.SDL_Surface)
             surface.SDL_FreeSurface(sf)
             surface.SDL_FreeSurface(csf)
Пример #6
0
 def test_SDL_ClearError(self):
     error.SDL_ClearError()
     assert error.SDL_GetError() == b""
Пример #7
0
 def test_SDL_ClearError(self):
     error.SDL_ClearError()
     self.assertEqual(error.SDL_GetError(), b"")