PageRenderTime 43ms CodeModel.GetById 1ms app.highlight 39ms RepoModel.GetById 1ms app.codeStats 0ms

/t/core_surface.t

http://github.com/PerlGameDev/SDL
Perl | 136 lines | 98 code | 27 blank | 11 comment | 4 complexity | 5686ab298e7b2889e79df91d263a68b6 MD5 | raw file
  1#!perl -w
  2# Copyright (C) 2009 kthakore
  3#
  4# Spec tests for SDL::Surface
  5#
  6
  7BEGIN {
  8	unshift @INC, 'blib/lib', 'blib/arch';
  9}
 10
 11use strict;
 12use warnings;
 13use SDL;
 14use SDL::Config;
 15use SDL::Surface;
 16use SDLx::App;
 17use SDL::Rect;
 18use SDL::Color;
 19use SDL::Video;
 20use SDL::PixelFormat;
 21use Test::More;
 22
 23use lib 't/lib';
 24use SDL::TestTool;
 25
 26my $videodriver = $ENV{SDL_VIDEODRIVER};
 27$ENV{SDL_VIDEODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING};
 28
 29if ( !SDL::TestTool->init(SDL_INIT_VIDEO) ) {
 30	plan( skip_all => 'Failed to init video' );
 31} else {
 32	plan( tests => 41 );
 33}
 34
 35my $surface = SDL::Surface->new( SDL_ANYFORMAT, 640, 320, 8, 0, 0, 0, 0 );
 36isa_ok( $surface, 'SDL::Surface' );
 37is( $surface->w,     640, 'surface has width' );
 38is( $surface->h,     320, 'surface has height' );
 39is( $surface->pitch, 640, 'surface has pitch' );
 40my $clip_rect = SDL::Rect->new( 0, 0, 0, 0 );
 41SDL::Video::get_clip_rect( $surface, $clip_rect );
 42isa_ok( $clip_rect, 'SDL::Rect' );
 43is( $clip_rect->x, 0,   'clip_rect has x' );
 44is( $clip_rect->y, 0,   'clip_rect has y' );
 45is( $clip_rect->w, 640, 'clip_rect has width' );
 46is( $clip_rect->h, 320, 'clip_rect has height' );
 47
 48my $image = SDL::Video::load_BMP('test/data/icon.bmp');
 49is( $image->w, 32, 'image has width' );
 50is( $image->h, 32, 'image has height' );
 51
 52my $pixel_format = $image->format;
 53isa_ok( $pixel_format, 'SDL::PixelFormat' );
 54is( $pixel_format->BitsPerPixel,  8,   ' BitsPerPixel' );
 55is( $pixel_format->BytesPerPixel, 1,   ' BytesPerPixel' );
 56is( $pixel_format->Rloss,         8,   ' Rloss' );
 57is( $pixel_format->Gloss,         8,   ' Gloss' );
 58is( $pixel_format->Bloss,         8,   ' Bloss' );
 59is( $pixel_format->Aloss,         8,   ' Aloss' );
 60is( $pixel_format->Rshift,        0,   ' Rshift' );
 61is( $pixel_format->Gshift,        0,   ' Gshift' );
 62is( $pixel_format->Bshift,        0,   ' Bshift' );
 63is( $pixel_format->Ashift,        0,   ' Ashift' );
 64is( $pixel_format->Rmask,         0,   ' Rmask' );
 65is( $pixel_format->Gmask,         0,   ' Gmask' );
 66is( $pixel_format->Bmask,         0,   ' Bmask' );
 67is( $pixel_format->Amask,         0,   ' Amask' );
 68is( $pixel_format->colorkey,      0,   ' colorkey' );
 69is( $pixel_format->alpha,         255, ' alpha' );
 70
 71my $pixel = SDL::Video::map_RGB( $pixel_format, 255, 127, 0 );
 72is( $pixel, 2, 'maping RGB to surface' );
 73SDL::Video::fill_rect( $surface, SDL::Rect->new( 0, 0, 32, 32 ), $pixel );
 74ok( 1, 'Managed to fill_rect' );
 75
 76my $small_rect = SDL::Rect->new( 0, 0, 64, 64 );
 77SDL::Video::blit_surface( $image, $small_rect, $surface, $small_rect );
 78ok( 1, 'Managed to blit' );
 79
 80#my $image_format = $surface->display;
 81#$surface->update_rect( 0, 0, 32, 32 );
 82#ok( 1, 'Managed to update_rect' );
 83#$surface->update_rects( SDL::Rect->new( 0, 0, 32, 32 ) );
 84#ok( 1, 'Managed to update_rects' );
 85
 86my $app = SDLx::App->new(
 87	title  => "Test",
 88	width  => 640,
 89	height => 480,
 90	init   => SDL_INIT_VIDEO
 91);
 92
 93pass 'did this pass';
 94
 95my $image_format = SDL::Video::display_format($image);
 96isa_ok( $image_format, 'SDL::Surface' );
 97
 98my $image_format_alpha = SDL::Video::display_format_alpha($image);
 99isa_ok( $image_format_alpha, 'SDL::Surface' );
100
101my $app_pixel_format = $app->format;
102
103my $rect = SDL::Rect->new( 0, 0, $app->w, $app->h );
104
105my $blue_pixel = SDL::Video::map_RGB( $app_pixel_format, 0x00, 0x00, 0xff );
106
107SDL::Video::fill_rect( $app, $rect, $blue_pixel );
108
109SDL::Video::update_rect( $app, 0, 0, 0, 0 );
110
111SDL::Video::update_rects( $app, $small_rect );
112
113my $ref           = $surface->get_pixels_ptr;
114my $other_surface = SDL::Surface->new_from( $ref, 640, 320, 8, $surface->pitch, 0, 0, 0, 0 );
115my $get_pixel     = $surface->get_pixel(0);
116ok( $get_pixel >= 0, "[get_pixel] returns integer ($get_pixel)" );
117$surface->set_pixels( 0, 42 );
118pass '[set_pixel] first pixel to 42';
119is( $surface->get_pixel(0), 42, '[get_pixel] returns integer (42)' );
120
121isa_ok( $other_surface, 'SDL::Surface' );
122is( $other_surface->w, $surface->w, '[new_form] have same w' );
123is( $other_surface->h, $surface->h, '[neh_form] have same h' );
124
125#TODO: Added more comparison stuff
126
127if ($videodriver) {
128	$ENV{SDL_VIDEODRIVER} = $videodriver;
129} else {
130	delete $ENV{SDL_VIDEODRIVER};
131}
132
133pass 'Final SegFault test';
134
135SDL::delay(100);
136sleep(2);