Help language development. Donate to The Perl Foundation

Gnome::Cairo cpan:MARTIMM last updated on 2022-02-20

t/ImageSurface.rakutest
use v6;
use NativeCall;
use Test;

use Gnome::Cairo::Types;
use Gnome::Cairo::Enums;
use Gnome::Cairo::ImageSurface;
use Gnome::Cairo;

#use Gnome::N::X;
#Gnome::N::debug(:on);

#-------------------------------------------------------------------------------
my Gnome::Cairo::ImageSurface $is;
#-------------------------------------------------------------------------------
subtest 'ISA test', {
  $is .= new( :format(CAIRO_FORMAT_RGB24), :width(128), :height(128));
  ok $is.is-valid, '.new( :format, :width, :height)';

  $is .= new(:png<t/data/Add.png>);
  ok $is.is-valid, '.new(:png)';
  is $is.status, CAIRO_STATUS_SUCCESS, '.status()';

  my Gnome::Cairo $c .= new(:surface($is));
  is $c.status, CAIRO_STATUS_SUCCESS,
    'cairo .status() = ' ~ $c.status-to-string($is.status);
}

#-------------------------------------------------------------------------------
# set environment variable 'raku-test-all' if rest must be tested too.
unless %*ENV<raku_test_all>:exists {
  done-testing;
  exit;
}

#-------------------------------------------------------------------------------
subtest 'Manipulations', {
  # loaded png image is ARGB
  is $is.get-format, CAIRO_FORMAT_ARGB32, '.get-format()';
  is $is.get-height, 16, '.get-height()';
  is $is.get-width, 16, '.get-width()';

  # 16 bits wide * (3 bytes rgb + 1 byte alpha)
  is $is.get-stride, 16 * 4, '.get-stride()';
}

#-------------------------------------------------------------------------------
done-testing;

=finish