Guido van Rossum | 5c97167 | 1996-07-22 15:23:25 +0000 | [diff] [blame] | 1 | # Testing rgbimg module |
| 2 | |
Guido van Rossum | de554ec | 1997-05-08 23:14:57 +0000 | [diff] [blame] | 3 | import rgbimg, os, uu |
| 4 | |
| 5 | from test_support import verbose, unlink |
Guido van Rossum | 5c97167 | 1996-07-22 15:23:25 +0000 | [diff] [blame] | 6 | |
| 7 | error = 'test_rgbimg.error' |
| 8 | |
| 9 | print 'RGBimg test suite:' |
| 10 | |
| 11 | def findfile(file): |
| 12 | if os.path.isabs(file): return file |
| 13 | import sys |
| 14 | for dn in sys.path: |
| 15 | fn = os.path.join(dn, file) |
| 16 | if os.path.exists(fn): return fn |
| 17 | return file |
| 18 | |
| 19 | def testimg(rgb_file, raw_file): |
| 20 | rgb_file = findfile(rgb_file) |
| 21 | raw_file = findfile(raw_file) |
| 22 | width, height = rgbimg.sizeofimage(rgb_file) |
| 23 | rgb = rgbimg.longimagedata(rgb_file) |
| 24 | if len(rgb) != width * height * 4: |
| 25 | raise error, 'bad image length' |
Guido van Rossum | de554ec | 1997-05-08 23:14:57 +0000 | [diff] [blame] | 26 | raw = open(raw_file, 'rb').read() |
Guido van Rossum | 5c97167 | 1996-07-22 15:23:25 +0000 | [diff] [blame] | 27 | if rgb != raw: |
Guido van Rossum | 228b8e8 | 1997-04-02 06:13:34 +0000 | [diff] [blame] | 28 | raise error, \ |
| 29 | 'images don\'t match for '+rgb_file+' and '+raw_file |
Guido van Rossum | 5c97167 | 1996-07-22 15:23:25 +0000 | [diff] [blame] | 30 | for depth in [1, 3, 4]: |
| 31 | rgbimg.longstoimage(rgb, width, height, depth, '@.rgb') |
| 32 | os.unlink('@.rgb') |
| 33 | |
Guido van Rossum | de554ec | 1997-05-08 23:14:57 +0000 | [diff] [blame] | 34 | table = [ |
| 35 | ('testrgb.uue', 'test.rgb'), |
| 36 | ('testimg.uue', 'test.rawimg'), |
| 37 | ('testimgr.uue', 'test.rawimg.rev'), |
| 38 | ] |
| 39 | for source, target in table: |
| 40 | source = findfile(source) |
| 41 | target = findfile(target) |
| 42 | if verbose: |
| 43 | print "uudecoding", source, "->", target, "..." |
| 44 | uu.decode(source, target) |
| 45 | |
| 46 | if verbose: |
| 47 | print "testing..." |
| 48 | |
Guido van Rossum | 5c97167 | 1996-07-22 15:23:25 +0000 | [diff] [blame] | 49 | ttob = rgbimg.ttob(0) |
| 50 | if ttob != 0: |
| 51 | raise error, 'ttob should start out as zero' |
| 52 | |
| 53 | testimg('test.rgb', 'test.rawimg') |
| 54 | |
| 55 | ttob = rgbimg.ttob(1) |
| 56 | if ttob != 0: |
| 57 | raise error, 'ttob should be zero' |
| 58 | |
| 59 | testimg('test.rgb', 'test.rawimg.rev') |
| 60 | |
| 61 | ttob = rgbimg.ttob(0) |
| 62 | if ttob != 1: |
| 63 | raise error, 'ttob should be one' |
| 64 | |
| 65 | ttob = rgbimg.ttob(0) |
| 66 | if ttob != 0: |
| 67 | raise error, 'ttob should be zero' |
Guido van Rossum | de554ec | 1997-05-08 23:14:57 +0000 | [diff] [blame] | 68 | |
| 69 | for source, target in table: |
| 70 | unlink(findfile(target)) |