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

use Gnome::GObject::Type:api<1>;
use Gnome::GObject::Value:api<1>;
use Gnome::Glib::List:api<1>;
use Gnome::Gtk3::Box:api<1>;
use Gnome::Gtk3::Label:api<1>;
use Gnome::Gtk3::MessageDialog:api<1>;
use Gnome::Gtk3::Enums:api<1>;

#use Gnome::N::X:api<1>;
#Gnome::N::debug(:on);

#-------------------------------------------------------------------------------
my Gnome::Gtk3::MessageDialog $md;
#-------------------------------------------------------------------------------
subtest 'ISA test', {
  $md .= new(:message('blub'));
  isa-ok $md, Gnome::Gtk3::MessageDialog, '.new(:message, ...)';

  $md .= new(:markup-message('<b>blub</b>'));
  isa-ok $md, Gnome::Gtk3::MessageDialog, '.new(:markup-message, ...)';
}

#-------------------------------------------------------------------------------
unless %*ENV<raku_test_all>:exists {
  done-testing;
  exit;
}

#-------------------------------------------------------------------------------
subtest 'Manipulations', {
  $md.set-markup('aba<i>ca</i>dabra');
  $md.secondary-text('En een gewone mededeling');
  my Gnome::Gtk3::Box $container .= new(:native-object($md.get-message-area));

  my Gnome::Glib::List $l .= new(:native-object($container.get-children));
  is $l.length, 2, '2 messages in dialog';

  my Gnome::Gtk3::Label $lbl .= new(:native-object($l.nth-data(0)));
  is $lbl.get-text, 'abacadabra', '.set-markup()';
  $lbl .= new(:native-object($l.nth-data(1)));
  is $lbl.get-text, 'En een gewone mededeling', '.format-secondary-text()';
}

#-------------------------------------------------------------------------------
subtest 'Properties ...', {
  use Gnome::GObject::Value:api<1>;
  use Gnome::GObject::Type:api<1>;

  #my Gnome::Gtk3::MessageDialog $md .= new;

  sub test-property (
    $type, Str $prop, Str $routine, $value, Bool :$approx = False
  ) {
    my Gnome::GObject::Value $gv .= new(:init($type));
    $md.get-property( $prop, $gv);
    my $gv-value = $gv."$routine"();
    if $approx {
      is-approx $gv-value, $value,
        "property $prop, value: " ~ $gv-value;
    }

    else {
      is $gv-value, $value,
        "property $prop, value: " ~ $gv-value;
    }
    $gv.clear-object;
  }

  test-property( G_TYPE_STRING, 'text', 'get-string', 'aba<i>ca</i>dabra');
  test-property( G_TYPE_STRING, 'secondary-text', 'get-string', 'En een gewone mededeling');

  test-property( G_TYPE_BOOLEAN, 'use-markup', 'get-boolean', True);
  test-property( G_TYPE_BOOLEAN, 'secondary-use-markup', 'get-boolean', False);
}

#-------------------------------------------------------------------------------
subtest 'Inherit Gnome::Gtk3::MessageDialog', {
  class MyClass is Gnome::Gtk3::MessageDialog {
    method new ( |c ) {
      self.bless(
        :GtkMessageDialog, |c, :buttons(GTK_BUTTONS_YES_NO)
      );
    }

    submethod BUILD ( *%options ) {
      self.format-secondary-markup('Press <b>Yes</b> if you are');
    }
  }

  my MyClass $mgc .= new(:message('Well, that is something!'));
  isa-ok $mgc, Gnome::Gtk3::MessageDialog, '$mgc.new()';
}

#`{{
#-------------------------------------------------------------------------------
subtest 'Inherit ...', {
}

#-------------------------------------------------------------------------------
subtest 'Interface ...', {
}

#-------------------------------------------------------------------------------
subtest 'Themes ...', {
}

#-------------------------------------------------------------------------------
subtest 'Signals ...', {
}
}}

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


