gir_ffi 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/History.txt +11 -0
  2. data/TODO.rdoc +5 -0
  3. data/examples/01_empty_window.rb +0 -1
  4. data/examples/02_hello_world.rb +0 -1
  5. data/examples/03_upgraded_hello_world.rb +0 -1
  6. data/examples/04_webkit.rb +0 -1
  7. data/lib/gir_ffi/arg_helper.rb +231 -94
  8. data/lib/gir_ffi/builder/argument.rb +372 -46
  9. data/lib/gir_ffi/builder/module.rb +25 -10
  10. data/lib/gir_ffi/builder/type/constant.rb +39 -0
  11. data/lib/gir_ffi/builder/type/enum.rb +15 -5
  12. data/lib/gir_ffi/builder/type/registered_type.rb +25 -6
  13. data/lib/gir_ffi/builder/type/struct.rb +1 -9
  14. data/lib/gir_ffi/builder/type/union.rb +5 -0
  15. data/lib/gir_ffi/builder/type.rb +13 -14
  16. data/lib/gir_ffi/builder.rb +7 -4
  17. data/lib/gir_ffi/builder_helper.rb +4 -3
  18. data/lib/gir_ffi/i_base_info.rb +4 -0
  19. data/lib/gir_ffi/i_constant_info.rb +9 -0
  20. data/lib/gir_ffi/i_registered_type_info.rb +0 -1
  21. data/lib/gir_ffi/i_repository.rb +8 -2
  22. data/lib/gir_ffi/i_type_info.rb +7 -0
  23. data/lib/gir_ffi/lib.rb +41 -3
  24. data/lib/gir_ffi/overrides/glib.rb +188 -4
  25. data/lib/gir_ffi/overrides/gobject.rb +16 -5
  26. data/tasks/test.rake +1 -1
  27. data/test/arg_helper_test.rb +5 -5
  28. data/test/builder_test.rb +64 -41
  29. data/test/class_base_test.rb +1 -1
  30. data/test/function_definition_builder_test.rb +24 -2
  31. data/test/g_object_overrides_test.rb +1 -3
  32. data/test/g_object_test.rb +1 -1
  33. data/test/generated_gimarshallingtests_test.rb +1677 -0
  34. data/test/generated_gio_test.rb +1 -1
  35. data/test/generated_gtk_test.rb +31 -2
  36. data/test/generated_regress_test.rb +278 -54
  37. data/test/girffi_test.rb +20 -5
  38. data/test/glib_overrides_test.rb +81 -0
  39. data/test/gtk_overrides_test.rb +2 -3
  40. data/test/i_object_info_test.rb +1 -1
  41. data/test/i_repository_test.rb +3 -4
  42. data/test/lib/Makefile.am +18 -2
  43. data/test/module_builder_test.rb +1 -1
  44. data/test/test_helper.rb +88 -5
  45. data/test/type_builder_test.rb +7 -10
  46. metadata +16 -13
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
2
 
3
3
  # Tests generated methods and functions in the Gio namespace.
4
- class GeneratedGioTest < Test::Unit::TestCase
4
+ class GeneratedGioTest < MiniTest::Spec
5
5
  context "In the generated Gio module" do
6
6
  setup do
7
7
  GirFFI.setup :Gio
@@ -1,10 +1,10 @@
1
1
  require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
2
 
3
3
  # Tests generated methods and functions in the Gtk namespace.
4
- class GeneratedGtkTest < Test::Unit::TestCase
4
+ class GeneratedGtkTest < MiniTest::Spec
5
5
  context "In the generated Gtk module" do
6
6
  setup do
7
- GirFFI.setup :Gtk
7
+ GirFFI.setup :Gtk, '2.0'
8
8
  end
9
9
 
10
10
  context "a Gtk::Builder instance" do
@@ -60,6 +60,35 @@ class GeneratedGtkTest < Test::Unit::TestCase
60
60
  assert_equal 2, ref_count(@w)
61
61
  end
62
62
  end
