qml 0.0.7 → 1.0.0

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 (296) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +3 -0
  3. data/.travis.yml +5 -9
  4. data/LICENSE.txt +1 -1
  5. data/README.md +84 -114
  6. data/changes.md +5 -0
  7. data/examples/fizzbuzz/fizzbuzz.rb +3 -4
  8. data/examples/todo_array/todo_array.rb +4 -4
  9. data/examples/todo_sequel/todo_sequel.rb +7 -7
  10. data/examples/twitter/twitter.rb +5 -3
  11. data/ext/qml/application.c +88 -0
  12. data/ext/qml/application.h +9 -0
  13. data/ext/qml/component.c +89 -0
  14. data/ext/qml/component.h +10 -0
  15. data/ext/qml/conversion.c +60 -0
  16. data/ext/qml/conversion.h +8 -0
  17. data/ext/qml/dispatcher.c +31 -0
  18. data/ext/qml/dispatcher.h +7 -0
  19. data/ext/qml/engine.c +135 -0
  20. data/ext/qml/engine.h +10 -0
  21. data/ext/qml/exporter.c +93 -0
  22. data/ext/qml/exporter.h +7 -0
  23. data/ext/qml/extconf.rb +38 -97
  24. data/ext/qml/interface.c +156 -0
  25. data/ext/qml/interface.h +11 -0
  26. data/ext/qml/js_array.c +47 -0
  27. data/ext/qml/js_array.h +7 -0
  28. data/ext/qml/js_function.c +109 -0
  29. data/ext/qml/js_function.h +7 -0
  30. data/ext/qml/js_object.c +284 -0
  31. data/ext/qml/js_object.h +19 -0
  32. data/ext/qml/js_wrapper.c +19 -0
  33. data/ext/qml/js_wrapper.h +7 -0
  34. data/ext/qml/lib/libqmlbind/.gitignore +38 -0
  35. data/ext/qml/lib/libqmlbind/.gitmodules +3 -0
  36. data/ext/qml/lib/libqmlbind/.travis.yml +14 -0
  37. data/ext/qml/lib/libqmlbind/LICENSE.txt +22 -0
  38. data/ext/qml/lib/libqmlbind/libqmlbind.pro +3 -0
  39. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind.h +14 -0
  40. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/application.h +18 -0
  41. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/component.h +21 -0
  42. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/engine.h +34 -0
  43. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/exporter.h +37 -0
  44. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/interface.h +16 -0
  45. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/iterator.h +19 -0
  46. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/metaobject.h +13 -0
  47. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/plugin.h +17 -0
  48. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/qmlbind_global.h +78 -0
  49. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/register.h +17 -0
  50. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/signal_emitter.h +15 -0
  51. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/string.h +15 -0
  52. data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/value.h +100 -0
  53. data/ext/qml/lib/libqmlbind/qmlbind/qmlbind.pro +62 -0
  54. data/ext/qml/lib/libqmlbind/qmlbind/src/api_application.cpp +103 -0
  55. data/ext/qml/lib/libqmlbind/qmlbind/src/api_component.cpp +54 -0
  56. data/ext/qml/lib/libqmlbind/qmlbind/src/api_engine.cpp +65 -0
  57. data/ext/qml/lib/libqmlbind/qmlbind/src/api_exporter.cpp +52 -0
  58. data/ext/qml/lib/libqmlbind/qmlbind/src/api_interface.cpp +19 -0
  59. data/ext/qml/lib/libqmlbind/qmlbind/src/api_iterator.cpp +32 -0
  60. data/ext/qml/lib/libqmlbind/qmlbind/src/api_metaobject.cpp +19 -0
  61. data/ext/qml/lib/libqmlbind/qmlbind/src/api_plugin.cpp +27 -0
  62. data/ext/qml/lib/libqmlbind/qmlbind/src/api_register.cpp +17 -0
  63. data/ext/qml/lib/libqmlbind/qmlbind/src/api_signal_emitter.cpp +27 -0
  64. data/ext/qml/lib/libqmlbind/qmlbind/src/api_string.cpp +22 -0
  65. data/ext/qml/lib/libqmlbind/qmlbind/src/api_value.cpp +215 -0
  66. data/ext/qml/lib/libqmlbind/qmlbind/src/backref.cpp +54 -0
  67. data/ext/qml/lib/libqmlbind/qmlbind/src/backref.h +29 -0
  68. data/ext/qml/lib/libqmlbind/qmlbind/src/engine.cpp +32 -0
  69. data/ext/qml/lib/libqmlbind/qmlbind/src/engine.h +27 -0
  70. data/ext/qml/lib/libqmlbind/qmlbind/src/exporter.cpp +73 -0
  71. data/ext/qml/lib/libqmlbind/qmlbind/src/exporter.h +46 -0
  72. data/ext/qml/lib/libqmlbind/qmlbind/src/interface.cpp +75 -0
  73. data/ext/qml/lib/libqmlbind/qmlbind/src/interface.h +37 -0
  74. data/ext/qml/lib/libqmlbind/qmlbind/src/metaobject.cpp +101 -0
  75. data/ext/qml/lib/libqmlbind/qmlbind/src/metaobject.h +29 -0
  76. data/ext/qml/lib/libqmlbind/qmlbind/src/signalemitter.cpp +33 -0
  77. data/ext/qml/lib/libqmlbind/qmlbind/src/signalemitter.h +25 -0
  78. data/ext/qml/lib/libqmlbind/qmlbind/src/ticktimer.cpp +15 -0
  79. data/ext/qml/lib/libqmlbind/qmlbind/src/ticktimer.h +19 -0
  80. data/ext/qml/lib/libqmlbind/qmlbind/src/typeregisterer.cpp +112 -0
  81. data/ext/qml/lib/libqmlbind/qmlbind/src/typeregisterer.h +28 -0
  82. data/ext/qml/lib/libqmlbind/qmlbind/src/util.h +13 -0
  83. data/ext/qml/lib/libqmlbind/qmlbind/src/wrapper.cpp +23 -0
  84. data/ext/qml/lib/libqmlbind/qmlbind/src/wrapper.h +29 -0
  85. data/ext/qml/lib/libqmlbind/readme.md +14 -0
  86. data/ext/qml/lib/libqmlbind/test/api.c +1 -0
  87. data/ext/qml/lib/libqmlbind/test/application_test.cpp +16 -0
  88. data/ext/qml/lib/libqmlbind/test/component_test.cpp +57 -0
  89. data/ext/qml/lib/libqmlbind/test/engine_test.cpp +94 -0
  90. data/ext/qml/lib/libqmlbind/test/exporter_test.cpp +312 -0
  91. data/ext/qml/lib/libqmlbind/test/fixtures/emptyhandlers.cpp +36 -0
  92. data/ext/qml/lib/libqmlbind/test/fixtures/emptyhandlers.h +6 -0
  93. data/ext/qml/lib/libqmlbind/test/fixtures/test.qml +5 -0
  94. data/ext/qml/lib/libqmlbind/test/fixtures/testmodule/qmldir +2 -0
  95. data/ext/qml/lib/libqmlbind/test/fixtures/testmodule/test.qml +5 -0
  96. data/ext/qml/lib/libqmlbind/test/iterator_test.cpp +37 -0
  97. data/ext/qml/lib/libqmlbind/test/main.cpp +11 -0
  98. data/ext/qml/lib/libqmlbind/test/plugin_test.cpp +41 -0
  99. data/ext/qml/lib/libqmlbind/test/test.pro +26 -0
  100. data/ext/qml/lib/libqmlbind/test/test_helper.h +20 -0
  101. data/ext/qml/lib/libqmlbind/test/value_test.cpp +252 -0
  102. data/ext/qml/lib/libqmlbind/testplugin/testplugin.cpp +11 -0
  103. data/ext/qml/lib/libqmlbind/testplugin/testplugin.h +21 -0
  104. data/ext/qml/lib/libqmlbind/testplugin/testplugin.json +3 -0
  105. data/ext/qml/lib/libqmlbind/testplugin/testplugin.pro +21 -0
  106. data/ext/qml/meta_object.c +81 -0
  107. data/ext/qml/meta_object.h +8 -0
  108. data/ext/qml/plugin_loader.c +71 -0
  109. data/ext/qml/plugin_loader.h +7 -0
  110. data/ext/qml/qml.c +95 -0
  111. data/ext/qml/qml.h +10 -0
  112. data/ext/qml/rubyqml-plugin/listmodel.cpp +102 -0
  113. data/ext/qml/rubyqml-plugin/listmodel.h +37 -0
  114. data/ext/qml/rubyqml-plugin/rubyqml-plugin.pro +19 -0
  115. data/ext/qml/rubyqml-plugin/rubyqmlplugin.cpp +25 -0
  116. data/ext/qml/rubyqml-plugin/rubyqmlplugin.h +19 -0
  117. data/ext/qml/signal_emitter.c +71 -0
  118. data/ext/qml/signal_emitter.h +9 -0
  119. data/lib/qml.rb +11 -10
  120. data/lib/qml/access.rb +64 -86
  121. data/lib/qml/application.rb +20 -71
  122. data/lib/qml/component.rb +41 -33
  123. data/lib/qml/core_ext.rb +1 -0
  124. data/lib/qml/core_ext/to_qml.rb +70 -0
  125. data/lib/qml/data.rb +1 -0
  126. data/lib/qml/data/array_model.rb +99 -101
  127. data/lib/qml/data/list_model.rb +107 -131
  128. data/lib/qml/data/list_model_access.rb +44 -0
  129. data/lib/qml/data/query_model.rb +45 -47
  130. data/lib/qml/dispatcher.rb +5 -13
  131. data/lib/qml/engine.rb +9 -58
  132. data/lib/qml/errors.rb +0 -21
  133. data/lib/qml/interface.rb +21 -0
  134. data/lib/qml/js_array.rb +8 -0
  135. data/lib/qml/js_object.rb +69 -0
  136. data/lib/qml/js_util.rb +18 -0
  137. data/lib/qml/plugin_loader.rb +1 -13
  138. data/lib/qml/plugins.rb +3 -17
  139. data/lib/qml/proc_access.rb +28 -0
  140. data/lib/qml/qt.rb +21 -3
  141. data/lib/qml/reactive.rb +147 -8
  142. data/lib/qml/signal.rb +67 -0
  143. data/lib/qml/version.rb +1 -1
  144. data/qml.gemspec +8 -2
  145. data/spec/qml/access_spec.rb +33 -120
  146. data/spec/qml/application_spec.rb +11 -24
  147. data/spec/qml/component_spec.rb +4 -4
  148. data/spec/qml/data/array_model_spec.rb +2 -2
  149. data/spec/qml/data/list_model_spec.rb +2 -2
  150. data/spec/qml/data/query_model_spec.rb +4 -4
  151. data/spec/qml/engine_spec.rb +23 -21
  152. data/spec/qml/interface_spec.rb +20 -0
  153. data/spec/qml/js_array_spec.rb +29 -0
  154. data/spec/qml/js_function_spec.rb +32 -0
  155. data/spec/qml/js_object_spec.rb +113 -0
  156. data/spec/qml/plugin_loader_spec.rb +9 -11
  157. data/spec/qml/qt_spec.rb +9 -0
  158. data/spec/qml/reactive_spec.rb +37 -0
  159. data/spec/qml/signal_connect_spec.rb +27 -0
  160. data/spec/qml/signal_spec.rb +73 -0
  161. data/spec/qml/to_qml_spec.rb +76 -0
  162. data/spec/shared/qml/access_example.rb +21 -0
  163. data/spec/shared/qml/data/list_model.rb +12 -13
  164. data/spec/spec_helper.rb +2 -3
  165. metadata +141 -166
  166. data/examples/imageprovider/imageprovider.rb +0 -57
  167. data/examples/imageprovider/main.qml +0 -51
  168. data/ext/qml/accessclass.cpp +0 -65
  169. data/ext/qml/accessclass.h +0 -19
  170. data/ext/qml/accessobject.cpp +0 -30
  171. data/ext/qml/accessobject.h +0 -22
  172. data/ext/qml/common.h +0 -18
  173. data/ext/qml/conversionerror.h +0 -14
  174. data/ext/qml/ext_accesswrapperfactory.cpp +0 -75
  175. data/ext/qml/ext_accesswrapperfactory.h +0 -39
  176. data/ext/qml/ext_anywrapper.cpp +0 -34
  177. data/ext/qml/ext_anywrapper.h +0 -23
  178. data/ext/qml/ext_kernel.cpp +0 -81
  179. data/ext/qml/ext_kernel.h +0 -9
  180. data/ext/qml/ext_metaobject.cpp +0 -399
  181. data/ext/qml/ext_metaobject.h +0 -60
  182. data/ext/qml/ext_pluginloader.cpp +0 -53
  183. data/ext/qml/ext_pluginloader.h +0 -30
  184. data/ext/qml/ext_pointer.cpp +0 -132
  185. data/ext/qml/ext_pointer.h +0 -41
  186. data/ext/qml/ext_testutil.cpp +0 -40
  187. data/ext/qml/ext_testutil.h +0 -9
  188. data/ext/qml/foreignclass.cpp +0 -72
  189. data/ext/qml/foreignclass.h +0 -88
  190. data/ext/qml/foreignmetaobject.cpp +0 -345
  191. data/ext/qml/foreignmetaobject.h +0 -46
  192. data/ext/qml/foreignobject.cpp +0 -22
  193. data/ext/qml/foreignobject.h +0 -21
  194. data/ext/qml/functioninfo.h +0 -16
  195. data/ext/qml/init.cpp +0 -67
  196. data/ext/qml/kernel.cpp +0 -39
  197. data/ext/qml/kernel.h +0 -32
  198. data/ext/qml/listmodel.cpp +0 -137
  199. data/ext/qml/listmodel.h +0 -45
  200. data/ext/qml/markable.h +0 -12
  201. data/ext/qml/objectdata.cpp +0 -26
  202. data/ext/qml/objectdata.h +0 -20
  203. data/ext/qml/objectgc.cpp +0 -69
  204. data/ext/qml/objectgc.h +0 -28
  205. data/ext/qml/plugins/core/applicationextension.cpp +0 -29
  206. data/ext/qml/plugins/core/applicationextension.h +0 -25
  207. data/ext/qml/plugins/core/componentextension.cpp +0 -41
  208. data/ext/qml/plugins/core/componentextension.h +0 -28
  209. data/ext/qml/plugins/core/contextextension.cpp +0 -39
  210. data/ext/qml/plugins/core/contextextension.h +0 -29
  211. data/ext/qml/plugins/core/core.pro +0 -29
  212. data/ext/qml/plugins/core/coreplugin.cpp +0 -87
  213. data/ext/qml/plugins/core/coreplugin.h +0 -49
  214. data/ext/qml/plugins/core/engineextension.cpp +0 -43
  215. data/ext/qml/plugins/core/engineextension.h +0 -31
  216. data/ext/qml/plugins/core/imageprovider.cpp +0 -38
  217. data/ext/qml/plugins/core/imageprovider.h +0 -18
  218. data/ext/qml/plugins/core/imagerequestpromise.cpp +0 -19
  219. data/ext/qml/plugins/core/imagerequestpromise.h +0 -21
  220. data/ext/qml/plugins/core/qmlexception.cpp +0 -11
  221. data/ext/qml/plugins/core/qmlexception.h +0 -17
  222. data/ext/qml/plugins/testutil/imageprovidertest.cpp +0 -40
  223. data/ext/qml/plugins/testutil/imageprovidertest.h +0 -17
  224. data/ext/qml/plugins/testutil/objectlifechecker.cpp +0 -17
  225. data/ext/qml/plugins/testutil/objectlifechecker.h +0 -24
  226. data/ext/qml/plugins/testutil/ownershiptest.cpp +0 -26
  227. data/ext/qml/plugins/testutil/ownershiptest.h +0 -30
  228. data/ext/qml/plugins/testutil/testobject.cpp +0 -6
  229. data/ext/qml/plugins/testutil/testobject.h +0 -108
  230. data/ext/qml/plugins/testutil/testobjectsubclass.cpp +0 -10
  231. data/ext/qml/plugins/testutil/testobjectsubclass.h +0 -19
  232. data/ext/qml/plugins/testutil/testutil.pro +0 -22
  233. data/ext/qml/plugins/testutil/testutilplugin.cpp +0 -55
  234. data/ext/qml/plugins/testutil/testutilplugin.h +0 -36
  235. data/ext/qml/qmltyperegisterer.cpp +0 -74
  236. data/ext/qml/qmltyperegisterer.h +0 -30
  237. data/ext/qml/rubyclass.cpp +0 -82
  238. data/ext/qml/rubyclass.h +0 -230
  239. data/ext/qml/rubyvalue.cpp +0 -656
  240. data/ext/qml/rubyvalue.h +0 -224
  241. data/ext/qml/signalforwarder.cpp +0 -64
  242. data/ext/qml/signalforwarder.h +0 -29
  243. data/ext/qml/util.cpp +0 -112
  244. data/ext/qml/util.h +0 -82
  245. data/ext/qml/valuereference.cpp +0 -50
  246. data/ext/qml/valuereference.h +0 -22
  247. data/ext/qml/weakvaluereference.cpp +0 -51
  248. data/ext/qml/weakvaluereference.h +0 -21
  249. data/lib/qml/context.rb +0 -71
  250. data/lib/qml/data/error.rb +0 -5
  251. data/lib/qml/dispatchable.rb +0 -34
  252. data/lib/qml/error_converter.rb +0 -16
  253. data/lib/qml/geometry.rb +0 -3
  254. data/lib/qml/geometry/point.rb +0 -5
  255. data/lib/qml/geometry/rectangle.rb +0 -5
  256. data/lib/qml/geometry/size.rb +0 -5
  257. data/lib/qml/image_provider.rb +0 -87
  258. data/lib/qml/init.rb +0 -29
  259. data/lib/qml/meta_object.rb +0 -20
  260. data/lib/qml/models.rb +0 -1
  261. data/lib/qml/qt_classes.rb +0 -9
  262. data/lib/qml/qt_object_base.rb +0 -233
  263. data/lib/qml/reactive/bindable.rb +0 -79
  264. data/lib/qml/reactive/chained_signal.rb +0 -25
  265. data/lib/qml/reactive/error.rb +0 -5
  266. data/lib/qml/reactive/object.rb +0 -293
  267. data/lib/qml/reactive/property.rb +0 -19
  268. data/lib/qml/reactive/signal.rb +0 -115
  269. data/lib/qml/reactive/signal_spy.rb +0 -27
  270. data/lib/qml/reactive/signals/map_signal.rb +0 -21
  271. data/lib/qml/reactive/signals/merge_signal.rb +0 -21
  272. data/lib/qml/reactive/signals/select_signal.rb +0 -21
  273. data/lib/qml/reactive/simple_property.rb +0 -17
  274. data/lib/qml/reactive/unbound_property.rb +0 -42
  275. data/lib/qml/reactive/unbound_signal.rb +0 -51
  276. data/lib/qml/test_util.rb +0 -1
  277. data/lib/qml/test_util/object_life_checker.rb +0 -17
  278. data/lib/qml/wrappable.rb +0 -9
  279. data/spec/qml/context_spec.rb +0 -43
  280. data/spec/qml/conversion_spec.rb +0 -60
  281. data/spec/qml/dispatchable_spec.rb +0 -26
  282. data/spec/qml/dispatcher_spec.rb +0 -71
  283. data/spec/qml/geometry/point_spec.rb +0 -4
  284. data/spec/qml/geometry/rectangle_spec.rb +0 -4
  285. data/spec/qml/geometry/size_spec.rb +0 -4
  286. data/spec/qml/image_provider_spec.rb +0 -33
  287. data/spec/qml/qt_object_base_spec.rb +0 -119
  288. data/spec/qml/reactive/object_spec.rb +0 -249
  289. data/spec/qml/reactive/property_spec.rb +0 -70
  290. data/spec/qml/reactive/signal_spec.rb +0 -191
  291. data/spec/qml/reactive/signal_spy_spec.rb +0 -26
  292. data/spec/qml/reactive/unbound_property_spec.rb +0 -40
  293. data/spec/qml/reactive/unbound_signal_spec.rb +0 -70
  294. data/spec/qml/test_object_spec.rb +0 -186
  295. data/spec/qml/wrappable_spec.rb +0 -10
  296. data/spec/shared/qml/reactive/object.rb +0 -39
