blob: 38bcdf565230b87b2e78593852209fe8f8ec0c50 [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
Guido van Rossume26132c1998-04-23 20:13:30 +00005from test_support import verbose, unlink, findfile
Guido van Rossumfa7fcb91994-01-12 09:55:11 +00006
7error = 'test_rgbimg.error'
8
9print 'RGBimg test suite:'
10
11def testimg(rgb_file, raw_file):
Guido van Rossum41360a41998-03-26 19:42:58 +000012 rgb_file = findfile(rgb_file)
13 raw_file = findfile(raw_file)
14 width, height = rgbimg.sizeofimage(rgb_file)
15 rgb = rgbimg.longimagedata(rgb_file)
16 if len(rgb) != width * height * 4:
17 raise error, 'bad image length'
18 raw = open(raw_file, 'rb').read()
19 if rgb != raw:
20 raise error, \
21 'images don\'t match for '+rgb_file+' and '+raw_file
22 for depth in [1, 3, 4]:
23 rgbimg.longstoimage(rgb, width, height, depth, '@.rgb')
24 os.unlink('@.rgb')
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000025
Guido van Rossumcb5cf9b1997-04-09 21:25:01 +000026table = [
27 ('testrgb.uue', 'test.rgb'),
28 ('testimg.uue', 'test.rawimg'),
29 ('testimgr.uue', 'test.rawimg.rev'),
30 ]
31for source, target in table:
32 source = findfile(source)
33 target = findfile(target)
34 if verbose:
Guido van Rossum41360a41998-03-26 19:42:58 +000035 print "uudecoding", source, "->", target, "..."
Guido van Rossumcb5cf9b1997-04-09 21:25:01 +000036 uu.decode(source, target)
37
38if verbose:
39 print "testing..."
40
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000041ttob = rgbimg.ttob(0)
42if ttob != 0:
Guido van Rossum41360a41998-03-26 19:42:58 +000043 raise error, 'ttob should start out as zero'
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000044
45testimg('test.rgb', 'test.rawimg')
46
47ttob = rgbimg.ttob(1)
48if ttob != 0:
Guido van Rossum41360a41998-03-26 19:42:58 +000049 raise error, 'ttob should be zero'
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000050
51testimg('test.rgb', 'test.rawimg.rev')
52
53ttob = rgbimg.ttob(0)
54if ttob != 1:
Guido van Rossum41360a41998-03-26 19:42:58 +000055 raise error, 'ttob should be one'
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000056
57ttob = rgbimg.ttob(0)
58if ttob != 0:
Guido van Rossum41360a41998-03-26 19:42:58 +000059 raise error, 'ttob should be zero'
Guido van Rossumcb5cf9b1997-04-09 21:25:01 +000060
61for source, target in table:
62 unlink(findfile(target))