gir_ffi 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -0
- data/Rakefile +0 -18
- data/TODO.rdoc +1 -1
- data/lib/gir_ffi/arg_helper.rb +165 -35
- data/lib/gir_ffi/builder.rb +4 -3
- data/lib/gir_ffi/class_base.rb +11 -3
- data/lib/gir_ffi/class_builder.rb +49 -35
- data/lib/gir_ffi/function_definition_builder.rb +194 -64
- data/lib/gir_ffi/i_arg_info.rb +3 -0
- data/lib/gir_ffi/i_callback_info.rb +1 -1
- data/lib/gir_ffi/i_interface_info.rb +67 -2
- data/lib/gir_ffi/i_repository.rb +5 -0
- data/lib/gir_ffi/lib.rb +22 -1
- data/lib/gir_ffi/module_builder.rb +1 -0
- data/lib/gir_ffi/overrides/gobject.rb +16 -13
- data/lib/gir_ffi/overrides/gtk.rb +1 -1
- data/tasks/notes.rake +12 -25
- data/tasks/setup.rb +0 -132
- data/tasks/test.rake +4 -12
- data/test/arg_helper_test.rb +25 -7
- data/test/builder_test.rb +36 -21
- data/test/class_base_test.rb +0 -7
- data/test/class_builder_test.rb +6 -0
- data/test/everything_test.rb +427 -1
- data/test/function_definition_builder_test.rb +69 -12
- data/test/gobject_overrides_test.rb +12 -3
- data/test/test_helper.rb +5 -0
- metadata +8 -10
- data/tasks/bones.rake +0 -87
- data/tasks/post_load.rake +0 -25
data/test/everything_test.rb
CHANGED
@@ -14,6 +14,8 @@ class EverythingTest < Test::Unit::TestCase
|
|
14
14
|
context "The generated Everything module" do
|
15
15
|
setup do
|
16
16
|
GirFFI.setup :Everything
|
17
|
+
GirFFI.setup :GObject
|
18
|
+
GirFFI.setup :GLib
|
17
19
|
end
|
18
20
|
|
19
21
|
context "the Everything::TestBoxed class" do
|
@@ -40,7 +42,7 @@ class EverythingTest < Test::Unit::TestCase
|
|
40
42
|
assert_equal 54, tb[:some_int8]
|
41
43
|
end
|
42
44
|
|
43
|
-
should "have non-zero result for #get_gtype" do
|
45
|
+
should "have non-zero positive result for #get_gtype" do
|
44
46
|
assert Everything::TestBoxed.get_gtype > 0
|
45
47
|
end
|
46
48
|
|
@@ -176,6 +178,10 @@ class EverythingTest < Test::Unit::TestCase
|
|
176
178
|
@o.instance_method_callback Proc.new { a = 2 }
|
177
179
|
assert_equal 2, a
|
178
180
|
end
|
181
|
+
|
182
|
+
should "not respond to #static_method" do
|
183
|
+
assert_raises(NoMethodError) { @o.static_method 1 }
|
184
|
+
end
|
179
185
|
end
|
180
186
|
end
|
181
187
|
|
@@ -271,13 +277,31 @@ class EverythingTest < Test::Unit::TestCase
|
|
271
277
|
assert_instance_of Everything::TestWi8021x, o
|
272
278
|
end
|
273
279
|
|
280
|
+
should "have a working #static_method" do
|
281
|
+
assert_equal(-84, Everything::TestWi8021x.static_method(-42))
|
282
|
+
end
|
283
|
+
|
274
284
|
context "an instance" do
|
275
285
|
setup do
|
276
286
|
@obj = Everything::TestWi8021x.new
|
277
287
|
end
|
288
|
+
|
278
289
|
should "set its boolean struct member with #set_testbool" do
|
279
290
|
@obj.set_testbool true
|
280
291
|
assert_equal 1, @obj[:testbool]
|
292
|
+
@obj.set_testbool false
|
293
|
+
assert_equal 0, @obj[:testbool]
|
294
|
+
end
|
295
|
+
|
296
|
+
should "get its boolean struct member with #get_testbool" do
|
297
|
+
@obj[:testbool] = 0
|
298
|
+
assert_equal false, @obj.get_testbool
|
299
|
+
@obj[:testbool] = 1
|
300
|
+
assert_equal true, @obj.get_testbool
|
301
|
+
end
|
302
|
+
|
303
|
+
should "get its boolean struct member with #get_property" do
|
304
|
+
@obj[:testbool] = 1
|
281
305
|
gv = GObject::Value.new
|
282
306
|
gv.init GObject.type_from_name "gboolean"
|
283
307
|
@obj.get_property "testbool", gv
|
@@ -286,16 +310,145 @@ class EverythingTest < Test::Unit::TestCase
|
|
286
310
|
end
|
287
311
|
end
|
288
312
|
|
313
|
+
# set_abort_on_error
|
314
|
+
|
315
|
+
context "test_array_fixed_size_int_in" do
|
316
|
+
should "return the correct result" do
|
317
|
+
assert_equal 5 + 4 + 3 + 2 + 1, Everything.test_array_fixed_size_int_in([5, 4, 3, 2, 1])
|
318
|
+
end
|
319
|
+
|
320
|
+
should "raise an error when called with the wrong number of arguments" do
|
321
|
+
assert_raises ArgumentError do
|
322
|
+
Everything.test_array_fixed_size_int_in [2]
|
323
|
+
end
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
should "have correct test_array_fixed_size_int_out" do
|
328
|
+
assert_equal [0, 1, 2, 3, 4], Everything.test_array_fixed_size_int_out
|
329
|
+
end
|
330
|
+
|
331
|
+
should "have correct test_array_fixed_size_int_return" do
|
332
|
+
assert_equal [0, 1, 2, 3, 4], Everything.test_array_fixed_size_int_return
|
333
|
+
end
|
334
|
+
|
335
|
+
should "have correct test_array_gint16_in" do
|
336
|
+
assert_equal 5 + 4 + 3, Everything.test_array_gint16_in([5, 4, 3])
|
337
|
+
end
|
338
|
+
|
339
|
+
should "have correct test_array_gint32_in" do
|
340
|
+
assert_equal 5 + 4 + 3, Everything.test_array_gint32_in([5, 4, 3])
|
341
|
+
end
|
342
|
+
|
343
|
+
should "have correct test_array_gint64_in" do
|
344
|
+
assert_equal 5 + 4 + 3, Everything.test_array_gint64_in([5, 4, 3])
|
345
|
+
end
|
346
|
+
|
347
|
+
should "have correct test_array_gint8_in" do
|
348
|
+
assert_equal 5 + 4 + 3, Everything.test_array_gint8_in([5, 4, 3])
|
349
|
+
end
|
350
|
+
|
351
|
+
should "have correct test_array_gtype_in" do
|
352
|
+
t1 = GObject.type_from_name "gboolean"
|
353
|
+
t2 = GObject.type_from_name "gint64"
|
354
|
+
assert_equal "[gboolean,gint64,]", Everything.test_array_gtype_in([t1, t2])
|
355
|
+
end
|
356
|
+
|
357
|
+
should "have correct test_array_int_full_out" do
|
358
|
+
assert_equal [0, 1, 2, 3, 4], Everything.test_array_int_full_out
|
359
|
+
end
|
360
|
+
|
361
|
+
should "have correct test_array_int_in" do
|
362
|
+
assert_equal 5 + 4 + 3, Everything.test_array_int_in([5, 4, 3])
|
363
|
+
end
|
364
|
+
|
365
|
+
should "have correct test_array_int_in_take" do
|
366
|
+
assert_equal 5 + 4 + 3, Everything.test_array_int_in_take([5, 4, 3])
|
367
|
+
end
|
368
|
+
|
369
|
+
should "have correct test_array_int_inout" do
|
370
|
+
assert_equal [3, 4], Everything.test_array_int_inout([5, 2, 3])
|
371
|
+
end
|
372
|
+
|
373
|
+
should "have correct test_array_int_none_out" do
|
374
|
+
assert_equal [1, 2, 3, 4, 5], Everything.test_array_int_none_out
|
375
|
+
end
|
376
|
+
|
377
|
+
should "have correct test_array_int_null_in" do
|
378
|
+
assert_nothing_raised { Everything.test_array_int_null_in nil }
|
379
|
+
end
|
380
|
+
|
381
|
+
should "have correct test_array_int_null_out" do
|
382
|
+
assert_equal nil, Everything.test_array_int_null_out
|
383
|
+
end
|
384
|
+
|
385
|
+
should "have correct test_array_int_out" do
|
386
|
+
assert_equal [0, 1, 2, 3, 4], Everything.test_array_int_out
|
387
|
+
end
|
388
|
+
|
389
|
+
should "have correct test_async_ready_callback" do
|
390
|
+
a = 1
|
391
|
+
main_loop = GLib.main_loop_new nil, false
|
392
|
+
|
393
|
+
Everything.test_async_ready_callback Proc.new {
|
394
|
+
GLib.main_loop_quit main_loop
|
395
|
+
a = 2
|
396
|
+
}
|
397
|
+
|
398
|
+
GLib.main_loop_run main_loop
|
399
|
+
|
400
|
+
assert_equal 2, a
|
401
|
+
end
|
402
|
+
|
289
403
|
should "have correct test_boolean" do
|
290
404
|
assert_equal false, Everything.test_boolean(false)
|
291
405
|
assert_equal true, Everything.test_boolean(true)
|
292
406
|
end
|
293
407
|
|
408
|
+
should "have correct test_boolean_false" do
|
409
|
+
assert_equal false, Everything.test_boolean(false)
|
410
|
+
end
|
411
|
+
|
412
|
+
should "have correct test_boolean_true" do
|
413
|
+
assert_equal true, Everything.test_boolean(true)
|
414
|
+
end
|
415
|
+
|
416
|
+
should "have correct test_cairo_context_full_return"
|
417
|
+
should "have correct test_cairo_context_none_in"
|
418
|
+
should "have correct test_cairo_surface_full_out"
|
419
|
+
should "have correct test_cairo_surface_full_return"
|
420
|
+
should "have correct test_cairo_surface_none_in"
|
421
|
+
should "have correct test_cairo_surface_none_return"
|
422
|
+
|
294
423
|
should "have correct test_callback" do
|
295
424
|
result = Everything.test_callback Proc.new { 5 }
|
296
425
|
assert_equal 5, result
|
297
426
|
end
|
298
427
|
|
428
|
+
should "have correct test_callback_async" do
|
429
|
+
a = 1
|
430
|
+
Everything.test_callback_async Proc.new {|b|
|
431
|
+
a = 2
|
432
|
+
b
|
433
|
+
}, 44
|
434
|
+
r = Everything.test_callback_thaw_async
|
435
|
+
assert_equal 44, r
|
436
|
+
assert_equal 2, a
|
437
|
+
end
|
438
|
+
|
439
|
+
should "have correct test_callback_destroy_notify" do
|
440
|
+
a = 1
|
441
|
+
r1 = Everything.test_callback_destroy_notify Proc.new {|b|
|
442
|
+
a = 2
|
443
|
+
b
|
444
|
+
}, 42, Proc.new { a = 3 }
|
445
|
+
assert_equal 2, a
|
446
|
+
assert_equal 42, r1
|
447
|
+
r2 = Everything.test_callback_thaw_notifications
|
448
|
+
assert_equal 3, a
|
449
|
+
assert_equal 42, r2
|
450
|
+
end
|
451
|
+
|
299
452
|
context "the test_callback_user_data function" do
|
300
453
|
should "return the callbacks return value" do
|
301
454
|
result = Everything.test_callback_user_data Proc.new {|u| 5 }, nil
|
@@ -312,11 +465,284 @@ class EverythingTest < Test::Unit::TestCase
|
|
312
465
|
end
|
313
466
|
end
|
314
467
|
|
468
|
+
should "have correct test_closure"
|
469
|
+
should "have correct test_closure_one_arg"
|
470
|
+
|
471
|
+
should "have correct test_double" do
|
472
|
+
r = Everything.test_double 5435.32
|
473
|
+
assert_equal 5435.32, r
|
474
|
+
end
|
475
|
+
|
476
|
+
should "have correct test_enum_param" do
|
477
|
+
r = Everything.test_enum_param :value3
|
478
|
+
assert_equal "value3", r
|
479
|
+
end
|
480
|
+
|
481
|
+
should "have correct test_filename_return"
|
482
|
+
|
483
|
+
should "have correct test_float" do
|
484
|
+
r = Everything.test_float 5435.32
|
485
|
+
assert_in_delta 5435.32, r, 0.001
|
486
|
+
end
|
487
|
+
|
488
|
+
should "have correct test_ghash_container_in"
|
489
|
+
should "have correct test_ghash_container_return"
|
490
|
+
should "have correct test_ghash_everything_in"
|
491
|
+
should "have correct test_ghash_everything_return"
|
492
|
+
should "have correct test_ghash_free"
|
493
|
+
should "have correct test_ghash_nested_everything_return"
|
494
|
+
should "have correct test_ghash_nested_everything_return2"
|
495
|
+
should "have correct test_ghash_nothing_in"
|
496
|
+
should "have correct test_ghash_nothing_in2"
|
497
|
+
should "have correct test_ghash_nothing_return"
|
498
|
+
should "have correct test_ghash_nothing_return2"
|
499
|
+
should "have correct test_ghash_null_in"
|
500
|
+
should "have correct test_ghash_null_out"
|
501
|
+
should "have correct test_ghash_null_return"
|
502
|
+
should "have correct test_glist_container_in"
|
503
|
+
should "have correct test_glist_container_return"
|
504
|
+
should "have correct test_glist_everything_in"
|
505
|
+
should "have correct test_glist_everything_return"
|
506
|
+
should "have correct test_glist_free"
|
507
|
+
should "have correct test_glist_nothing_in"
|
508
|
+
should "have correct test_glist_nothing_in2"
|
509
|
+
should "have correct test_glist_nothing_return"
|
510
|
+
should "have correct test_glist_nothing_return2"
|
511
|
+
should "have correct test_glist_null_in"
|
512
|
+
should "have correct test_glist_null_out"
|
513
|
+
should "have correct test_gslist_container_in"
|
514
|
+
should "have correct test_gslist_container_return"
|
515
|
+
should "have correct test_gslist_everything_in"
|
516
|
+
should "have correct test_gslist_everything_return"
|
517
|
+
should "have correct test_gslist_free"
|
518
|
+
should "have correct test_gslist_nothing_in"
|
519
|
+
should "have correct test_gslist_nothing_in2"
|
520
|
+
should "have correct test_gslist_nothing_return"
|
521
|
+
should "have correct test_gslist_nothing_return2"
|
522
|
+
should "have correct test_gslist_null_in"
|
523
|
+
should "have correct test_gslist_null_out"
|
524
|
+
|
315
525
|
should "have correct test_gtype" do
|
316
526
|
result = Everything.test_gtype 23
|
317
527
|
assert_equal 23, result
|
318
528
|
end
|
319
529
|
|
530
|
+
should "have correct test_int" do
|
531
|
+
result = Everything.test_int 23
|
532
|
+
assert_equal 23, result
|
533
|
+
end
|
534
|
+
|
535
|
+
should "have correct test_int16" do
|
536
|
+
result = Everything.test_int16 23
|
537
|
+
assert_equal 23, result
|
538
|
+
end
|
539
|
+
|
540
|
+
should "have correct test_int32" do
|
541
|
+
result = Everything.test_int32 23
|
542
|
+
assert_equal 23, result
|
543
|
+
end
|
544
|
+
|
545
|
+
should "have correct test_int64" do
|
546
|
+
result = Everything.test_int64 2300000000000
|
547
|
+
assert_equal 2300000000000, result
|
548
|
+
end
|
549
|
+
|
550
|
+
should "have correct test_int8" do
|
551
|
+
result = Everything.test_int8 23
|
552
|
+
assert_equal 23, result
|
553
|
+
end
|
554
|
+
|
555
|
+
should "have correct test_int_out_utf8" do
|
556
|
+
len = Everything.test_int_out_utf8 "How long?"
|
557
|
+
assert_equal 9, len
|
558
|
+
end
|
559
|
+
|
560
|
+
should "have correct test_int_value_arg" do
|
561
|
+
gv = GObject::Value.new
|
562
|
+
gv.init GObject.type_from_name "gint"
|
563
|
+
gv.set_int 343
|
564
|
+
result = Everything.test_int_value_arg gv
|
565
|
+
assert_equal 343, result
|
566
|
+
end
|
567
|
+
|
568
|
+
should "have correct test_long" do
|
569
|
+
result = Everything.test_long 2300000000000
|
570
|
+
assert_equal 2300000000000, result
|
571
|
+
end
|
572
|
+
|
573
|
+
should "have correct test_multi_callback" do
|
574
|
+
a = 1
|
575
|
+
result = Everything.test_multi_callback Proc.new {
|
576
|
+
a += 1
|
577
|
+
23
|
578
|
+
}
|
579
|
+
assert_equal 2 * 23, result
|
580
|
+
assert_equal 3, a
|
581
|
+
end
|
582
|
+
|
583
|
+
should "have correct test_multi_double_args" do
|
584
|
+
one, two = Everything.test_multi_double_args 23.1
|
585
|
+
assert_equal 2 * 23.1, one
|
586
|
+
assert_equal 3 * 23.1, two
|
587
|
+
end
|
588
|
+
|
589
|
+
should "have correct test_object_null_in" do
|
590
|
+
assert_nothing_raised { Everything.test_object_null_in nil }
|
591
|
+
end
|
592
|
+
|
593
|
+
should "have correct test_object_null_out" do
|
594
|
+
result = Everything.test_object_null_out
|
595
|
+
assert_equal nil, result
|
596
|
+
end
|
597
|
+
|
598
|
+
should "have correct test_short" do
|
599
|
+
result = Everything.test_short 23
|
600
|
+
assert_equal 23, result
|
601
|
+
end
|
602
|
+
|
603
|
+
should "have correct test_simple_boxed_a_const_return" do
|
604
|
+
result = Everything.test_simple_boxed_a_const_return
|
605
|
+
assert_equal [5, 6, 7.0], [result[:some_int], result[:some_int8], result[:some_double]]
|
606
|
+
end
|
607
|
+
|
608
|
+
context "the test_simple_callback function" do
|
609
|
+
should "call the passed-in proc" do
|
610
|
+
a = 0
|
611
|
+
Everything.test_simple_callback Proc.new { a = 1 }
|
612
|
+
assert_equal 1, a
|
613
|
+
end
|
614
|
+
|
615
|
+
# XXX: The scope data does not seem to be reliable enough.
|
616
|
+
if false
|
617
|
+
should "not store the proc in CALLBACKS" do
|
618
|
+
n = Everything::Lib::CALLBACKS.length
|
619
|
+
Everything.test_simple_callback Proc.new { }
|
620
|
+
assert_equal n, Everything::Lib::CALLBACKS.length
|
621
|
+
end
|
622
|
+
end
|
623
|
+
end
|
624
|
+
|
625
|
+
should "have correct test_size" do
|
626
|
+
assert_equal 2354, Everything.test_size(2354)
|
627
|
+
end
|
628
|
+
|
629
|
+
should "have correct test_ssize"
|
630
|
+
should "have correct test_strv_in"
|
631
|
+
should "have correct test_strv_in_container"
|
632
|
+
should "have correct test_strv_out"
|
633
|
+
should "have correct test_strv_out_c"
|
634
|
+
should "have correct test_strv_out_container"
|
635
|
+
should "have correct test_strv_outarg"
|
636
|
+
should "have correct test_timet"
|
637
|
+
|
638
|
+
should "have correct test_torture_signature_0" do
|
639
|
+
y, z, q = Everything.test_torture_signature_0 86, "foo", 2
|
640
|
+
assert_equal [86, 2*86, 3+2], [y, z, q]
|
641
|
+
end
|
642
|
+
|
643
|
+
context "its #test_torture_signature_1 method" do
|
644
|
+
should "work for m even" do
|
645
|
+
ret, y, z, q = Everything.test_torture_signature_1(-21, "hello", 12)
|
646
|
+
assert_equal [true, -21, 2 * -21, "hello".length + 12], [ret, y, z, q]
|
647
|
+
end
|
648
|
+
|
649
|
+
should "throw an exception for m odd" do
|
650
|
+
assert_raises RuntimeError do
|
651
|
+
Everything.test_torture_signature_1(-21, "hello", 11)
|
652
|
+
end
|
653
|
+
end
|
654
|
+
end
|
655
|
+
|
656
|
+
should "have correct test_torture_signature_2" do
|
657
|
+
a = 1
|
658
|
+
y, z, q = Everything.test_torture_signature_2 244,
|
659
|
+
Proc.new {|u| a = u }, 2, Proc.new { a = 3 },
|
660
|
+
"foofoo", 31
|
661
|
+
assert_equal [244, 2*244, 6+31], [y, z, q]
|
662
|
+
assert_equal 3, a
|
663
|
+
end
|
664
|
+
|
665
|
+
should "have correct test_uint" do
|
666
|
+
assert_equal 31, Everything.test_uint(31)
|
667
|
+
end
|
668
|
+
|
669
|
+
should "have correct test_uint16" do
|
670
|
+
assert_equal 31, Everything.test_uint16(31)
|
671
|
+
end
|
672
|
+
|
673
|
+
should "have correct test_uint32" do
|
674
|
+
assert_equal 540000, Everything.test_uint32(540000)
|
675
|
+
end
|
676
|
+
|
677
|
+
should "have correct test_uint64" do
|
678
|
+
assert_equal 54_000_000_000_000, Everything.test_uint64(54_000_000_000_000)
|
679
|
+
end
|
680
|
+
|
681
|
+
should "have correct test_uint8" do
|
682
|
+
assert_equal 31, Everything.test_uint8(31)
|
683
|
+
end
|
684
|
+
|
685
|
+
should "have correct test_ulong" do
|
686
|
+
assert_equal 54_000_000_000_000, Everything.test_uint64(54_000_000_000_000)
|
687
|
+
end
|
688
|
+
|
689
|
+
should "have correct test_ushort" do
|
690
|
+
assert_equal 54_000_000, Everything.test_uint64(54_000_000)
|
691
|
+
end
|
692
|
+
|
693
|
+
should "have correct test_utf8_const_in" do
|
694
|
+
# TODO: Capture stderr to automatically look for error messages.
|
695
|
+
assert_nothing_raised do
|
696
|
+
Everything.test_utf8_const_in("const \xe2\x99\xa5 utf8")
|
697
|
+
end
|
698
|
+
end
|
699
|
+
|
700
|
+
should "have correct test_utf8_const_return" do
|
701
|
+
result = Everything.test_utf8_const_return
|
702
|
+
assert_equal "const \xe2\x99\xa5 utf8", result
|
703
|
+
end
|
704
|
+
|
705
|
+
should "have correct test_utf8_inout" do
|
706
|
+
result = Everything.test_utf8_inout "const \xe2\x99\xa5 utf8"
|
707
|
+
assert_equal "nonconst \xe2\x99\xa5 utf8", result
|
708
|
+
end
|
709
|
+
|
710
|
+
should "have correct test_utf8_nonconst_in" do
|
711
|
+
assert_nothing_raised do
|
712
|
+
Everything.test_utf8_nonconst_in "nonconst \xe2\x99\xa5 utf8"
|
713
|
+
end
|
714
|
+
end
|
715
|
+
|
716
|
+
should "have correct test_utf8_nonconst_return" do
|
717
|
+
result = Everything.test_utf8_nonconst_return
|
718
|
+
assert_equal "nonconst \xe2\x99\xa5 utf8", result
|
719
|
+
end
|
720
|
+
|
721
|
+
should "have correct test_utf8_null_in" do
|
722
|
+
assert_nothing_raised do
|
723
|
+
Everything.test_utf8_null_in nil
|
724
|
+
end
|
725
|
+
end
|
726
|
+
|
727
|
+
should "have correct test_utf8_null_out" do
|
728
|
+
assert_equal nil, Everything.test_utf8_null_out
|
729
|
+
end
|
730
|
+
|
731
|
+
should "have correct test_utf8_out" do
|
732
|
+
result = Everything.test_utf8_out
|
733
|
+
assert_equal "nonconst \xe2\x99\xa5 utf8", result
|
734
|
+
end
|
735
|
+
|
736
|
+
should "have correct test_utf8_out_nonconst_return" do
|
737
|
+
r, out = Everything.test_utf8_out_nonconst_return
|
738
|
+
assert_equal ["first", "second"], [r, out]
|
739
|
+
end
|
740
|
+
|
741
|
+
should "have correct test_utf8_out_out" do
|
742
|
+
out0, out1 = Everything.test_utf8_out_nonconst_return
|
743
|
+
assert_equal ["first", "second"], [out0, out1]
|
744
|
+
end
|
745
|
+
|
320
746
|
should "have correct test_value_return" do
|
321
747
|
result = Everything.test_value_return 3423
|
322
748
|
assert_equal 3423, result.get_int
|
@@ -9,13 +9,16 @@ class FunctionDefinitionBuilderTest < Test::Unit::TestCase
|
|
9
9
|
code = fbuilder.generate
|
10
10
|
|
11
11
|
expected = "
|
12
|
-
def init
|
12
|
+
def init argv
|
13
|
+
argc = argv.length
|
13
14
|
_v1 = GirFFI::ArgHelper.int_to_inoutptr argc
|
14
|
-
_v3 = GirFFI::ArgHelper.
|
15
|
+
_v3 = GirFFI::ArgHelper.utf8_array_to_inoutptr argv
|
15
16
|
::Lib.gtk_init _v1, _v3
|
16
17
|
_v2 = GirFFI::ArgHelper.outptr_to_int _v1
|
17
|
-
|
18
|
-
|
18
|
+
GirFFI::ArgHelper.cleanup_ptr _v1
|
19
|
+
_v4 = GirFFI::ArgHelper.outptr_to_utf8_array _v3, _v2
|
20
|
+
GirFFI::ArgHelper.cleanup_ptr_array_ptr _v3, _v2
|
21
|
+
return _v4
|
19
22
|
end
|
20
23
|
"
|
21
24
|
|
@@ -43,14 +46,16 @@ class FunctionDefinitionBuilderTest < Test::Unit::TestCase
|
|
43
46
|
|
44
47
|
expected =
|
45
48
|
"def signal_connect_data instance, detailed_signal, c_handler, data, destroy_data, connect_flags
|
46
|
-
|
49
|
+
_v1 = GirFFI::ArgHelper.object_to_inptr instance
|
50
|
+
_v2 = GirFFI::ArgHelper.utf8_to_inptr detailed_signal
|
47
51
|
_v3 = GirFFI::ArgHelper.mapped_callback_args c_handler
|
48
52
|
::Lib::CALLBACKS << _v3
|
49
53
|
_v4 = GirFFI::ArgHelper.object_to_inptr data
|
50
54
|
_v5 = GirFFI::ArgHelper.mapped_callback_args destroy_data
|
51
55
|
::Lib::CALLBACKS << _v5
|
52
|
-
|
53
|
-
|
56
|
+
_v6 = connect_flags
|
57
|
+
_v7 = ::Lib.g_signal_connect_data _v1, _v2, _v3, _v4, _v5, _v6
|
58
|
+
return _v7
|
54
59
|
end"
|
55
60
|
|
56
61
|
assert_equal cws(expected), cws(code)
|
@@ -63,15 +68,67 @@ class FunctionDefinitionBuilderTest < Test::Unit::TestCase
|
|
63
68
|
|
64
69
|
expected =
|
65
70
|
"def new_from_file x
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
+
_v1 = GirFFI::ArgHelper.utf8_to_inptr x
|
72
|
+
_v4 = FFI::MemoryPointer.new(:pointer).write_pointer nil
|
73
|
+
_v2 = ::Lib.test_obj_new_from_file _v1, _v4
|
74
|
+
GirFFI::ArgHelper.check_error(_v4)
|
75
|
+
_v3 = ::Everything::TestObj.wrap(_v2)
|
76
|
+
GirFFI::ArgHelper.sink_if_floating(_v3)
|
77
|
+
return _v3
|
78
|
+
end"
|
79
|
+
|
80
|
+
assert_equal cws(expected), cws(code)
|
81
|
+
end
|
82
|
+
|
83
|
+
should "build correct definition of Everything:test_array_int_null_in" do
|
84
|
+
go = get_function_introspection_data 'Everything', 'test_array_int_null_in'
|
85
|
+
fbuilder = GirFFI::FunctionDefinitionBuilder.new go, Lib
|
86
|
+
code = fbuilder.generate
|
87
|
+
|
88
|
+
expected =
|
89
|
+
"def test_array_int_null_in arr
|
90
|
+
_v1 = GirFFI::ArgHelper.int_array_to_inptr arr
|
91
|
+
len = arr.nil? ? 0 : arr.length
|
92
|
+
_v2 = len
|
93
|
+
::Lib.test_array_int_null_in _v1, _v2
|
94
|
+
GirFFI::ArgHelper.cleanup_ptr _v1
|
95
|
+
end"
|
96
|
+
|
97
|
+
assert_equal cws(expected), cws(code)
|
98
|
+
end
|
99
|
+
|
100
|
+
should "build correct definition of Everything:test_array_int_null_out" do
|
101
|
+
go = get_function_introspection_data 'Everything', 'test_array_int_null_out'
|
102
|
+
fbuilder = GirFFI::FunctionDefinitionBuilder.new go, Lib
|
103
|
+
code = fbuilder.generate
|
104
|
+
|
105
|
+
expected =
|
106
|
+
"def test_array_int_null_out
|
107
|
+
_v1 = GirFFI::ArgHelper.pointer_outptr
|
108
|
+
_v3 = GirFFI::ArgHelper.int_outptr
|
109
|
+
::Lib.test_array_int_null_out _v1, _v3
|
110
|
+
_v4 = GirFFI::ArgHelper.outptr_to_int _v3
|
111
|
+
GirFFI::ArgHelper.cleanup_ptr _v3
|
112
|
+
_v2 = GirFFI::ArgHelper.outptr_to_int_array _v1, _v4
|
113
|
+
GirFFI::ArgHelper.cleanup_ptr_ptr _v1
|
71
114
|
return _v2
|
72
115
|
end"
|
73
116
|
|
74
117
|
assert_equal cws(expected), cws(code)
|
75
118
|
end
|
119
|
+
|
120
|
+
should "build correct definition of Everything:test_utf8_nonconst_in" do
|
121
|
+
go = get_function_introspection_data 'Everything', 'test_utf8_nonconst_in'
|
122
|
+
fbuilder = GirFFI::FunctionDefinitionBuilder.new go, Lib
|
123
|
+
code = fbuilder.generate
|
124
|
+
|
125
|
+
expected =
|
126
|
+
"def test_utf8_nonconst_in in_
|
127
|
+
_v1 = GirFFI::ArgHelper.utf8_to_inptr in_
|
128
|
+
::Lib.test_utf8_nonconst_in _v1
|
129
|
+
end"
|
130
|
+
|
131
|
+
assert_equal cws(expected), cws(code)
|
132
|
+
end
|
76
133
|
end
|
77
134
|
end
|
@@ -2,7 +2,7 @@ require File.expand_path('test_helper.rb', File.dirname(__FILE__))
|
|
2
2
|
require 'gir_ffi'
|
3
3
|
|
4
4
|
class GObjectOverridesTest < Test::Unit::TestCase
|
5
|
-
context "
|
5
|
+
context "In the GObject module with overridden functions" do
|
6
6
|
setup do
|
7
7
|
GirFFI.setup :GObject
|
8
8
|
GirFFI.setup :Everything
|
@@ -71,7 +71,7 @@ class GObjectOverridesTest < Test::Unit::TestCase
|
|
71
71
|
GObject.signal_connect_data o, "test-with-static-scope-arg", callback, nil, nil, 0
|
72
72
|
GObject.signal_emit o, "test-with-static-scope-arg", sb
|
73
73
|
|
74
|
-
sb2 = Everything::TestSimpleBoxedA.
|
74
|
+
sb2 = Everything::TestSimpleBoxedA.wrap b2
|
75
75
|
assert sb.equals(sb2)
|
76
76
|
end
|
77
77
|
end
|
@@ -116,6 +116,13 @@ class GObjectOverridesTest < Test::Unit::TestCase
|
|
116
116
|
assert_equal true, rv.get_boolean
|
117
117
|
end
|
118
118
|
|
119
|
+
should "require a block" do
|
120
|
+
o = Everything::TestSubObj.new
|
121
|
+
assert_raises ArgumentError do
|
122
|
+
GObject.signal_connect o, "test"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
119
126
|
context "connecting a signal with extra arguments" do
|
120
127
|
setup do
|
121
128
|
@a = nil
|
@@ -123,12 +130,13 @@ class GObjectOverridesTest < Test::Unit::TestCase
|
|
123
130
|
|
124
131
|
o = Everything::TestSubObj.new
|
125
132
|
sb = Everything::TestSimpleBoxedA.new
|
133
|
+
sb[:some_int] = 23
|
126
134
|
|
127
135
|
GObject.signal_connect(o, "test-with-static-scope-arg", 2) { |i, object, d|
|
128
136
|
@a = d
|
129
137
|
@b = object
|
130
138
|
}
|
131
|
-
GObject.signal_emit o, "test-with-static-scope-arg"
|
139
|
+
GObject.signal_emit o, "test-with-static-scope-arg", sb
|
132
140
|
end
|
133
141
|
|
134
142
|
should "move the user data argument" do
|
@@ -137,6 +145,7 @@ class GObjectOverridesTest < Test::Unit::TestCase
|
|
137
145
|
|
138
146
|
should "pass on the extra arguments" do
|
139
147
|
assert_instance_of Everything::TestSimpleBoxedA, @b
|
148
|
+
assert_equal 23, @b[:some_int]
|
140
149
|
end
|
141
150
|
end
|
142
151
|
|
data/test/test_helper.rb
CHANGED
@@ -3,6 +3,11 @@ require 'rr'
|
|
3
3
|
require 'ffi'
|
4
4
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
5
|
|
6
|
+
if RUBY_PLATFORM == 'java'
|
7
|
+
require 'java'
|
8
|
+
JRuby.objectspace = true
|
9
|
+
end
|
10
|
+
|
6
11
|
# Since the tests will call Gtk+ functions, Gtk+ must be initialized.
|
7
12
|
module DummyGtk
|
8
13
|
module Lib
|