blob: 1fa201d4670be3c996d67cd3c9f58f55f601a29c [file] [log] [blame]
Guido van Rossum5c971671996-07-22 15:23:25 +00001# Testing rgbimg module
2
Guido van Rossumde554ec1997-05-08 23:14:57 +00003import rgbimg, os, uu
4
Guido van Rossume03c0501998-08-12 02:38:11 +00005from test_support import verbose, unlink, findfile
Guido van Rossum5c971671996-07-22 15:23:25 +00006
Guido van Rossum8d691c82000-09-01 19:25:51 +00007class error(Exception):
8 pass
Guido van Rossum5c971671996-07-22 15:23:25 +00009
10print 'RGBimg test suite:'
11
Guido van Rossum5c971671996-07-22 15:23:25 +000012def testimg(rgb_file, raw_file):
Guido van Rossum548703a1998-03-26 22:14:20 +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 Rossum5c971671996-07-22 15:23:25 +000026
Guido van Rossumde554ec1997-05-08 23:14:57 +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 Rossum548703a1998-03-26 22:14:20 +000036 print "uudecoding", source, "->", target, "..."
Guido van Rossumde554ec1997-05-08 23:14:57 +000037 uu.decode(source, target)
38
39if verbose:
40 print "testing..."
41
Guido van Rossum5c971671996-07-22 15:23:25 +000042ttob = rgbimg.ttob(0)
43if ttob != 0:
Guido van Rossum548703a1998-03-26 22:14:20 +000044 raise error, 'ttob should start out as zero'
Guido van Rossum5c971671996-07-22 15:23:25 +000045
46testimg('test.rgb', 'test.rawimg')
47
48ttob = rgbimg.ttob(1)
49if ttob != 0:
Guido van Rossum548703a1998-03-26 22:14:20 +000050 raise error, 'ttob should be zero'
Guido van Rossum5c971671996-07-22 15:23:25 +000051
52testimg('test.rgb', 'test.rawimg.rev')
53
54ttob = rgbimg.ttob(0)
55if ttob != 1:
Guido van Rossum548703a1998-03-26 22:14:20 +000056 raise error, 'ttob should be one'
Guido van Rossum5c971671996-07-22 15:23:25 +000057
58ttob = rgbimg.ttob(0)
59if ttob != 0:
Guido van Rossum548703a1998-03-26 22:14:20 +000060 raise error, 'ttob should be zero'
Guido van Rossumde554ec1997-05-08 23:14:57 +000061
62for source, target in table:
63 unlink(findfile(target))