File: image.t

package info (click to toggle)
libsdl-perl 2.548-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,972 kB
  • sloc: perl: 13,985; ansic: 583; makefile: 35
file content (217 lines) | stat: -rw-r--r-- 6,350 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/usr/bin/perl -w
use strict;
use warnings;
use SDL;
use SDL::Config;
use SDL::Version;
use SDL::Image;
use SDL::RWOps;

use Test::More;
use lib 't/lib';
use SDL::TestTool;

my $videodriver = $ENV{SDL_VIDEODRIVER};
$ENV{SDL_VIDEODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING};

if ( !SDL::TestTool->init(SDL_INIT_VIDEO) ) {
	plan( skip_all => 'Failed to init video' );
} elsif ( !SDL::Config->has('SDL_image') ) {
	plan( skip_all => 'SDL_image support not compiled' );
}

my @done = qw/
	linked_version
	load_rw
	load_typed_rw
	load_PNG_rw
	load_BMP_rw
	load_GIF_rw
	load_JPG_rw
	load_LBM_rw
	load_PCX_rw
	load_PNM_rw
	load_TIF_rw
	load_XCF_rw
	load_XPM_rw
	load_XV_rw
	is_PNG
	is_BMP
	is_GIF
	is_JPG
	is_LBM
	is_PCX
	is_PNM
	is_TIF
	is_XCF
	is_XPM
	is_XV
	/;

can_ok( "SDL::Image", @done );

my $lver = SDL::Image::linked_version();
isa_ok( $lver, "SDL::Version", '[linked_version] got version back!' );
printf( "got version: %d.%d.%d\n", $lver->major, $lver->minor, $lver->patch );

SKIP:
{
	skip( 'PNG support not compiled', 14 ) unless SDL::Config->has('png');
	isa_ok(
		SDL::Image::load("test/data/highlight.png"),
		"SDL::Surface", "[load] Gets Surface"
	);

	my $file = SDL::RWOps->new_file( "test/data/logo.png", "rb" );
	isa_ok(
		SDL::Image::load_rw( $file, 1 ),
		"SDL::Surface", "[load_rw] Gets surface"
	);

	my $file2 = SDL::RWOps->new_file( "test/data/menu.png", "rb" );
	isa_ok(
		SDL::Image::load_typed_rw( $file2, 1, "PNG" ),
		"SDL::Surface", "[loadtyped_rw] Makes surface from png"
	);

	my $file3 = SDL::RWOps->new_file( "test/data/menu.png", "rb" );
	is( SDL::Image::is_PNG($file3),
		1, "[is_PNG] gets correct value for png file"
	);

	is( SDL::Image::is_BMP($file3), 0, '[is_BMP] returned correct value' );
	is( SDL::Image::is_GIF($file3), 0, '[is_GIF] returned correct value' );
	is( SDL::Image::is_JPG($file3), 0, '[is_JPG] returned correct value' );
	is( SDL::Image::is_LBM($file3), 0, '[is_LMB] returned correct value' );
	is( SDL::Image::is_PCX($file3), 0, '[is_PCX] returned correct value' );
	is( SDL::Image::is_PNM($file3), 0, '[is_PNM] returned correct value' );
	is( SDL::Image::is_TIF($file3), 0, '[is_TIF] returned correct value' );
	is( SDL::Image::is_XCF($file3), 0, '[is_XCF] returned correct value' );
	is( SDL::Image::is_XPM($file3), 0, '[is_XPM] returned correct value' );
	is( SDL::Image::is_XV($file3),  0, '[is_XV] returned correct value' );
}

SKIP:
{
	skip( 'JPEG support not compiled', 14 ) unless SDL::Config->has('jpeg');
	isa_ok(
		SDL::Image::load("test/data/picture.jpg"),
		"SDL::Surface", "[load] Gets Surface"
	);

	my $file = SDL::RWOps->new_file( "test/data/picture.jpg", "rb" );
	isa_ok(
		SDL::Image::load_rw( $file, 1 ),
		"SDL::Surface", "[load_rw] Gets surface"
	);

	my $file2 = SDL::RWOps->new_file( "test/data/picture.jpg", "rb" );
	isa_ok(
		SDL::Image::load_typed_rw( $file2, 1, "JPG" ),
		"SDL::Surface", "[loadtyped_rw] Makes surface from jpg"
	);

	my $file3 = SDL::RWOps->new_file( "test/data/picture.jpg", "rb" );
	is( SDL::Image::is_JPG($file3),
		1, "[is_JPG] gets correct value for jpg file"
	);

	is( SDL::Image::is_BMP($file3), 0, '[is_BMP] returned correct value' );
	is( SDL::Image::is_GIF($file3), 0, '[is_GIF] returned correct value' );
	is( SDL::Image::is_PNG($file3), 0, '[is_PNG] returned correct value' );
	is( SDL::Image::is_LBM($file3), 0, '[is_LMB] returned correct value' );
	is( SDL::Image::is_PCX($file3), 0, '[is_PCX] returned correct value' );
	is( SDL::Image::is_PNM($file3), 0, '[is_PNM] returned correct value' );
	is( SDL::Image::is_TIF($file3), 0, '[is_TIF] returned correct value' );
	is( SDL::Image::is_XCF($file3), 0, '[is_XCF] returned correct value' );
	is( SDL::Image::is_XPM($file3), 0, '[is_XPM] returned correct value' );
	is( SDL::Image::is_XV($file3),  0, '[is_XV] returned correct value' );
}