@@ -1,70 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe QML::Reactive::Property do
4
-
5
- describe '#initialize' do
6
-
7
- context 'when a value is given' do
8
- it 'initializes with the value' do
9
- p = QML::Reactive::Property.new(2)
10
- expect(p.value).to eq(2)
11
- end
12
- end
13
-
14
- context 'when a block is given' do
15
- it 'initializes with the property binding' do
16
- p1 = QML::Reactive::Property.new(2)
17
- p2 = QML::Reactive::Property.new { p1.value + 2 }
18
- p1.value = 10
19
- expect(p2.value).to eq(12)
20
- end
21
- end
22
- end
23
-
24
- describe 'access to the value' do
25
- describe '#value, #value=' do
26
- it 'sets and gets the contained value' do
27
- property = QML::Reactive::Property.new
28
- property.value = 'hogehoge'
29
- expect(property.value).to eq('hogehoge')
30
- end
31
- end
32
- end
33
-
34
- describe 'property binding' do
35
-
36
- describe '#bind' do
37
-
38
- it 'sets a property binding' do
39
- p1 = QML::Reactive::Property.new 'foo'
40
- p2 = QML::Reactive::Property.new 'bar'
41
- p3 = QML::Reactive::Property.new
42
- p4 = QML::Reactive::Property.new
43
- p3.bind { p1.value + p2.value }
44
- p4.bind { p3.value }
45
- p1.value = 'hoge'
46
- p2.value = 'piyo'
47
- expect(p3.value).to eq('hogepiyo')
48
- expect(p4.value).to eq('hogepiyo')
49
- end
50
-
51
- context 'when binding is recursive' do
52
- it 'raises error' do
53
- property = QML::Reactive::Property.new
54
- expect{ property.bind { property.value } }.to raise_error(QML::Reactive::Error)
55
- end
56
- end
57
- end
58
- end
59
-
60
- describe '#changed' do
61
- it 'returns a signal that is emitted when the value is changed' do
62
- property = QML::Reactive::Property.new
63
- changed_value = nil
64
- property.changed.connect { |val| changed_value = val }
65
-
66
- property.value = 'piyopiyo'
67
- expect(changed_value).to eq('piyopiyo')
68
- end
69
- end
70
- end
@@ -1,191 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe QML::Reactive::Signal do
4
-
5
- before do
6
- @signal = QML::Reactive::Signal.new([:foo, :bar])
7
- @variadic_signal = QML::Reactive::Signal.new(nil)
8
- end
9
-
10
- describe 'connection' do
11
-
12
- describe '#connect, #emit' do
13
-
14
- context 'when non-variadic' do
15
-
16
- before do
17
- @signal.connect { |foo, bar| @received = [foo, bar] }
18
- end
19
-
20
- it 'connects a block and calls it' do
21
- @signal.emit('apple', 'orange')
22
- expect(@received).to eq(['apple', 'orange'])
23
- end
24
-
25
- context 'when the number of arguments is wrong' do
26
- it 'fails with an ArgumentError' do
27
- expect { @signal.emit('apple') }.to raise_error(ArgumentError)
28
- end
29
- end
30
- end
31
-
32
- context 'when variadic' do
33
-
34
- it 'connects a block and calls it' do
35
- received = nil
36
- @variadic_signal.connect { |foo, bar| received = [foo, bar] }
37
- @variadic_signal.emit('apple', 'orange')
38
- expect(received).to eq(['apple', 'orange'])
39
- end
40
- end
41
-
42
- it 'calls connected blocks in the order they have been conncted' do
43
- received = []
44
- @signal.connect { received << 'first' }
45
- @signal.connect { received << 'second' }
46
- @signal.emit('foo', 'bar')
47
- expect(received).to eq(['first', 'second'])
48
- end
49
- end
50
-
51
- describe '#each' do
52
- it 'is an alias of #connect' do
53
- expect(@signal.method(:each)).to eq @signal.method(:connect)
54
- end
55
- end
56
-
57
- describe '::Connection#disconnect' do
58
-
59
- it 'disconnects the connection' do
60
- connection = @signal.connect { |foo, bar| @received = foo + bar }
61
- @signal.emit('apple', 'orange')
62
- connection.disconnect
63
- @signal.emit('banana', 'grape')
64
- expect(@received).to eq('appleorange')
65
- end
66
-
67
- it 'disconnects the whole chained connections if possible' do
68
- signal = QML::Reactive::Signal.new [:arg]
69
- mapped = signal.map { |arg| arg * 2 }
70
-
71
- connection = mapped.connect {}
72
-
73
- connection.disconnect
74
- expect(signal.connection_count).to eq(0)
75
- end
76
- end
77
-
78
- describe '#connection_count' do
79
- it 'returns the number of connections' do
80
- prc1 = ->(foo, bar) {}
81
- prc2 = ->(foo, bar) {}
82
- @signal.connect(&prc1)
83
- @signal.connect(&prc2)
84
- expect(@signal.connection_count).to eq(2)
85
- end
86
- end
87
- end
88
-
89
- describe 'attributes' do
90
-
91
- describe '#arity' do
92
-
93
- context 'when non-variadic' do
94
- it 'returns the number of arguments' do
95
- expect(@signal.arity).to eq(2)
96
- end
97
- end
98
-
99
- context 'when variadic' do
100
- it 'returns the number of arguments' do
101
- expect(@variadic_signal.arity).to eq(-1)
102
- end
103
- end
104
- end
105
-
106
- describe '#parameters' do
107
-
108
- context 'when non-variadic' do
109
- it 'returns the parameter information' do
110
- expect(@signal.parameters).to eq([[:req, :foo], [:req, :bar]])
111
- end
112
- end
113
-
114
- context 'when variadic' do
115
- it 'returns the parameter information' do
116
- expect(@variadic_signal.parameters).to eq([[:rest, :args]])
117
- end
118
- end
119
- end
120
- end
121
-
122
- describe 'alternatives for #emit' do
123
-
124
- before do
125
- @signal.connect { |foo, bar| @received = foo + bar }
126
- end
127
-
128
- describe '#to_proc' do
129
- it 'returns a Proc that emits the original signal' do
130
- prc = @signal.to_proc
131
- prc.call('foo', 'bar')
132
- expect(prc).to be_a(Proc)
133
- expect(@received).to eq('foobar')
134
- end
135
- end
136
-
137
- describe '#[]' do
138
- it 'is an alias of #emit' do
139
- @signal["some", "text"]
140
- expect(@received).to eq("sometext")
141
- end
142
- end
143
-
144
- describe '#call' do
145
- it 'is an alias of #emit' do
146
- @signal.call("some", "text")
147
- expect(@received).to eq("sometext")
148
- end
149
- end
150
- end
151
-
152
- describe 'transformations' do
153
-
154
- describe '#map' do
155
- it 'returns another Signal that transforms the original signal parameters' do
156
- received = nil
157
- @signal
158
- .map { |foo, bar| foo * bar }
159
- .connect { |arg| received = arg }
160
- @signal.emit(20, 30)
161
- expect(received).to eq(600)
162
- end
163
- end
164
-
165
- describe '#select' do
166
- it 'returns another Signal which is filtered by the given block' do
167
- count = 0
168
- @signal.select { |foo| foo % 2 == 0 } .connect { count += 1 }
169
- 10.times { |i| @signal.emit(i, i) }
170
- expect(count).to eq(5)
171
- end
172
- end
173
-
174
- describe '#merge' do
175
- it 'merges multiple signals' do
176
- received = []
177
-
178
- signal = QML::Reactive::Signal.new [:foo]
179
- signal2 = QML::Reactive::Signal.new [:foo]
180
- signal.merge(signal2).connect { |foo| received << foo }
181
-
182
- signal.emit(:one)
183
- signal2.emit(:two)
184
- signal.emit(:three)
185
- expect(received).to eq([:one, :two, :three])
186
- end
187
- end
188
- end
189
- end
190
-
191
-
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe QML::Reactive::SignalSpy do
4
-
5
- it 'records signal emittion' do
6
- signal = QML::Reactive::Signal.new([:arg1, :arg2])
7
- spy = QML::Reactive::SignalSpy.new(signal)
8
- signal.emit(10, 20)
9
- signal.emit('foo', 'bar')
10
- expect(spy.args).to eq([[10, 20], ['foo', 'bar']])
11
- end
12
-
13
- end
14
-
15
- describe QML::Reactive::Signal do
16
-
17
- describe '#spy' do
18
- it 'returns a SignalSpy for the signal' do
19
- signal = QML::Reactive::Signal.new([:arg1, :arg2])
20
- spy = signal.spy
21
- signal.emit(10, 20)
22
- signal.emit('foo', 'bar')
23
- expect(spy.args).to eq([[10, 20], ['foo', 'bar']])
24
- end
25
- end
26
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe QML::Reactive::UnboundProperty do
4
- include_context 'Reactive test objects'
5
- let(:property) { button_class.instance_property(:name) }
6
- let(:alias_property) { button_class.instance_property(:title) }
7
-
8
- describe '#name' do
9
- it 'returns the name' do
10
- expect(property.name).to eq(:name)
11
- expect(alias_property.name).to eq(:title)
12
- end
13
- end
14
-
15
- describe '#owner' do
16
- it 'returns the owner class' do
17
- expect(property.owner).to be(button_class)
18
- expect(alias_property.owner).to be(button_class)
19
- end
20
- end
21
-
22
- describe '#original' do
23
- it 'returns the original name of the alias property' do
24
- expect(alias_property.original).to eq(:name)
25
- end
26
- end
27
-
28
- describe '#alias?' do
29
- context 'for non-alias properties' do
30
- it 'returns false' do
31
- expect(property).not_to be_alias
32
- end
33
- end
34
- context 'for alias properties' do
35
- it 'returns true' do
36
- expect(alias_property).to be_alias
37
- end
38
- end
39
- end
40
- end
@@ -1,70 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe QML::Reactive::UnboundSignal do
4
- include_context 'Reactive test objects'
5
- let(:signal) { button_class.instance_signal(:pressed) }
6
- let(:alias_signal) { button_class.instance_signal(:clicked) }
7
- let(:variadic_signal) { button_class.instance_signal(:message) }
8
-
9
- describe '#name' do
10
- it 'returns the name' do
11
- expect(signal.name).to eq(:pressed)
12
- expect(alias_signal.name).to eq(:clicked)
13
- end
14
- end
15
-
16
- describe '#owner' do
17
- it 'returns the owner class' do
18
- expect(signal.owner).to be(button_class)
19
- expect(alias_signal.owner).to be(button_class)
20
- end
21
- end
22
-
23
- describe '#original' do
24
- it 'returns the original name of the alias signal' do
25
- expect(alias_signal.original).to eq(:pressed)
26
- end
27
- end
28
-
29
- describe '#variadic?' do
30
- context 'for non-variadic signals' do
31
- it 'returns false' do
32
- expect(signal).not_to be_variadic
33
- end
34
- end
35
- context 'for variadic signals' do
36
- it 'returns true' do
37
- expect(variadic_signal).to be_variadic
38
- end
39
- end
40
- end
41
-
42
- describe '#alias?' do
43
- context 'for non-alias signals' do
44
- it 'returns false' do
45
- expect(signal).not_to be_alias
46
- end
47
- end
48
- context 'for alias signals' do
49
- it 'returns true' do
50
- expect(alias_signal).to be_alias
51
- end
52
- end
53
- end
54
-
55
- describe '#arity' do
56
- it 'returns the number of arguments' do
57
- expect(signal.arity).to eq(1)
58
- expect(variadic_signal.arity).to eq(-1)
59
- expect(alias_signal.arity).to eq(1)
60
- end
61
- end
62
-
63
- describe '#parameters' do
64
- it 'returns parameter names' do
65
- expect(signal.parameters).to eq([[:req, :pos]])
66
- expect(alias_signal.parameters).to eq([[:req, :pos]])
67
- expect(variadic_signal.parameters).to eq([[:rest, :args]])
68
- end
69
- end
70
- end
@@ -1,186 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "test object" do
4
-
5
- let(:plugin) { QML::Plugins.test_util }
6
- let(:obj) { plugin.createTestObject }
7
-
8
- describe '#normalMethod' do
9
-
10
- it 'should call the method' do
11
- expect(obj.normalMethod(1, "23")).to eq(24)
12
- end
13
-
14
- context 'if the arguments are not convertible' do
15
- it 'should raise error' do
16
- expect { obj.normalMethod([1, 2], 'bar') }.to raise_error QML::MethodError
17
- end
18
- end
19
-
20
- context 'if the number of arguments is wrong' do
21
- it 'should raise error' do
22
- expect { obj.normalMethod(1) }.to raise_error QML::MethodError
23
- end
24
- end
25
- end
26
-
27
- describe '#normal_method' do
28
- it 'is same as #normalMethod' do
29
- expect(obj.normalMethod(1, "23")).to eq(24)
30
- end
31
- end
32
-
33
- describe '#variantMethod' do
34
-
35
- it 'should call the method with QVariant arguments' do
36
- expect(obj.variantMethod(20, [1, 3, 4, 9])).to eq(37)
37
- end
38
- end
39
-
40
- describe '#overloadedMethod' do
41
-
42
- it 'should call the method with the same arity' do
43
- expect(obj.overloadedMethod('foo', 1)).to eq('2 params')
44
- end
45
-
46
- context 'when multiple methods with the same arity are provided' do
47
-
48
- it 'should call the method defined last' do
49
- expect(obj.overloadedMethod('hoge')).to eq('last')
50
- end
51
- end
52
- end
53
-
54
- describe '#someSignal signal' do
55
-
56
- it 'should emit the signal' do
57
- spy = QML::Reactive::SignalSpy.new(obj.someSignal)
58
- obj.emitSomeSignal('poyopoyo')
59
- expect(spy.args.first).to eq(['poyopoyo'])
60
- end
61
- end
62
-
63
- describe '#some_signal signal' do
64
-
65
- it 'is same as #someSignal' do
66
- spy = QML::Reactive::SignalSpy.new(obj.some_signal)
67
- obj.emit_some_signal('poyopoyo')
68
- expect(spy.args.first).to eq(['poyopoyo'])
69
- end
70
- end
71
-
72
- describe '#throwingMethod' do
73
- it 'raises a QML::CxxError' do
74
- expect { obj.throwingMethod }.to raise_error(QML::CppError, "<std::runtime_error> test error")
75
- end
76
- end
77
-
78
- describe '#metaObjectMethod' do
79
- it 'returns the QML::MetaObject of the test object' do
80
- expect(obj.metaObjectMethod).to eq obj.class.meta_object
81
- end
82
- end
83
-
84
- describe '#selfReturningMethod' do
85
- it 'returns the same Ruby object' do
86
- expect(obj.selfReturningMethod).to be obj
87
- end
88
- end
89
-
90
- describe '#name property' do
91
-
92
- it 'should be set' do
93
- obj.name = 'abcd'
94
- expect(obj.getName).to eq('abcd')
95
- end
96
-
97
- it 'should notify when changed' do
98
- spy = QML::Reactive::SignalSpy.new(obj.name_changed)
99
- obj.name = 'hogepoyo'
100
- expect(spy.args.first).to eq(['hogepoyo'])
101
- end
102
-
103
- context 'with wrong type' do
104
-
105
- it 'raise error' do
106
- expect { obj.name = 123 }.to raise_error QML::PropertyError
107
- end
108
- end
109
- end
110
-
111
- describe '#someValue property' do
112
- context 'as #some_value' do
113
- it 'can be set and get' do
114
- obj.some_value = 123
115
- expect(obj.some_value).to eq 123
116
- end
117
- end
118
- end
119
-
120
- describe 'enums' do
121
-
122
- it 'should be set' do
123
- k = obj.class
124
- expect(k::Foo).to eq(0)
125
- expect(k::Bar).to eq(1)
126
- expect(k::FooBar).to eq(2)
127
- expect(k::FOO_BAR).to eq(2)
128
- expect(k::Enums).to match_array [0,1,2]
129
- end
130
-
131
- it 'can be set and get' do
132
- obj.enum_value = obj.class::FOO_BAR
133
- expect(obj.enum_value).to eq(obj.class::FOO_BAR)
134
- end
135
- end
136
-
137
- describe 'QtObjectBase#inspect' do
138
- it 'inspects the class name and property values' do
139
- expect(obj.inspect).to eq %{#<[class for RubyQml::TestObject]:#{obj.__id__} enumValue=0 name="" objectName="" someValue=0.0>}
140
- end
141
- end
142
-
143
- context 'in subclass' do
144
- let(:subobj) { plugin.createTestObject }
145
- it "can call TestObject's method" do
146
- expect(subobj.normalMethod(1, "23")).to eq(24)
147
- end
148
- end
149
-
150
- context 'in non-main threads' do
151
-
152
- require 'celluloid'
153
-
154
- class TestCaller
155
- include Celluloid
156
-
157
- def initialize(obj)
158
- @obj = obj
159
- end
160
-
161
- def call(method, *args)
162
- @obj.public_send(method, *args)
163
- rescue => e
164
- e
165
- end
166
- end
167
-
168
- let(:test_caller) { TestCaller.new(obj) }
169
-
170
- describe '#normal_method' do
171
- it 'fails' do
172
- expect(test_caller.call(:normal_method, 1, "23")).to be_a QML::InvalidThreadError
173
- end
174
- end
175
- describe '#name' do
176
- it 'fails' do
177
- expect(test_caller.call(:name)).to be_a QML::InvalidThreadError
178
- end
179
- end
180
- describe '#name=' do
181
- it 'fails' do
182
- expect(test_caller.call(:name=, "hoge")).to be_a QML::InvalidThreadError
183
- end
184
- end
185
- end
186
- end