blob: f2622e40674abccd332f0e4d6ba255c9cd07f225 [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
Fredrik Lundhf7850422001-01-17 21:51:36 +00005from test_support import verbose, unlink, findfile
Guido van Rossumfa7fcb91994-01-12 09:55:11 +00006
Fred Drakeb65b0062000-08-18 14:50:20 +00007class error(Exception):
Fred Drake004d5e62000-10-23 17:22:08 +00008 pass
Guido van Rossumfa7fcb91994-01-12 09:55:11 +00009
10print 'RGBimg test suite:'
11
12def testimg(rgb_file, raw_file):
Fred Drake004d5e62000-10-23 17:22:08 +000013 rgb_file = findfile(rgb_file)
14 raw_file = findfile(raw_file)
15 width, height = rgbimg.sizeofimage(rgb_file)
16 rgb = rgbimg.longimagedata(rgb_file)
17 if len(rgb) != width * height * 4:
18 raise error, 'bad image length'
19 raw = open(raw_file, 'rb').read()
20 if rgb != raw:
21 raise error, \
22 'images don\'t match for '+rgb_file+' and '+raw_file
23 for depth in [1, 3, 4]:
24 rgbimg.longstoimage(rgb, width, height, depth, '@.rgb')
25 os.unlink('@.rgb')
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000026
Guido van Rossumcb5cf9b1997-04-09 21:25:01 +000027table = [
28 ('testrgb.uue', 'test.rgb'),
29 ('testimg.uue', 'test.rawimg'),
30 ('testimgr.uue', 'test.rawimg.rev'),
31 ]
32for source, target in table:
33 source = findfile(source)
34 target = findfile(target)
35 if verbose:
Guido van Rossum41360a41998-03-26 19:42:58 +000036 print "uudecoding", source, "->", target, "..."
Guido van Rossumcb5cf9b1997-04-09 21:25:01 +000037 uu.decode(source, target)
38
39if verbose:
40 print "testing..."
41
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000042ttob = rgbimg.ttob(0)
43if ttob != 0:
Fred Drake004d5e62000-10-23 17:22:08 +000044 raise error, 'ttob should start out as zero'
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000045
46testimg('test.rgb', 'test.rawimg')
47
48ttob = rgbimg.ttob(1)
49if ttob != 0:
Fred Drake004d5e62000-10-23 17:22:08 +000050 raise error, 'ttob should be zero'
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000051
52testimg('test.rgb', 'test.rawimg.rev')
53
54ttob = rgbimg.ttob(0)
55if ttob != 1:
Fred Drake004d5e62000-10-23 17:22:08 +000056 raise error, 'ttob should be one'
Guido van Rossumfa7fcb91994-01-12 09:55:11 +000057
58ttob = rgbimg.ttob(0)
59if ttob != 0:
Fred Drake004d5e62000-10-23 17:22:08 +000060 raise error, 'ttob should be zero'
Guido van Rossumcb5cf9b1997-04-09 21:25:01 +000061
62for source, target in table:
63 unlink(findfile(target))