From: Leon Brocard Date: Tue, 10 Nov 2009 15:20:49 +0000 (+0000) Subject: Implement and test set_error, get_error, clear_error X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a34d2ce398bbc387b659df52f258fff90c89bd4f;p=sdlgit%2FSDL_perl.git Implement and test set_error, get_error, clear_error --- diff --git a/lib/SDL.pm b/lib/SDL.pm index 6792188..bffc723 100644 --- a/lib/SDL.pm +++ b/lib/SDL.pm @@ -80,5 +80,11 @@ sub verify (\%@) { } } +# workaround as: +# extern DECLSPEC void SDLCALL SDL_SetError(const char *fmt, ...); +sub set_error { + my($format, @arguments) = @_; + SDL::set_error_real(sprintf($format, @arguments)); +} 1; diff --git a/src/SDL.xs b/src/SDL.xs index 6299cdd..81e3e7c 100644 --- a/src/SDL.xs +++ b/src/SDL.xs @@ -256,6 +256,15 @@ XS(boot_SDL_perl) MODULE = SDL_perl PACKAGE = SDL PROTOTYPES : DISABLE + +# workaround as: +# extern DECLSPEC void SDLCALL SDL_SetError(const char *fmt, ...); +void +set_error_real (fmt, ...) + char *fmt + CODE: + SDL_SetError(fmt, items); + char * get_error () CODE: @@ -263,6 +272,11 @@ get_error () OUTPUT: RETVAL +void +clear_error () + CODE: + SDL_ClearError(); + int init ( flags ) Uint32 flags diff --git a/t/core.t b/t/core.t index 2384ffe..f78ab28 100644 --- a/t/core.t +++ b/t/core.t @@ -42,9 +42,6 @@ is(SDL::putenv('PERLSDL_TEST=hello'), 0, '[putenv] returns 0'); is(SDL::getenv('PERLSDL_TEST'), 'hello', '[getenv] returns hello'); my @left = qw/ - set_error - error - clear_error load_object load_function unload_function diff --git a/t/core_error.t b/t/core_error.t new file mode 100644 index 0000000..01990dd --- /dev/null +++ b/t/core_error.t @@ -0,0 +1,19 @@ +#!/usr/bin/perl +use strict; +use warnings; +use SDL; +use Test::More tests => 5; + +is( SDL::init(SDL_INIT_VIDEO), 0, '[init] returns 0 on success' ); + +SDL::set_error('Hello'); +is( SDL::get_error, 'Hello', '[get_error] returns Hello' ); + +SDL::set_error('Hello %s!', 'SDL'); +is( SDL::get_error, 'Hello SDL!', '[get_error] returns Hello SDL!' ); + +SDL::set_error('Hello %s! Three is %d.', 'SDL', 3); +is( SDL::get_error, 'Hello SDL! Three is 3.', '[get_error] returns Hello SDL! Three is 3.' ); + +SDL::clear_error(); +is( SDL::get_error, '', '[get_error] returns no error' );