File: test-gdk-event.rb

package info (click to toggle)
ruby-gnome2 3.1.0-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 16,072 kB
  • ctags: 17,433
  • sloc: ansic: 93,621; ruby: 62,273; xml: 335; sh: 246; makefile: 25
file content (704 lines) | stat: -rw-r--r-- 13,552 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013-2014  Ruby-GNOME2 Project Team
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

class TestGdkEvent < Test::Unit::TestCase
  class TestConstant < self
    def test_propagate
      assert_false(Gdk::Event::PROPAGATE)
    end

    def test_stop
      assert_true(Gdk::Event::STOP)
    end
  end

  module TestAnyMethods
    def test_window
      assert_nil(event.window)
    end

    def test_send_event
      assert_false(event.send_event?)
    end
  end

  class TestAny < self
    include TestAnyMethods

    def setup
      @event = Gdk::EventAny.new(:delete)
    end

    def event
      @event
    end

    def test_delete
      assert_equal("GDK_DELETE",
                   Gdk::EventAny.new(:delete).event_type.name)
    end

    def test_destroy
      assert_equal("GDK_DESTROY",
                   Gdk::EventAny.new(:destroy).event_type.name)
    end
  end

  class TestKey < self
    include TestAnyMethods

    def setup
      @key = Gdk::EventKey.new(:key_press)
    end

    def event
      @key
    end

    def test_key_press
      assert_equal("GDK_KEY_PRESS",
                   Gdk::EventKey.new(:key_press).event_type.name)
    end

    def test_key_release
      assert_equal("GDK_KEY_RELEASE",
                   Gdk::EventKey.new(:key_release).event_type.name)
    end

    def test_time
      assert_kind_of(Integer, @key.time)
    end

    def test_state
      assert_not_nil(@key.state)
    end

    def test_keyval
      assert_kind_of(Integer, @key.keyval)
    end
  end

  class TestButton < self
    include TestAnyMethods

    def setup
      @button = Gdk::EventButton.new(:button_press)
    end

    def event
      @button
    end

    def test_button_press
      assert_equal("GDK_BUTTON_PRESS",
                   Gdk::EventButton.new(:button_press).event_type.name)
    end

    def test_button2_press
      assert_equal("GDK_2BUTTON_PRESS",
                   Gdk::EventButton.new(:button2_press).event_type.name)
    end

    def test_button3_press
      assert_equal("GDK_3BUTTON_PRESS",
                   Gdk::EventButton.new(:button3_press).event_type.name)
    end

    def test_button_release
      assert_equal("GDK_BUTTON_RELEASE",
                   Gdk::EventButton.new(:button_release).event_type.name)
    end

    def test_time
      assert_kind_of(Integer, @button.time)
    end

    def test_x
      assert_kind_of(Float, @button.x)
    end

    def test_y
      assert_kind_of(Float, @button.y)
    end

    def test_state
      assert_not_nil(@button.state)
    end

    def test_button
      assert_kind_of(Integer, @button.button)
    end

    def test_x_root
      assert_kind_of(Float, @button.x_root)
    end

    def test_y_root
      assert_kind_of(Float, @button.y_root)
    end
  end

  class TestTouch < self
    include TestAnyMethods

    def setup
      @touch = Gdk::EventTouch.new(:touch_begin)
    end

    def event
      @touch
    end

    def test_time
      assert_kind_of(Integer, @touch.time)
    end

    def test_x
      assert_kind_of(Float, @touch.x)
    end

    def test_y
      assert_kind_of(Float, @touch.y)
    end

    def test_axes
      assert_nothing_raised do
        @touch.axes
      end
    end

    def test_state
      assert_not_nil(@touch.state)
    end

    def test_touch_begin
      assert_equal("GDK_TOUCH_BEGIN",
                   Gdk::EventTouch.new(:touch_begin).event_type.name)
    end

    def test_touch_update
      assert_equal("GDK_TOUCH_UPDATE",
                   Gdk::EventTouch.new(:touch_update).event_type.name)
    end

    def test_touch_cancel
      assert_equal("GDK_TOUCH_CANCEL",
                   Gdk::EventTouch.new(:touch_cancel).event_type.name)
    end

    def test_touch_end
      assert_equal("GDK_TOUCH_END",
                   Gdk::EventTouch.new(:touch_end).event_type.name)
    end

    def test_emulating_pointer
      assert_nothing_raised do
        @touch.emulating_pointer
      end
    end

    def test_device
      assert_nothing_raised do
        @touch.device
      end
    end

    def test_x_root
      assert_kind_of(Float, @touch.x_root)
    end

    def test_y_root
      assert_kind_of(Float, @touch.y_root)
    end
  end

  class TestScroll < self
    include TestAnyMethods

    def setup
      @scroll = Gdk::EventScroll.new
    end

    def event
      @scroll
    end

    def test_time
      assert_kind_of(Integer, @scroll.time)
    end

    def test_x
      assert_kind_of(Float, @scroll.x)
    end

    def test_y
      assert_kind_of(Float, @scroll.y)
    end

    def test_state
      assert_not_nil(@scroll.state)
    end

    def test_direction
      assert_kind_of(Gdk::EventScroll::Direction, @scroll.direction)
    end

    def test_x_root
      assert_kind_of(Float, @scroll.x_root)
    end

    def test_y_root
      assert_kind_of(Float, @scroll.y_root)
    end
  end

  class TestMotion < self
    include TestAnyMethods

    def setup
      @motion = Gdk::EventMotion.new
    end

    def event
      @motion
    end

    def test_time
      assert_kind_of(Integer, @motion.time)
    end

    def test_x
      assert_kind_of(Float, @motion.x)
    end

    def test_y
      assert_kind_of(Float, @motion.y)
    end

    def test_state
      assert_not_nil(@motion.state)
    end

    def test_x_root
      assert_kind_of(Float, @motion.x_root)
    end

    def test_y_root
      assert_kind_of(Float, @motion.y_root)
    end

    def test_request
      assert_nothing_raised do
        @motion.request
      end
    end
  end

  class TestVisibility < self
    include TestAnyMethods

    def setup
      @visibility = Gdk::EventVisibility.new(:visibility_notify)
    end

    def event
      @visibility
    end

    def test_state
      assert_kind_of(Gdk::EventVisibility::State, @visibility.state)
    end
  end

  class TestCrossing < self
    include TestAnyMethods

    def setup
      @crossing = Gdk::EventCrossing.new(:enter_notify)
    end

    def event
      @crossing
    end

    def test_enter_notify
      assert_equal("GDK_ENTER_NOTIFY",
                   Gdk::EventCrossing.new(:enter_notify).event_type.name)
    end

    def test_leave_notify
      assert_equal("GDK_LEAVE_NOTIFY",
                   Gdk::EventCrossing.new(:leave_notify).event_type.name)
    end

    def test_time
      assert_kind_of(Integer, @crossing.time)
    end

    def test_x
      # TODO: Is Float better?
      assert_kind_of(Integer, @crossing.x)
    end

    def test_y
      # TODO: Is Float better?
      assert_kind_of(Integer, @crossing.y)
    end

    def test_x_root
      assert_kind_of(Float, @crossing.x_root)
    end

    def test_y_root
      assert_kind_of(Float, @crossing.y_root)
    end

    def test_mode
      assert_kind_of(Gdk::EventCrossing::Mode, @crossing.mode)
    end

    def test_detail
      assert_not_nil(@crossing.detail)
    end

    def test_state
      assert_not_nil(@crossing.state)
    end
  end

  class TestFocus < self
    include TestAnyMethods

    def setup
      @focus = Gdk::EventFocus.new
    end

    def event
      @focus
    end

    def test_in
      assert_false(@focus.in?)
    end
  end

  class TestConfigure < self
    include TestAnyMethods

    def setup
      @configure = Gdk::EventConfigure.new
    end

    def event
      @configure
    end

    def test_x
      assert_kind_of(Integer, @configure.x)
    end

    def test_y
      assert_kind_of(Integer, @configure.y)
    end

    def test_width
      assert_kind_of(Integer, @configure.width)
    end

    def test_height
      assert_kind_of(Integer, @configure.height)
    end
  end

  class TestProperty < self
    include TestAnyMethods

    def setup
      @property = Gdk::EventProperty.new
    end

    def event
      @property
    end

    def test_atom
      assert_nothing_raised do
        @property.atom
      end
    end

    def test_time
      assert_kind_of(Integer, @property.time)
    end

    def test_state
      assert_equal(Gdk::EventProperty::State::NEW_VALUE, @property.state)
    end
  end

  class TestSelection < self
    include TestAnyMethods

    def setup
      @selection = Gdk::EventSelection.new(:selection_clear)
    end

    def event
      @selection
    end

    def test_selection_clear
      assert_equal("GDK_SELECTION_CLEAR",
                   Gdk::EventSelection.new(:selection_clear).event_type.name)
    end

    def test_selection_notify
      assert_equal("GDK_SELECTION_NOTIFY",
                   Gdk::EventSelection.new(:selection_notify).event_type.name)
    end

    def test_selection_request
      assert_equal("GDK_SELECTION_REQUEST",
                   Gdk::EventSelection.new(:selection_request).event_type.name)
    end

    def test_selection
      assert_nothing_raised do
        @selection.selection
      end
    end

    def test_target
      assert_nothing_raised do
        @selection.target
      end
    end

    def test_property
      assert_nothing_raised do
        @selection.property
      end
    end

    def test_time
      assert_kind_of(Integer, @selection.time)
    end
  end

  class TestDND < self
    include TestAnyMethods

    def setup
      @dnd = Gdk::EventDND.new(:drag_enter)
    end

    def event
      @dnd
    end

    def test_drag_enter
      assert_equal("GDK_DRAG_ENTER",
                   Gdk::EventDND.new(:drag_enter).event_type.name)
    end

    def test_drag_leave
      assert_equal("GDK_DRAG_LEAVE",
                   Gdk::EventDND.new(:drag_leave).event_type.name)
    end

    def test_drag_motion
      assert_equal("GDK_DRAG_MOTION",
                   Gdk::EventDND.new(:drag_motion).event_type.name)
    end

    def test_drag_status
      assert_equal("GDK_DRAG_STATUS",
                   Gdk::EventDND.new(:drag_status).event_type.name)
    end

    def test_drop_start
      assert_equal("GDK_DROP_START",
                   Gdk::EventDND.new(:drop_start).event_type.name)
    end

    def test_drop_finished
      assert_equal("GDK_DROP_FINISHED",
                   Gdk::EventDND.new(:drop_finished).event_type.name)
    end

    def test_context
      assert_nothing_raised do
        @dnd.context
      end
    end

    def test_time
      assert_kind_of(Integer, @dnd.time)
    end

    def test_x_root
      assert_kind_of(Integer, @dnd.x_root)
    end

    def test_y_root
      assert_kind_of(Integer, @dnd.y_root)
    end
  end

  class TestProximity < self
    include TestAnyMethods

    def setup
      @proximity = Gdk::EventProximity.new(:proximity_in)
    end

    def event
      @proximity
    end

    def test_proximity_in
      assert_equal("GDK_PROXIMITY_IN",
                   Gdk::EventProximity.new(:proximity_in).event_type.name)
    end

    def test_proximity_out
      assert_equal("GDK_PROXIMITY_OUT",
                   Gdk::EventProximity.new(:proximity_out).event_type.name)
    end

    def test_time
      assert_kind_of(Integer, @proximity.time)
    end

    def test_device
      assert_nothing_raised do
        @proximity.device
      end
    end
  end

  class TestWindowState < self
    include TestAnyMethods

    def setup
      @window_state = Gdk::EventWindowState.new
    end

    def event
      @window_state
    end

    def test_changed_mask
      assert_nothing_raised do
        @window_state.changed_mask
      end
    end

    def test_new_window_state
      assert_nothing_raised do
        @window_state.new_window_state
      end
    end
  end

  class TestSetting < self
    include TestAnyMethods

    def setup
      @setting = Gdk::EventSetting.new
    end

    def event
      @setting
    end

    def test_action
      assert_nothing_raised do
        @setting.action
      end
    end

    def test_name
      assert_nothing_raised do
        @setting.name
      end
    end
  end

  class TestOwnerChange < self
    def setup
      @owner_change = Gdk::EventOwnerChange.new
    end

    def event
      @owner_change
    end

    def test_owner
      assert_nothing_raised do
        @owner_change.owner
      end
    end

    def test_reason
      assert_nothing_raised do
        @owner_change.reason
      end
    end

    def test_selection
      assert_nothing_raised do
        @owner_change.selection
      end
    end

    def test_time
      assert_kind_of(Integer, @owner_change.time)
    end

    def test_selection_time
      assert_kind_of(Integer, @owner_change.selection_time)
    end
  end

  class TestGrabBroken < self
    include TestAnyMethods

    def setup
      @grab_broken = Gdk::EventGrabBroken.new
    end

    def event
      @grab_broken
    end

    def test_keyboard
      assert_boolean(@grab_broken.keyboard?)
    end

    def test_implicit
      assert_boolean(@grab_broken.implicit?)
    end

    def test_grab_window
      assert_nothing_raised do
        @grab_broken.grab_window
      end
    end
  end
end