MINT-core 1.0.1 → 2.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 (214) hide show
  1. data/Gemfile +22 -3
  2. data/Gemfile.lock +98 -22
  3. data/History.txt +262 -0
  4. data/LICENSE +30 -0
  5. data/MINT-core.gemspec +25 -80
  6. data/Manifest.txt +145 -30
  7. data/README.rdoc +6 -163
  8. data/Rakefile +16 -17
  9. data/bin/mint-aui +3 -3
  10. data/bin/mint-cui-gfx +3 -2
  11. data/bin/mint-juggernaut.sh +0 -0
  12. data/bin/mint-tuplespace +0 -0
  13. data/lib/MINT-core.rb +53 -15
  14. data/lib/MINT-core/agent/agent.rb +1 -1
  15. data/lib/MINT-core/agent/aui.rb +0 -14
  16. data/lib/MINT-core/agent/auicontrol.rb +91 -38
  17. data/lib/MINT-core/agent/cui-gfx.rb +3 -3
  18. data/lib/MINT-core/agent/cuicontrol.rb +94 -24
  19. data/lib/MINT-core/connector/redis_connector.rb +16 -0
  20. data/lib/MINT-core/manager/mapping_manager.rb +101 -0
  21. data/lib/MINT-core/manager/mapping_parser.rb +89 -0
  22. data/lib/MINT-core/manager/mapping_server.rb +99 -0
  23. data/lib/MINT-core/manager/position_updater.rb +33 -0
  24. data/lib/MINT-core/manager/scxml_client.rb +118 -0
  25. data/lib/MINT-core/manager/scxml_server.rb +86 -0
  26. data/lib/MINT-core/mapping/action/action.rb +32 -0
  27. data/lib/MINT-core/mapping/action/backend_action.rb +32 -0
  28. data/lib/MINT-core/mapping/action/bind_action.rb +88 -0
  29. data/lib/MINT-core/mapping/action/event_action.rb +40 -0
  30. data/lib/MINT-core/mapping/complementary_mapping.rb +31 -0
  31. data/lib/MINT-core/mapping/mapping.rb +170 -34
  32. data/lib/MINT-core/mapping/observation/negation_observation.rb +64 -0
  33. data/lib/MINT-core/mapping/observation/observation.rb +219 -0
  34. data/lib/MINT-core/mapping/sequential.rb +1 -2
  35. data/lib/MINT-core/mapping/sequential_mapping.rb +60 -0
  36. data/lib/MINT-core/model/aui/AIChoiceElement.rb +17 -0
  37. data/lib/MINT-core/model/aui/AICommand.rb +7 -0
  38. data/lib/MINT-core/model/aui/AIContainer.rb +73 -0
  39. data/lib/MINT-core/model/aui/AIContext.rb +12 -0
  40. data/lib/MINT-core/model/aui/AIIN.rb +8 -0
  41. data/lib/MINT-core/model/aui/AIINContinuous.rb +56 -0
  42. data/lib/MINT-core/model/aui/AIINDiscrete.rb +8 -0
  43. data/lib/MINT-core/model/aui/AIMultiChoice.rb +1 -2
  44. data/lib/MINT-core/model/aui/AIMultiChoiceElement.rb +4 -51
  45. data/lib/MINT-core/model/aui/AIO.rb +76 -123
  46. data/lib/MINT-core/model/aui/AIOUT.rb +8 -0
  47. data/lib/MINT-core/model/aui/AIOUTContinuous.rb +61 -0
  48. data/lib/MINT-core/model/aui/AIReference.rb +16 -0
  49. data/lib/MINT-core/model/aui/AISingleChoice.rb +18 -1
  50. data/lib/MINT-core/model/aui/AISingleChoiceElement.rb +10 -56
  51. data/lib/MINT-core/model/aui/AISinglePresence.rb +39 -71
  52. data/lib/MINT-core/model/aui/aicommand.scxml +47 -0
  53. data/lib/MINT-core/model/aui/aicontainer.scxml +41 -0
  54. data/lib/MINT-core/model/aui/aicontext.scxml +34 -0
  55. data/lib/MINT-core/model/aui/aiincontinuous.scxml +59 -0
  56. data/lib/MINT-core/model/aui/aiinrange.scxml +86 -0
  57. data/lib/MINT-core/model/aui/aimultichoice.scxml +67 -0
  58. data/lib/MINT-core/model/aui/aimultichoiceelement.scxml +51 -0
  59. data/lib/MINT-core/model/aui/aio.scxml +18 -27
  60. data/lib/MINT-core/model/aui/aioutcontinuous.scxml +66 -0
  61. data/lib/MINT-core/model/aui/aireference.scxml +28 -0
  62. data/lib/MINT-core/model/aui/aisinglechoice.scxml +60 -0
  63. data/lib/MINT-core/model/aui/aisinglechoiceelement.scxml +45 -60
  64. data/lib/MINT-core/model/aui/aisinglepresence.scxml +15 -24
  65. data/lib/MINT-core/model/aui/model.rb +15 -38
  66. data/lib/MINT-core/model/cui/gfx/CIC.rb +34 -10
  67. data/lib/MINT-core/model/cui/gfx/CIO.rb +66 -115
  68. data/lib/MINT-core/model/cui/gfx/CarouFredSel.scxml +58 -0
  69. data/lib/MINT-core/model/cui/gfx/MarkableRadioButton.rb +8 -0
  70. data/lib/MINT-core/model/cui/gfx/RadioButton.rb +8 -0
  71. data/lib/MINT-core/model/cui/gfx/RadioButtonGroup.rb +6 -0
  72. data/lib/MINT-core/model/cui/gfx/button.rb +16 -0
  73. data/lib/MINT-core/model/cui/gfx/button.scxml +58 -0
  74. data/lib/MINT-core/model/cui/gfx/caroufredsel.rb +48 -0
  75. data/lib/MINT-core/model/cui/gfx/cic.scxml +57 -0
  76. data/lib/MINT-core/model/cui/gfx/cio.scxml +54 -0
  77. data/lib/MINT-core/model/cui/gfx/markableradiobutton.scxml +67 -0
  78. data/lib/MINT-core/model/cui/gfx/model.rb +39 -176
  79. data/lib/MINT-core/model/cui/gfx/radiobutton.scxml +59 -0
  80. data/lib/MINT-core/model/interactor.rb +167 -46
  81. data/lib/MINT-core/model/interactor.scxml +3 -0
  82. data/lib/MINT-core/model/interactor_helpers.rb +25 -0
  83. data/lib/MINT-core/model/ir/body/OneHandPoseNavigation.rb +15 -0
  84. data/lib/MINT-core/model/ir/body/body.rb +5 -0
  85. data/lib/MINT-core/model/ir/body/fingertip.rb +114 -0
  86. data/lib/MINT-core/model/ir/body/fingertip.scxml +43 -0
  87. data/lib/MINT-core/model/{body → ir/body}/gesture_button.rb +0 -0
  88. data/lib/MINT-core/model/ir/body/hand.rb +5 -0
  89. data/lib/MINT-core/model/ir/body/head.rb +102 -0
  90. data/lib/MINT-core/model/ir/body/head.scxml +92 -0
  91. data/lib/MINT-core/model/ir/body/onehandposenavigation.scxml +53 -0
  92. data/lib/MINT-core/model/ir/body/pose.rb +99 -0
  93. data/lib/MINT-core/model/ir/browserscreen.rb +27 -0
  94. data/lib/MINT-core/model/ir/browserscreen.scxml +14 -0
  95. data/lib/MINT-core/model/{device → ir}/button.rb +1 -1
  96. data/lib/MINT-core/model/ir/ir.rb +5 -0
  97. data/lib/MINT-core/model/ir/irmedia.rb +5 -0
  98. data/lib/MINT-core/model/ir/irmode.rb +5 -0
  99. data/lib/MINT-core/model/{device → ir}/joypad.rb +1 -1
  100. data/lib/MINT-core/model/ir/mouse.rb +44 -0
  101. data/lib/MINT-core/model/ir/mouse.scxml +35 -0
  102. data/lib/MINT-core/model/{device/mouse.rb → ir/mouse_old.rb} +2 -2
  103. data/lib/MINT-core/model/{device → ir}/pointer.rb +20 -22
  104. data/lib/MINT-core/model/ir/pointer.scxml +19 -0
  105. data/lib/MINT-core/model/ir/screen.rb +5 -0
  106. data/lib/MINT-core/model/{device → ir}/wheel.rb +1 -1
  107. data/lib/MINT-core/model/mim/aicommand_activate_to_button_press.xml +13 -0
  108. data/lib/MINT-core/model/mim/aicommand_deactivate_to_button_release.xml +13 -0
  109. data/lib/MINT-core/model/mim/aio_defocus_to_cio_unhighlight.xml +13 -0
  110. data/lib/MINT-core/model/mim/aio_focus_to_cio_highlight.xml +14 -0
  111. data/lib/MINT-core/model/mim/aio_present_to_cio_display.xml +14 -0
  112. data/lib/MINT-core/model/mim/aio_suspend_to_cio_hide.xml +13 -0
  113. data/lib/MINT-core/model/mim/aisinglechoice_present_to_child_present.xml +14 -0
  114. data/lib/MINT-core/model/mim/aisinglechoiceelement_chosen_to_radiobutton_select.xml +13 -0
  115. data/lib/MINT-core/model/mim/aisinglechoiceelement_unchosen_to_radiobutton_unselect.xml +13 -0
  116. data/lib/MINT-core/model/mim/aisinglepresence_children_finished_to_caroufredsel_init_js.xml +14 -0
  117. data/lib/MINT-core/model/mim/aisinglepresence_present_to_child_present.xml +15 -0
  118. data/lib/MINT-core/model/mim/browserscreen_reload_to_cuicontrol_refresh_all.xml +12 -0
  119. data/lib/MINT-core/model/mim/button_press_to_aicommand_activate.xml +12 -0
  120. data/lib/MINT-core/model/mim/button_release_to_aicommand_deactivate.xml +12 -0
  121. data/lib/MINT-core/model/mim/caroufredsel_refreshing_to_caroufredsel_init_js.xml +14 -0
  122. data/lib/MINT-core/model/mim/cio_display_to_aio_defocus.xml +13 -0
  123. data/lib/MINT-core/model/mim/cio_display_to_aio_present.xml +12 -0
  124. data/lib/MINT-core/model/mim/cio_display_to_cio_display_cache_add.xml +11 -0
  125. data/lib/MINT-core/model/mim/cio_hide_to_aio_suspend.xml +12 -0
  126. data/lib/MINT-core/model/mim/cio_hide_to_cio_display_cache_remove.xml +12 -0
  127. data/lib/MINT-core/model/mim/cio_highlight_to_aio_focus.xml +13 -0
  128. data/lib/MINT-core/model/mim/head_looking_left_to_aisinglepresence_prev.xml +14 -0
  129. data/lib/MINT-core/model/mim/head_looking_right_to_aisinglepresence_next.xml +15 -0
  130. data/lib/MINT-core/model/mim/head_nodding_to_aisinglepresence_next.xml +15 -0
  131. data/lib/MINT-core/model/mim/head_tilting_left_to_aisinglepresence_prev.xml +14 -0
  132. data/lib/MINT-core/model/mim/head_tilting_right_to_aisinglepresence_next.xml +15 -0
  133. data/lib/MINT-core/model/mim/left_button_aisinglepresence_enter.xml +15 -0
  134. data/lib/MINT-core/model/mim/left_button_aisinglepresence_next.xml +15 -0
  135. data/lib/MINT-core/model/mim/mim_default.xml +52 -0
  136. data/lib/MINT-core/model/mim/mint-mappings.xsd +127 -0
  137. data/lib/MINT-core/model/mim/mouse_press_to_aicommand_activate.xml +17 -0
  138. data/lib/MINT-core/model/mim/mouse_press_to_aisinglechoiceelement_choose.xml +17 -0
  139. data/lib/MINT-core/model/mim/mouse_press_to_aisinglechoiceelement_unchoose.xml +17 -0
  140. data/lib/MINT-core/model/mim/mouse_release_to_aicommand_deactivate.xml +16 -0
  141. data/lib/MINT-core/model/mim/mouse_stop_to_cio_highlight.xml +13 -0
  142. data/lib/MINT-core/model/mim/onehandposnav_confirm_to_aichoiceelement_choose.xml +14 -0
  143. data/lib/MINT-core/model/mim/onehandposnav_next_to_aio_next.xml +14 -0
  144. data/lib/MINT-core/model/mim/onehandposnav_previous_to_aio_prev.xml +14 -0
  145. data/lib/MINT-core/model/mim/radiobutton_selected_to_aisinglechoiceelement_choose.xml +13 -0
  146. data/lib/MINT-core/model/mim/radiobutton_unselected_to_aisinglechoiceelement_unchoose.xml +13 -0
  147. data/lib/MINT-core/model/mim/right_button_aisinglepresence_prev.xml +15 -0
  148. data/lib/MINT-core/model/task.rb +6 -6
  149. data/script/console +0 -0
  150. data/script/destroy +0 -0
  151. data/script/generate +0 -0
  152. data/spec/AICommand_spec.rb +20 -0
  153. data/spec/AIContainer_spec.rb +161 -0
  154. data/spec/AIINContinuous_spec.rb +92 -0
  155. data/spec/AIOUTContinuous_spec.rb +93 -0
  156. data/spec/AIO_spec.rb +73 -0
  157. data/spec/AIReference_spec.rb +105 -0
  158. data/spec/AISinglePresence_spec.rb +204 -60
  159. data/spec/Button_spec.rb +114 -0
  160. data/spec/CIO_spec.rb +145 -0
  161. data/spec/Interactor_spec.rb +95 -0
  162. data/spec/MappingManager_spec.rb +126 -0
  163. data/spec/Spontaneous_spec.rb +53 -0
  164. data/spec/aio_agent_spec.rb +215 -186
  165. data/spec/aisinglechoice_spec.rb +147 -88
  166. data/spec/aisinglechoiceelement_spec.rb +154 -70
  167. data/spec/complementary_mapping_spec.rb +158 -0
  168. data/spec/core_spec.rb +27 -15
  169. data/spec/cui_helper.rb +100 -0
  170. data/spec/examples/browserscreen_reload_to_cuicontrol_refresh_all.xml +12 -0
  171. data/spec/examples/mim_streaming_example.xml +9 -0
  172. data/spec/examples/mouse_highlight.xml +22 -0
  173. data/spec/examples/performance_mapping.xml +15 -0
  174. data/spec/examples/reset_click.xml +24 -0
  175. data/spec/interactor_test.scxml +32 -0
  176. data/spec/interactor_test_2.scxml +16 -0
  177. data/spec/mapping_performance_spec.rb +118 -0
  178. data/spec/mapping_server_spec.rb +161 -0
  179. data/spec/mapping_spec.rb +307 -0
  180. data/spec/music_spec.rb +301 -135
  181. data/spec/performance_counter.scxml +9 -0
  182. data/spec/sequential_mappings_spec.rb +69 -0
  183. data/spec/shared/aio_shared.rb +144 -0
  184. data/spec/spec_helper.rb +22 -3
  185. data/spec/spontaneous.scxml +11 -0
  186. data/spec/support/connection_helper.rb +19 -0
  187. data/spec/support/redis_connector_monkey_patch.rb +1 -0
  188. data/spec/support/statemachine_helper.rb +84 -0
  189. data/spec/sync_mappings_spec.rb +96 -0
  190. metadata +219 -354
  191. data/lib/MINT-core/mapping/complementary.rb +0 -100
  192. data/lib/MINT-core/mapping/on_state_change.rb +0 -65
  193. data/lib/MINT-core/model/aui/AIC.rb +0 -86
  194. data/lib/MINT-core/model/aui/AIChoice.rb +0 -65
  195. data/lib/MINT-core/model/aui/AIINChoose.rb +0 -54
  196. data/lib/MINT-core/model/aui/AIOUTDiscrete.rb +0 -43
  197. data/lib/MINT-core/model/aui/aic.png +0 -0
  198. data/lib/MINT-core/model/aui/aic.scxml +0 -50
  199. data/lib/MINT-core/model/aui/aichoice.png +0 -0
  200. data/lib/MINT-core/model/aui/aichoice.scxml +0 -60
  201. data/lib/MINT-core/model/aui/aio.png +0 -0
  202. data/lib/MINT-core/model/aui/aisinglechoiceelement.png +0 -0
  203. data/lib/MINT-core/model/aui/aisinglepresence.png +0 -0
  204. data/lib/MINT-core/model/body/handgesture.rb +0 -279
  205. data/lib/MINT-core/model/body/head.png +0 -0
  206. data/lib/MINT-core/model/body/head.rb +0 -51
  207. data/lib/MINT-core/model/body/head.scxml +0 -28
  208. data/lib/MINT-core/model/cui/gfx/screen.rb +0 -18
  209. data/lib/MINT-core/overrides/rinda.rb +0 -34
  210. data/spec/AIC_spec.rb +0 -69
  211. data/spec/MINT-core_spec.rb +0 -11
  212. data/spec/aio_spec.rb +0 -144
  213. data/spec/cio_spec.rb +0 -369
  214. data/tasks/rspec.rake +0 -21