63
+
64
+ context "Gtk::RadioButton" do
65
+ context ".new" do
66
+ should "work when called with nil" do
67
+ assert_nothing_raised {
68
+ Gtk::RadioButton.new nil
69
+ }
70
+ end
71
+ end
72
+
73
+ context "#get_group" do
74
+ should "return a GLib::SList object" do
75
+ btn = Gtk::RadioButton.new nil
76
+ grp = btn.get_group
77
+ assert_instance_of GLib::SList, grp
78
+ end
79
+ end
80
+
81
+ context ".new" do
82
+ should "work when called with the result of #get_group" do
83
+ assert_nothing_raised {
84
+ btn = Gtk::RadioButton.new nil
85
+ grp = btn.get_group
86
+ btn2 = Gtk::RadioButton.new grp
87
+ }
88
+ end
89
+ end
90
+
91
+ end
63
92
  end
64
93
  end
65
94
 
@@ -1,13 +1,27 @@
1
+ # coding: utf-8
1
2
  require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
3
 
3
4
  # Tests generated methods and functions in the Regress namespace.
4
- class GeneratedRegressTest < Test::Unit::TestCase
5
+ class GeneratedRegressTest < MiniTest::Spec
5
6
  context "The generated Regress module" do
6
7
  setup do
7
8
  GirFFI.setup :Regress
8
- GirFFI.setup :GObject
9
- GirFFI.setup :GLib
10
- GirFFI.setup :Gtk
9
+ end
10
+
11
+ it "has the constant DOUBLE_CONSTANT" do
12
+ assert_equal 44.22, Regress::DOUBLE_CONSTANT
13
+ end
14
+
15
+ it "has the constant INT_CONSTANT" do
16
+ assert_equal 4422, Regress::INT_CONSTANT
17
+ end
18
+
19
+ it "has the constant Mixed_Case_Constant" do
20
+ assert_equal 4423, Regress::Mixed_Case_Constant
21
+ end
22
+
23
+ it "has the constant STRING_CONSTANT" do
24
+ assert_equal "Some String", Regress::STRING_CONSTANT
11
25
  end
12
26
 
13
27
  context "the Regress::TestBoxed class" do
@@ -75,7 +89,11 @@ class GeneratedRegressTest < Test::Unit::TestCase
75
89
  end
76
90
  end
77
91
 
78
- # TestFlags
92
+ it "has the bitfield TestFlags" do
93
+ assert_equal 1, Regress::TestFlags[:flag1]
94
+ assert_equal 2, Regress::TestFlags[:flag2]
95
+ assert_equal 4, Regress::TestFlags[:flag3]
96
+ end
79
97
 
80
98
  context "the Regress::TestFloating class" do
81
99
  context "an instance" do
@@ -93,6 +111,18 @@ class GeneratedRegressTest < Test::Unit::TestCase
93
111
  end
94
112
  end
95
113
 
114
+ describe "TestFundamentalObject" do
115
+ it "must be tested"
116
+ end
117
+
118
+ describe "TestFundamentalSubObject" do
119
+ it "must be tested"
120
+ end
121
+
122
+ describe "TestInterface" do
123
+ it "must be tested"
124
+ end
125
+
96
126
  context "the Regress::TestObj class" do
97
127
  should "create an instance using #new_from_file" do
98
128
  o = Regress::TestObj.new_from_file("foo")
@@ -267,9 +297,56 @@ class GeneratedRegressTest < Test::Unit::TestCase
267
297
  end
268
298
  end
269
299
 
270
- # TestStructB
271
- # TestStructC
272
- # TestSubObj
300
+ describe "TestStructB" do
301
+ describe "an instance" do
302
+ it "has a working method #clone" do
303
+ a = Regress::TestStructB.new
304
+ a[:some_int8] = 42
305
+ a[:nested_a][:some_int] = 2556
306
+ a[:nested_a][:some_int8] = -10
307
+ a[:nested_a][:some_double] = 1.03455e20
308
+ a[:nested_a][:some_enum] = :value2
309
+
310
+ b = a.clone
311
+
312
+ assert_equal 42, b[:some_int8]
313
+ assert_equal 2556, b[:nested_a][:some_int]
314
+ assert_equal(-10, b[:nested_a][:some_int8])
315
+ assert_equal 1.03455e20, b[:nested_a][:some_double]
316
+ assert_equal :value2, b[:nested_a][:some_enum]
317
+ end
318
+ end
319
+ end
320
+
321
+ # XXX: TestStructC is not typedef'd in regress.h
322
+ # describe "TestStructC"
323
+
324
+ describe "TestSubObj" do
325
+ it "is created with #new" do
326
+ tso = Regress::TestSubObj.new
327
+ assert_instance_of Regress::TestSubObj, tso
328
+ end
329
+
330
+ describe "an instance" do
331
+ before do
332
+ @tso = Regress::TestSubObj.new
333
+ end
334
+
335
+ it "has a working method #instance_method" do
336
+ res = @tso.instance_method
337
+ assert_equal 0, res
338
+ end
339
+
340
+ it "has a working method #unset_bare" do
341
+ @tso.unset_bare
342
+ pass
343
+ end
344
+
345
+ it "has a field parent_instance" do
346
+ assert_instance_of Regress::TestObj::Struct, @tso[:parent_instance]
347
+ end
348
+ end
349
+ end
273
350
 
