Move blit out of Surface.xs, enable BlitSurface
[sdlgit/SDL_perl.git] / t / core_surface.t
1 #!perl -w
2 # Copyright (C) 2009 kthakore
3 #
4 # Spec tests for SDL::Surface
5 #
6
7 BEGIN {
8     unshift @INC, 'blib/lib', 'blib/arch';
9 }
10
11 use strict;
12 use SDL;
13 use SDL::Config;
14 use SDL::Surface;
15 use SDL::App;
16 use SDL::Rect;
17 use SDL::Color;
18 use Test::More tests => 17;
19
20 my $surface
21     = SDL::Surface->new( SDL::SDL_ANYFORMAT(), 640, 320, 8, 0, 0, 0, 0 );
22 isa_ok( $surface, 'SDL::Surface' );
23 is( $surface->w,     640, 'surface has width' );
24 is( $surface->h,     320, 'surface has height' );
25 is( $surface->pitch, 640, 'surface has pitch' );
26 my $clip_rect = SDL::Rect->new( 0, 0, 0, 0 );
27 SDL::GetClipRect( $surface, $clip_rect );
28 isa_ok( $clip_rect, 'SDL::Rect' );
29 is( $clip_rect->x, 0,   'clip_rect has x' );
30 is( $clip_rect->y, 0,   'clip_rect has y' );
31 is( $clip_rect->w, 640, 'clip_rect has width' );
32 is( $clip_rect->h, 320, 'clip_rect has height' );
33
34 my $image = SDL::IMG_Load('test/data/logo.png');
35 is( $image->w, 608, 'image has width' );
36 is( $image->h, 126, 'image has height' );
37
38 $surface->fill_rect( SDL::Rect->new( 0, 0, 32, 32 ),
39     SDL::Color->new( 200, 200, 200 ) );
40 ok( 1, 'Managed to fill_rect' );
41
42 my $small_rect = SDL::Rect->new( 0, 0, 64, 64 );
43 SDL::BlitSurface($image, $small_rect, $surface, $small_rect );
44 ok( 1, 'Managed to blit' );
45
46 #my $image_format = $surface->display;
47 #$surface->update_rect( 0, 0, 32, 32 );
48 #ok( 1, 'Managed to update_rect' );
49 #$surface->update_rects( SDL::Rect->new( 0, 0, 32, 32 ) );
50 #ok( 1, 'Managed to update_rects' );
51
52 my $app = SDL::App->new(
53     -title  => "Test",
54     -width  => 640,
55     -height => 480,
56     -init   => SDL_INIT_VIDEO
57 );
58
59 pass 'did this pass';
60
61 my $image_format = $image->display;
62 isa_ok( $image_format, 'SDL::Surface' );
63
64 my $image_format_alpha = $image->display_alpha;
65 isa_ok( $image_format_alpha, 'SDL::Surface' );
66
67 my $rect = SDL::Rect->new( 0, 0, $app->w, $app->h );
68
69 my $blue = SDL::Color->new( 0x00, 0x00, 0xff, );
70
71 $app->fill_rect( $rect, $blue );
72
73 diag( 'This is in surface : ' . SDL::Surface::get_pixels($app) );
74
75 pass 'did this pass';
76