/t/image.t

http://github.com/PerlGameDev/SDL · Perl · 217 lines · 185 code · 29 blank · 3 comment · 4 complexity · c3c6c12e7bd64cd547ec5852d94226a8 MD5 · raw file

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