/t/image.t
Perl | 217 lines | 185 code | 29 blank | 3 comment | 7 complexity | c3c6c12e7bd64cd547ec5852d94226a8 MD5 | raw file
1#!/usr/bin/perl -w 2use strict; 3use warnings; 4use SDL; 5use SDL::Config; 6use SDL::Version; 7use SDL::Image; 8use SDL::RWOps; 9 10use Test::More; 11use lib 't/lib'; 12use SDL::TestTool; 13 14my $videodriver = $ENV{SDL_VIDEODRIVER}; 15$ENV{SDL_VIDEODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING}; 16 17if ( !SDL::TestTool->init(SDL_INIT_VIDEO) ) { 18 plan( skip_all => 'Failed to init video' ); 19} elsif ( !SDL::Config->has('SDL_image') ) { 20 plan( skip_all => 'SDL_image support not compiled' ); 21} 22 23my @done = qw/ 24 linked_version 25 load_rw 26 load_typed_rw 27 load_PNG_rw 28 load_BMP_rw 29 load_GIF_rw 30 load_JPG_rw 31 load_LBM_rw 32 load_PCX_rw 33 load_PNM_rw 34 load_TIF_rw 35 load_XCF_rw 36 load_XPM_rw 37 load_XV_rw 38 is_PNG 39 is_BMP 40 is_GIF 41 is_JPG 42 is_LBM 43 is_PCX 44 is_PNM 45 is_TIF 46 is_XCF 47 is_XPM 48 is_XV 49 /; 50 51can_ok( "SDL::Image", @done ); 52 53my $lver = SDL::Image::linked_version(); 54isa_ok( $lver, "SDL::Version", '[linked_version] got version back!' ); 55printf( "got version: %d.%d.%d\n", $lver->major, $lver->minor, $lver->patch ); 56 57SKIP: 58{ 59 skip( 'PNG support not compiled', 14 ) unless SDL::Config->has('png'); 60 isa_ok( 61 SDL::Image::load("test/data/highlight.png"), 62 "SDL::Surface", "[load] Gets Surface" 63 ); 64 65 my $file = SDL::RWOps->new_file( "test/data/logo.png", "rb" ); 66 isa_ok( 67 SDL::Image::load_rw( $file, 1 ), 68 "SDL::Surface", "[load_rw] Gets surface" 69 ); 70 71 my $file2 = SDL::RWOps->new_file( "test/data/menu.png", "rb" ); 72 isa_ok( 73 SDL::Image::load_typed_rw( $file2, 1, "PNG" ), 74 "SDL::Surface", "[loadtyped_rw] Makes surface from png" 75 ); 76 77 my $file3 = SDL::RWOps->new_file( "test/data/menu.png", "rb" ); 78 is( SDL::Image::is_PNG($file3), 79 1, "[is_PNG] gets correct value for png file" 80 ); 81 82 is( SDL::Image::is_BMP($file3), 0, '[is_BMP] returned correct value' ); 83 is( SDL::Image::is_GIF($file3), 0, '[is_GIF] returned correct value' ); 84 is( SDL::Image::is_JPG($file3), 0, '[is_JPG] returned correct value' ); 85 is( SDL::Image::is_LBM($file3), 0, '[is_LMB] returned correct value' ); 86 is( SDL::Image::is_PCX($file3), 0, '[is_PCX] returned correct value' ); 87 is( SDL::Image::is_PNM($file3), 0, '[is_PNM] returned correct value' ); 88 is( SDL::Image::is_TIF($file3), 0, '[is_TIF] returned correct value' ); 89 is( SDL::Image::is_XCF($file3), 0, '[is_XCF] returned correct value' ); 90 is( SDL::Image::is_XPM($file3), 0, '[is_XPM] returned correct value' ); 91 is( SDL::Image::is_XV($file3), 0, '[is_XV] returned correct value' ); 92} 93 94SKIP: 95{ 96 skip( 'JPEG support not compiled', 14 ) unless SDL::Config->has('jpeg'); 97 isa_ok( 98 SDL::Image::load("test/data/picture.jpg"), 99 "SDL::Surface", "[load] Gets Surface" 100 ); 101 102 my $file = SDL::RWOps->new_file( "test/data/picture.jpg", "rb" ); 103 isa_ok( 104 SDL::Image::load_rw( $file, 1 ), 105 "SDL::Surface", "[load_rw] Gets surface" 106 ); 107 108 my $file2 = SDL::RWOps->new_file( "test/data/picture.jpg", "rb" ); 109 isa_ok( 110 SDL::Image::load_typed_rw( $file2, 1, "JPG" ), 111 "SDL::Surface", "[loadtyped_rw] Makes surface from jpg" 112 ); 113 114 my $file3 = SDL::RWOps->new_file( "test/data/picture.jpg", "rb" ); 115 is( SDL::Image::is_JPG($file3), 116 1, "[is_JPG] gets correct value for jpg file" 117 ); 118 119 is( SDL::Image::is_BMP($file3), 0, '[is_BMP] returned correct value' ); 120 is( SDL::Image::is_GIF($file3), 0, '[is_GIF] returned correct value' ); 121 is( SDL::Image::is_PNG($file3), 0, '[is_PNG] returned correct value' ); 122 is( SDL::Image::is_LBM($file3), 0, '[is_LMB] returned correct value' ); 123 is( SDL::Image::is_PCX($file3), 0, '[is_PCX] returned correct value' ); 124 is( SDL::Image::is_PNM($file3), 0, '[is_PNM] returned correct value' ); 125 is( SDL::Image::is_TIF($file3), 0, '[is_TIF] returned correct value' ); 126 is( SDL::Image::is_XCF($file3), 0, '[is_XCF] returned correct value' ); 127 is( SDL::Image::is_XPM($file3), 0, '[is_XPM] returned correct value' ); 128 is( SDL::Image::is_XV($file3), 0, '[is_XV] returned correct value' ); 129} 130 131SKIP: 132{ 133 skip( 'TIFF support not compiled', 14 ) unless SDL::Config->has('tiff'); 134 isa_ok( 135 SDL::Image::load("test/data/picture.tif"), 136 "SDL::Surface", "[load] Gets Surface" 137 ); 138 139 my $file = SDL::RWOps->new_file( "test/data/picture.tif", "rb" ); 140 isa_ok( 141 SDL::Image::load_rw( $file, 1 ), 142 "SDL::Surface", "[load_rw] Gets surface" 143 ); 144 145 my $file2 = SDL::RWOps->new_file( "test/data/picture.tif", "rb" ); 146 isa_ok( 147 SDL::Image::load_typed_rw( $file2, 1, "TIF" ), 148 "SDL::Surface", "[loadtyped_rw] Makes surface from tif" 149 ); 150 151 my $file3 = SDL::RWOps->new_file( "test/data/picture.tif", "rb" ); 152 is( SDL::Image::is_TIF($file3), 153 1, "[is_TIF] gets correct value for tif file" 154 ); 155 156 is( SDL::Image::is_BMP($file3), 0, '[is_BMP] returned correct value' ); 157 is( SDL::Image::is_GIF($file3), 0, '[is_GIF] returned correct value' ); 158 is( SDL::Image::is_JPG($file3), 0, '[is_JPG] returned correct value' ); 159 is( SDL::Image::is_LBM($file3), 0, '[is_LMB] returned correct value' ); 160 is( SDL::Image::is_PCX($file3), 0, '[is_PCX] returned correct value' ); 161 is( SDL::Image::is_PNM($file3), 0, '[is_PNM] returned correct value' ); 162 is( SDL::Image::is_PNG($file3), 0, '[is_PNG] returned correct value' ); 163 is( SDL::Image::is_XCF($file3), 0, '[is_XCF] returned correct value' ); 164 is( SDL::Image::is_XPM($file3), 0, '[is_XPM] returned correct value' ); 165 is( SDL::Image::is_XV($file3), 0, '[is_XV] returned correct value' ); 166} 167 168#need to get DEFINES to SDL::Image::Constants; 169#IMG_INIT_JPG =?o 170is( IMG_INIT_JPG, 0x00000001, '[IMG_INIT_JPG] constant loaded properly' ); 171is( IMG_INIT_PNG, 0x00000002, '[IMG_INIT_PNG] constant loaded properly' ); 172is( IMG_INIT_TIF, 0x00000004, '[IMG_INIT_TIF] constant loaded properly' ); 173 174SKIP: 175{ 176 skip( 'This is only for version >= 1.2.10', 2 ) if $lver < 1.2.10; 177 SKIP: 178 { 179 skip( 'JPEG support not compiled', 1 ) unless SDL::Config->has('jpeg'); 180 is( SDL::Image::init(IMG_INIT_JPG), IMG_INIT_JPG, 181 '[init] Inited JPEG' 182 ); 183 } 184 185 SKIP: 186 { 187 skip( 'TIFF support not compiled', 1 ) unless SDL::Config->has('tiff'); 188 is( SDL::Image::init(IMG_INIT_TIF), IMG_INIT_TIF, 189 '[init] Inited TIFF' 190 ); 191 } 192 193 SKIP: 194 { 195 skip( 'PNG support not compiled', 1 ) unless SDL::Config->has('png'); 196 is( SDL::Image::init(IMG_INIT_PNG), IMG_INIT_PNG, '[init] Inited PNG' ); 197 } 198 199 can_ok( 200 'SDL::Image', qw/ 201 load_ICO_rw 202 load_CUR_rw 203 is_ICO 204 is_CUR/ 205 ); 206 207 SDL::Image::quit(); 208 pass '[quit] we can quit fine'; 209} 210 211if ($videodriver) { 212 $ENV{SDL_VIDEODRIVER} = $videodriver; 213} else { 214 delete $ENV{SDL_VIDEODRIVER}; 215} 216 217done_testing;