blob: cdadc660dd5f59bdfe62da162de1e4080565d50b [file] [log] [blame]
Guido van Rossumfa7fcb91994-01-12 09:55:11 +00001# Testing rgbimg module
2
3import rgbimg, os
4
5error = 'test_rgbimg.error'
6
7print 'RGBimg test suite:'
8
Guido van Rossumb19d8621994-03-09 12:54:32 +00009def findfile(file):
10 if os.path.isabs(file): return file
11 import sys
12 for dn in sys.path:
13 fn = os.path.join(dn, file)
14 if os.path.exists(fn): return fn
15 return file
16
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000017def testimg(rgb_file, raw_file):
Guido van Rossumb19d8621994-03-09 12:54:32 +000018 rgb_file = findfile(rgb_file)
19 raw_file = findfile(raw_file)
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000020 width, height = rgbimg.sizeofimage(rgb_file)
21 rgb = rgbimg.longimagedata(rgb_file)
22 if len(rgb) != width * height * 4:
23 raise error, 'bad image length'
24 raw = open(raw_file, 'r').read()
25 if rgb != raw:
26 raise error, 'images don\'t match for '+rgb_file+' and '+raw_file
27 for depth in [1, 3, 4]:
28 rgbimg.longstoimage(rgb, width, height, depth, '@.rgb')
29 os.unlink('@.rgb')
30
31ttob = rgbimg.ttob(0)
32if ttob != 0:
33 raise error, 'ttob should start out as zero'
34
35testimg('test.rgb', 'test.rawimg')
36
37ttob = rgbimg.ttob(1)
38if ttob != 0:
39 raise error, 'ttob should be zero'
40
41testimg('test.rgb', 'test.rawimg.rev')
42
43ttob = rgbimg.ttob(0)
44if ttob != 1:
45 raise error, 'ttob should be one'
46
47ttob = rgbimg.ttob(0)
48if ttob != 0:
49 raise error, 'ttob should be zero'