gir_ffi 0.14.1 → 0.15.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +56 -0
  3. data/README.md +12 -12
  4. data/TODO.md +14 -35
  5. data/docs/Documentation.md +6 -0
  6. data/docs/Subclassing.md +38 -0
  7. data/lib/ffi-glib.rb +26 -21
  8. data/lib/ffi-glib/array.rb +14 -4
  9. data/lib/ffi-glib/byte_array.rb +9 -3
  10. data/lib/ffi-glib/container_class_methods.rb +1 -1
  11. data/lib/ffi-glib/destroy_notify.rb +2 -2
  12. data/lib/ffi-glib/error.rb +1 -1
  13. data/lib/ffi-glib/hash_table.rb +4 -5
  14. data/lib/ffi-glib/list.rb +12 -6
  15. data/lib/ffi-glib/list_methods.rb +13 -1
  16. data/lib/ffi-glib/main_loop.rb +3 -3
  17. data/lib/ffi-glib/ptr_array.rb +30 -8
  18. data/lib/ffi-glib/s_list.rb +11 -5
  19. data/lib/ffi-glib/variant.rb +1 -1
  20. data/lib/ffi-gobject.rb +13 -16
  21. data/lib/ffi-gobject/object.rb +82 -87
  22. data/lib/ffi-gobject/object_class.rb +1 -1
  23. data/lib/ffi-gobject/param_spec.rb +1 -1
  24. data/lib/ffi-gobject/ruby_closure.rb +2 -2
  25. data/lib/ffi-gobject/value.rb +136 -126
  26. data/lib/ffi-gobject_introspection.rb +20 -20
  27. data/lib/ffi-gobject_introspection/gobject_type_init.rb +2 -2
  28. data/lib/ffi-gobject_introspection/i_arg_info.rb +2 -2
  29. data/lib/ffi-gobject_introspection/i_base_info.rb +34 -23
  30. data/lib/ffi-gobject_introspection/i_callable_info.rb +4 -4
  31. data/lib/ffi-gobject_introspection/i_constant_info.rb +2 -2
  32. data/lib/ffi-gobject_introspection/i_enum_info.rb +1 -0
  33. data/lib/ffi-gobject_introspection/i_field_info.rb +1 -1
  34. data/lib/ffi-gobject_introspection/i_function_info.rb +1 -1
  35. data/lib/ffi-gobject_introspection/i_interface_info.rb +1 -1
  36. data/lib/ffi-gobject_introspection/i_object_info.rb +2 -2
  37. data/lib/ffi-gobject_introspection/i_property_info.rb +2 -2
  38. data/lib/ffi-gobject_introspection/i_repository.rb +9 -6
  39. data/lib/ffi-gobject_introspection/i_struct_info.rb +2 -1
  40. data/lib/ffi-gobject_introspection/i_type_info.rb +13 -7
  41. data/lib/ffi-gobject_introspection/i_unresolved_info.rb +1 -1
  42. data/lib/ffi-gobject_introspection/i_vfunc_info.rb +1 -1
  43. data/lib/ffi-gobject_introspection/lib.rb +30 -19
  44. data/lib/ffi-gobject_introspection/strv.rb +1 -1
  45. data/lib/gir_ffi-base.rb +1 -1
  46. data/lib/gir_ffi-base/gobject.rb +26 -25
  47. data/lib/gir_ffi-base/gobject/lib.rb +7 -2
  48. data/lib/gir_ffi.rb +3 -3
  49. data/lib/gir_ffi/allocation_helper.rb +1 -1
  50. data/lib/gir_ffi/arg_helper.rb +4 -4
  51. data/lib/gir_ffi/{in_out_pointer.rb → array_element_convertor.rb} +16 -24
  52. data/lib/gir_ffi/boolean.rb +1 -1
  53. data/lib/gir_ffi/boxed_base.rb +2 -6
  54. data/lib/gir_ffi/builder.rb +19 -11
  55. data/lib/gir_ffi/builder_helper.rb +10 -2
  56. data/lib/gir_ffi/builders/argument_builder.rb +19 -19
  57. data/lib/gir_ffi/builders/argument_builder_collection.rb +2 -2
  58. data/lib/gir_ffi/builders/base_argument_builder.rb +2 -1
  59. data/lib/gir_ffi/builders/base_method_builder.rb +8 -8
  60. data/lib/gir_ffi/builders/base_return_value_builder.rb +1 -1
  61. data/lib/gir_ffi/builders/base_type_builder.rb +2 -2
  62. data/lib/gir_ffi/builders/c_to_ruby_convertor.rb +5 -5
  63. data/lib/gir_ffi/builders/callback_argument_builder.rb +10 -8
  64. data/lib/gir_ffi/builders/callback_builder.rb +28 -14
  65. data/lib/gir_ffi/builders/callback_return_value_builder.rb +6 -8
  66. data/lib/gir_ffi/builders/class_struct_builder.rb +24 -0
  67. data/lib/gir_ffi/builders/closure_argument_builder.rb +1 -1
  68. data/lib/gir_ffi/builders/closure_return_value_builder.rb +1 -1
  69. data/lib/gir_ffi/builders/constant_builder.rb +1 -1
  70. data/lib/gir_ffi/builders/constructor_builder.rb +9 -9
  71. data/lib/gir_ffi/builders/enum_builder.rb +11 -7
  72. data/lib/gir_ffi/builders/field_builder.rb +20 -18
  73. data/lib/gir_ffi/builders/flags_builder.rb +2 -2
  74. data/lib/gir_ffi/builders/full_c_to_ruby_convertor.rb +1 -1
  75. data/lib/gir_ffi/builders/function_builder.rb +11 -5
  76. data/lib/gir_ffi/builders/initializer_builder.rb +3 -3
  77. data/lib/gir_ffi/builders/initializer_return_value_builder.rb +2 -2
  78. data/lib/gir_ffi/builders/interface_builder.rb +5 -3
  79. data/lib/gir_ffi/builders/mapping_method_builder.rb +10 -10
  80. data/lib/gir_ffi/builders/marshalling_method_builder.rb +12 -9
  81. data/lib/gir_ffi/builders/method_template.rb +5 -5
  82. data/lib/gir_ffi/builders/module_builder.rb +7 -7
  83. data/lib/gir_ffi/builders/null_argument_builder.rb +0 -2
  84. data/lib/gir_ffi/builders/null_return_value_builder.rb +0 -2
  85. data/lib/gir_ffi/builders/object_builder.rb +22 -12
  86. data/lib/gir_ffi/builders/property_argument_builder.rb +1 -1
  87. data/lib/gir_ffi/builders/property_builder.rb +14 -14
  88. data/lib/gir_ffi/builders/property_return_value_builder.rb +1 -1
  89. data/lib/gir_ffi/builders/registered_type_builder.rb +14 -5
  90. data/lib/gir_ffi/builders/return_value_builder.rb +4 -4
  91. data/lib/gir_ffi/builders/ruby_to_c_convertor.rb +6 -6
  92. data/lib/gir_ffi/builders/signal_closure_builder.rb +5 -7
  93. data/lib/gir_ffi/builders/struct_builder.rb +8 -6
  94. data/lib/gir_ffi/builders/struct_like.rb +1 -1
  95. data/lib/gir_ffi/builders/type_builder.rb +12 -12
  96. data/lib/gir_ffi/builders/unintrospectable_boxed_builder.rb +2 -2
  97. data/lib/gir_ffi/builders/unintrospectable_builder.rb +2 -2
  98. data/lib/gir_ffi/builders/union_builder.rb +4 -4
  99. data/lib/gir_ffi/builders/user_defined_builder.rb +10 -3
  100. data/lib/gir_ffi/builders/vfunc_argument_builder.rb +2 -2
  101. data/lib/gir_ffi/builders/vfunc_builder.rb +8 -8
  102. data/lib/gir_ffi/builders/with_layout.rb +2 -2
  103. data/lib/gir_ffi/callback_base.rb +7 -9
  104. data/lib/gir_ffi/class_base.rb +6 -5
  105. data/lib/gir_ffi/core.rb +36 -22
  106. data/lib/gir_ffi/enum_base.rb +1 -1
  107. data/lib/gir_ffi/enum_like_base.rb +2 -2
  108. data/lib/gir_ffi/error_argument_info.rb +2 -2
  109. data/lib/gir_ffi/error_type_info.rb +1 -1
  110. data/lib/gir_ffi/ffi_ext.rb +1 -1
  111. data/lib/gir_ffi/ffi_ext/pointer.rb +1 -1
  112. data/lib/gir_ffi/flags_base.rb +1 -1
  113. data/lib/gir_ffi/glib_error.rb +1 -2
  114. data/lib/gir_ffi/in_pointer.rb +17 -0
  115. data/lib/gir_ffi/info_ext.rb +15 -15
  116. data/lib/gir_ffi/info_ext/full_type_name.rb +3 -3
  117. data/lib/gir_ffi/info_ext/i_arg_info.rb +1 -1
  118. data/lib/gir_ffi/info_ext/i_callable_info.rb +1 -1
  119. data/lib/gir_ffi/info_ext/i_callback_info.rb +1 -1
  120. data/lib/gir_ffi/info_ext/i_field_info.rb +1 -1
  121. data/lib/gir_ffi/info_ext/i_function_info.rb +1 -1
  122. data/lib/gir_ffi/info_ext/i_property_info.rb +2 -2
  123. data/lib/gir_ffi/info_ext/i_registered_type_info.rb +4 -5
  124. data/lib/gir_ffi/info_ext/i_signal_info.rb +7 -3
  125. data/lib/gir_ffi/info_ext/i_type_info.rb +48 -26
  126. data/lib/gir_ffi/info_ext/i_unresolved_info.rb +1 -1
  127. data/lib/gir_ffi/info_ext/i_value_info.rb +2 -2
  128. data/lib/gir_ffi/info_ext/i_vfunc_info.rb +2 -2
  129. data/lib/gir_ffi/info_ext/safe_constant_name.rb +8 -8
  130. data/lib/gir_ffi/info_ext/safe_function_name.rb +2 -2
  131. data/lib/gir_ffi/interface_base.rb +3 -3
  132. data/lib/gir_ffi/lib_c.rb +1 -1
  133. data/lib/gir_ffi/method_stubber.rb +1 -1
  134. data/lib/gir_ffi/module_base.rb +1 -1
  135. data/lib/gir_ffi/object_base.rb +30 -4
  136. data/lib/gir_ffi/receiver_argument_info.rb +1 -1
  137. data/lib/gir_ffi/receiver_type_info.rb +2 -2
  138. data/lib/gir_ffi/registered_type_base.rb +1 -1
  139. data/lib/gir_ffi/return_value_info.rb +1 -2
  140. data/lib/gir_ffi/sized_array.rb +4 -2
  141. data/lib/gir_ffi/struct.rb +1 -1
  142. data/lib/gir_ffi/struct_base.rb +2 -10
  143. data/lib/gir_ffi/struct_like_base.rb +9 -5
  144. data/lib/gir_ffi/type_map.rb +2 -23
  145. data/lib/gir_ffi/unintrospectable_boxed_info.rb +2 -2
  146. data/lib/gir_ffi/unintrospectable_type_info.rb +6 -2
  147. data/lib/gir_ffi/union.rb +1 -1
  148. data/lib/gir_ffi/union_base.rb +2 -10
  149. data/lib/gir_ffi/user_defined_object_info.rb +9 -4
  150. data/lib/gir_ffi/user_defined_property_info.rb +33 -33
  151. data/lib/gir_ffi/version.rb +1 -1
  152. data/lib/gir_ffi/vfunc_implementation.rb +1 -0
  153. metadata +102 -155
  154. data/Gemfile +0 -12
  155. data/Rakefile +0 -9
  156. data/lib/ffi-glib/array_methods.rb +0 -16
  157. data/tasks/test.rake +0 -203
  158. data/test/base_test_helper.rb +0 -63
  159. data/test/ffi-glib/array_test.rb +0 -188
  160. data/test/ffi-glib/byte_array_test.rb +0 -22
  161. data/test/ffi-glib/bytes_test.rb +0 -56
  162. data/test/ffi-glib/closure_test.rb +0 -38
  163. data/test/ffi-glib/destroy_notify_test.rb +0 -18
  164. data/test/ffi-glib/hash_table_test.rb +0 -68
  165. data/test/ffi-glib/list_test.rb +0 -86
  166. data/test/ffi-glib/main_loop_test.rb +0 -53
  167. data/test/ffi-glib/ptr_array_test.rb +0 -112
  168. data/test/ffi-glib/ruby_closure_test.rb +0 -62
  169. data/test/ffi-glib/s_list_test.rb +0 -76
  170. data/test/ffi-glib/strv_test.rb +0 -60
  171. data/test/ffi-glib/variant_test.rb +0 -12
  172. data/test/ffi-gobject/gobject_test.rb +0 -72
  173. data/test/ffi-gobject/object_class_test.rb +0 -31
  174. data/test/ffi-gobject/object_test.rb +0 -140
  175. data/test/ffi-gobject/param_spec_test.rb +0 -32
  176. data/test/ffi-gobject/value_test.rb +0 -370
  177. data/test/ffi-gobject_introspection/gobject_type_init_test.rb +0 -26
  178. data/test/ffi-gobject_introspection/i_base_info_test.rb +0 -53
  179. data/test/ffi-gobject_introspection/i_constant_info_test.rb +0 -33
  180. data/test/ffi-gobject_introspection/i_enum_info_test.rb +0 -18
  181. data/test/ffi-gobject_introspection/i_function_info_test.rb +0 -6
  182. data/test/ffi-gobject_introspection/i_interface_info_test.rb +0 -23
  183. data/test/ffi-gobject_introspection/i_object_info_test.rb +0 -49
  184. data/test/ffi-gobject_introspection/i_property_info_test.rb +0 -47
  185. data/test/ffi-gobject_introspection/i_registered_type_info_test.rb +0 -27
  186. data/test/ffi-gobject_introspection/i_repository_test.rb +0 -81
  187. data/test/ffi-gobject_introspection/i_struct_info_test.rb +0 -23
  188. data/test/ffi-gobject_introspection/i_type_info_test.rb +0 -33
  189. data/test/ffi-gobject_introspection/i_union_info_test.rb +0 -17
  190. data/test/ffi-gobject_introspection/i_vfunc_info_test.rb +0 -41
  191. data/test/ffi-gobject_introspection/lib_test.rb +0 -13
  192. data/test/ffi-gobject_introspection/strv_test.rb +0 -46
  193. data/test/ffi-gobject_test.rb +0 -151
  194. data/test/gir_ffi/allocation_helper_test.rb +0 -36
  195. data/test/gir_ffi/arg_helper_test.rb +0 -140
  196. data/test/gir_ffi/boolean_test.rb +0 -43
  197. data/test/gir_ffi/boxed_base_test.rb +0 -65
  198. data/test/gir_ffi/builder_test.rb +0 -300
  199. data/test/gir_ffi/builders/argument_builder_test.rb +0 -657
  200. data/test/gir_ffi/builders/base_argument_builder_test.rb +0 -6
  201. data/test/gir_ffi/builders/callback_argument_builder_test.rb +0 -129
  202. data/test/gir_ffi/builders/callback_builder_test.rb +0 -118
  203. data/test/gir_ffi/builders/callback_return_value_builder_test.rb +0 -85
  204. data/test/gir_ffi/builders/constant_builder_test.rb +0 -6
  205. data/test/gir_ffi/builders/constructor_builder_test.rb +0 -37
  206. data/test/gir_ffi/builders/enum_builder_test.rb +0 -23
  207. data/test/gir_ffi/builders/field_builder_test.rb +0 -134
  208. data/test/gir_ffi/builders/function_builder_test.rb +0 -538
  209. data/test/gir_ffi/builders/initializer_builder_test.rb +0 -54
  210. data/test/gir_ffi/builders/interface_builder_test.rb +0 -32
  211. data/test/gir_ffi/builders/module_builder_test.rb +0 -43
  212. data/test/gir_ffi/builders/object_builder_test.rb +0 -98
  213. data/test/gir_ffi/builders/property_builder_test.rb +0 -161
  214. data/test/gir_ffi/builders/registered_type_builder_test.rb +0 -30
  215. data/test/gir_ffi/builders/return_value_builder_test.rb +0 -440
  216. data/test/gir_ffi/builders/signal_closure_builder_test.rb +0 -188
  217. data/test/gir_ffi/builders/struct_builder_test.rb +0 -93
  218. data/test/gir_ffi/builders/unintrospectable_boxed_builder_test.rb +0 -35
  219. data/test/gir_ffi/builders/unintrospectable_builder_test.rb +0 -73
  220. data/test/gir_ffi/builders/union_builder_test.rb +0 -31
  221. data/test/gir_ffi/builders/user_defined_builder_test.rb +0 -524
  222. data/test/gir_ffi/builders/vfunc_argument_builder_test.rb +0 -101
  223. data/test/gir_ffi/builders/vfunc_builder_test.rb +0 -253
  224. data/test/gir_ffi/callback_base_test.rb +0 -22
  225. data/test/gir_ffi/class_base_test.rb +0 -168
  226. data/test/gir_ffi/core_test.rb +0 -98
  227. data/test/gir_ffi/enum_base_test.rb +0 -43
  228. data/test/gir_ffi/error_type_info_test.rb +0 -50
  229. data/test/gir_ffi/ffi_ext/pointer_test.rb +0 -20
  230. data/test/gir_ffi/g_type_test.rb +0 -31
  231. data/test/gir_ffi/in_out_pointer_test.rb +0 -56
  232. data/test/gir_ffi/in_pointer_test.rb +0 -183
  233. data/test/gir_ffi/info_ext/i_callable_info_test.rb +0 -26
  234. data/test/gir_ffi/info_ext/i_callback_info_test.rb +0 -21
  235. data/test/gir_ffi/info_ext/i_field_info_test.rb +0 -37
  236. data/test/gir_ffi/info_ext/i_function_info_test.rb +0 -74
  237. data/test/gir_ffi/info_ext/i_signal_info_test.rb +0 -32
  238. data/test/gir_ffi/info_ext/i_type_info_test.rb +0 -697
  239. data/test/gir_ffi/info_ext/i_unresolved_info_test.rb +0 -19
  240. data/test/gir_ffi/info_ext/safe_constant_name_test.rb +0 -26
  241. data/test/gir_ffi/info_ext/safe_function_name_test.rb +0 -26
  242. data/test/gir_ffi/interface_base_test.rb +0 -20
  243. data/test/gir_ffi/method_stubber_test.rb +0 -65
  244. data/test/gir_ffi/object_base_test.rb +0 -64
  245. data/test/gir_ffi/object_store_test.rb +0 -41
  246. data/test/gir_ffi/receiver_argument_info_test.rb +0 -33
  247. data/test/gir_ffi/sized_array_test.rb +0 -206
  248. data/test/gir_ffi/struct_base_test.rb +0 -23
  249. data/test/gir_ffi/struct_like_base_test.rb +0 -167
  250. data/test/gir_ffi/type_map_test.rb +0 -17
  251. data/test/gir_ffi/unintrospectable_type_info_test.rb +0 -121
  252. data/test/gir_ffi/union_base_test.rb +0 -23
  253. data/test/gir_ffi/user_defined_object_info_test.rb +0 -119
  254. data/test/gir_ffi/user_defined_property_info_test.rb +0 -39
  255. data/test/gir_ffi/variable_name_generator_test.rb +0 -18
  256. data/test/gir_ffi/version_test.rb +0 -9
  257. data/test/gir_ffi/zero_terminated_test.rb +0 -108
  258. data/test/gir_ffi_test_helper.rb +0 -84
  259. data/test/integration/callback_exceptions_test.rb +0 -63
  260. data/test/integration/derived_classes_test.rb +0 -53
  261. data/test/integration/generated_everything_test.rb +0 -452
  262. data/test/integration/generated_gimarshallingtests_test.rb +0 -2995
  263. data/test/integration/generated_gio_test.rb +0 -116
  264. data/test/integration/generated_glib_test.rb +0 -12
  265. data/test/integration/generated_gobject_test.rb +0 -116
  266. data/test/integration/generated_gst_test.rb +0 -34
  267. data/test/integration/generated_gtk_source_test.rb +0 -27
  268. data/test/integration/generated_gtop_test.rb +0 -29
  269. data/test/integration/generated_pango_ft2_test.rb +0 -17
  270. data/test/integration/generated_pango_test.rb +0 -24
  271. data/test/integration/generated_regress_test.rb +0 -3850
  272. data/test/integration/generated_secret_test.rb +0 -17
  273. data/test/integration/generated_utility_test.rb +0 -174
  274. data/test/integration/generated_warnlib_test.rb +0 -49
  275. data/test/integration/method_lookup_test.rb +0 -34
  276. data/test/introspection_test_helper.rb +0 -52
  277. data/test/lib/Makefile.am +0 -110
  278. data/test/lib/autogen.sh +0 -4
  279. data/test/lib/configure.ac +0 -34
  280. data/test/lib/m4/jhflags.m4 +0 -21
  281. data/test/minitest/stats_plugin.rb +0 -30
