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,10 +1,10 @@
1
1
  require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
2
 
3
3
  module GirFFI
4
- class IRepositoryTest < Test::Unit::TestCase
4
+ class IRepositoryTest < MiniTest::Spec
5
5
  context "An IRepository object" do
6
6
  should "not be created by calling new()" do
7
- assert_raise NoMethodError do
7
+ assert_raises NoMethodError do
8
8
  IRepository.new
9
9
  end
10
10
  end
@@ -23,7 +23,7 @@ module GirFFI
23
23
 
24
24
  context "The namespace method" do
25
25
  should "raise an error if the namespace doesn't exist" do
26
- assert_raise RuntimeError do
26
+ assert_raises RuntimeError do
27
27
  IRepository.default.require 'VeryUnlikelyGObjectNamespaceName', nil
28
28
  end
29
29
  end
@@ -44,7 +44,6 @@ module GirFFI
44
44
  context "Enumerating the infos" do
45
45
  setup do
46
46
  @gir = IRepository.default
47
- @gir.require 'Gtk', nil
48
47
  end
49
48
 
50
49
  should "yield more than one object" do
data/test/lib/Makefile.am CHANGED
@@ -3,7 +3,7 @@ AUTOMAKE_OPTIONS = 1.7
3
3
 
4
4
  # We need to build a shared library, which can be dlopened
5
5
  # it does not work with noinst_LTLIBRARIES
6
- testlib_LTLIBRARIES = libregress.la
6
+ testlib_LTLIBRARIES = libregress.la libgimarshallingtests.la
7
7
 
8
8
  testlibdir = $(prefix)/unused
9
9
  install-testlibLTLIBRARIES: # prevent it from being installed
@@ -12,6 +12,10 @@ libregress_la_SOURCES = $(GI_DATADIR)/tests/regress.c $(GI_DATADIR)/tests/regres
12
12
  libregress_la_CFLAGS = $(GIO_CFLAGS) $(CAIRO_CFLAGS)
13
13
  libregress_la_LDFLAGS = -module -avoid-version $(GIO_LIBS) $(CAIRO_LIBS)
14
14
 
15
+ libgimarshallingtests_la_SOURCES = $(GI_DATADIR)/tests/gimarshallingtests.c $(GI_DATADIR)/tests/gimarshallingtests.h
16
+ libgimarshallingtests_la_CFLAGS = $(GIO_CFLAGS)
17
+ libgimarshallingtests_la_LDFLAGS = -module -avoid-version
18
+
15
19
  # g-i doesn't ship these as shared libraries anymore; we build them here
16
20
  Regress-1.0.gir: libregress.la Makefile
17
21
  $(AM_V_GEN) g-ir-scanner --include=cairo-1.0 --include=Gio-2.0 \
@@ -24,7 +28,19 @@ Regress-1.0.gir: libregress.la Makefile
24
28
  Regress-1.0.typelib: Regress-1.0.gir Makefile
25
29
  $(AM_V_GEN) g-ir-compiler $< -o $@
26
30
 
31
+ GIMarshallingTests-1.0.gir: libgimarshallingtests.la Makefile
32
+ $(AM_V_GEN) g-ir-scanner --include=Gio-2.0 \
33
+ --namespace=GIMarshallingTests --nsversion=1.0 \
34
+ --symbol-prefix=gi_marshalling_tests \
35
+ --warn-all --warn-error \
36
+ --library=libgimarshallingtests.la \
37
+ --libtool="$(top_builddir)/libtool" \
38
+ --output $@ \
39
+ $(libgimarshallingtests_la_SOURCES)
40
+ GIMarshallingTests-1.0.typelib: GIMarshallingTests-1.0.gir Makefile
41
+ $(AM_V_GEN) g-ir-compiler $< -o $@
42
+
27
43
  .la.so:
28
44
  test -L $@ || $(LN_S) .libs/$@ $@
29
45
 
30
- all: $(testlib_LTLIBRARIES:.la=.so) Regress-1.0.typelib
46
+ all: $(testlib_LTLIBRARIES:.la=.so) Regress-1.0.typelib GIMarshallingTests-1.0.typelib
@@ -1,6 +1,6 @@
1
1
  require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
2
 
3
- class ModuleBuilderTest < Test::Unit::TestCase
3
+ class ModuleBuilderTest < MiniTest::Spec
4
4
  context "The Builder::Module object" do
5
5
  context "for Gtk" do
6
6
  setup do
data/test/test_helper.rb CHANGED
@@ -1,7 +1,10 @@
1
- require 'shoulda'
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
2
3
  require 'rr'
3
4
  require 'ffi'
4
5
 
6
+ Thread.abort_on_exception = true
7
+
5
8
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
9
 
7
10
  require 'gir_ffi'
@@ -12,15 +15,18 @@ if RUBY_PLATFORM == 'java'
12
15
  end
13
16
 
14
17
  # Since the tests will call Gtk+ functions, Gtk+ must be initialized.
15
- GirFFI.setup :Gtk
18
+ GirFFI.setup :Gtk, '2.0'
16
19
  Gtk.init
17
20
 
