blob: 52814b4ede586ece5813e4a142537d82b095b5b8 [file] [log] [blame]
Guido van Rossum5c971671996-07-22 15:23:25 +00001# Testing rgbimg module
2
3import rgbimg, os
4
5error = 'test_rgbimg.error'
6
7print 'RGBimg test suite:'
8
9def 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
17def testimg(rgb_file, raw_file):
18 rgb_file = findfile(rgb_file)
19 raw_file = findfile(raw_file)
20 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:
Guido van Rossum228b8e81997-04-02 06:13:34 +000026 raise error, \
27 'images don\'t match for '+rgb_file+' and '+raw_file
Guido van Rossum5c971671996-07-22 15:23:25 +000028 for depth in [1, 3, 4]:
29 rgbimg.longstoimage(rgb, width, height, depth, '@.rgb')
30 os.unlink('@.rgb')
31
32ttob = rgbimg.ttob(0)
33if ttob != 0:
34 raise error, 'ttob should start out as zero'
35
36testimg('test.rgb', 'test.rawimg')
37
38ttob = rgbimg.ttob(1)
39if ttob != 0:
40 raise error, 'ttob should be zero'
41
42testimg('test.rgb', 'test.rawimg.rev')
43
44ttob = rgbimg.ttob(0)
45if ttob != 1:
46 raise error, 'ttob should be one'
47
48ttob = rgbimg.ttob(0)
49if ttob != 0:
50 raise error, 'ttob should be zero'