274
351
  context "the Regress::TestWi8021x class" do
275
352
  should "create an instance using #new" do
@@ -310,9 +387,16 @@ class GeneratedRegressTest < Test::Unit::TestCase
310
387
  end
311
388
  end
312
389
 
313
- # set_abort_on_error
390
+ it "has the constant UTF8_CONSTANT" do
391
+ assert_equal "const ♥ utf8", Regress::UTF8_CONSTANT
392
+ end
393
+
394
+ it "has the function #set_abort_on_error" do
395
+ Regress.set_abort_on_error false
396
+ Regress.set_abort_on_error true
397
+ end
314
398
 
315
- context "test_array_fixed_size_int_in" do
399
+ describe "#test_array_fixed_size_int_in" do
316
400
  should "return the correct result" do
317
401
  assert_equal 5 + 4 + 3 + 2 + 1, Regress.test_array_fixed_size_int_in([5, 4, 3, 2, 1])
318
402
  end
@@ -383,6 +467,7 @@ class GeneratedRegressTest < Test::Unit::TestCase
383
467
  end
384
468
 
385
469
  should "have correct test_async_ready_callback" do
470
+ GirFFI.setup :Gtk, '2.0'
386
471
  a = 1
387
472
 
388
473
  Regress.test_async_ready_callback Proc.new {
@@ -408,12 +493,35 @@ class GeneratedRegressTest < Test::Unit::TestCase
408
493
  assert_equal true, Regress.test_boolean_true(true)
409
494
  end
410
495
 
411
- should "have correct test_cairo_context_full_return"
412
- should "have correct test_cairo_context_none_in"
413
- should "have correct test_cairo_surface_full_out"
414
- should "have correct test_cairo_surface_full_return"
415
- should "have correct test_cairo_surface_none_in"
416
- should "have correct test_cairo_surface_none_return"
496
+ it "has correct #test_cairo_context_full_return" do
497
+ ct = Regress.test_cairo_context_full_return
498
+ assert_instance_of Cairo::Context, ct
499
+ end
500
+
501
+ it "has correct #test_cairo_context_none_in" do
502
+ ct = Regress.test_cairo_context_full_return
503
+ Regress.test_cairo_context_none_in ct
504
+ end
505
+
506
+ it "has correct #test_cairo_surface_full_out" do
507
+ cs = Regress.test_cairo_surface_full_out
508
+ assert_instance_of Cairo::Surface, cs
509
+ end
510
+
511
+ it "has correct #test_cairo_surface_full_return" do
512
+ cs = Regress.test_cairo_surface_full_return
513
+ assert_instance_of Cairo::Surface, cs
514
+ end
515
+
516
+ it "has correct #test_cairo_surface_none_in" do
517
+ cs = Regress.test_cairo_surface_full_return
518
+ Regress.test_cairo_surface_none_in cs
519
+ end
520
+
521
+ it "has correct #test_cairo_surface_none_return" do
522
+ cs = Regress.test_cairo_surface_none_return
523
+ assert_instance_of Cairo::Surface, cs
524
+ end
417
525
 
418
526
  should "have correct test_callback" do
419
527
  result = Regress.test_callback Proc.new { 5 }
@@ -444,7 +552,7 @@ class GeneratedRegressTest < Test::Unit::TestCase
444
552
  assert_equal 42, r2
445
553
  end
446
554
 
447
- context "the test_callback_user_data function" do
555
+ describe "the #test_callback_user_data function" do
448
556
  should "return the callbacks return value" do
449
557
  result = Regress.test_callback_user_data Proc.new {|u| 5 }, nil
450
558
  assert_equal 5, result
@@ -472,6 +580,13 @@ class GeneratedRegressTest < Test::Unit::TestCase
472
580
  assert_equal 4, r
473
581
  end
474
582
 
583
+ it "has a correct #test_date_in_gvalue function" do
584
+ r = Regress.test_date_in_gvalue
585
+ date = r.ruby_value
586
+ assert_equal [1984, :december, 5],
587
+ [date.get_year, date.get_month, date.get_day]
588
+ end
589
+
475
590
  should "have correct test_double" do
476
591
  r = Regress.test_double 5435.32
477
592
  assert_equal 5435.32, r
@@ -482,33 +597,94 @@ class GeneratedRegressTest < Test::Unit::TestCase
482
597
  assert_equal "value3", r
483
598
  end
484
599
 
485
- should "have correct test_filename_return"
600
+ # TODO: Find a way to test encoding issues.
601
+ it "has correct #test_filename_return" do
602
+ arr = Regress.test_filename_return
603
+ assert_equal ["åäö", "/etc/fstab"], arr.to_a
604
+ end
486
605
 
487
606
  should "have correct test_float" do
488
607
  r = Regress.test_float 5435.32
489
608
  assert_in_delta 5435.32, r, 0.001
490
609
  end
491
610
 
492
- should "have correct test_ghash_container_return"
493
- should "have correct test_ghash_everything_return"
611
+ describe "#test_ghash_container_return" do
612
+ before do
613
+ @hash = Regress.test_ghash_container_return
614
+ end
615
+
616
+ it "returns an instance of GLib::Hash" do
617
+ @hash.must_be_instance_of GLib::HashTable
618
+ end
619
+
620
+ it "returns the correct values" do
621
+ @hash.to_hash.must_be :==, {"foo" => "bar", "baz" => "bat",
622
+ "qux" => "quux"}
623
+ end
624
+ end
625
+
626
+ it "has correct #test_ghash_everything_return" do
627
+ ghash = Regress.test_ghash_everything_return
628
+ ghash.to_hash.must_be :==, {"foo" => "bar", "baz" => "bat",
629
+ "qux" => "quux"}
630
+ end
631
+
494
632
  should "have correct test_ghash_nested_everything_return"
495
633
  should "have correct test_ghash_nested_everything_return2"
496
- should "have correct test_ghash_nothing_in"
497
- should "have correct test_ghash_nothing_in2"
498
- should "have correct test_ghash_nothing_return"
499
- should "have correct test_ghash_nothing_return2"
500
- should "have correct test_ghash_null_in"
501
- should "have correct test_ghash_null_out"
502
- should "have correct test_ghash_null_return"
503
634
 
504
- should "have correct test_glist_container_return" do
505
- arr = Regress.test_glist_container_return
506
- assert_equal ["1", "2", "3"], arr
635
+ it "has correct #test_ghash_nothing_in" do
636
+ Regress.test_ghash_nothing_in({"foo" => "bar", "baz" => "bat",
637
+ "qux" => "quux"})
638
+ end
639
+
640
+ it "has correct #test_ghash_nothing_in2" do
641
+ Regress.test_ghash_nothing_in2({"foo" => "bar", "baz" => "bat",
642
+ "qux" => "quux"})
643
+ end
644
+
645
+ it "has correct #test_ghash_nothing_return" do
646
+ ghash = Regress.test_ghash_nothing_return
647
+ ghash.to_hash.must_be :==, {"foo" => "bar", "baz" => "bat",
648
+ "qux" => "quux"}
649
+ end
650
+
651
+ it "has correct #test_ghash_nothing_return2" do
652
+ ghash = Regress.test_ghash_nothing_return2
653
+ ghash.to_hash.must_be :==, {"foo" => "bar", "baz" => "bat",
654
+ "qux" => "quux"}
655
+ end
656
+
657
+ it "has correct #test_ghash_null_in" do
658
+ Regress.test_ghash_null_in(nil)
659
+ end
660
+
661
+ it "has correct #test_ghash_null_out" do
662
+ ghash = Regress.test_ghash_null_out
663
+ ghash.must_be_nil
664
+ end
665
+
666
+ it "has correct #test_ghash_null_return" do
667
+ ghash = Regress.test_ghash_null_return
668
+ ghash.must_be_nil
669
+ end
670
+
671
+ context "#test_glist_container_return" do
672
+ setup do
673
+ @list = Regress.test_glist_container_return
674
+ end
675
+
676
+ should "return an instance of GLib::SList" do
677
+ assert_instance_of GLib::List, @list
678
+ end
679
+
680
+ should "return the correct values" do
681
+ assert_equal ["1", "2", "3"], @list.to_a
682
+ end
507
683
  end
508
684
 
509
685
  should "have correct test_glist_everything_return" do
510
- arr = Regress.test_glist_everything_return
511
- assert_equal ["1", "2", "3"], arr
686
+ list = Regress.test_glist_everything_return
687
+ assert_equal ["1", "2", "3"], list.to_a
512
688
  end
513
689
 
514
690
  should "have correct test_glist_nothing_in" do
@@ -524,13 +700,13 @@ class GeneratedRegressTest < Test::Unit::TestCase
524
700
  end
525
701
 
526
702
  should "have correct test_glist_nothing_return" do
527
- arr = Regress.test_glist_nothing_return
528
- assert_equal ["1", "2", "3"], arr
703
+ list = Regress.test_glist_nothing_return
704
+ assert_equal ["1", "2", "3"], list.to_a
529
705
  end
530
706
 
531
707
  should "have correct test_glist_nothing_return2" do
532
- arr = Regress.test_glist_nothing_return2
533
- assert_equal ["1", "2", "3"], arr
708
+ list = Regress.test_glist_nothing_return2
709
+ assert_equal ["1", "2", "3"], list.to_a
534
710
  end
535
711
 
536
712
  should "have correct test_glist_null_in" do
@@ -541,17 +717,26 @@ class GeneratedRegressTest < Test::Unit::TestCase
541
717
 
542
718
  should "have correct test_glist_null_out" do
543
719
  result = Regress.test_glist_null_out
544
- assert_equal [], result
720
+ assert_equal nil, result
545
721
  end
546
722
 
547
- should "have correct test_gslist_container_return" do
548
- arr = Regress.test_gslist_container_return
549
- assert_equal ["1", "2", "3"], arr
723
+ context "#test_gslist_container_return" do
724
+ setup do
725
+ @slist = Regress.test_gslist_container_return
726
+ end
727
+
728
+ should "return a GLib::SList object" do
729
+ assert_instance_of GLib::SList, @slist
730
+ end
731
+
732
+ should "return the correct values" do
733
+ assert_equal ["1", "2", "3"], @slist.to_a
734
+ end
550
735
  end
551
736
 
552
737
  should "have correct test_gslist_everything_return" do
553
- arr = Regress.test_gslist_everything_return
554
- assert_equal ["1", "2", "3"], arr
738
+ slist = Regress.test_gslist_everything_return
739
+ assert_equal ["1", "2", "3"], slist.to_a
555
740
  end
556
741
 
557
742
  should "have correct test_gslist_nothing_in" do
@@ -567,13 +752,13 @@ class GeneratedRegressTest < Test::Unit::TestCase
567
752
  end
568
753
 
569
754
  should "have correct test_gslist_nothing_return" do
570
- arr = Regress.test_gslist_nothing_return
571
- assert_equal ["1", "2", "3"], arr
755
+ slist = Regress.test_gslist_nothing_return
756
+ assert_equal ["1", "2", "3"], slist.to_a
572
757
  end
573
758
 
574
759
  should "have correct test_gslist_nothing_return2" do
575
- arr = Regress.test_gslist_nothing_return2
576
- assert_equal ["1", "2", "3"], arr
760
+ slist = Regress.test_gslist_nothing_return2
761
+ assert_equal ["1", "2", "3"], slist.to_a
577
762
  end
578
763
 
579
764
  should "have correct test_gslist_null_in" do
@@ -582,9 +767,11 @@ class GeneratedRegressTest < Test::Unit::TestCase
582
767
  }
