/t/sdlx_text.t

http://github.com/PerlGameDev/SDL · Raku · 58 lines · 46 code · 12 blank · 0 comment · 6 complexity · c39826073f3a860c867b1d03aa874e58 MD5 · raw file

  1. use strict;
  2. use warnings;
  3. use SDL;
  4. use SDL::Config;
  5. use SDL::Color;
  6. use SDL::Surface;
  7. use SDLx::App;
  8. BEGIN {
  9. use FindBin;
  10. use Test::More;
  11. use lib 't/lib';
  12. use SDL::TestTool;
  13. if ( !SDL::Config->has('SDL_ttf') ) {
  14. plan( skip_all => 'SDL_ttf support not compiled' );
  15. }
  16. }
  17. use_ok( 'SDLx::Text' );
  18. my $videodriver = $ENV{SDL_VIDEODRIVER};
  19. $ENV{SDL_VIDEODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING};
  20. use File::Spec;
  21. my $score = SDLx::Text->new(
  22. font => File::Spec->catfile($FindBin::Bin, '..', 'share', 'GenBasR.ttf')
  23. );
  24. isa_ok( $score, 'SDLx::Text');
  25. is($score->x, 0, 'default x position');
  26. is($score->y, 0, 'default y position');
  27. is($score->h_align, 'left', 'default horizontal alignment');
  28. isa_ok( $score->font, 'SDL::TTF::Font' );
  29. isa_ok($score->color, 'SDL::Color', 'default color');
  30. is($score->size, 24, 'default size');
  31. $score->text('Hello');
  32. is( $score->text, 'Hello', 'text() as a getter' );
  33. ok( $score->w >= 50 && $score->w <= 53, 'Hello! is 50..53 px wide!' );
  34. is( $score->h, 28, 'Hello! is 28 px high!' );
  35. isa_ok($score->surface, 'SDL::Surface');
  36. my $value = undef;
  37. my $other_self = $score->text($value);
  38. isa_ok($score, 'SDLx::Text');
  39. END {
  40. if ($videodriver) {
  41. $ENV{SDL_VIDEODRIVER} = $videodriver;
  42. } else {
  43. delete $ENV{SDL_VIDEODRIVER};
  44. }
  45. done_testing;
  46. }