Testing text handler for a Gtk3::Entry



If I save the following code as test.t and run it with

perl test.t

it segfaults at the signal_emit() call.

How can I test the handler for insert-text?

Regards

Jeff

package MyPackage;

use warnings;
use strict;
use Gtk3 -init;
use Glib 1.220 qw(TRUE FALSE);    # To get TRUE and FALSE

sub new {
    my $self = Gtk3::Dialog->new;
    $self->{'entry-widget'} = Gtk3::Entry->new;
    $self->{'entry-widget'}->signal_connect(
        'insert-text' => \&insert_text_handler, $self );
    return $self
}

sub insert_text_handler {
    my ( $widget, $string, $len, $position, $self ) = @_;

    # only allow integers
    if ( $string =~ /^\d+$/smx ) {
        $widget->signal_handlers_block_by_func( \&insert_text_handler );
        $widget->insert_text( $string, $len, $position++ );
        $widget->signal_handlers_unblock_by_func( \&insert_text_handler );
    }
    $widget->signal_stop_emission_by_name('insert-text');
    return $position;
}

package main;
use warnings;
use strict;
use Test::More tests => 2;

ok( my $dialog = MyPackage->new,  'Created dialog' );

$dialog->{'entry-widget'}->signal_connect_after(
    'insert-text' => sub {
        is( $dialog->get_text, '', 'ignored -' );
        Gtk3->main_quit
    });
$dialog->{'entry-widget'}->signal_emit('insert-text', '-', 1, 0);

Gtk3->main;

__END__

Attachment: signature.asc
Description: OpenPGP digital signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]