@@ -0,0 +1,9 @@
1
+ <scxml initial="initialized" name="PerformanceCounter" version="0.9" xmlns="http://www.w3.org/2005/07/scxml"><!-- node-size-and-position x=0.0 y=0.0 w=630.0 h=510.0 -->
2
+ <state id="initialized"><!-- node-size-and-position x=10.0 y=40.0 w=80.0 h=30.0 -->
3
+ <transition cond="counter &lt; (amount-1)" event="finished">
4
+ <invoke src="inc_counter" type="x-mint"></invoke>
5
+ </transition>
6
+ <transition cond="counter == (amount-1)" event="finished" target="finished"></transition>
7
+ </state>
8
+ <state id="finished"><!-- node-size-and-position x=30.0 y=140.0 w=100.0 h=40.0 --></state>
9
+ </scxml>
@@ -0,0 +1,69 @@
1
+ require "spec_helper"
2
+
3
+ require "em-spec/rspec"
4
+
5
+ describe 'In a sequential mapping' do
6
+ include EventMachine::SpecHelper
7
+
8
+ before :all do
9
+ connection_options = { :adapter => "redis"}
10
+ DataMapper.setup(:default, connection_options)
11
+
12
+
13
+ connect do |redis|
14
+ require "MINT-core"
15
+ class Logging
16
+ def self.log(mapping,data)
17
+ p "log: #{mapping} #{data}"
18
+ end
19
+ end
20
+ DataMapper.finalize
21
+ DataMapper::Model.raise_on_save_failure = true
22
+ end
23
+ end
24
+
25
+ it 'observations and events should handle list of interactors' do
26
+ def my_callback(mapping_name,data)
27
+ if mapping_name.eql? "Reset Click"
28
+ @data << data
29
+ end
30
+ end
31
+
32
+
33
+ connect true do |redis|
34
+ m = MappingManager.new
35
+
36
+ def my_callback(mapping_name,data)
37
+ p data
38
+
39
+ end
40
+
41
+ m.register_callback("BrowserScreen reload to CIO refresh", method(:my_callback))
42
+ m.load("#{File.dirname(__FILE__)}/examples/mim_streaming_example.xml")
43
+
44
+
45
+ check_result = Proc.new {
46
+ MINT::CIO.first(:name=>"c1").states.should ==[:displayed]
47
+ MINT::CIO.first(:name=>"c2").states.should ==[:displayed]
48
+ MINT::CIO.first(:name=>"c3").states.should ==[:hidden]
49
+
50
+ done
51
+ }
52
+
53
+ test_complex_state_flow_w_name redis,[["Interactor.CIO","c1" ,["refreshing",["displaying", "init_js"],"displayed"]],["Interactor.CIO","c2" ,["refreshing",["displaying", "init_js"],"displayed"]],["Interactor.CIO","c3" ,["refreshing_while_hidden","hidden"]]],check_result do |count|
54
+ Fiber.new{
55
+ b = MINT::BrowserScreen.create(:name=>'screen')
56
+ MINT::AIO.create(:name =>"c1", :states=>[:presenting])
57
+ MINT::AIO.create(:name =>"c2", :states=>[:presenting])
58
+ MINT::AIO.create(:name =>"c3", :states=>[:suspended])
59
+
60
+ MINT::CIO.create(:name =>"c1", :states=>[:displayed])
61
+ MINT::CIO.create(:name =>"c2", :states=>[:displayed])
62
+ MINT::CIO.create(:name =>"c3", :states=>[:hidden])
63
+
64
+ b.process_event :reload
65
+ }.resume
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,144 @@
1
+ share_examples_for 'An AIO interactor' do
2
+ include EventMachine::SpecHelper
3
+
4
+ before :all do
5
+ connection_options = { :adapter => "redis"}
6
+ DataMapper.setup(:default, connection_options)
7
+
8
+ connect do |redis|
9
+ require "MINT-core"
10
+ require "support/redis_connector_monkey_patch" # TODO dirty patch for a bug that i have not found :(
11
+ DataMapper.finalize
12
+ DataMapper::Model.raise_on_save_failure = true
13
+ end
14
+ end
15
+
16
+ it 'should publish initialize when created' do
17
+ connect true do |redis|
18
+ test_state_flow redis,@interactor_class.create_channel_name+".test" ,%w(initialized) do
19
+ @interactor_class.create(:name => "test")
20
+ end
21
+ end
22
+ end
23
+
24
+ it 'should change to initialized when created' do
25
+ @a = @interactor_class.create(:name => "test")
26
+ @a.states.should ==[:initialized]
27
+ @a.new_states.should == [:initialized]
28
+ end
29
+
30
+ it 'should save with correct identifier' do
31
+ @a = @interactor_class.create(:name => "test")
32
+ redis = Redis.connect
33
+ r = redis.hgetall("mint_interactors:"+@interactor_class.getModel+"test")
34
+ r['name'].should == "test"
35
+ end
36
+
37
+ it 'should transform to organizing state for present action' do
38
+ @a = @interactor_class.create(:name => "test")
39
+ @a.process_event(:organize).should ==[:organized]
40
+ @a.states.should == [:organized]
41
+ @a.new_states.should == [:organized]
42
+ end
43
+
44
+ it 'should recover state after save and reload' do
45
+ @a = @interactor_class.create(:name => "test")
46
+ @a.process_event(:organize).should == [:organized]
47
+ @a.save
48
+ b = @interactor_class.first(:mint_model =>@interactor_class.getModel, :name => "test")
49
+ b.states.should == [:organized]
50
+ end
51
+
52
+ describe "and basic navigation" do
53
+ it "should save prev/next links" do
54
+ a = @interactor_class.create(:name => "test")
55
+ b = @interactor_class.create(:name=>"next")
56
+ a.next = "next"
57
+ b.previous = "test"
58
+ b.save.should == true
59
+ a.save.should == true
60
+
61
+ n = @interactor_class.first(:name=>"next")
62
+ n.previous.should == a
63
+
64
+ m = @interactor_class.first(:name=>"test")
65
+ m.next.should == b
66
+ end
67
+
68
+ it 'should move focus to next element upon next' do
69
+ a = @interactor_class.create(:name => "test",:next => "next")
70
+ b = @interactor_class.create(:name=>"next",:previous => "test")
71
+
72
+ a.process_event(:organize)
73
+ b.process_event(:organize)
74
+
75
+ a.process_event(:present)
76
+ b.process_event(:present)
77
+
78
+ a.process_event(:focus).should include :focused
79
+ a.process_event(:next).should include :defocused
80
+
81
+ b = @interactor_class.first(:name=>"next")
82
+ b.states.should include :focused
83
+ a.states.should include :defocused
84
+ end
85
+
86
+ it 'should move focus to previous element upon previous' do
87
+ a = @interactor_class.create(:name => "test",:next => "next")
88
+ b = @interactor_class.create(:name=>"next",:previous => "test")
89
+
90
+ a.process_event(:organize)
91
+ b.process_event(:organize)
92
+
93
+ a.process_event(:present)
94
+ b.process_event(:present)
95
+
96
+ b.process_event(:focus).should include :focused
97
+ b.process_event(:prev).should include :defocused
98
+
99
+ a = @interactor_class.first(:name=>"test")
100
+ a.states.should include :focused
101
+ b.states.should include :defocused
102
+ end
103
+
104
+ it 'should not defocus on next if there is no next element' do
105
+ a = @interactor_class.create(:name => "test")
106
+ a.process_event(:organize)
107
+
108
+ a.process_event(:present)
109
+
110
+ a.process_event(:focus).should include :focused
111
+ a.process_event(:next)
112
+ a.states.should include :focused
113
+ end
114
+
115
+ it 'should not defocus on previous if there is no previous element' do
116
+ a = @interactor_class.create(:name => "test")
117
+ a.process_event(:organize)
118
+
119
+ a.process_event(:present)
120
+
121
+ a.process_event(:focus).should include :focused
122
+ a.process_event(:prev).should include :focused
123
+ end
124
+
125
+ it 'should move focus to parent upon parent' do
126
+ a = @interactor_class.create(:name => "test",:parent =>"parent")
127
+ b = MINT::AIContainer.create(:name=>"parent",:children =>["test"])
128
+
129
+ a.process_event(:organize)
130
+ b.process_event(:organize)
131
+
132
+ a.process_event(:present)
133
+ b.process_event(:present)
134
+
135
+ a.process_event(:focus).should include :focused
136
+ a.process_event(:parent).should include :defocused
137
+
138
+ b = MINT::AIContainer.first(:name=>"parent")
139
+ b.states.should include :focused
140
+ a.states.should include :defocused
141
+
142
+ end
143
+ end
144
+ end
@@ -1,7 +1,26 @@
1
1
  $:.unshift(File.dirname(__FILE__) + '/../lib')