583
768
  end
584
769
 
585
- should "have correct test_gslist_null_out" do
586
- result = Regress.test_gslist_null_out
587
- assert_equal [], result
770
+ context "#test_gslist_null_out" do
771
+ should "return nil" do
772
+ result = Regress.test_gslist_null_out
773
+ assert_equal nil, result
774
+ end
588
775
  end
589
776
 
590
777
  should "have correct test_gtype" do
@@ -661,7 +848,7 @@ class GeneratedRegressTest < Test::Unit::TestCase
661
848
  assert_equal [5, 6, 7.0], [result[:some_int], result[:some_int8], result[:some_double]]
662
849
  end
663
850
 
664
- context "the test_simple_callback function" do
851
+ describe "the #test_simple_callback function" do
665
852
  should "call the passed-in proc" do
666
853
  a = 0
667
854
  Regress.test_simple_callback Proc.new { a = 1 }
@@ -690,10 +877,30 @@ class GeneratedRegressTest < Test::Unit::TestCase
690
877
  assert_equal true, Regress.test_strv_in(['1', '2', '3'])
691
878
  end
692
879
 
693
- should "have correct test_strv_out"
694
- should "have correct test_strv_out_c"
695
- should "have correct test_strv_out_container"
696
- should "have correct test_strv_outarg"
880
+ it "has correct #test_strv_in_gvalue" do
881
+ gv = Regress.test_strv_in_gvalue
882
+ assert_equal ['one', 'two', 'three'], gv.ruby_value
883
+ end
884
+
885
+ it "has correct #test_strv_out" do
886
+ arr = Regress.test_strv_out
887
+ assert_equal ["thanks", "for", "all", "the", "fish"], arr
888
+ end
889
+
890
+ it "has correct #test_strv_out_c" do
891
+ arr = Regress.test_strv_out_c
892
+ assert_equal ["thanks", "for", "all", "the", "fish"], arr
893
+ end
894
+
895
+ it "has correct #test_strv_out_container" do
896
+ arr = Regress.test_strv_out_container
897
+ assert_equal ['1', '2', '3'], arr
898
+ end
899
+
900
+ it "has correct #test_strv_outarg" do
901
+ arr = Regress.test_strv_outarg
902
+ assert_equal ['1', '2', '3'], arr
903
+ end
697
904
 