SKIP:
{
	skip( 'TIFF support not compiled', 14 ) unless SDL::Config->has('tiff');
	isa_ok(
		SDL::Image::load("test/data/picture.tif"),
		"SDL::Surface", "[load] Gets Surface"
	);

	my $file = SDL::RWOps->new_file( "test/data/picture.tif", "rb" );
	isa_ok(
		SDL::Image::load_rw( $file, 1 ),
		"SDL::Surface", "[load_rw] Gets surface"
	);

	my $file2 = SDL::RWOps->new_file( "test/data/picture.tif", "rb" );
	isa_ok(
		SDL::Image::load_typed_rw( $file2, 1, "TIF" ),
		"SDL::Surface", "[loadtyped_rw] Makes surface from tif"
	);

	my $file3 = SDL::RWOps->new_file( "test/data/picture.tif", "rb" );
	is( SDL::Image::is_TIF($file3),
		1, "[is_TIF] gets correct value for tif file"
	);

	is( SDL::Image::is_BMP($file3), 0, '[is_BMP] returned correct value' );
	is( SDL::Image::is_GIF($file3), 0, '[is_GIF] returned correct value' );
	is( SDL::Image::is_JPG($file3), 0, '[is_JPG] returned correct value' );
	is( SDL::Image::is_LBM($file3), 0, '[is_LMB] returned correct value' );
	is( SDL::Image::is_PCX($file3), 0, '[is_PCX] returned correct value' );
	is( SDL::Image::is_PNM($file3), 0, '[is_PNM] returned correct value' );
	is( SDL::Image::is_PNG($file3), 0, '[is_PNG] returned correct value' );
	is( SDL::Image::is_XCF($file3), 0, '[is_XCF] returned correct value' );
	is( SDL::Image::is_XPM($file3), 0, '[is_XPM] returned correct value' );
	is( SDL::Image::is_XV($file3),  0, '[is_XV] returned correct value' );
}

#need to get DEFINES to SDL::Image::Constants;
#IMG_INIT_JPG =?o
is( IMG_INIT_JPG, 0x00000001, '[IMG_INIT_JPG] constant loaded properly' );
is( IMG_INIT_PNG, 0x00000002, '[IMG_INIT_PNG] constant loaded properly' );
is( IMG_INIT_TIF, 0x00000004, '[IMG_INIT_TIF] constant loaded properly' );

SKIP:
{
	skip( 'This is only for version >= 1.2.10', 2 ) if $lver < 1.2.10;
	SKIP:
	{
		skip( 'JPEG support not compiled', 1 ) unless SDL::Config->has('jpeg');
		is( SDL::Image::init(IMG_INIT_JPG), IMG_INIT_JPG,
			'[init] Inited JPEG'
		);
	}

	SKIP:
	{
		skip( 'TIFF support not compiled', 1 ) unless SDL::Config->has('tiff');
		is( SDL::Image::init(IMG_INIT_TIF), IMG_INIT_TIF,
			'[init] Inited TIFF'
		);
	}

	SKIP:
	{
		skip( 'PNG support not compiled', 1 ) unless SDL::Config->has('png');
		is( SDL::Image::init(IMG_INIT_PNG), IMG_INIT_PNG, '[init] Inited PNG' );
	}

	can_ok(
		'SDL::Image', qw/
			load_ICO_rw
			load_CUR_rw
			is_ICO
			is_CUR/
	);

	SDL::Image::quit();
	pass '[quit] we can quit fine';
}

if ($videodriver) {
	$ENV{SDL_VIDEODRIVER} = $videodriver;
} else {
	delete $ENV{SDL_VIDEODRIVER};
}

done_testing;