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

use Gnome::Gtk3::FileFilter:api<1>;

use Gnome::Glib::Variant:api<1>;

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

#-------------------------------------------------------------------------------
my Gnome::Gtk3::FileFilter ( $ff, $ff2);
#-------------------------------------------------------------------------------
subtest 'ISA test', {
  $ff .= new;
  isa-ok $ff, Gnome::Gtk3::FileFilter, ".new";
}

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

#-------------------------------------------------------------------------------
subtest 'Manipulations', {
  $ff.set-name('text documents');
  is $ff.get-name, 'text documents', '.get-name() / .set-name()';

  lives-ok {
    $ff.add-mime-type('application/x-my-wonderful-script');
    $ff.add-pattern('*.mwscript');
    $ff.add-pixbuf-formats;
  }, '.add-mime-type() / .add-pattern() / .add-pixbuf-formats()';
  
  my Gnome::Glib::Variant() $variant = $ff.to-gvariant;
  ok $variant.is-valid, '.to-gvariant()';
  $ff2 .= new(:$variant);
}

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

=finish


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

    submethod BUILD ( *%options ) {

    }
  }

  my MyClass $mgc .= new;
  isa-ok $mgc, Gnome::Gtk3::FileFilter, 'MyClass.new()';
}

#-------------------------------------------------------------------------------
subtest 'Properties …', {
#  my Gnome::Gtk3::FileFilter $ff .= new;
  my @r = $ff.get-properties(
#    name, type,  …
  );
  is-deeply @r, [
#    value, …
  ], 'properties: ' ~ (
#    name, …
  ).join(', ');
}

#-------------------------------------------------------------------------------
subtest 'Signals …', {
  use Gnome::Gtk3::Main:api<1>;
  use Gnome::N::GlibToRakuTypes:api<1>;

  my Gnome::Gtk3::Main $main .= new;

  class SignalHandlers {
    has Bool $!signal-processed = False;

    method … (
      'any-args',
      Gnome::Gtk3::FileFilter() :$_native-object, gulong :$_handler-id
      # --> …
    ) {

      isa-ok $_native-object, Gnome::Gtk3::FileFilter;
      $!signal-processed = True;
    }

    method signal-emitter ( Gnome::Gtk3::FileFilter :$_widget --> Str ) {

      while $main.gtk-events-pending() { $main.iteration-do(False); }

      $_widget.emit-by-name(
        'signal',
      #  'any-args',
      #  :return-type(int32),
      #  :parameters([int32,])
      );
      is $!signal-processed, True, '\'…\' signal processed';

      while $main.gtk-events-pending() { $main.iteration-do(False); }

      #$!signal-processed = False;
      #$_widget.emit-by-name(
      #  'signal',
      #  'any-args',
      #  :return-type(int32),
      #  :parameters([int32,])
      #);
      #is $!signal-processed, True, '\'…\' signal processed';

      while $main.gtk-events-pending() { $main.iteration-do(False); }
      sleep(0.4);
      $main.gtk-main-quit;

      'done'
    }
  }

  my Gnome::Gtk3::FileFilter $ff .= new;

  #my Gnome::Gtk3::Window $w .= new;
  #$w.add($m);

  my SignalHandlers $sh .= new;
  $ff.register-signal( $sh, 'method', 'signal');

  my Promise $p = $ff.start-thread(
    $sh, 'signal-emitter',
    # :!new-context,
    # :start-time(now + 1)
  );

  is $main.gtk-main-level, 0, "loop level 0";
  $main.gtk-main;
  #is $main.gtk-main-level, 0, "loop level is 0 again";

  is $p.result, 'done', 'emitter finished';
}

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

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


