blob: 3bc206f08c9accda5e5e444616e7d89f33f4e332 [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
Guido van Rossumbc8b2bd1997-09-07 16:50:45 +000014 print "__file__ =", __file__
15 for dn in [os.path.dirname(__file__)] + sys.path:
Guido van Rossumb19d8621994-03-09 12:54:32 +000016 fn = os.path.join(dn, file)
17 if os.path.exists(fn): return fn
18 return file
19
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000020def testimg(rgb_file, raw_file):
Guido van Rossumb19d8621994-03-09 12:54:32 +000021 rgb_file = findfile(rgb_file)
22 raw_file = findfile(raw_file)
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000023 width, height = rgbimg.sizeofimage(rgb_file)
24 rgb = rgbimg.longimagedata(rgb_file)
25 if len(rgb) != width * height * 4:
26 raise error, 'bad image length'
Guido van Rossumcb5cf9b1997-04-09 21:25:01 +000027 raw = open(raw_file, 'rb').read()
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000028 if rgb != raw:
Barry Warsaw66e7f3a1996-12-11 21:40:04 +000029 raise error, \
30 'images don\'t match for '+rgb_file+' and '+raw_file
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000031 for depth in [1, 3, 4]:
32 rgbimg.longstoimage(rgb, width, height, depth, '@.rgb')
33 os.unlink('@.rgb')
34
Guido van Rossumcb5cf9b1997-04-09 21:25:01 +000035table = [
36 ('testrgb.uue', 'test.rgb'),
37 ('testimg.uue', 'test.rawimg'),
38 ('testimgr.uue', 'test.rawimg.rev'),
39 ]
40for source, target in table:
41 source = findfile(source)
42 target = findfile(target)
43 if verbose:
44 print "uudecoding", source, "->", target, "..."
45 uu.decode(source, target)
46
47if verbose:
48 print "testing..."
49
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000050ttob = rgbimg.ttob(0)
51if ttob != 0:
52 raise error, 'ttob should start out as zero'
53
54testimg('test.rgb', 'test.rawimg')
55
56ttob = rgbimg.ttob(1)
57if ttob != 0:
58 raise error, 'ttob should be zero'
59
60testimg('test.rgb', 'test.rawimg.rev')
61
62ttob = rgbimg.ttob(0)
63if ttob != 1:
64 raise error, 'ttob should be one'
65
66ttob = rgbimg.ttob(0)
67if ttob != 0:
68 raise error, 'ttob should be zero'
Guido van Rossumcb5cf9b1997-04-09 21:25:01 +000069
70for source, target in table:
71 unlink(findfile(target))