2
2
 
3
3
  require 'rubygems'
4
- require "spec"
5
- require "MINT-core"
6
- require "MINT-scxml"
4
+ require "rspec"
5
+ require "bundler/setup"
6
+ require 'statemachine'
7
+ require "cassowary"
8
+ require 'RMagick'
9
+ require 'drb/drb'
10
+ require 'redis'
11
+ require 'dm-core'
12
+ require 'dm-serializer'
13
+ require 'dm-types'
14
+ require 'eventmachine'
15
+ require 'em-hiredis'
16
+ require 'em-spec/rspec'
7
17
 
18
+ require 'support/connection_helper'
19
+ require 'support/statemachine_helper'
20
+ require 'stringio'
21
+
22
+ RSpec.configure do |config|
23
+ config.include ConnectionHelper
24
+ config.include StatemachineHelper
25
+ config.include EventMachine::SpecHelper
26
+ end
@@ -0,0 +1,11 @@
1
+ <scxml initial="initialized" name="Spontaneous" version="0.9" xmlns="http://www.w3.org/2005/07/scxml"><!-- node-size-and-position x=0.0 y=0.0 w=885.0 h=723.0 -->
2
+ <state id="initialized"><!-- node-size-and-position x=220.0 y=130.0 w=100.0 h=40.0 -->
3
+ <transition event="position" target="superstate"></transition>
4
+ </state>
5
+ <state id="superstate" initial="positioning"><!-- node-size-and-position x=180.0 y=220.0 w=160.0 h=190.0 -->
6
+ <state id="positioned"><!-- node-size-and-position x=20.0 y=130.0 w=100.0 h=40.0 --></state>
7
+ <state id="positioning"><!-- node-size-and-position x=10.0 y=40.0 w=100.0 h=40.0 -->
8
+ <transition target="positioned"></transition>
9
+ </state>
10
+ </state>
11
+ </scxml>
@@ -0,0 +1,19 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+ require "MINT-core/connector/redis_connector"
4
+
5
+
6
+ module ConnectionHelper
7
+ def connect(wait = false, timeout = 10, &blk)
8
+ em(timeout) do
9
+ RedisConnector.reset
10
+ redis = RedisConnector.redis
11
+
12
+ redis.flushall.callback {
13
+ blk.call(redis)
14
+ EM.stop_event_loop if not wait
15
+ }
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,84 @@
1
+ module StatemachineHelper
2
+ def test_state_flow(redis, channel, expected_states, &blk)
3
+ redis.pubsub.subscribe(channel) { |message|
4
+ # p [:message, channel, message]
5
+ m = MultiJson.decode message
6
+ r = expected_states.shift
7
+ r = r.lines.to_a if r.is_a? String
8
+ m["new_states"].should == r
9
+
10
+ done if expected_states.length==0
11
+ }.callback {blk.call}
12
+
13
+ EM.add_timer(3) {
14
+ raise "failed to wait for state change to >>#{expected_states.first}<<, which not occurred during the last 3 seconds"
15
+ done # EM.stop
16
+ }
17
+ end
18
+
19
+ def test_state_flow_w_name(redis, channel, name, expected_states, cb, &blk)
20
+ redis.pubsub.subscribe(channel+".#{name}") { |message|
21
+ m = MultiJson.decode message
22
+ if m["name"].eql? name
23
+ #p [:message, channel, message]
24
+ r = expected_states.shift
25
+ r = r.lines.to_a if r.is_a? String
26
+ m["new_states"].should == r
27
+
28
+ if expected_states.length==0
29
+ redis.pubsub.unsubscribe(channel+".#{name}")
30
+ cb.call
31
+ end
32
+
33
+ end
34
+ }.callback {blk.call}
35
+
36
+ EM.add_timer(60) {
37
+ raise "failed to wait for state change to >>#{expected_states.first}<<, which not occurred during the last 3 seconds"
38
+ done # EM.stop
39
+
40
+ }
41
+ end
42
+
43
+ def test_complex_state_flow_w_name(redis, interactors, cb, &blk)
44
+
45
+ @counter = interactors.size
46
+ res_cb_new = Proc.new do
47
+ @counter -=1
48
+ cb.call if @counter == 0
49
+ end
50
+
51
+ @subcounter = interactors.size
52
+ sub_cb_new = Proc.new do
53
+ @subcounter -=1
54
+ blk.call if @subcounter == 0
55
+ end
56
+
57
+ interactors.each do |i|
58
+ channel, name, expected_states = i
59
+ test_state_flow_w_name(redis, channel, name, expected_states, res_cb_new, &sub_cb_new)
60
+ end
61
+
62
+
63
+ end
64
+
65
+
66
+ def test_msg_flow (redis,channel,interactor,attribute,value, publish_data)
67
+
68
+ #redis.subscribe(interactor.create_channel_name).callback {blk.call}
69
+
70
+ # redis.on(:message) { |c, message|
71
+
72
+ end_reached = publish_data.length
73
+ publish_data.each_with_index do |data,i|
74
+ redis.publish(channel,MultiJson.encode(data.to_json)).callback { |c|
75
+ #interactor.method(attribute).call.should == value[i]
76
+ done if end_reached == i
77
+ }
78
+ end
79
+
80
+ end
81
+ end
82
+
83
+
84
+
@@ -0,0 +1,96 @@
1
+
2
+ require "spec_helper"
3
+
4
+ require "em-spec/rspec"
5
+
6
+ require "cui_helper"
7
+
8
+
9
+ describe 'Sync wth AIO' do
10
+ include EventMachine::SpecHelper
11
+
12
+ before :all do
13
+ connection_options = { :adapter => "redis"}
14
+ DataMapper.setup(:default, connection_options)
15
+
16
+
17
+ connect do |redis|
18
+ require "MINT-core"
19
+ class Logging
20
+ def self.log(mapping,data)
21
+ p "log: #{mapping} #{data}"
22
+ end
23
+ end
24
+ DataMapper.finalize
25
+ DataMapper::Model.raise_on_save_failure = true
26
+ end
27
+ end
28
+
29
+ it 'should sync highlight movements of CIO to AUI' do
30
+ connect true do |redis|
31
+
32
+ # Sync AIO to defocused
33
+ parser = MINT::MappingParser.new
34
+ m = parser.build_from_scxml File.dirname(__FILE__) +"/../lib/MINT-core/model/mim/cio_display_to_aio_defocus.xml"
35
+ m.start
36
+
37
+ # Sync AIO to focused
38
+ parser = MINT::MappingParser.new
39
+ m = parser.build_from_scxml File.dirname(__FILE__) +"/../lib/MINT-core/model/mim/cio_highlight_to_aio_focus.xml"
40
+ m.start
41
+
42
+ check_result = Proc.new {
43
+ MINT::AIO.first(:name=>"left").states.should ==[:focused]
44
+ MINT::CIO.first(:name=>"left").states.should ==[:highlighted]
45
+ MINT::AIO.first(:name=>"center").states.should ==[:defocused]
46
+
47
+ done
48
+ }
49
+
50
+
51
+ test_complex_state_flow_w_name redis,[["Interactor.CIO","center" ,["initialized","displayed"]],["Interactor.AIO","center" ,["defocused"]]],check_result do |count|
52
+ center = CUIHelper.scenario2
53
+ p "testcound:#{count}"
54
+ center.process_event(:left).should ==[:displayed]
55
+ end
56
+
57
+ #
58
+ end
59
+ end
60
+
61
+ it 'should sync AUI focus movements to CUI' do
62
+ connect true do |redis|
63
+
64
+ # Sync CIO to displayed
65
+ parser = MINT::MappingParser.new
66
+ m = parser.build_from_scxml File.dirname(__FILE__) +"/../lib/MINT-core/model/mim/aio_defocus_to_cio_unhighlight.xml"
67
+ m.start
68
+
69
+ # Sync CIO to highlighted
70
+ parser = MINT::MappingParser.new
71
+ m = parser.build_from_scxml File.dirname(__FILE__) +"/../lib/MINT-core/model/mim/aio_focus_to_cio_highlight.xml"
72
+ m.start
73
+
74
+ check_result = Proc.new {
75
+ MINT::AIO.first(:name=>"left").states.should ==[:focused]
76
+ MINT::AIO.first(:name=>"center").states.should ==[:defocused]
77
+
78
+ MINT::CIO.first(:name=>"center").states.should ==[:displayed]
79
+ MINT::CIO.first(:name=>"left").states.should ==[:highlighted]
80
+
81
+ done
82
+ }
83
+
84
+ test_complex_state_flow_w_name redis,[["Interactor.AIO","center" ,["defocused"]],["Interactor.CIO","center" ,["displayed"]]],check_result do |count|
85
+ center = CUIHelper.scenario3
86
+ a_center = MINT::AIO.first(:name => "center")
87
+ a_center.process_event("next").should ==[:defocused]
88
+ end
89
+
90
+
91
+
92
+
93
+ #MINThighlightedst(:nameA>"dowleftates.should ==[:highlighted]
94
+ end
95
+ end
96
+ end