def __init__(self, appClass, resolution=DEFAULT_RESOLUTION, debugWindowSize=None, fakeFullscreen=False): resolution = Point2D(resolution) testMode = not 'AVG_DEPLOY' in os.environ if testMode and debugWindowSize is not None: debugWindowSize = Point2D(debugWindowSize) else: debugWindowSize = Point2D(0, 0) if fakeFullscreen: if os.name != 'nt': raise RuntimeError('Fakefullscreen is supported only on windows') elif not testMode: self.__enableFakeFullscreen() fullscreen = False else: fullscreen = not testMode player.enableMouse(not 'AVG_DISABLE_MOUSE' in os.environ) player.showCursor(testMode) self._setupBaseDivs(resolution) player.setResolution( fullscreen, int(debugWindowSize.x), int(debugWindowSize.y), 0 # color depth ) self._startApp(appClass)
def testBitmapManager(self): WAIT_TIMEOUT = 2000 def expectException(returnValue, nextAction): if isinstance(returnValue, Exception): nextAction() else: raise RuntimeError("Expected exception, got %s (%s)" % (returnValue, type(returnValue))) def loadValidBitmap(): def validBitmapCb(bitmap): self.assert_(not isinstance(bitmap, Exception)) player.setTimeout(0, loadBitmapWithPixelFormat) avg.BitmapManager.get().loadBitmap("media/rgb24alpha-64x64.png", validBitmapCb) def loadBitmapWithPixelFormat(): def validBitmapCb(bitmap): self.assert_(not isinstance(bitmap, Exception)) self.assert_(bitmap.getFormat() == avg.B5G6R5) player.setTimeout(0, loadUnexistentBitmap) avg.BitmapManager.get().loadBitmap("media/rgb24alpha-64x64.png", validBitmapCb, avg.B5G6R5) def loadUnexistentBitmap(): avg.BitmapManager.get().loadBitmap( "nonexistent.png", lambda bmp: expectException( returnValue=bmp, nextAction=lambda: player.setTimeout(0, loadBrokenBitmap))) def loadBrokenBitmap(): import tempfile tempFileName = os.path.join(tempfile.gettempdir(), "broken.png") open(tempFileName, "w") def cleanupAndTestReturnValue(returnValue): os.unlink(tempFileName) expectException(returnValue=returnValue, nextAction=player.stop) avg.BitmapManager.get().loadBitmap(tempFileName, cleanupAndTestReturnValue) def reportStuck(): raise RuntimeError("BitmapManager didn't reply " "within %dms timeout" % WAIT_TIMEOUT) player.stop() for multithread in [False, True]: self.loadEmptyScene() if multithread: avg.BitmapManager.get().setNumThreads(2) player.setTimeout(WAIT_TIMEOUT, reportStuck) player.setResolution(0, 0, 0, 0) loadValidBitmap() player.play() avg.BitmapManager.get().setNumThreads(1)
def testSetResolution(self): root = self.loadEmptyScene() avg.ImageNode(href="rgb24-65x65.png", parent=root) player.setResolution(0, 79, 59, 0) self.start(False, (lambda: self.compareImage("testSetResolution"), ))
def testBitmapManager(self): WAIT_TIMEOUT = 2000 def expectException(returnValue, nextAction): if isinstance(returnValue, Exception): nextAction() else: raise RuntimeError("Expected exception, got %s (%s)" % ( returnValue, type(returnValue))) def loadValidBitmap(): def validBitmapCb(bitmap): self.assert_(not isinstance(bitmap, Exception)) player.setTimeout(0, loadBitmapWithPixelFormat) avg.BitmapManager.get().loadBitmap("media/rgb24alpha-64x64.png", validBitmapCb) def loadBitmapWithPixelFormat(): def validBitmapCb(bitmap): self.assert_(not isinstance(bitmap, Exception)) self.assert_(bitmap.getFormat() == avg.B5G6R5) player.setTimeout(0, loadUnexistentBitmap) avg.BitmapManager.get().loadBitmap("media/rgb24alpha-64x64.png", validBitmapCb, avg.B5G6R5) def loadUnexistentBitmap(): avg.BitmapManager.get().loadBitmap("nonexistent.png", lambda bmp: expectException( returnValue=bmp, nextAction=lambda: player.setTimeout(0, loadBrokenBitmap))) def loadBrokenBitmap(): import tempfile tempFileName = os.path.join(tempfile.gettempdir(), "broken.png") open(tempFileName, "w") def cleanupAndTestReturnValue(returnValue): os.unlink(tempFileName) expectException(returnValue=returnValue, nextAction=player.stop) avg.BitmapManager.get().loadBitmap(tempFileName, cleanupAndTestReturnValue) def reportStuck(): raise RuntimeError("BitmapManager didn't reply " "within %dms timeout" % WAIT_TIMEOUT) player.stop() for multithread in [False, True]: self.loadEmptyScene() if multithread: avg.BitmapManager.get().setNumThreads(2) player.setTimeout(WAIT_TIMEOUT, reportStuck) player.setResolution(0, 0, 0, 0) loadValidBitmap() player.play() avg.BitmapManager.get().setNumThreads(1)
def testSetResolution(self): root = self.loadEmptyScene() avg.ImageNode(href="rgb24-65x65.png", parent=root) player.setWindowPos(0, 0) player.setResolution(0, 79, 59, 0) self.start(False, (lambda: self.compareImage("testSetResolution"), ))
def __setupPlayer(self): player.setMultiSampleSamples(1) player.setResolution(0, 0, 0, 0)
def __init__(self, parentNode): if options.fullscreen: player.setResolution(True, 1920, 1200, 0) AVGApp.__init__(self, parentNode)