698
905
  should "have correct test_timet" do
699
906
  # Time rounded to seconds.
@@ -753,6 +960,16 @@ class GeneratedRegressTest < Test::Unit::TestCase
753
960
  assert_equal 54_000_000_000_000, Regress.test_uint64(54_000_000_000_000)
754
961
  end
755
962
 
963
+ it "has a correct #test_unichar" do
964
+ assert_equal 120, Regress.test_unichar(120)
965
+ assert_equal 540_000, Regress.test_unichar(540_000)
966
+ end
967
+
968
+ it "has a correct #test_unsigned_enum_param" do
969
+ assert_equal "value1", Regress.test_unsigned_enum_param(:value1)
970
+ assert_equal "value2", Regress.test_unsigned_enum_param(:value2)
971
+ end
972
+
756
973
  should "have correct test_ushort" do
757
974
  assert_equal 54_000_000, Regress.test_uint64(54_000_000)
758
975
  end
@@ -809,6 +1026,13 @@ class GeneratedRegressTest < Test::Unit::TestCase
809
1026
  assert_equal 3423, result.get_int
810
1027
  end
811
1028
 
1029
+ it "raises an appropriate NoMethodError when a function is not found" do
1030
+ begin
1031
+ Regress.this_method_does_not_exist
1032
+ rescue => e
1033
+ assert_equal "undefined method `this_method_does_not_exist' for Regress:Module", e.message
1034
+ end
1035
+ end
812
1036
  end
