Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 1 | # Testing rgbimg module |
| 2 | |
Guido van Rossum | cb5cf9b | 1997-04-09 21:25:01 +0000 | [diff] [blame] | 3 | import rgbimg, os, uu |
| 4 | |
| 5 | from test_support import verbose, unlink |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 6 | |
| 7 | error = 'test_rgbimg.error' |
| 8 | |
| 9 | print 'RGBimg test suite:' |
| 10 | |
Guido van Rossum | b19d862 | 1994-03-09 12:54:32 +0000 | [diff] [blame] | 11 | def findfile(file): |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 12 | 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 Rossum | b19d862 | 1994-03-09 12:54:32 +0000 | [diff] [blame] | 23 | |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 24 | def testimg(rgb_file, raw_file): |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 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' |
| 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 Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 38 | |
Guido van Rossum | cb5cf9b | 1997-04-09 21:25:01 +0000 | [diff] [blame] | 39 | table = [ |
| 40 | ('testrgb.uue', 'test.rgb'), |
| 41 | ('testimg.uue', 'test.rawimg'), |
| 42 | ('testimgr.uue', 'test.rawimg.rev'), |
| 43 | ] |
| 44 | for source, target in table: |
| 45 | source = findfile(source) |
| 46 | target = findfile(target) |
| 47 | if verbose: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 48 | print "uudecoding", source, "->", target, "..." |
Guido van Rossum | cb5cf9b | 1997-04-09 21:25:01 +0000 | [diff] [blame] | 49 | uu.decode(source, target) |
| 50 | |
| 51 | if verbose: |
| 52 | print "testing..." |
| 53 | |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 54 | ttob = rgbimg.ttob(0) |
| 55 | if ttob != 0: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 56 | raise error, 'ttob should start out as zero' |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 57 | |
| 58 | testimg('test.rgb', 'test.rawimg') |
| 59 | |
| 60 | ttob = rgbimg.ttob(1) |
| 61 | if ttob != 0: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 62 | raise error, 'ttob should be zero' |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 63 | |
| 64 | testimg('test.rgb', 'test.rawimg.rev') |
| 65 | |
| 66 | ttob = rgbimg.ttob(0) |
| 67 | if ttob != 1: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 68 | raise error, 'ttob should be one' |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 69 | |
| 70 | ttob = rgbimg.ttob(0) |
| 71 | if ttob != 0: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 72 | raise error, 'ttob should be zero' |
Guido van Rossum | cb5cf9b | 1997-04-09 21:25:01 +0000 | [diff] [blame] | 73 | |
| 74 | for source, target in table: |
| 75 | unlink(findfile(target)) |