blob: 0c449dac76e2ba93b8fd0c72b924aff808e21995 [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):
Guido van Rossum41360a41998-03-26 19:42:58 +000012 if os.path.isabs(file): return file
13 import sys
14 path = sys.path
15 try:
16 path = [os.path.dirname(__file__)] + path
17 except NameError:
18 pass
19 for dn in path:
20 fn = os.path.join(dn, file)
21 if os.path.exists(fn): return fn
22 return file
Guido van Rossumb19d8621994-03-09 12:54:32 +000023
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000024def testimg(rgb_file, raw_file):
Guido van Rossum41360a41998-03-26 19:42:58 +000025 rgb_file = findfile(rgb_file)
26 raw_file = findfile(raw_file)
27 width, height = rgbimg.sizeofimage(rgb_file)
28 rgb = rgbimg.longimagedata(rgb_file)
29 if len(rgb) != width * height * 4:
30 raise error, 'bad image length'
31 raw = open(raw_file, 'rb').read()
32 if rgb != raw:
33 raise error, \
34 'images don\'t match for '+rgb_file+' and '+raw_file
35 for depth in [1, 3, 4]:
36 rgbimg.longstoimage(rgb, width, height, depth, '@.rgb')
37 os.unlink('@.rgb')
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000038
Guido van Rossumcb5cf9b1997-04-09 21:25:01 +000039table = [
40 ('testrgb.uue', 'test.rgb'),
41 ('testimg.uue', 'test.rawimg'),
42 ('testimgr.uue', 'test.rawimg.rev'),
43 ]
44for source, target in table:
45 source = findfile(source)
46 target = findfile(target)
47 if verbose:
Guido van Rossum41360a41998-03-26 19:42:58 +000048 print "uudecoding", source, "->", target, "..."
Guido van Rossumcb5cf9b1997-04-09 21:25:01 +000049 uu.decode(source, target)
50
51if verbose:
52 print "testing..."
53
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000054ttob = rgbimg.ttob(0)
55if ttob != 0:
Guido van Rossum41360a41998-03-26 19:42:58 +000056 raise error, 'ttob should start out as zero'
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000057
58testimg('test.rgb', 'test.rawimg')
59
60ttob = rgbimg.ttob(1)
61if ttob != 0:
Guido van Rossum41360a41998-03-26 19:42:58 +000062 raise error, 'ttob should be zero'
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000063
64testimg('test.rgb', 'test.rawimg.rev')
65
66ttob = rgbimg.ttob(0)
67if ttob != 1:
Guido van Rossum41360a41998-03-26 19:42:58 +000068 raise error, 'ttob should be one'
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000069
70ttob = rgbimg.ttob(0)
71if ttob != 0:
Guido van Rossum41360a41998-03-26 19:42:58 +000072 raise error, 'ttob should be zero'
Guido van Rossumcb5cf9b1997-04-09 21:25:01 +000073
74for source, target in table:
75 unlink(findfile(target))