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 | |
Barry Warsaw | 04f357c | 2002-07-23 19:04:11 +0000 | [diff] [blame] | 5 | from test.test_support import verbose, unlink, findfile |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 6 | |
Fred Drake | b65b006 | 2000-08-18 14:50:20 +0000 | [diff] [blame] | 7 | class error(Exception): |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 8 | pass |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 9 | |
| 10 | print 'RGBimg test suite:' |
| 11 | |
| 12 | def testimg(rgb_file, raw_file): |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 13 | 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 Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 26 | |
Guido van Rossum | cb5cf9b | 1997-04-09 21:25:01 +0000 | [diff] [blame] | 27 | table = [ |
Guido van Rossum | e2ae77b | 2001-10-24 20:42:55 +0000 | [diff] [blame] | 28 | ('testrgb'+os.extsep+'uue', 'test'+os.extsep+'rgb'), |
| 29 | ('testimg'+os.extsep+'uue', 'test'+os.extsep+'rawimg'), |
| 30 | ('testimgr'+os.extsep+'uue', 'test'+os.extsep+'rawimg'+os.extsep+'rev'), |
Guido van Rossum | cb5cf9b | 1997-04-09 21:25:01 +0000 | [diff] [blame] | 31 | ] |
| 32 | for source, target in table: |
| 33 | source = findfile(source) |
| 34 | target = findfile(target) |
| 35 | if verbose: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 36 | print "uudecoding", source, "->", target, "..." |
Guido van Rossum | cb5cf9b | 1997-04-09 21:25:01 +0000 | [diff] [blame] | 37 | uu.decode(source, target) |
| 38 | |
| 39 | if verbose: |
| 40 | print "testing..." |
| 41 | |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 42 | ttob = rgbimg.ttob(0) |
| 43 | if ttob != 0: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 44 | raise error, 'ttob should start out as zero' |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 45 | |
Guido van Rossum | e2ae77b | 2001-10-24 20:42:55 +0000 | [diff] [blame] | 46 | testimg('test'+os.extsep+'rgb', 'test'+os.extsep+'rawimg') |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 47 | |
| 48 | ttob = rgbimg.ttob(1) |
| 49 | if ttob != 0: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 50 | raise error, 'ttob should be zero' |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 51 | |
Guido van Rossum | e2ae77b | 2001-10-24 20:42:55 +0000 | [diff] [blame] | 52 | testimg('test'+os.extsep+'rgb', 'test'+os.extsep+'rawimg'+os.extsep+'rev') |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 53 | |
| 54 | ttob = rgbimg.ttob(0) |
| 55 | if ttob != 1: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 56 | raise error, 'ttob should be one' |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 57 | |
| 58 | ttob = rgbimg.ttob(0) |
| 59 | if ttob != 0: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 60 | raise error, 'ttob should be zero' |
Guido van Rossum | cb5cf9b | 1997-04-09 21:25:01 +0000 | [diff] [blame] | 61 | |
| 62 | for source, target in table: |
| 63 | unlink(findfile(target)) |