blob: f0f772c8eb75efa519602c239162b1435a93b65e [file] [log] [blame]
Guido van Rossumfa7fcb91994-01-12 09:55:11 +00001# Testing rgbimg module
2
Guido van Rossumcb5cf9b1997-04-09 21:25:01 +00003import rgbimg, os, uu
4
5from test_support import verbose, unlink
Guido van Rossumfa7fcb91994-01-12 09:55:11 +00006
7error = 'test_rgbimg.error'
8
9print 'RGBimg test suite:'
10
Guido van Rossumb19d8621994-03-09 12:54:32 +000011def findfile(file):
12 if os.path.isabs(file): return file
13 import sys
14 for dn in sys.path:
15 fn = os.path.join(dn, file)
16 if os.path.exists(fn): return fn
17 return file
18
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000019def testimg(rgb_file, raw_file):
Guido van Rossumb19d8621994-03-09 12:54:32 +000020 rgb_file = findfile(rgb_file)
21 raw_file = findfile(raw_file)
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000022 width, height = rgbimg.sizeofimage(rgb_file)
23 rgb = rgbimg.longimagedata(rgb_file)
24 if len(rgb) != width * height * 4:
25 raise error, 'bad image length'
Guido van Rossumcb5cf9b1997-04-09 21:25:01 +000026 raw = open(raw_file, 'rb').read()
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000027 if rgb != raw:
Barry Warsaw66e7f3a1996-12-11 21:40:04 +000028 raise error, \
29 'images don\'t match for '+rgb_file+' and '+raw_file
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000030 for depth in [1, 3, 4]:
31 rgbimg.longstoimage(rgb, width, height, depth, '@.rgb')
32 os.unlink('@.rgb')
33
Guido van Rossumcb5cf9b1997-04-09 21:25:01 +000034table = [
35 ('testrgb.uue', 'test.rgb'),
36 ('testimg.uue', 'test.rawimg'),
37 ('testimgr.uue', 'test.rawimg.rev'),
38 ]
39for source, target in table:
40 source = findfile(source)
41 target = findfile(target)
42 if verbose:
43 print "uudecoding", source, "->", target, "..."
44 uu.decode(source, target)
45
46if verbose:
47 print "testing..."
48
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000049ttob = rgbimg.ttob(0)
50if ttob != 0:
51 raise error, 'ttob should start out as zero'
52
53testimg('test.rgb', 'test.rawimg')
54
55ttob = rgbimg.ttob(1)
56if ttob != 0:
57 raise error, 'ttob should be zero'
58
59testimg('test.rgb', 'test.rawimg.rev')
60
61ttob = rgbimg.ttob(0)
62if ttob != 1:
63 raise error, 'ttob should be one'
64
65ttob = rgbimg.ttob(0)
66if ttob != 0:
67 raise error, 'ttob should be zero'
Guido van Rossumcb5cf9b1997-04-09 21:25:01 +000068
69for source, target in table:
70 unlink(findfile(target))