blob: c5b7c83b005a88d6df2f4fcf31e8db201acd7269 [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
5from test_support import verbose, unlink
Guido van Rossum5c971671996-07-22 15:23:25 +00006
7error = 'test_rgbimg.error'
8
9print 'RGBimg test suite:'
10
11def findfile(file):
12 if os.path.isabs(file): return file
13 import sys
Guido van Rossuma11cccc1997-10-06 20:19:59 +000014 path = sys.path
15 try:
16 path = [os.path.dirname(__file__)] + path
17 except NameError:
18 pass
19 for dn in path:
Guido van Rossum5c971671996-07-22 15:23:25 +000020 fn = os.path.join(dn, file)
21 if os.path.exists(fn): return fn
22 return file
23
24def testimg(rgb_file, raw_file):
25 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'
Guido van Rossumde554ec1997-05-08 23:14:57 +000031 raw = open(raw_file, 'rb').read()
Guido van Rossum5c971671996-07-22 15:23:25 +000032 if rgb != raw:
Guido van Rossum228b8e81997-04-02 06:13:34 +000033 raise error, \
34 'images don\'t match for '+rgb_file+' and '+raw_file
Guido van Rossum5c971671996-07-22 15:23:25 +000035 for depth in [1, 3, 4]:
36 rgbimg.longstoimage(rgb, width, height, depth, '@.rgb')
37 os.unlink('@.rgb')
38
Guido van Rossumde554ec1997-05-08 23:14:57 +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:
48 print "uudecoding", source, "->", target, "..."
49 uu.decode(source, target)
50
51if verbose:
52 print "testing..."
53
Guido van Rossum5c971671996-07-22 15:23:25 +000054ttob = rgbimg.ttob(0)
55if ttob != 0:
56 raise error, 'ttob should start out as zero'
57
58testimg('test.rgb', 'test.rawimg')
59
60ttob = rgbimg.ttob(1)
61if ttob != 0:
62 raise error, 'ttob should be zero'
63
64testimg('test.rgb', 'test.rawimg.rev')
65
66ttob = rgbimg.ttob(0)
67if ttob != 1:
68 raise error, 'ttob should be one'
69
70ttob = rgbimg.ttob(0)
71if ttob != 0:
72 raise error, 'ttob should be zero'
Guido van Rossumde554ec1997-05-08 23:14:57 +000073
74for source, target in table:
75 unlink(findfile(target))