2
2
# -*- coding: utf-8 -*-
3
# libavg - Media Playback Engine.
4
# Copyright (C) 2003-2008 Ulrich von Zadow
6
# This library is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU Lesser General Public
8
# License as published by the Free Software Foundation; either
9
# version 2 of the License, or (at your option) any later version.
11
# This library is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
# Lesser General Public License for more details.
16
# You should have received a copy of the GNU Lesser General Public
17
# License along with this library; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
# Current versions can be found at www.libavg.de
5
25
import sys, os, platform, math
20
CREATE_BASELINE_IMAGES = False
21
40
BASELINE_DIR = "baseline"
22
41
RESULT_DIR = "resultimages"
24
43
ourSaveDifferences = True
25
44
g_CustomOGLOptions = False
45
g_UsePOW2Textures = False
47
g_UsePixelBuffers = True
27
49
def almostEqual(a,b):
35
57
return math.fabs(a-b) < 0.000001
59
def setUpVideo(player):
60
if g_CustomOGLOptions:
61
player.setOGLOptions(g_UsePOW2Textures, g_UseShaders, g_UsePixelBuffers, 1)
62
player.setMultiSampleSamples(1)
38
65
class AVGTestCase(unittest.TestCase):
39
66
def __init__(self, testFuncName, bpp):
43
70
self.Log = avg.Logger.get()
44
71
unittest.TestCase.__init__(self, testFuncName)
47
74
self.__Player.setResolution(0, 0, 0, self.__bpp)
48
if g_CustomOGLOptions:
49
self.__Player.setOGLOptions(g_UsePOW2Textures, g_YCbCrMode,
51
self.__Player.setMultiSampleSamples(1)
75
setUpVideo(self.__Player)
76
self.__Player.enableAudio(False)
55
77
print "-------- ", self.__testFuncName, " --------"
57
79
def start(self, filename, actions):
78
100
def compareImage(self, fileName, warn):
79
global CREATE_BASELINE_IMAGES
80
101
global ourSaveDifferences
81
102
Bmp = self.__Player.screenshot()
82
if CREATE_BASELINE_IMAGES:
83
Bmp.save(BASELINE_DIR+"/"+fileName+".png")
86
BaselineBmp = avg.Bitmap(BASELINE_DIR+"/"+fileName+".png")
87
DiffBmp = Bmp.subtract(BaselineBmp)
88
average = DiffBmp.getAvg()
89
stdDev = DiffBmp.getStdDev()
90
if (average > 0.1 or stdDev > 0.5):
91
if ourSaveDifferences:
92
Bmp.save(RESULT_DIR+"/"+fileName+".png")
93
BaselineBmp.save(RESULT_DIR+"/"+fileName+"_baseline.png")
94
DiffBmp.save(RESULT_DIR+"/"+fileName+"_diff.png")
95
if (average > 2 or stdDev > 5):
97
": Difference image has avg=%(avg).2f, std dev=%(stddev).2f"%
98
{'avg':average, 'stddev':stdDev})
102
Bmp.save(RESULT_DIR+"/"+fileName+".png")
103
self.Log.trace(self.Log.WARNING, "Could not load image "+fileName+".png")
104
BaselineBmp = avg.Bitmap(BASELINE_DIR+"/"+fileName+".png")
105
DiffBmp = Bmp.subtract(BaselineBmp)
106
average = DiffBmp.getAvg()
107
stdDev = DiffBmp.getStdDev()
108
if (average > 0.1 or stdDev > 0.5):
109
if ourSaveDifferences:
110
Bmp.save(RESULT_DIR+"/"+fileName+".png")
111
BaselineBmp.save(RESULT_DIR+"/"+fileName+"_baseline.png")
112
DiffBmp.save(RESULT_DIR+"/"+fileName+"_diff.png")
113
if (average > 2 or stdDev > 6):
115
": Difference image has avg=%(avg).2f, std dev=%(stddev).2f"%
116
{'avg':average, 'stddev':stdDev})
120
Bmp.save(RESULT_DIR+"/"+fileName+".png")
121
self.Log.trace(self.Log.WARNING, "Could not load image "+fileName+".png")
106
124
def areSimilarBmps(self, bmp1, bmp2, maxAvg, maxStdDev):
107
125
DiffBmp = bmp1.subtract(bmp2)
128
def setOGLOptions(UsePOW2Textures, YCbCrMode, UsePixelBuffers):
153
def setUseShaders(val):
154
global g_CustomOGLOptions
158
def setUsePOW2Textures(val):
129
159
global g_CustomOGLOptions
130
160
global g_UsePOW2Textures
161
g_CustomOGLOptions = True
162
g_UsePOW2Textures = val
164
def setUsePixelBuffers(val):
165
global g_CustomOGLOptions
132
166
global g_UsePixelBuffers
133
167
g_CustomOGLOptions = True
134
g_UsePOW2Textures = UsePOW2Textures
135
g_YCbCrMode = YCbCrMode
136
g_UsePixelBuffers = UsePixelBuffers
168
g_UsePixelBuffers = val
172
return ourSaveDifferences
138
174
def rmBrokenDir():
148
184
global ourSaveDifferences
149
185
ourSaveDifferences = False
187
def AVGTestSuite (availableTests, TestCase, tests, extraargs=(), extrakwargs={}):
188
suite = unittest.TestSuite()
190
for testname in tests:
191
if testname in availableTests:
193
elif 'test'+testname in availableTests:
194
name = 'test' + testname
196
print "no test named %s" % testname
200
testNames = availableTests
201
for name in testNames:
202
suite.addTest(TestCase(*([name,]+list(extraargs)), **extrakwargs ))