"Fossies" - the Fresh Open Source Software Archive

Member "Gtk3-0.035/t/zz-GdkEvent.t" (1 May 2019, 14059 Bytes) of package /linux/privat/Gtk3-0.035.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "zz-GdkEvent.t": 0.030_vs_0.031.

    1 #!/usr/bin/perl
    2 
    3 # Originally copied from Gtk2/t/GdkEvent.t.
    4 
    5 BEGIN { require './t/inc/setup.pl' }
    6 
    7 use strict;
    8 use warnings;
    9 
   10 plan tests => 146;
   11 
   12 sub fields_ok {
   13   my ($event, %fields_values) = @_;
   14   foreach my $field (keys %fields_values) {
   15     field_ok ($event, $field, $fields_values{$field});
   16   }
   17 }
   18 
   19 sub field_ok {
   20   my ($event, $field, $value) = @_;
   21   $event->$field ($value);
   22   is ($event->$field, $value);
   23 }
   24 
   25 # Any #########################################################################
   26 
   27 isa_ok (my $event = Gtk3::Gdk::Event->new ('enter-notify'),
   28     'Gtk3::Gdk::Event', 'Gtk3::Gdk::Event->new any');
   29 
   30 isa_ok ($event->copy, 'Gtk3::Gdk::Event');
   31 
   32 is ($event->type, 'enter-notify');
   33 
   34 my $window = Gtk3::Gdk::Window->new (undef, {
   35             width => 20,
   36             height => 20,
   37             window_type => 'toplevel'
   38         });
   39 field_ok ($event, window => $window);
   40 field_ok ($event, window => undef);
   41 field_ok ($event, send_event => 23);
   42 
   43 my $screen = Gtk3::Gdk::Screen::get_default;
   44 $event->set_screen ($screen);
   45 is ($event->get_screen, $screen, '$event->get_screen');
   46 
   47 my $device = Gtk3::Gdk::Display::get_default->list_devices->[0]; # FIXME?
   48 $event->set_device ($device);
   49 is ($event->get_device, $device, '$event->get_device');
   50 
   51 $event->set_source_device ($device);
   52 is ($event->get_source_device, $device, '$event->get_source_device');
   53 
   54 # Expose #######################################################################
   55 
   56 isa_ok ($event = Gtk3::Gdk::Event->new ('expose'),
   57     'Gtk3::Gdk::EventExpose', 'Gtk3::Gdk::Event->new expose');
   58 
   59 field_ok ($event, count => 10);
   60 
   61 my $rect = {x => 0, y => 0, width => 100, height => 100}; # FIXME: [0, 0, 100, 100]
   62 $event->area ($rect);
   63 is_deeply ($event->area, $rect, '$expose_event->area');
   64 
   65 my $region = Cairo::Region->create ($rect);
   66 $event->region ($region);
   67 isa_ok ($event->region, 'Cairo::Region', '$expose_event->region');
   68 is_deeply ($event->region->get_rectangle (0), $rect);
   69 $event->region (undef);
   70 is ($event->region, undef, '$expose_event->region undef');
   71 
   72 # Visibility ###################################################################
   73 
   74 isa_ok ($event = Gtk3::Gdk::Event->new ('visibility-notify'),
   75     'Gtk3::Gdk::EventVisibility', 'Gtk3::Gdk::Event->new visibility');
   76 
   77 field_ok ($event, state => 'partial');
   78 
   79 # Motion #######################################################################
   80 
   81 isa_ok ($event = Gtk3::Gdk::Event->new ('motion-notify'),
   82     'Gtk3::Gdk::EventMotion', 'Gtk3::Gdk::Event->new motion');
   83 
   84 fields_ok ($event, time => 42,
   85                    x => 13,
   86                    y => 14,
   87                    x_root => 15,
   88                    y_root => 16,
   89                    state => [qw/shift-mask control-mask/],
   90                    is_hint => 2);
   91 
   92 # FIXME: $event->axes not accessible currently
   93 
   94 field_ok ($event, device => $device);
   95 field_ok ($event, device => undef);
   96 
   97 is ($event->get_time, 42, '$event->get_time');
   98 # FIXME: special case for get_time()
   99 # is (Gtk3::Gdk::Event::get_time (undef), 0,
  100 #     "get_time with no event gets GDK_CURRENT_TIME, which is 0");
  101 
  102 is ($event->get_state, [qw/shift-mask control-mask/], '$event->get_state');
  103 
  104 is_deeply ([$event->get_coords], [13, 14], '$event->get_coords');
  105 
  106 is_deeply ([$event->get_root_coords], [15, 16], '$event->get_root_coords');
  107 
  108 is ($event->get_axis ("x"), 13);
  109 
  110 $event = Gtk3::Gdk::Event->new ('motion-notify');
  111 $event->device ($device);
  112 $event->window ($window);
  113 
  114 SKIP: {
  115   skip 'request_motions; missing annotations', 0
  116     unless Gtk3::CHECK_VERSION(3, 2, 0);
  117   $event->request_motions;
  118 }
  119 
  120 # Button #######################################################################
  121 
  122 foreach (qw/3button-press
  123             2button-press
  124             button-press/)
  125 {
  126   isa_ok ($event = Gtk3::Gdk::Event->new ($_),
  127           'Gtk3::Gdk::EventButton', "Gtk3::Gdk::Event->new $_");
  128 }
  129 
  130 SKIP: {
  131   skip 'aliases', 2
  132     unless Gtk3::CHECK_VERSION (3, 6, 0);
  133   foreach (qw/triple-button-press
  134               double-button-press/)
  135   {
  136     isa_ok ($event = Gtk3::Gdk::Event->new ($_),
  137             'Gtk3::Gdk::EventButton', "Gtk3::Gdk::Event->new $_");
  138   }
  139 }
  140 
  141 $event = Gtk3::Gdk::Event->new ('button-press');
  142 fields_ok ($event, time => 42,
  143                    x => 13,
  144                    y => 14,
  145                    x_root => 15,
  146                    y_root => 16,
  147                    state => [qw/shift-mask control-mask/],
  148                    button => 2);
  149 
  150 # FIXME: $event->axes not accessible currently
  151 
  152 field_ok ($event, device => $device);
  153 field_ok ($event, device => undef);
  154 
  155 SKIP: {
  156   skip 'get_button&get_click_count; new in 3.2', 2
  157     unless Gtk3::CHECK_VERSION(3, 2, 0);
  158 
  159   is ($event->get_button, 2);
  160   is ($event->get_click_count, 1);
  161 }
  162 
  163 # Scroll #######################################################################
  164 
  165 isa_ok ($event = Gtk3::Gdk::Event->new ('scroll'),
  166     'Gtk3::Gdk::EventScroll', 'Gtk3::Gdk::Event->new scroll');
  167 
  168 fields_ok ($event, time => 42,
  169                    x => 13,
  170                    y => 14,
  171                    x_root => 15,
  172                    y_root => 16,
  173                    state => [qw/shift-mask control-mask/],
  174                    direction => 'down');
  175 
  176 field_ok ($event, device => $device);
  177 field_ok ($event, device => undef);
  178 
  179 SKIP: {
  180   skip 'new 3.4 stuff', 2
  181     unless Gtk3::CHECK_VERSION(3, 4, 0);
  182 
  183   $event->delta_x (17);
  184   $event->delta_y (18);
  185 
  186   is ($event->get_scroll_direction, 'down');
  187 
  188   #  <https://bugzilla.gnome.org/show_bug.cgi?id=677774>
  189   skip 'direction&get_scroll_deltas; missing annotations', 1
  190     unless Gtk3::CHECK_VERSION(3, 6, 0);
  191   $event->direction ('smooth');
  192   is_deeply ([$event->get_scroll_deltas], [17, 18]);
  193 }
  194 
  195 # Key ##########################################################################
  196 
  197 isa_ok ($event = Gtk3::Gdk::Event->new ('key-press'),
  198     'Gtk3::Gdk::EventKey', 'Gtk3::Gdk::Event->new key');
  199 
  200 fields_ok ($event, time => 42,
  201                    state => [qw/shift-mask control-mask/],
  202                    keyval => 44,
  203                    hardware_keycode => 10,
  204                    group => 11,
  205                    is_modifier => Glib::TRUE);
  206 
  207 SKIP: {
  208   skip 'keycode&keyval; new in 3.2', 2
  209     unless Gtk3::CHECK_VERSION(3, 2, 0);
  210 
  211   is ($event->get_keycode, 10);
  212   is ($event->get_keyval, 44);
  213 }
  214 
  215 # Crossing #####################################################################
  216 
  217 isa_ok ($event = Gtk3::Gdk::Event->new ('enter-notify'),
  218     'Gtk3::Gdk::EventCrossing', 'Gtk3::Gdk::Event->new crossing');
  219 
  220 fields_ok ($event, time => 42,
  221                    x => 13,
  222                    y => 14,
  223                    x_root => 15,
  224                    y_root => 16,
  225                    mode => 'grab',
  226                    detail => 'nonlinear',
  227                    focus => Glib::TRUE,
  228                    state => [qw/shift-mask control-mask/]);
  229 
  230 field_ok ($event, subwindow => $window);
  231 field_ok ($event, subwindow => undef);
  232 
  233 # Focus ########################################################################
  234 
  235 isa_ok ($event = Gtk3::Gdk::Event->new ('focus-change'),
  236     'Gtk3::Gdk::EventFocus', 'Gtk3::Gdk::Event->new focus');
  237 
  238 fields_ok ($event, in => 10);
  239 
  240 # Configure ####################################################################
  241 
  242 isa_ok ($event = Gtk3::Gdk::Event->new ('configure'),
  243     'Gtk3::Gdk::EventConfigure', 'Gtk3::Gdk::Event->new configure');
  244 
  245 fields_ok ($event, x => 13,
  246                    y => 14,
  247                    width => 10,
  248                    height => 10);
  249 
  250 # Property #####################################################################
  251 
  252 isa_ok ($event = Gtk3::Gdk::Event->new ('property-notify'),
  253     'Gtk3::Gdk::EventProperty', 'Gtk3::Gdk::Event->new property');
  254 
  255 fields_ok ($event, time => 42);
  256 
  257 SKIP: {
  258   skip 'atom stuff; missing annotations', 3
  259     unless Gtk3::CHECK_VERSION(3, 2, 0);
  260 
  261   my $atom = Gtk3::Gdk::Atom::intern ('foo', Glib::FALSE);
  262   $event->atom ($atom);
  263   isa_ok ($event->atom, 'Gtk3::Gdk::Atom', '$property_event->atom');
  264   is ($event->atom->name, $atom->name, '$property_event->atom');
  265   $event->atom (undef);
  266   is ($event->atom, undef);
  267 }
  268 
  269 SKIP: {
  270   # <https://bugzilla.gnome.org/show_bug.cgi?id=677775>
  271   skip 'state accessor; missing annotations', 1
  272     unless Gtk3::CHECK_VERSION (3, 6, 0);
  273   field_ok ($event, state => 'new-value');
  274 }
  275 
  276 # Proximity ####################################################################
  277 
  278 isa_ok ($event = Gtk3::Gdk::Event->new ('proximity-in'),
  279     'Gtk3::Gdk::EventProximity', 'Gtk3::Gdk::Event->new proximity');
  280 
  281 fields_ok ($event, time => 42);
  282 
  283 field_ok ($event, device => $device);
  284 field_ok ($event, device => undef);
  285 
  286 # Setting ######################################################################
  287 
  288 isa_ok ($event = Gtk3::Gdk::Event->new ('setting'),
  289     'Gtk3::Gdk::EventSetting', 'Gtk3::Gdk::Event->new setting');
  290 
  291 fields_ok ($event, action => 'new');
  292 
  293 # FIXME: $event->name not accessible currently
  294 
  295 # WindowState ##################################################################
  296 
  297 isa_ok ($event = Gtk3::Gdk::Event->new ('window-state'),
  298     'Gtk3::Gdk::EventWindowState', 'Gtk3::Gdk::Event->new windowstate');
  299 
  300 fields_ok ($event, changed_mask => [qw/withdrawn above/],
  301                    new_window_state => [qw/maximized sticky/]);
  302 
  303 # DND ##########################################################################
  304 
  305 isa_ok ($event = Gtk3::Gdk::Event->new ('drag-enter'),
  306     'Gtk3::Gdk::EventDND', 'Gtk3::Gdk::Event->new dnd');
  307 
  308 fields_ok ($event, time => 42,
  309                    x_root => 15,
  310                    y_root => 16);
  311 
  312 my $drag_context = Gtk3::Gdk::DragContext->new;
  313 field_ok ($event, context => $drag_context);
  314 field_ok ($event, context => undef);
  315 
  316 # Selection ####################################################################
  317 
  318 isa_ok ($event = Gtk3::Gdk::Event->new ('selection-clear'),
  319     'Gtk3::Gdk::EventSelection', 'Gtk3::Gdk::Event->new selection');
  320 
  321 fields_ok ($event, time => 42);
  322 
  323 SKIP: {
  324   skip 'atom stuff; missing annotations', 3
  325     unless Gtk3::CHECK_VERSION(3, 2, 0);
  326 
  327   my $atom = Gtk3::Gdk::Atom::intern ('foo', Glib::FALSE);
  328   $event->property ($atom);
  329   is ($event->property->name, $atom->name);
  330   $event->selection ($atom);
  331   is ($event->selection->name, $atom->name);
  332   $event->target ($atom);
  333   is ($event->target->name, $atom->name);
  334 }
  335 
  336 field_ok ($event, requestor => $window);
  337 field_ok ($event, requestor => undef);
  338 
  339 # OwnerChange ##################################################################
  340 
  341 isa_ok ($event = Gtk3::Gdk::Event->new ("owner-change"),
  342     "Gtk3::Gdk::EventOwnerChange");
  343 
  344 fields_ok ($event, reason => 'destroy',
  345                    time => 42,
  346                    selection_time => 42);
  347 
  348 field_ok ($event, owner => $window);
  349 field_ok ($event, owner => undef);
  350 
  351 SKIP: {
  352   skip 'atom stuff; missing annotations', 1
  353     unless Gtk3::CHECK_VERSION(3, 2, 0);
  354 
  355   my $atom = Gtk3::Gdk::Atom::intern ('foo', Glib::FALSE);
  356   $event->selection ($atom);
  357   is ($event->selection->name, $atom->name);
  358 }
  359 
  360 # GrabBroken ##################################################################
  361 
  362 isa_ok ($event = Gtk3::Gdk::Event->new ("grab-broken"),
  363     "Gtk3::Gdk::EventGrabBroken");
  364 
  365 fields_ok ($event, keyboard => Glib::TRUE,
  366                    implicit => Glib::FALSE);
  367 
  368 field_ok ($event, grab_window => $window);
  369 field_ok ($event, grab_window => undef);
  370 
  371 # Touch #######################################################################
  372 
  373 SKIP: {
  374   skip 'touch stuff; new in 3.4', 10
  375     unless Gtk3::CHECK_VERSION(3, 4, 0);
  376 
  377   isa_ok ($event = Gtk3::Gdk::Event->new ("touch-begin"),
  378           "Gtk3::Gdk::EventTouch");
  379 
  380   fields_ok ($event, time => 42,
  381                      x => 13, y => 14,
  382                      x_root => 15, y_root => 16,
  383                      state => [qw/shift-mask control-mask/],
  384                      emulating_pointer => Glib::TRUE);
  385 
  386   field_ok ($event, device => $device);
  387   field_ok ($event, device => undef);
  388 
  389   # FIXME: $event->axes not usable currently
  390 
  391   # FIXME: $event->sequence and get_event_sequence not usable currently
  392 }
  393 
  394 # Misc. #######################################################################
  395 
  396 SKIP: {
  397   skip 'misc. stuff; missing annotations', 4
  398     unless Gtk3::CHECK_VERSION(3, 2, 0);
  399 
  400   # First, clear all pending events.
  401   Gtk3::main_iteration while Gtk3::events_pending;
  402 
  403   # Then add our own.
  404   my $event = Gtk3::Gdk::Event->new ('button-press');
  405   $event->put;
  406   ok (Gtk3::Gdk::events_pending);
  407   isa_ok (Gtk3::Gdk::Event::get (), 'Gtk3::Gdk::EventButton');
  408 
  409   my $i_know_you = 0;
  410   Gtk3::Gdk::Event::handler_set (sub {
  411     return if $i_know_you++;
  412     my ($cb_event, $data) = @_;
  413     isa_ok ($cb_event, 'Gtk3::Gdk::EventButton');
  414     # pass to gtk+ default handler
  415     Gtk3::main_do_event ($cb_event);
  416   });
  417 
  418   $event->put;
  419   Gtk3::main_iteration while Gtk3::events_pending;
  420 
  421   # reset
  422   Gtk3::Gdk::Event::handler_set (undef);
  423 
  424   Gtk3::Gdk::set_show_events (Glib::FALSE);
  425   ok (!Gtk3::Gdk::get_show_events);
  426 }
  427 
  428 # Test that our custom event handling does not break callback marshalling due
  429 # to incorrect handling of the perl stack.
  430 {
  431   my $widget = Gtk3::Label->new ('Test');
  432   $widget->signal_connect (key_press_event => sub {
  433     my ($cb_widget, $cb_event) = @_;
  434     is ($cb_widget, $widget);
  435     isa_ok ($cb_event, 'Gtk3::Gdk::EventKey');
  436     is ($cb_event->keyval, 44);
  437     Glib::TRUE;
  438   });
  439   my $event = Gtk3::Gdk::Event->new ('key-press');
  440   $event->keyval (44);
  441   $widget->signal_emit (key_press_event => $event);
  442 }
  443 
  444 SKIP: {
  445   skip 'new 3.4 stuff', 1
  446     unless Gtk3::CHECK_VERSION (3, 4, 0);
  447   my $event = Gtk3::Gdk::Event->new ('button-press');
  448   $event->button (Gtk3::Gdk::BUTTON_SECONDARY ());
  449   $event->window ($window);
  450   ok ($event->triggers_context_menu);
  451 }
  452 
  453 # FIXME: gdk_events_get_angle, gdk_events_get_center, gdk_events_get_distance
  454 # are misbound
  455 # {
  456 #   my $event1 = Gtk3::Gdk::Event->new ('button-press');
  457 #   $event1->x (1); $event1->y (0);
  458 #   my $event2 = Gtk3::Gdk::Event->new ('button-press');
  459 #   $event2->x (0); $event2->y (1);
  460 #   warn join ', ', $event1->_get_angle ($event2);
  461 #   warn join ', ', $event1->_get_center ($event2);
  462 #   warn join ', ', $event1->_get_distance ($event2);
  463 # }
  464 
  465 __END__
  466 
  467 Copyright (C) 2003-2012 by the gtk2-perl team (see the file AUTHORS for the
  468 full list).  See LICENSE for more information.