### ----------------------------------------------------
### -- Gnome::Cairo
### -- Licenses: Artistic-2.0
### -- Authors: Marcel Timmerman
### -- File: t/ImageSurface.rakutest
### ----------------------------------------------------
use v6;
use NativeCall;
use Test;

use Gnome::Cairo::Types:api<1>;
use Gnome::Cairo::Enums:api<1>;
use Gnome::Cairo::ImageSurface:api<1>;
use Gnome::Cairo;

#use Gnome::N::X:api<1>;
#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


