~ubuntu-branches/ubuntu/utopic/libavg/utopic

« back to all changes in this revision

Viewing changes to src/test/testcase.py

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2010-05-02 23:50:04 UTC
  • mfrom: (1.1.4 upstream) (2.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100502235004-i6u38zelbi2k12ii
Tags: 1.0.1-1
* new upstream release (Closes: #565512)
* Remove patches that have been merged upstream.
* Add a patch that avoids building tests by default.
* Remove .py extension from two more scripts in /usr/bin .
* Add 2 example files to /usr/share/doc/python-libavg/examples/ .
* Describe a workaround for bug #579937 in README.Debian.
* Install debian/libavg.pth into /usr/share/pyshared/ .
  (Closes: #575551)
* Add get-orig-source target to debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
# -*- coding: utf-8 -*-
 
3
# libavg - Media Playback Engine.
 
4
# Copyright (C) 2003-2008 Ulrich von Zadow
 
5
#
 
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.
 
10
#
 
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.
 
15
#
 
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
 
19
#
 
20
# Current versions can be found at www.libavg.de
 
21
#
 
22
 
3
23
import unittest
4
24
 
5
25
import sys, os, platform, math
17
37
else:    
18
38
    import avg
19
39
 
20
 
CREATE_BASELINE_IMAGES = False
21
40
BASELINE_DIR = "baseline"
22
41
RESULT_DIR = "resultimages"
23
42
 
24
43
ourSaveDifferences = True
25
44
g_CustomOGLOptions = False
 
45
g_UsePOW2Textures = False
 
46
g_UseShaders = True
 
47
g_UsePixelBuffers = True
26
48
 
27
49
def almostEqual(a,b):
28
50
    try:
34
56
    except:
35
57
        return math.fabs(a-b) < 0.000001
36
58
 
 
59
def setUpVideo(player):
 
60
    if g_CustomOGLOptions:
 
61
        player.setOGLOptions(g_UsePOW2Textures, g_UseShaders, g_UsePixelBuffers, 1)
 
62
    player.setMultiSampleSamples(1)
 
63
 
37
64
 
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)
45
72
 
46
 
    def setUpVideo(self):
 
73
    def setUp(self):
47
74
        self.__Player.setResolution(0, 0, 0, self.__bpp)
48
 
        if g_CustomOGLOptions:
49
 
            self.__Player.setOGLOptions(g_UsePOW2Textures, g_YCbCrMode, 
50
 
                    g_UsePixelBuffers, 1)
51
 
        self.__Player.setMultiSampleSamples(1)
52
 
 
53
 
    def setUp(self):
54
 
        self.setUpVideo()
 
75
        setUpVideo(self.__Player)
 
76
        self.__Player.enableAudio(False)
55
77
        print "-------- ", self.__testFuncName, " --------"
56
78
 
57
79
    def start(self, filename, actions):
61
83
        self.actions = actions
62
84
        self.curFrame = 0
63
85
        self.__Player.setOnFrameHandler(self.nextAction)
64
 
        self.__Player.setFramerate(100)
 
86
        self.__Player.setFramerate(10000)
65
87
        self.__Player.play()
66
88
        self.assert_(self.__Player.isPlaying() == 0)
67
89
 
76
98
        self.curFrame += 1
77
99
 
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")
84
 
        else:
85
 
            try:
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):
96
 
                    print ("  "+fileName+
97
 
                            ": Difference image has avg=%(avg).2f, std dev=%(stddev).2f"%
98
 
                            {'avg':average, 'stddev':stdDev})
99
 
                    if not(warn):
100
 
                        self.assert_(False)
101
 
            except RuntimeError:
102
 
                Bmp.save(RESULT_DIR+"/"+fileName+".png")
103
 
                self.Log.trace(self.Log.WARNING, "Could not load image "+fileName+".png")
104
 
                self.assert_(False)
 
103
        try:
 
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):
 
114
                print ("  "+fileName+
 
115
                        ": Difference image has avg=%(avg).2f, std dev=%(stddev).2f"%
 
116
                        {'avg':average, 'stddev':stdDev})
 
117
                if not(warn):
 
118
                    self.assert_(False)
 
119
        except RuntimeError:
 
120
            Bmp.save(RESULT_DIR+"/"+fileName+".png")
 
121
            self.Log.trace(self.Log.WARNING, "Could not load image "+fileName+".png")
 
122
            raise
105
123
 
106
124
    def areSimilarBmps(self, bmp1, bmp2, maxAvg, maxStdDev):
107
125
        DiffBmp = bmp1.subtract(bmp2)
117
135
            exceptionRaised = True
118
136
        self.assert_(exceptionRaised)
119
137
 
 
138
    def getSrcDirName(self):
 
139
        s = os.getenv("srcdir")
 
140
        if s == None:
 
141
            return "./"
 
142
        else:
 
143
            return s+"/"
 
144
 
120
145
    def _loadEmpty(self):
121
146
        self.__Player.loadString("""
122
147
        <?xml version="1.0"?>
125
150
        """)
126
151
 
127
152
 
128
 
def setOGLOptions(UsePOW2Textures, YCbCrMode, UsePixelBuffers):
 
153
def setUseShaders(val):
 
154
    global g_CustomOGLOptions
 
155
    global g_UseShaders
 
156
    g_UseShaders = val
 
157
 
 
158
def setUsePOW2Textures(val):
129
159
    global g_CustomOGLOptions
130
160
    global g_UsePOW2Textures
131
 
    global g_YCbCrMode
 
161
    g_CustomOGLOptions = True
 
162
    g_UsePOW2Textures = val
 
163
 
 
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
 
169
 
 
170
 
 
171
def isDirWritable():
 
172
    return ourSaveDifferences
137
173
 
138
174
def rmBrokenDir():
139
175
    try:
148
184
            global ourSaveDifferences
149
185
            ourSaveDifferences = False
150
186
 
 
187
def AVGTestSuite (availableTests, TestCase, tests, extraargs=(), extrakwargs={}):
 
188
    suite = unittest.TestSuite()
 
189
    if tests:
 
190
        for testname in tests:
 
191
            if testname in availableTests:
 
192
                name = testname
 
193
            elif 'test'+testname in availableTests:
 
194
                name = 'test' + testname
 
195
            else:
 
196
                print "no test named %s" % testname
 
197
                sys.exit(1)
 
198
            testNames = (name,)
 
199
    else:
 
200
            testNames = availableTests
 
201
    for name in testNames:
 
202
        suite.addTest(TestCase(*([name,]+list(extraargs)), **extrakwargs ))
 
203
    return suite