@@ -1,188 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'gir_ffi_test_helper'
4
-
5
- describe GirFFI::Builders::SignalClosureBuilder do
6
- let(:builder) { GirFFI::Builders::SignalClosureBuilder.new signal_info }
7
-
8
- describe '#build_class' do
9
- let(:signal_info) do
10
- get_signal_introspection_data 'Regress', 'TestObj', 'test'
11
- end
12
-
13
- it 'builds a descendant of RubyClosure' do
14
- klass = builder.build_class
15
- klass.superclass.must_equal GObject::RubyClosure
16
- end
17
- end
18
-
19
- describe '#marshaller_definition' do
20
- describe 'for a signal with no arguments or return value' do
21
- let(:signal_info) do
22
- get_signal_introspection_data 'Regress', 'TestObj', 'test'
23
- end
24
-
25
- it 'returns a valid marshaller converting only the receiver' do
26
- expected = <<-CODE.reset_indentation
27
- def self.marshaller(closure, return_value, param_values, _invocation_hint, _marshal_data)
28
- _instance = param_values.first.get_value_plain
29
- _v1 = _instance
30
- wrap(closure.to_ptr).invoke_block(_v1)
31
- end
32
- CODE
33
-
34
- builder.marshaller_definition.must_equal expected
35
- end
36
- end
37
-
38
- describe 'for a signal with an argument and a return value' do
39
- let(:signal_info) do
40
- get_signal_introspection_data 'Regress', 'TestObj', 'sig-with-int64-prop'
41
- end
42
-
43
- it 'returns a valid mapping method' do
44
- skip unless signal_info
45
-
46
- expected = <<-CODE.reset_indentation
47
- def self.marshaller(closure, return_value, param_values, _invocation_hint, _marshal_data)
48
- _instance, i = param_values.map(&:get_value_plain)
49
- _v1 = _instance
50
- _v2 = i
51
- _v3 = wrap(closure.to_ptr).invoke_block(_v1, _v2)
52
- return_value.set_value _v3
53
- end
54
- CODE
55
-
56
- builder.marshaller_definition.must_equal expected
57
- end
58
- end
59
-
60
- describe 'for a signal with an enum argument' do
61
- let(:signal_info) do
62
- get_signal_introspection_data 'Gio', 'MountOperation', 'reply'
63
- end
64
-
65
- it 'returns a valid mapping method' do
66
- expected = <<-CODE.reset_indentation
67
- def self.marshaller(closure, return_value, param_values, _invocation_hint, _marshal_data)
68
- _instance, result = param_values.map(&:get_value_plain)
69
- _v1 = _instance
70
- _v2 = result
71
- wrap(closure.to_ptr).invoke_block(_v1, _v2)
72
- end
73
- CODE
74
-
75
- builder.marshaller_definition.must_equal expected
76
- end
77
- end
78
-
79
- describe 'for a signal with a array plus length arguments' do
80
- let(:signal_info) do
81
- get_signal_introspection_data 'Regress', 'TestObj', 'sig-with-array-len-prop'
82
- end
83
-
84
- it 'returns a valid mapping method' do
85
- skip unless signal_info
86
-
87
- expected = <<-CODE.reset_indentation
88
- def self.marshaller(closure, return_value, param_values, _invocation_hint, _marshal_data)
89
- _instance, arr, len = param_values.map(&:get_value_plain)
90
- _v1 = _instance
91
- _v2 = len
92
- _v3 = GirFFI::SizedArray.wrap(:guint32, _v2, arr)
93
- wrap(closure.to_ptr).invoke_block(_v1, _v3)
94
- end
95
- CODE
96
-
97
- builder.marshaller_definition.must_equal expected
98
- end
99
- end
100
-
101
- describe 'for a signal with a struct argument' do
102
- let(:signal_info) do
103
- get_signal_introspection_data 'Regress', 'TestObj', 'test-with-static-scope-arg'
104
- end
105
-
106
- it 'returns a valid mapping method' do
107
- skip unless signal_info
108
-
109
- expected = <<-CODE.reset_indentation
110
- def self.marshaller(closure, return_value, param_values, _invocation_hint, _marshal_data)
111
- _instance, object = param_values.map(&:get_value_plain)
112
- _v1 = _instance
113
- _v2 = Regress::TestSimpleBoxedA.wrap(object)
114
- wrap(closure.to_ptr).invoke_block(_v1, _v2)
115
- end
116
- CODE
117
-
118
- builder.marshaller_definition.must_equal expected
119
- end
120
- end
121
-
122
- describe 'for a signal returning an array of integers' do
123
- let(:signal_info) do
124
- get_signal_introspection_data 'Regress', 'TestObj', 'sig-with-intarray-ret'
125
- end
126
-
127
- it 'returns a valid mapping method' do
128
- skip unless signal_info
129
-
130
- expected = <<-CODE.reset_indentation
131
- def self.marshaller(closure, return_value, param_values, _invocation_hint, _marshal_data)
132
- _instance, i = param_values.map(&:get_value_plain)
133
- _v1 = _instance
134
- _v2 = i
135
- _v3 = wrap(closure.to_ptr).invoke_block(_v1, _v2)
136
- _v4 = GLib::Array.from(:gint32, _v3)
137
- return_value.set_value _v4
138
- end
139
- CODE
140
-
141
- builder.marshaller_definition.must_equal expected
142
- end
143
- end
144
-
145
- describe 'for a signal returning an string' do
146
- let(:signal_info) do
147
- get_signal_introspection_data 'Gtk', 'Scale', 'format-value'
148
- end
149
-
150
- it 'returns a mapping method that passes the string result to return_value directly' do
151
- skip unless signal_info
152
-
153
- expected = <<-CODE.reset_indentation
154
- def self.marshaller(closure, return_value, param_values, _invocation_hint, _marshal_data)
155
- _instance, value = param_values.map(&:get_value_plain)
156
- _v1 = _instance
157
- _v2 = value
158
- _v3 = wrap(closure.to_ptr).invoke_block(_v1, _v2)
159
- return_value.set_value _v3
160
- end
161
- CODE
162
-
163
- builder.marshaller_definition.must_equal expected
164
- end
165
- end
166
-
167
- describe 'for a signal with GList argument' do
168
- let(:signal_info) do
169
- get_signal_introspection_data 'Regress', 'AnnotationObject', 'list-signal'
170
- end
171
-
172
- it 'returns a valid mapping method' do
173
- skip unless signal_info
174
-
175
- expected = <<-CODE.reset_indentation
176
- def self.marshaller(closure, return_value, param_values, _invocation_hint, _marshal_data)
177
- _instance, list = param_values.map(&:get_value_plain)
178
- _v1 = _instance
179
- _v2 = GLib::List.wrap(:utf8, list)
180
- wrap(closure.to_ptr).invoke_block(_v1, _v2)
181
- end
182
- CODE
183
-
184
- builder.marshaller_definition.must_equal expected
185
- end
186
- end
187
- end
188
- end
@@ -1,93 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'gir_ffi_test_helper'
4
-
5
- describe GirFFI::Builders::StructBuilder do
6
- describe '#layout_specification' do
7
- it 'returns the correct layout for Regress::TestStructA' do
8
- info = get_introspection_data 'Regress', 'TestStructA'
9
- builder = GirFFI::Builders::StructBuilder.new info
10
- builder.layout_specification.must_equal [:some_int, :int32, 0,
11
- :some_int8, :int8, 4,
12
- :some_double, :double, 8,
13
- :some_enum, Regress::TestEnum, 16]
14
- end
15
-
16
- describe 'for a struct with a simple layout' do
17
- before do
18
- @field = Object.new
19
-
20
- @struct = Object.new
21
- allow(@struct).to receive(:namespace).and_return 'Foo'
22
- allow(@struct).to receive(:safe_name).and_return 'Bar'
23
- allow(@struct).to receive(:fields).and_return [@field]
24
-
25
- @builder = GirFFI::Builders::StructBuilder.new @struct
26
- end
27
-
28
- it 'creates the correct layout specification' do
29
- expect(@field).to receive(:layout_specification).and_return [:bar, :int32, 0]
30
- spec = @builder.layout_specification
31
- assert_equal [:bar, :int32, 0], spec
32
- end
33
- end
34
-
35
- describe 'for a struct with a layout with a complex type' do
36
- it 'does not flatten the complex type specification' do
37
- expect(simplefield = Object.new).to receive(:layout_specification).and_return [:bar, :foo, 0]
38
- expect(complexfield = Object.new).to receive(:layout_specification).and_return [:baz, [:qux, 2], 0]
39
- expect(struct = Object.new).to receive(:fields).and_return [simplefield, complexfield]
40
-
41
- allow(struct).to receive(:safe_name).and_return 'Bar'
42
- allow(struct).to receive(:namespace).and_return 'Foo'
43
-
44
- builder = GirFFI::Builders::StructBuilder.new struct
45
- spec = builder.layout_specification
46
- assert_equal [:bar, :foo, 0, :baz, [:qux, 2], 0], spec
47
- end
48
- end
49
- end
50
-
51
- describe '#superclass' do
52
- it 'returns StructBase for a normal struct' do
53
- info = get_introspection_data 'Regress', 'TestStructA'
54
- builder = GirFFI::Builders::StructBuilder.new info
55
- builder.superclass.must_equal GirFFI::StructBase
56
- end
57
-
58
- it 'returns BoxedBase for a boxed type' do
59
- info = get_introspection_data 'Regress', 'TestSimpleBoxedB'
60
- builder = GirFFI::Builders::StructBuilder.new info
61
- builder.superclass.must_equal GirFFI::BoxedBase
62
- end
63
-
64
- it 'returns the GObject parent class for a type class' do
65
- info = get_introspection_data 'GIMarshallingTests', 'SubSubObjectClass'
66
- builder = GirFFI::Builders::StructBuilder.new info
67
- builder.superclass.must_equal GIMarshallingTests::SubObjectClass
68
- end
69
-
70
- it 'returns ObjectClass for InitiallyUnownedClass' do
71
- info = get_introspection_data 'GObject', 'InitiallyUnownedClass'
72
- builder = GirFFI::Builders::StructBuilder.new info
73
- builder.superclass.must_equal GObject::ObjectClass
74
- end
75
- end
76
-
77
- describe '#setup_class' do
78
- before do
79
- save_module :Regress
80
- end
81
-
82
- it 'stubs the structs methods' do
83
- info = get_introspection_data 'Regress', 'TestStructA'
84
- builder = GirFFI::Builders::StructBuilder.new info
85
- builder.setup_class
86
- assert_defines_instance_method Regress::TestStructA, :clone
87
- end
88
-
89
- after do
90
- restore_module :Regress
91
- end
92
- end
93
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'gir_ffi_test_helper'
4
-
5
- GirFFI.setup :GIMarshallingTests
6
-
7
- describe GirFFI::Builders::UnintrospectableBoxedBuilder do
8
- let(:instance) { GIMarshallingTests::PropertiesObject.new }
9
- let(:property) { instance.object_class.find_property 'some-boxed-glist' }
10
- let(:gtype) { property.value_type }
11
- let(:info) { GirFFI::UnintrospectableBoxedInfo.new(gtype) }
12
- let(:bldr) { GirFFI::Builders::UnintrospectableBoxedBuilder.new(info) }
13
- let(:boxed_class) { bldr.build_class }
14
-
15
- before do
16
- skip unless get_property_introspection_data('GIMarshallingTests',
17
- 'PropertiesObject',
18
- 'some-boxed-glist')
19
- end
20
-
21
- it 'builds a class' do
22
- boxed_class.must_be_instance_of Class
23
- end
24
-
25
- it 'builds a class derived from GirFFI::BoxedBase' do
26
- boxed_class.superclass.must_equal GirFFI::BoxedBase
27
- end
28
-
29
- it 'returns the same class when built again' do
30
- other_bldr = GirFFI::Builders::UnintrospectableBoxedBuilder.new(info)
31
- other_class = other_bldr.build_class
32
-
33
- other_class.must_equal boxed_class
34
- end
35
- end
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'gir_ffi_test_helper'
4
-
5
- GirFFI.setup :Gio
6
- GirFFI.setup :Gst
7
-
8
- describe GirFFI::Builders::UnintrospectableBuilder do
9
- describe 'building the GLocalFile type' do
10
- before do
11
- Gio.file_new_for_path '/'
12
-
13
- @gtype = GObject.type_from_name 'GLocalFile'
14
- @info = GirFFI::UnintrospectableTypeInfo.new(@gtype)
15
- @bldr = GirFFI::Builders::UnintrospectableBuilder.new(@info)
16
- @klass = @bldr.build_class
17
- end
18
-
19
- it 'builds a class' do
20
- assert_instance_of Class, @klass
21
- end
22
-
23
- it 'builds a class derived from GObject::Object' do
24
- assert_includes @klass.registered_ancestors, GObject::Object
25
- end
26
-
27
- it 'builds a class derived from Gio::File' do
28
- assert_includes @klass.registered_ancestors, Gio::File
29
- end
30
-
31
- it 'returns the same class when built again' do
32
- other_bldr = GirFFI::Builders::UnintrospectableBuilder.new(@info)
33
- other_klass = other_bldr.build_class
34
-
35
- assert_equal @klass, other_klass
36
- end
37
-
38
- describe 'its #find_signal method' do
39
- it "returns nil for a signal that doesn't exist" do
40
- @bldr.find_signal('foo').must_be_nil
41
- end
42
-
43
- it 'finds signals in ancestor classes' do
44
- signal = @bldr.find_signal 'notify'
45
- signal.name.must_equal 'notify'
46
- end
47
- end
48
-
49
- describe '#object_class_struct' do
50
- it 'returns the parent class struct' do
51
- @bldr.object_class_struct.must_equal GObject::ObjectClass
52
- end
53
- end
54
- end
55
-
56
- describe 'building the GstFakeSink type' do
57
- let(:instance) { Gst::ElementFactory.make('fakesink', 'sink') }
58
- let(:sink_class) { instance.class }
59
- let(:builder) { sink_class.gir_ffi_builder }
60
-
61
- before do
62
- Gst.init []
63
- end
64
-
65
- describe 'its #find_signal method' do
66
- it 'finds signals that are not defined in the GIR' do
67
- signal = builder.find_signal 'handoff'
68
- signal.wont_be_nil
69
- signal.name.must_equal 'handoff'
70
- end
71
- end
72
- end
73
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'gir_ffi_test_helper'
4
-
5
- describe GirFFI::Builders::UnionBuilder do
6
- let(:union_info) { get_introspection_data('GObject', 'TypeCValue') }
7
- let(:builder) { GirFFI::Builders::UnionBuilder.new union_info }
8
-
9
- describe '#setup_instance_method' do
10
- it "returns nil looking for a method that doesn't exist" do
11
- builder.setup_instance_method('blub').must_be_nil
12
- end
13
- end
14
-
15
- describe '#layout_specification' do
16
- it 'returns the correct layout for GObject::TypeCValue' do
17
- long_type = FFI.type_size(:long) == 8 ? :int64 : :int32
18
- builder.layout_specification.must_equal [:v_int, :int32, 0,
19
- :v_long, long_type, 0,
20
- :v_int64, :int64, 0,
21
- :v_double, :double, 0,
22
- :v_pointer, :pointer, 0]
23
- end
24
- end
25
-
26
- describe '#layout_superclass' do
27
- it 'returns GirFFI::Union' do
28
- builder.layout_superclass.must_equal GirFFI::Union
29
- end
30
- end
31
- end
@@ -1,524 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'gir_ffi_test_helper'
4
-
5
- GirFFI.setup :GIMarshallingTests
6
- GirFFI.setup :Regress
7
-
8
- describe GirFFI::Builders::UserDefinedBuilder do
9
- let(:base_class) { GIMarshallingTests::Object }
10
- let(:derived_class) do
11
- Object.const_set("DerivedClass#{Sequence.next}", Class.new(base_class))
12
- end
13
- let(:builder) { GirFFI::Builders::UserDefinedBuilder.new info }
14
- let(:info) { GirFFI::UserDefinedObjectInfo.new derived_class }
15
-
16
- describe '#build_class' do
17
- before do
18
- builder.build_class
19
- end
20
-
21
- describe 'with type info containing one integer property' do
22
- let(:info) do
23
- GirFFI::UserDefinedObjectInfo.new derived_class do |it|
24
- it.install_property GObject.param_spec_int('foo-bar', 'foo bar',
25
- 'The Foo Bar Property',
26
- 10, 20, 15,
27
- readable: true, writable: true)
28
- end
29
- end
30
-
31
- it 'registers a type that is bigger than the parent' do
32
- gtype = derived_class.gtype
33
- q = GObject.type_query gtype
34
- q.instance_size.must_be :>, GIMarshallingTests::Object::Struct.size
35
- end
36
-
37
- it "gives the type's Struct fields for the parent and the property" do
38
- derived_class::Struct.members.must_equal [:parent, :foo_bar]
39
- end
40
-
41
- it 'creates accessor functions for the property' do
42
- obj = derived_class.new
43
- obj.foo_bar = 13
44
- obj.foo_bar.must_equal 13
45
- end
46
-
47
- it 'makes the property retrievable using #get_property' do
48
- obj = derived_class.new
49
- obj.foo_bar = 13
50
- obj.get_property('foo-bar').must_equal 13
51
- end
52
-
53
- it 'makes the property settable using #set_property' do
54
- obj = derived_class.new
55
- obj.set_property('foo-bar', 20)
56
- obj.foo_bar.must_equal 20
57
- end
58
-
59
- it 'keeps parent properties accessible through their accessors' do
60
- obj = derived_class.new
61
- obj.int = 24
62
- obj.int.must_equal 24
63
- end
64
-
65
- it 'keeps parent properties accessible through get_property and set_property' do
66
- obj = derived_class.new
67
- obj.set_property('int', 24)
68
- obj.get_property('int').must_equal 24
69
- end
70
- end
71
-
72
- describe 'with type info containing properties of several different types' do
73
- let(:info) do
74
- GirFFI::UserDefinedObjectInfo.new derived_class do |it|
75
- it.install_property GObject.param_spec_string('string-prop', 'string property',
76
- 'The String Property',
77
- 'this is the default value',
78
- readable: true, writable: true)
79
- it.install_property GObject.param_spec_int('int-prop', 'integer property',
80
- 'The Integer Property',
81
- 10, 20, 15,
82
- readable: true, writable: true)
83
- it.install_property GObject.param_spec_long('long-prop', 'long property',
84
- 'The Long Property',
85
- 10.0, 50.0, 42.0,
86
- readable: true, writable: true)
87
- end
88
- end
89
-
90
- it 'registers a type of the proper size' do
91
- expected_size = derived_class::Struct.size
92
- gtype = derived_class.gtype
93
- q = GObject.type_query gtype
94
- q.instance_size.must_equal expected_size
95
- end
96
-
97
- it "gives the type's Struct fields for the parent and the properties with the correct offsets" do
98
- offsets = derived_class::Struct.offsets
99
- alignment = derived_class::Struct.alignment
100
- alignment.must_equal 8 # TODO: Fix tests for platforms where this fails.
101
- offsets.must_equal [[:parent, 0], [:string_prop, 32], [:int_prop, 40], [:long_prop, 48]]
102
- end
103
-
104
- it 'creates accessor functions for the string property' do
105
- obj = derived_class.new
106
- obj.string_prop = 'hello!'
107
- obj.string_prop.must_equal 'hello!'
108
- end
109
-
110
- it 'creates accessor functions for the integer property' do
111
- obj = derived_class.new
112
- obj.int_prop = 13
113
- obj.int_prop.must_equal 13
114
- end
115
- end
116
-
117
- describe 'with a boxed property' do
118
- let(:boxed_gtype) { GIMarshallingTests::BoxedStruct.gtype }
119
- let(:info) do
120
- GirFFI::UserDefinedObjectInfo.new derived_class do |it|
121
- it.install_property GObject.param_spec_boxed('boxed-prop', 'boxed property',
122
- 'The Boxed Property',
123
- boxed_gtype,
124
- readable: true, writable: true)
125
- end
126
- end
127
-
128
- it 'registers a type of the proper size' do
129
- expected_size = derived_class::Struct.size
130
- gtype = derived_class.gtype
131
- q = GObject.type_query gtype
132
- q.instance_size.must_equal expected_size
133
- end
134
-
135
- it "gives the type's Struct fields for the parent and the property" do
136
- derived_class::Struct.members.must_equal [:parent, :boxed_prop]
137
- end
138
-
139
- it 'creates accessor functions for the property' do
140
- obj = derived_class.new
141
- boxed = GIMarshallingTests::BoxedStruct.new
142
- boxed.long_ = 423
143
- obj.boxed_prop = boxed
144
- obj.boxed_prop.long_.must_equal 423
145
- end
146
- end
147
-
148
- describe 'with an object property' do
149
- let(:object_gtype) { GIMarshallingTests::Object.gtype }
150
- let(:info) do
151
- GirFFI::UserDefinedObjectInfo.new derived_class do |it|
152
- it.install_property GObject.param_spec_object('object-prop', 'object property',
153
- 'The Object Property',
154
- object_gtype,
155
- readable: true, writable: true)
156
- end
157
- end
158
-
159
- it 'registers a type of the proper size' do
160
- expected_size = derived_class::Struct.size
161
- gtype = derived_class.gtype
162
- q = GObject.type_query gtype
163
- q.instance_size.must_equal expected_size
164
- end
165
-
166
- it "gives the type's Struct fields for the parent and the property" do
167
- derived_class::Struct.members.must_equal [:parent, :object_prop]
168
- end
169
-
170
- it 'creates accessor functions for the property' do
171
- obj = derived_class.new
172
- object = GIMarshallingTests::Object.new 42
173
- object.int = 423
174
- obj.object_prop = object
175
- obj.object_prop.int.must_equal 423
176
- end
177
-
178
- it 'allows clearing the property throught the setter method' do
179
- obj = derived_class.new
180
- obj.object_prop = nil
181
- obj.object_prop.must_be_nil
182
- end
183
-
184
- it 'handles reference counting correctly when using the accessor' do
185
- obj = derived_class.new
186
- object = GIMarshallingTests::Object.new 42
187
- obj.object_prop = object
188
- object_ref_count(object).must_equal 2
189
- end
190
-
191
- it 'handles reference counting correctly when using the set_property method' do
192
- obj = derived_class.new
193
- object = GIMarshallingTests::Object.new 42
194
-
195
- object_ref_count(object).must_equal 1
196
- obj.set_property('object_prop', object)
197
- object_ref_count(object).must_equal 4 # Due to extra Value#set_value + Value#get_value
198
- end
199
- end
200
-
201
- describe 'with a boolean property' do
202
- let(:object_gtype) { GIMarshallingTests::Object.gtype }
203
- let(:info) do
204
- GirFFI::UserDefinedObjectInfo.new derived_class do |it|
205
- it.install_property GObject.param_spec_boolean('the-prop', 'the property',
206
- 'The Property',
207
- true,
208
- readable: true, writable: true)
209
- end
210
- end
211
-
212
- it 'creates accessor functions for the property' do
213
- obj = derived_class.new
214
- obj.the_prop = true
215
- obj.the_prop.must_equal true
216
- end
217
- end
218
-
219
- describe 'with a char property' do
220
- let(:object_gtype) { GIMarshallingTests::Object.gtype }
221
- let(:info) do
222
- GirFFI::UserDefinedObjectInfo.new derived_class do |it|
223
- it.install_property GObject.param_spec_char('the-prop', 'the property',
224
- 'The Property',
225
- -20, 100, 15,
226
- readable: true, writable: true)
227
- end
228
- end
229
-
230
- it 'creates accessor functions for the property' do
231
- obj = derived_class.new
232
- obj.the_prop = -13
233
- obj.the_prop.must_equal(-13)
234
- end
235
- end
236
-
237
- describe 'with a uchar property' do
238
- let(:object_gtype) { GIMarshallingTests::Object.gtype }
239
- let(:info) do
240
- GirFFI::UserDefinedObjectInfo.new derived_class do |it|
241
- it.install_property GObject.param_spec_uchar('the-prop', 'the property',
242
- 'The Property',
243
- 10, 100, 15,
244
- readable: true, writable: true)
245
- end
246
- end
247
-
248
- it 'creates accessor functions for the property' do
249
- obj = derived_class.new
250
- obj.the_prop = 13
251
- obj.the_prop.must_equal 13
252
- end
253
- end
254
-
255
- describe 'with a uint property' do
256
- let(:object_gtype) { GIMarshallingTests::Object.gtype }
257
- let(:info) do
258
- GirFFI::UserDefinedObjectInfo.new derived_class do |it|
259
- it.install_property GObject.param_spec_uint('the-prop', 'the property',
260
- 'The Property',
261
- 10, 100, 15,
262
- readable: true, writable: true)
263
- end
264
- end
265
-
266
- it 'creates accessor functions for the property' do
267
- obj = derived_class.new
268
- obj.the_prop = 423
269
- obj.the_prop.must_equal 423
270
- end
271
- end
272
-
273
- describe 'with a ulong property' do
274
- let(:object_gtype) { GIMarshallingTests::Object.gtype }
275
- let(:info) do
276
- GirFFI::UserDefinedObjectInfo.new derived_class do |it|
277
- it.install_property GObject.param_spec_ulong('the-prop', 'the property',
278
- 'The Property',
279
- 10, 100, 15,
280
- readable: true, writable: true)
281
- end
282
- end
283
-
284
- it 'creates accessor functions for the property' do
285
- obj = derived_class.new
286
- obj.the_prop = 423_432
287
- obj.the_prop.must_equal 423_432
288
- end
289
- end
290
-
291
- describe 'with a int64 property' do
292
- let(:object_gtype) { GIMarshallingTests::Object.gtype }
293
- let(:info) do
294
- GirFFI::UserDefinedObjectInfo.new derived_class do |it|
295
- it.install_property GObject.param_spec_int64('the-prop', 'the property',
296
- 'The Property',
297
- 10, 100, 15,
298
- readable: true, writable: true)
299
- end
300
- end
301
-
302
- it 'creates accessor functions for the property' do
303
- obj = derived_class.new
304
- obj.the_prop = -423_432
305
- obj.the_prop.must_equal(-423_432)
306
- end
307
- end
308
-
309
- describe 'with a uint64 property' do
310
- let(:object_gtype) { GIMarshallingTests::Object.gtype }
311
- let(:info) do
312
- GirFFI::UserDefinedObjectInfo.new derived_class do |it|
313
- it.install_property GObject.param_spec_uint64('the-prop', 'the property',
314
- 'The Property',
315
- 10, 100, 15,
316
- readable: true, writable: true)
317
- end
318
- end
319
-
320
- it 'creates accessor functions for the property' do
321
- obj = derived_class.new
322
- obj.the_prop = 423_432
323
- obj.the_prop.must_equal 423_432
324
- end
325
- end
326
-
327
- describe 'with a float property' do
328
- let(:object_gtype) { GIMarshallingTests::Object.gtype }
329
- let(:info) do
330
- GirFFI::UserDefinedObjectInfo.new derived_class do |it|
331
- it.install_property GObject.param_spec_float('the-prop', 'the property',
332
- 'The Property',
333
- 10.0, 100.0, 15.0,
334
- readable: true, writable: true)
335
- end
336
- end
337
-
338
- it 'creates accessor functions for the property' do
339
- obj = derived_class.new
340
- obj.the_prop = 42.23
341
- obj.the_prop.must_be_within_epsilon 42.23
342
- end
343
- end
344
-
345
- describe 'with a double property' do
346
- let(:object_gtype) { GIMarshallingTests::Object.gtype }
347
- let(:info) do
348
- GirFFI::UserDefinedObjectInfo.new derived_class do |it|
349
- it.install_property GObject.param_spec_double('the-prop', 'the property',
350
- 'The Property',
351
- 10.0, 100.0, 15.0,
352
- readable: true, writable: true)
353
- end
354
- end
355
-
356
- it 'creates accessor functions for the property' do
357
- obj = derived_class.new
358
- obj.the_prop = 42.23
359
- obj.the_prop.must_equal 42.23
360
- end
361
- end
362
-
363
- describe 'with an enum property' do
364
- let(:object_gtype) { GIMarshallingTests::Object.gtype }
365
- let(:info) do
366
- GirFFI::UserDefinedObjectInfo.new derived_class do |it|
367
- prop = GObject.param_spec_enum('the-prop', 'the property',
368
- 'The Property',
369
- GIMarshallingTests::GEnum.gtype, 0,
370
- readable: true, writable: true)
371
- it.install_property prop
372
- end
373
- end
374
-
375
- it 'creates accessor functions for the property' do
376
- obj = derived_class.new
377
- obj.the_prop = :value2
378
- obj.the_prop.must_equal :value2
379
- end
380
- end
381
-
382
- describe 'with a flags property' do
383
- let(:object_gtype) { GIMarshallingTests::Object.gtype }
384
- let(:info) do
385
- GirFFI::UserDefinedObjectInfo.new derived_class do |it|
386
- prop = GObject.param_spec_flags('the-prop', 'the property',
387
- 'The Property',
388
- GIMarshallingTests::Flags.gtype, 0,
389
- readable: true, writable: true)
390
- it.install_property prop
391
- end
392
- end
393
-
394
- it 'creates accessor functions for the property' do
395
- obj = derived_class.new
396
- obj.the_prop = { value2: true }
397
- obj.the_prop.must_equal value2: true
398
- end
399
- end
400
-
401
- describe 'when deriving from a class with hidden struct size' do
402
- let(:parent_class) { Regress::TestInheritDrawable }
403
- let(:parent_size) do
404
- GObject.type_query(parent_class.gtype).instance_size
405
- end
406
- let(:derived_class) do
407
- Object.const_set("DerivedClass#{Sequence.next}", Class.new(parent_class))
408
- end
409
- let(:info) do
410
- GirFFI::UserDefinedObjectInfo.new derived_class do |it|
411
- it.install_property GObject.param_spec_int('int-prop', 'integer property',
412
- 'Integer Property',
413
- 10, 20, 15,
414
- readable: true, writable: true)
415
- end
416
- end
417
-
418
- it 'registers a type that is bigger than the parent' do
419
- class_size = GObject.type_query(derived_class.gtype).instance_size
420
- class_size.must_be :>, parent_size
421
- end
422
-
423
- it 'leaves enough space in derived struct layout' do
424
- struct_size = derived_class::Struct.size
425
- struct_size.must_be :>, parent_size
426
- end
427
- end
428
-
429
- describe 'with type info containing an overridden g_name' do
430
- let(:info) do
431
- GirFFI::UserDefinedObjectInfo.new derived_class do |it|
432
- it.g_name = "OtherName#{Sequence.next}"
433
- end
434
- end
435
-
436
- it 'registers a type under the overridden name' do
437
- registered_name = GObject.type_name(derived_class.gtype)
438
- registered_name.must_equal info.g_name
439
- registered_name.wont_equal derived_class.name
440
- end
441
- end
442
-
443
- describe 'with type info containing a vfunc' do
444
- let(:info) do
445
- GirFFI::UserDefinedObjectInfo.new derived_class do |it|
446
- it.install_vfunc_implementation :method_int8_in, proc { |instance, in_|
447
- instance.int = in_
448
- }
449
- end
450
- end
451
-
452
- it 'allows the vfunc to be called through its invoker' do
453
- obj = derived_class.new
454
- obj.method_int8_in 12
455
- obj.int.must_equal 12
456
- end
457
- end
458
-
459
- describe 'when using a default vfunc implementation' do
460
- let(:base_class) { Regress::TestObj }
461
- let(:info) do
462
- GirFFI::UserDefinedObjectInfo.new derived_class do |it|
463
- it.install_vfunc_implementation :matrix
464
- end
465
- end
466
-
467
- before do
468
- derived_class.class_eval do
469
- def matrix(_arg)
470
- 44
471
- end
472
- end
473
- end
474
-
475
- it 'allows the vfunc to be called through its invoker' do
476
- obj = derived_class.new
477
- obj.do_matrix('bar').must_equal 44
478
- end
479
- end
480
-
481
- describe 'with type info containing a vfunc from an included Interface' do
482
- let(:info) do
483
- derived_class.class_eval { include GIMarshallingTests::Interface }
484
- GirFFI::UserDefinedObjectInfo.new derived_class do |it|
485
- it.install_vfunc_implementation :test_int8_in,
486
- proc { |instance, in_| instance.int = in_ }
487
- end
488
- end
489
-
490
- it 'marks the type as conforming to the included Interface' do
491
- iface_gtype = GIMarshallingTests::Interface.gtype
492
- GObject.type_interfaces(derived_class.gtype).to_a.must_equal [iface_gtype]
493
- end
494
-
495
- it 'allows the vfunc to be called through its invoker' do
496
- obj = derived_class.new
497
- obj.test_int8_in 12
498
- obj.int.must_equal 12
499
- end
500
- end
501
-
502
- it 'keeps the gtype for an already registered class' do
503
- gtype = derived_class.gtype
504
- other_builder = GirFFI::Builders::UserDefinedBuilder.new info
505
- other_class = other_builder.build_class
506
- other_class.gtype.must_equal gtype
507
- end
508
-
509
- it 'creates a class with a new GType' do
510
- derived_class.gtype.wont_equal GIMarshallingTests::Object.gtype
511
- end
512
-
513
- it 'makes the registered class return objects with the correct GType' do
514
- obj = derived_class.new
515
- GObject.type_from_instance(obj).must_equal derived_class.gtype
516
- end
517
- end
518
-
519
- describe '#object_class_struct' do
520
- it 'returns the parent class struct' do
521
- builder.object_class_struct.must_equal GIMarshallingTests::ObjectClass
522
- end
523
- end
524
- end