18
21
  GirFFI::IRepository.prepend_search_path File.join(File.dirname(__FILE__), 'lib')
19
22
  module GirFFI
20
23
  class IRepository
21
24
  def shared_library_with_regress namespace
22
- if namespace == "Regress"
25
+ case namespace
26
+ when "Regress"
23
27
  return File.join(File.dirname(__FILE__), 'lib', 'libregress.so')
28
+ when "GIMarshallingTests"
29
+ return File.join(File.dirname(__FILE__), 'lib', 'libgimarshallingtests.so')
24
30
  else
25
31
  return shared_library_without_regress namespace
26
32
  end
@@ -35,7 +41,7 @@ end
35
41
  module Lib
36
42
  end
37
43
 
38
- class Test::Unit::TestCase
44
+ class MiniTest::Unit::TestCase
39
45
  include RR::Adapters::TestUnit
40
46
  def cws code
41
47
  code.gsub(/(^\s*|\s*$)/, "")
@@ -53,12 +59,26 @@ class Test::Unit::TestCase
53
59
  gir.find_by_name(namespace, klass).find_method function
54
60
  end
55
61
 
56
- def cleanup_module name
62
+ SAVED_MODULES = {}
63
+
64
+ def save_module name
57
65
  if Object.const_defined? name
66
+ puts "Saving #{name} over existing" if SAVED_MODULES.has_key? name
67
+ SAVED_MODULES[name] = Object.const_get name
58
68
  Object.send(:remove_const, name)
59
69
  end
60
70
  end
61
71
 
72
+ def restore_module name
73
+ if SAVED_MODULES.has_key? name
74
+ if Object.const_defined? name
75
+ Object.send(:remove_const, name)
76
+ end
77
+ Object.const_set name, SAVED_MODULES[name]
78
+ SAVED_MODULES.delete name
79
+ end
80
+ end
81
+
62
82
  def ref_count object
63
83
  GObject::Object::Struct.new(object.to_ptr)[:ref_count]
64
84
  end
@@ -66,4 +86,67 @@ class Test::Unit::TestCase
66
86
  def is_floating? object
67
87
  (GObject::Object::Struct.new(object.to_ptr)[:qdata].address & 2) == 2
68
88
  end
89
+
90
+ def assert_nothing_raised
91
+ yield
92
+ assert true
93
+ end
94
+
95
+ def assert_not_nil it
96
+ refute_nil it
97
+ end
98
+
99
+ def max_for_unsigned_type type
100
+ ( 1 << (FFI.type_size(type) * 8) ) - 1
101
+ end
102
+
103
+ def max_for_type type
104
+ ( 1 << (FFI.type_size(type) * 8 - 1) ) - 1
105
+ end
106
+
107
+ def min_for_type type
108
+ ~max_for_type(type)
109
+ end
110
+
111
+ def max_long
112
+ max_for_type :long
113
+ end
114
+
115
+ def min_long
116
+ min_for_type :long
117
+ end
118
+
119
+ def max_size_t
120
+ max_for_unsigned_type :size_t
121
+ end
122
+
123
+ def max_ssize_t
124
+ # FFI has no :ssize_t, but it's the same number of bits as :size_t
125
+ max_for_type :size_t
126
+ end
127
+
128
+ def min_ssize_t
129
+ min_for_type :size_t
130
+ end
131
+
132
+ def max_ushort
133
+ max_for_unsigned_type :ushort
134
+ end
135
+
136
+ def max_uint
137
+ max_for_unsigned_type :uint
138
+ end
139
+
140
+ def max_ulong
141
+ max_for_unsigned_type :ulong
142
+ end
143
+ end
144
+
145
+ class MiniTest::Spec
146
+ class << self
147
+ alias :setup :before
148
+ alias :teardown :after
149
+ alias :should :it
150
+ alias :context :describe
151
+ end
69
152
  end
@@ -1,12 +1,9 @@
1
1
  require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
2
 
3
- class TypeBuilderTest < Test::Unit::TestCase
3
+ class TypeBuilderTest < MiniTest::Spec
4
4
  context "The Builder::Type class" do
5
- setup do
6
- @gir = GirFFI::IRepository.default
7
- end
8
-
9
5
  should "use parent struct as default layout" do
6
+ @gir = GirFFI::IRepository.default
10
7
  @gir.require 'GObject', nil
11
8
 
12
9
  stub(info = Object.new).parent { @gir.find_by_name 'GObject', 'Object' }
@@ -23,7 +20,7 @@ class TypeBuilderTest < Test::Unit::TestCase
23
20
 
24
21
  context "for Gtk::Widget" do
25
22
  setup do
26
- @cbuilder = GirFFI::Builder::Type::Object.new @gir.find_by_name('Gtk', 'Widget')
23
+ @cbuilder = GirFFI::Builder::Type::Object.new get_function_introspection_data('Gtk', 'Widget')
27
24
  end
28
25
 
29
26
  context "looking at Gtk::Widget#show" do
@@ -42,19 +39,19 @@ class TypeBuilderTest < Test::Unit::TestCase
42
39
 
43
40
  context 'the find_signal method' do
44
41
  should 'find the signal "test" for TestObj' do
