Added test for time
[sdlgit/SDL_perl.git] / t / core_surface.t
CommitLineData
b7ed9095 1#!perl -w
2# Copyright (C) 2009 kthakore
3#
4# Spec tests for SDL::Surface
5#
6
7BEGIN {
9a70569a 8 unshift @INC, 'blib/lib', 'blib/arch';
9}
b7ed9095 10
11use strict;
12use SDL;
13use SDL::Config;
14use SDL::Surface;
15use SDL::App;
16use SDL::Rect;
17use SDL::Color;
f7de3b23 18use SDL::Video;
50d9130a 19use SDL::PixelFormat;
2e2fd270 20use Test::More tests => 35;
9a70569a 21
22my $surface
af85b4e9 23 = SDL::Surface->new( SDL::SDL_ANYFORMAT(), 640, 320, 8, 0, 0, 0, 0 );
9a70569a 24isa_ok( $surface, 'SDL::Surface' );
af85b4e9 25is( $surface->w, 640, 'surface has width' );
26is( $surface->h, 320, 'surface has height' );
27is( $surface->pitch, 640, 'surface has pitch' );
28my $clip_rect = SDL::Rect->new( 0, 0, 0, 0 );
29SDL::GetClipRect( $surface, $clip_rect );
30isa_ok( $clip_rect, 'SDL::Rect' );
31is( $clip_rect->x, 0, 'clip_rect has x' );
32is( $clip_rect->y, 0, 'clip_rect has y' );
33is( $clip_rect->w, 640, 'clip_rect has width' );
34is( $clip_rect->h, 320, 'clip_rect has height' );
9a70569a 35
a7fbee87 36my $image = SDL::IMG_Load('test/data/logo.png');
9a70569a 37is( $image->w, 608, 'image has width' );
38is( $image->h, 126, 'image has height' );
39
50d9130a 40my $pixel_format = $image->format;
2e2fd270 41isa_ok( $pixel_format, 'SDL::PixelFormat' );
42is( $pixel_format->BitsPerPixel, 24, '24 BitsPerPixel' );
43is( $pixel_format->BytesPerPixel, 3, '3 BytesPerPixel' );
44is( $pixel_format->Rloss, 0, '0 Rloss' );
45is( $pixel_format->Gloss, 0, '0 Gloss' );
46is( $pixel_format->Bloss, 0, '0 Bloss' );
47is( $pixel_format->Aloss, 8, '8 Aloss' );
48is( $pixel_format->Rshift, 0, '0 Rshift' );
49is( $pixel_format->Gshift, 8, '8 Gshift' );
50is( $pixel_format->Bshift, 16, '16 Bshift' );
51is( $pixel_format->Ashift, 0, '0 Ashift' );
52is( $pixel_format->Rmask, 255, '255 Rmask' );
53is( $pixel_format->Gmask, 65280, '65280 Gmask' );
54is( $pixel_format->Bmask, 16711680, '16711680 Bmask' );
55is( $pixel_format->Amask, 0, '0 Amask' );
56is( $pixel_format->colorkey, 0, '0 colorkey' );
57is( $pixel_format->alpha, 255, '255 alpha' );
58
59my $pixel = SDL::MapRGB( $pixel_format, 255, 127, 0 );
60is( $pixel, 32767, '32767 pixel' );
34a219f7 61SDL::FillRect( $surface, SDL::Rect->new( 0, 0, 32, 32 ), $pixel );
9a70569a 62ok( 1, 'Managed to fill_rect' );
63
64my $small_rect = SDL::Rect->new( 0, 0, 64, 64 );
2e2fd270 65SDL::BlitSurface( $image, $small_rect, $surface, $small_rect );
9a70569a 66ok( 1, 'Managed to blit' );
67
68#my $image_format = $surface->display;
69#$surface->update_rect( 0, 0, 32, 32 );
70#ok( 1, 'Managed to update_rect' );
71#$surface->update_rects( SDL::Rect->new( 0, 0, 32, 32 ) );
72#ok( 1, 'Managed to update_rects' );
73
74my $app = SDL::App->new(
75 -title => "Test",
76 -width => 640,
77 -height => 480,
78 -init => SDL_INIT_VIDEO
79);
b7ed9095 80
81pass 'did this pass';
82
f7ce55ec 83my $image_format = SDL::DisplayFormat($image);
41a5a9ee 84isa_ok( $image_format, 'SDL::Surface' );
85
f7ce55ec 86my $image_format_alpha = SDL::DisplayFormatAlpha($image);
41a5a9ee 87isa_ok( $image_format_alpha, 'SDL::Surface' );
88
34a219f7 89my $app_pixel_format = $app->format;
b7ed9095 90
34a219f7 91my $rect = SDL::Rect->new( 0, 0, $app->w, $app->h );
b7ed9095 92
34a219f7 93my $blue_pixel = SDL::MapRGB( $app_pixel_format, 0x00, 0x00, 0xff );
94SDL::FillRect( $app, $rect, $blue_pixel );
f7de3b23 95SDL::Video::update_rect( $app, 0, 0, 0, 0 );
96SDL::Video::update_rects( $app, $small_rect );
b7ed9095 97
9a70569a 98diag( 'This is in surface : ' . SDL::Surface::get_pixels($app) );
b7ed9095 99
100pass 'did this pass';
101
d5a2f5ac 102SDL::delay(100);