813
1037
 
814
1038
  end
data/test/girffi_test.rb CHANGED
@@ -1,11 +1,26 @@
1
1
  require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
2
 
3
- class GirFFITest < Test::Unit::TestCase
3
+ class GirFFITest < MiniTest::Spec
4
4
  context "GirFFI" do
5
- should "be able to set up cairo" do
6
- assert_nothing_raised {
7
- GirFFI.setup :cairo
8
- }
5
+ it "sets up cairo as Cairo" do
6
+ GirFFI.setup :cairo
7
+ assert Object.const_defined?(:Cairo)
8
+ end
9
+
10
+ it "sets up xlib, which has no shared library" do
11
+ gir = GirFFI::IRepository.default
12
+ gir.require 'xlib'
13
+ assert_nil gir.shared_library('xlib'), "Precondition for test failed"
14
+ GirFFI.setup :xlib
15
+ end
16
+
17
+ it "sets up dependencies" do
18
+ save_module :GObject
19
+ save_module :Regress
20
+ GirFFI.setup :Regress
21
+ assert Object.const_defined?(:GObject)
22
+ restore_module :Regress
23
+ restore_module :GObject
9
24
  end
10
25
  end
11
26
  end
@@ -0,0 +1,81 @@
1
+ require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
+
3
+ describe "With the GLib overrides" do
4
+ describe "a HashTable provided by the system" do
5
+ before do
6
+ GirFFI.setup :Regress
7
+ @hash = Regress.test_ghash_container_return
8
+ end
9
+
10
+ it "has a working #each method" do
11
+ a = {}
12
+ @hash.each {|k, v| a[k] = v}
13
+ a.must_be :==, {"foo" => "bar", "baz" => "bat",
14
+ "qux" => "quux"}
15
+ end
16
+
17
+ it "includes Enumerable" do
18
+ GLib::HashTable.must_include Enumerable
19
+ end
20
+
21
+ it "has a working #to_hash method" do
22
+ @hash.to_hash.must_be :==, {"foo" => "bar", "baz" => "bat",
23
+ "qux" => "quux"}
24
+ end
25
+ end
26
+
27
+ describe "HashTable" do
28
+ it "can be created (for now) with Glib.hash_table_new" do
29
+ h = GLib.hash_table_new :utf8, :utf8
30
+ h.to_hash.must_be :==, {}
31
+ end
32
+
33
+ it "allows key-value pairs to be inserted" do
34
+ h = GLib.hash_table_new :utf8, :utf8
35
+ h.insert "foo", "bar"
36
+ h.to_hash.must_be :==, {"foo" => "bar"}
37
+ end
38
+ end
39
+
40
+ describe "ByteArray" do
41
+ it "can be created (for now) with Glib.byte_array_new" do
42
+ ba = GLib.byte_array_new
43
+ assert_instance_of GLib::ByteArray, ba
44
+ end
45
+
46
+ it "allows strings to be appended to it" do
47
+ ba = GLib.byte_array_new
48
+ GLib::byte_array_append ba, "abdc"
49
+ pass
50
+ end
51
+
52
+ it "has a working #to_s method" do
53
+ ba = GLib.byte_array_new
54
+ ba = GLib::byte_array_append ba, "abdc"
55
+ assert_equal "abdc", ba.to_string
56
+ end
57
+ end
58
+
59
+ describe "Array" do
60
+ it "can be created (for now) with Glib.array_new" do
61
+ arr = GLib.array_new :int32
62
+ assert_instance_of GLib::Array, arr
63
+ assert_equal :int32, arr.element_type
64
+ end
65
+
66
+ it "allows values to be appended to it" do
67
+ ba = GLib.array_new :int32
68
+ GLib.array_append_vals ba, [1, 2, 3]
69
+ assert_equal 3, ba[:len]
70
+ end
71
+
72
+ # TODO: Make GLib::Array a full Enumerable"
73
+ it "has a working #to_a method" do
74
+ ba = GLib.array_new :int32
75
+ GLib.array_append_vals ba, [1, 2, 3]
76
+ assert_equal [1, 2, 3], ba.to_a
77
+ end
78
+ end
79
+ end
80
+
81
+
@@ -1,10 +1,9 @@
1
1
  require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
2
 
3
- class GtkOverridesTest < Test::Unit::TestCase
3
+ class GtkOverridesTest < MiniTest::Spec
4
4
  context "The Gtk.init function" do
5
5
  setup do
6
- cleanup_module :Gtk
7
- GirFFI.setup :Gtk
6
+ GirFFI.setup :Gtk, '2.0'
8
7
  end
9
8
 
10
9
  should "not take any arguments" do
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
2
 
3
3
  module GirFFI
4
- class IObjectInfoTest < Test::Unit::TestCase
4
+ class IObjectInfoTest < MiniTest::Spec
5
5
  context "An IObjectInfo object" do
6
6
 
7
7
  setup do