45
- builder = GirFFI::Builder::Type::Object.new @gir.find_by_name('Regress', 'TestObj')
42
+ builder = GirFFI::Builder::Type::Object.new get_function_introspection_data('Regress', 'TestObj')
46
43
  sig = builder.find_signal 'test'
47
44
  assert_equal 'test', sig.name
48
45
  end
49
46
 
50
47
  should 'find the signal "test" for TestSubObj' do
51
- builder = GirFFI::Builder::Type::Object.new @gir.find_by_name('Regress', 'TestSubObj')
48
+ builder = GirFFI::Builder::Type::Object.new get_function_introspection_data('Regress', 'TestSubObj')
52
49
  sig = builder.find_signal 'test'
53
50
  assert_equal 'test', sig.name
54
51
  end
55
52
 
56
53
  should 'find the signal "changed" for Gtk::Entry' do
57
- builder = GirFFI::Builder::Type::Object.new @gir.find_by_name('Gtk', 'Entry')
54
+ builder = GirFFI::Builder::Type::Object.new get_function_introspection_data('Gtk', 'Entry')
58
55
  sig = builder.find_signal 'changed'
59
56
  assert_equal 'changed', sig.name
60
57
  end
@@ -62,7 +59,7 @@ class TypeBuilderTest < Test::Unit::TestCase
62
59
 
63
60
  context "for GObject::TypeCValue (a union)" do
64
61
  setup do
65
- @cbuilder = GirFFI::Builder::Type::Union.new @gir.find_by_name('GObject', 'TypeCValue')
62
+ @cbuilder = GirFFI::Builder::Type::Union.new get_function_introspection_data('GObject', 'TypeCValue')
66
63
  end
67
64
 
68
65
  should "not raise an error looking for a method that doesn't exist" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gir_ffi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 8
10
- version: 0.0.8
9
+ - 9
10
+ version: 0.0.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matijs van Zuijlen
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-08 00:00:00 +02:00
19
- default_executable:
18
+ date: 2011-05-02 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: ffi
@@ -35,19 +34,19 @@ dependencies:
35
34
  type: :runtime
36
35
  version_requirements: *id001
37
36
  - !ruby/object:Gem::Dependency
38
- name: shoulda
37
+ name: minitest
39
38
  prerelease: false
40
39
  requirement: &id002 !ruby/object:Gem::Requirement
41
40
  none: false
42
41
  requirements:
43
- - - ~>
42
+ - - ">="
44
43
  - !ruby/object:Gem::Version
45
- hash: 37
44
+ hash: 11
46
45
  segments:
47
46
  - 2
48
- - 11
49
- - 3
50
- version: 2.11.3
47
+ - 0
48
+ - 2
49
+ version: 2.0.2
51
50
  type: :development
52
51
  version_requirements: *id002
53
52
  - !ruby/object:Gem::Dependency
@@ -90,6 +89,7 @@ files:
90
89
  - lib/gir_ffi/builder/module.rb
91
90
  - lib/gir_ffi/builder/function.rb
92
91
  - lib/gir_ffi/builder/type/base.rb
92
+ - lib/gir_ffi/builder/type/constant.rb
93
93
  - lib/gir_ffi/builder/type/interface.rb
94
94
  - lib/gir_ffi/builder/type/struct_based.rb
95
95
  - lib/gir_ffi/builder/type/struct.rb
@@ -146,8 +146,10 @@ files:
146
146
  - test/generated_gtk_test.rb
147
147
  - test/type_builder_test.rb
148
148
  - test/builder_test.rb
149
+ - test/glib_overrides_test.rb
149
150
  - test/gtk_overrides_test.rb
150
151
  - test/generated_gio_test.rb
152
+ - test/generated_gimarshallingtests_test.rb
151
153
  - tasks/test.rake
152
154
  - tasks/setup.rb
153
155
  - tasks/notes.rake
@@ -164,7 +166,6 @@ files:
164
166
  - README.rdoc
165
167
  - History.txt
166
168
  - Rakefile
167
- has_rdoc: true
168
169
  homepage: http://www.github.com/mvz/ruby-gir-ffi
169
170
  licenses: []
170
171
 
@@ -195,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
196
  requirements: []
196
197
 
197
198
  rubyforge_project:
198
- rubygems_version: 1.6.2
199
+ rubygems_version: 1.7.2
199
200
  signing_key:
200
201
  specification_version: 3
201
202
  summary: FFI-based GObject binding using the GObject Introspection Repository
@@ -206,10 +207,12 @@ test_files:
206
207
  - test/function_definition_builder_test.rb
207
208
  - test/g_object_overrides_test.rb
208
209
  - test/g_object_test.rb
210
+ - test/generated_gimarshallingtests_test.rb
209
211
  - test/generated_gio_test.rb
210
212
  - test/generated_gtk_test.rb
211
213
  - test/generated_regress_test.rb
212
214
  - test/girffi_test.rb
215
+ - test/glib_overrides_test.rb
213
216
  - test/gtk_overrides_test.rb
214
217
  - test/i_object_info_test.rb
215
218
  - test/i_repository_test.rb