diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2011-04-19 17:48:50 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2011-04-19 17:48:50 +0200 |
commit | 1885a987a7d9178b51c6e447dc3bb0fc8ac325ea (patch) | |
tree | 43c05dd7e1ae279699dc0e6f3f1349f20ca57a15 | |
parent | fc35c3abd3ea359e6977b5cd59118db5b9b09a51 (diff) | |
download | ffi-efl-1885a987a7d9178b51c6e447dc3bb0fc8ac325ea.zip ffi-efl-1885a987a7d9178b51c6e447dc3bb0fc8ac325ea.tar.gz |
add ecore event specs
-rw-r--r-- | lib/e17/ecore.rb | 9 | ||||
-rw-r--r-- | lib/e17/ecore/event.rb | 54 | ||||
-rw-r--r-- | spec/ecore_event_spec.rb | 116 | ||||
-rw-r--r-- | spec/ecore_spec.rb | 106 |
4 files changed, 115 insertions, 170 deletions
diff --git a/lib/e17/ecore.rb b/lib/e17/ecore.rb index fe4786f..b0be458 100644 --- a/lib/e17/ecore.rb +++ b/lib/e17/ecore.rb @@ -6,6 +6,15 @@ require 'e17/ecore/ecore-ffi' module E17 module Ecore # + # ecore-1/Ecore.h line 95 + EVENT_NONE = 0 + EVENT_SIGNAL_USER = 1 # User signal event + EVENT_SIGNAL_HUP = 2 # Hup signal event + EVENT_SIGNAL_EXIT = 3 # Exit signal event + EVENT_SIGNAL_POWER = 4 # Power signal event + EVENT_SIGNAL_REALTIME = 5 # Realtime signal event + EVENT_COUNT = 6 + # class EcorePipe def initialize cb, data @ptr = E17::API.ecore_pipe_add cb, data diff --git a/lib/e17/ecore/event.rb b/lib/e17/ecore/event.rb deleted file mode 100644 index 56b5c69..0000000 --- a/lib/e17/ecore/event.rb +++ /dev/null @@ -1,54 +0,0 @@ -#! /usr/bin/env ruby -# -*- coding: UTF-8 -*- -# -require 'e17/ffi_helper' -# -module E17 - module ECORE - # - extend FFIHelper - extend FFI::Library - # - ffi_lib 'ecore' - # -# enum :ecore_signals, [:none,0,:signal_user,:signal_hup,:signal_exit,:signal_power,:signal_realtime] - EVENT_NONE = 0 - EVENT_SIGNAL_USER = 1 # User signal event - EVENT_SIGNAL_HUP = 2 # Hup signal event - EVENT_SIGNAL_EXIT = 3 # Exit signal event - EVENT_SIGNAL_POWER = 4 # Power signal event - EVENT_SIGNAL_REALTIME = 5 # Realtime signal event - EVENT_COUNT = 6 - # - typedef :pointer, :ecore_event - typedef :pointer, :ecore_event_filter - typedef :pointer, :ecore_event_handler - # - callback :ecore_end_cb, [:pointer, :pointer], :void - callback :ecore_data_cb, [:pointer], :pointer - callback :ecore_filter_cb, [:pointer, :pointer, :int, :pointer], :bool - callback :ecore_event_handler_cb, [:pointer, :int, :pointer], :bool - # - fcts = [ - # http://docs.enlightenment.org/auto/ecore/group__Ecore__Event__Group.html - [ :ecore_event_handler_add, [:int, :ecore_event_handler_cb, :pointer], :ecore_event_handler], - [ :ecore_event_handler_del, [:ecore_event_handler], :pointer], - [ :ecore_event_add, [:int, :pointer, :ecore_end_cb, :pointer], :ecore_event], - [ :ecore_event_del, [:ecore_event], :pointer], - [ :ecore_event_handler_data_get, [:ecore_event_handler], :pointer], - [ :ecore_event_handler_data_set, [:ecore_event_handler, :pointer], :pointer], - [ :ecore_event_type_new, [], :int], - [ :ecore_event_filter_add, [:ecore_data_cb, :ecore_filter_cb, :ecore_end_cb, :pointer], :ecore_event_filter], - [ :ecore_event_filter_del, [:ecore_event_filter], :pointer], - [ :ecore_event_current_type_get, [], :int], - [ :ecore_event_current_event_get, [], :pointer], - ] - # - attach_fcts fcts - # - create_aliases 'ecore_'.length, fcts - # - end -end -# -# EOF diff --git a/spec/ecore_event_spec.rb b/spec/ecore_event_spec.rb deleted file mode 100644 index d8bc5cc..0000000 --- a/spec/ecore_event_spec.rb +++ /dev/null @@ -1,116 +0,0 @@ -#! /usr/bin/env ruby -# -*- coding: UTF-8 -*- -# -require 'e17/ecore' -require 'e17/ecore/event' -# -describe E17::ECORE do - # - include E17 - # - before(:all) do - USER_SIGNAL_CB = Proc.new do |data, type, event| - data.read_string.should eql "ok" - type.should eql ECORE::EVENT_SIGNAL_USER - event.read_int.should eql 666 - ECORE.event_current_type_get.should eql ECORE::EVENT_SIGNAL_USER - ECORE.event_current_event_get.address.should eql event.address - ECORE.main_loop_quit - end - EVENT_FREE_CB = Proc.new do |data,event| - data.read_string.should eql "none" - event.read_int.should eql 666 - end - OK = FFI::MemoryPointer.from_string "ok" - KO = FFI::MemoryPointer.from_string "ko" - NONE = FFI::MemoryPointer.from_string "none" - end - # - it 'should be able to add, del event hanlder and process event' do - ECORE.init - evt = FFI::MemoryPointer.new(:int) - evt.write_int 666 - # add, del, add event handler - evt_handler = ECORE.event_handler_add ECORE::EVENT_SIGNAL_USER, USER_SIGNAL_CB, KO - evt_handler.null?.should be_false - ECORE.event_handler_del(evt_handler).address.should eql KO.address - evt_handler = ECORE.event_handler_add ECORE::EVENT_SIGNAL_USER, USER_SIGNAL_CB, OK - evt_handler.null?.should be_false - # add, del, add event - ecore_evt = ECORE.event_add ECORE::EVENT_SIGNAL_USER, evt, EVENT_FREE_CB, NONE - ecore_evt.null?.should be_false - ECORE.event_del(ecore_evt).address.should eql NONE.address - ecore_evt = ECORE.event_add ECORE::EVENT_SIGNAL_USER, evt, EVENT_FREE_CB, NONE - ecore_evt.null?.should be_false - ECORE.main_loop_begin # process event - ECORE.shutdown - end - # - it "should be able to get and set event handler data" do - ECORE.init - evt = FFI::MemoryPointer.new(:int) - evt.write_int 666 - evt_handler = ECORE.event_handler_add ECORE::EVENT_SIGNAL_USER, USER_SIGNAL_CB, KO - evt_handler.null?.should be_false - ECORE.event_handler_data_get(evt_handler).read_string.should eql "ko" - ECORE.event_handler_data_set(evt_handler, OK).address.should eql KO.address - ECORE.event_handler_data_get(evt_handler).read_string.should eql "ok" - ecore_evt = ECORE.event_add ECORE::EVENT_SIGNAL_USER, evt, EVENT_FREE_CB, NONE - ecore_evt.null?.should be_false - ECORE.main_loop_begin # process event - ECORE.shutdown - end - # - it "should be able to create new event type" do - ECORE.init - ECORE.ecore_event_type_new.should_not eql 0 - ECORE.ecore_event_type_new.should_not eql 0 - ECORE.ecore_event_type_new.should_not eql 0 - ECORE.shutdown - end - # - it "should be possible to add and del event filters" do - ECORE.init - loop_data = FFI::MemoryPointer.from_string("loop_data") - event_free_cb = Proc.new do |data,event| - data.read_string.should eql "ko" - event.read_int.should eql 69 - end - start_cb = Proc.new do |data| - data.read_string.should eql "ok" - loop_data - end - count = 0 - filter_cb = Proc.new do |data,loop_data,type,event| - data.read_string.should eql "ok" - loop_data.read_string.should eql "loop_data" - type.should eql ECORE::EVENT_SIGNAL_USER - count += 1 - if event.read_int == 69 - count.should eql 1 - false # drop first event - else - count.should eql 2 - event.read_int.should eql 666 - true - end - end - end_cb = Proc.new do |data,loop_data| - data.read_string.should eql "ok" - loop_data.read_string.should eql "loop_data" - end - filter = ECORE.ecore_event_filter_add start_cb, filter_cb, end_cb, OK - ECORE.event_handler_add ECORE::EVENT_SIGNAL_USER, USER_SIGNAL_CB, OK - e1 = FFI::MemoryPointer.new(:int) - e1.write_int 69 - evt1 = ECORE.event_add ECORE::EVENT_SIGNAL_USER, e1, event_free_cb, KO - e2 = FFI::MemoryPointer.new(:int) - e2.write_int 666 - evt2 = ECORE.event_add ECORE::EVENT_SIGNAL_USER, e2, EVENT_FREE_CB, NONE - ECORE.main_loop_begin # process event - ECORE.ecore_event_filter_del(filter).address.should eql OK.address - evt2 = ECORE.event_add ECORE::EVENT_SIGNAL_USER, e2, EVENT_FREE_CB, NONE - ECORE.main_loop_begin # process event - ECORE.shutdown - end -end diff --git a/spec/ecore_spec.rb b/spec/ecore_spec.rb index 183e64c..6184dba 100644 --- a/spec/ecore_spec.rb +++ b/spec/ecore_spec.rb @@ -7,6 +7,24 @@ describe E17::Ecore do # include E17 # + before(:all) do + USER_SIGNAL_CB = Proc.new do |data, type, event| + data.read_string.should eql "ok" + type.should eql Ecore::EVENT_SIGNAL_USER + event.read_int.should eql 666 + Ecore.event_current_type_get.should eql Ecore::EVENT_SIGNAL_USER + Ecore.event_current_event_get.address.should eql event.address + Ecore.main_loop_quit + end + EVENT_FREE_CB = Proc.new do |data,event| + data.read_string.should eql "none" + event.read_int.should eql 666 + end + OK = FFI::MemoryPointer.from_string "ok" + KO = FFI::MemoryPointer.from_string "ko" + NONE = FFI::MemoryPointer.from_string "none" + end + # it "should init" do Ecore.init.should eql 1 Ecore.init.should eql 2 @@ -41,4 +59,92 @@ describe E17::Ecore do pipe.del.address.should eql data.address Ecore.shutdown end + # + it 'should be able to add, del event hanlder and process event' do + Ecore.init + evt = FFI::MemoryPointer.new(:int) + evt.write_int 666 + # add, del, add event handler + evt_handler = Ecore.event_handler_add Ecore::EVENT_SIGNAL_USER, USER_SIGNAL_CB, KO + evt_handler.null?.should be_false + Ecore.event_handler_del(evt_handler).address.should eql KO.address + evt_handler = Ecore.event_handler_add Ecore::EVENT_SIGNAL_USER, USER_SIGNAL_CB, OK + evt_handler.null?.should be_false + # add, del, add event + ecore_evt = Ecore.event_add Ecore::EVENT_SIGNAL_USER, evt, EVENT_FREE_CB, NONE + ecore_evt.null?.should be_false + Ecore.event_del(ecore_evt).address.should eql NONE.address + ecore_evt = Ecore.event_add Ecore::EVENT_SIGNAL_USER, evt, EVENT_FREE_CB, NONE + ecore_evt.null?.should be_false + Ecore.main_loop_begin # process event + Ecore.shutdown + end + # + it "should be able to get and set event handler data" do + Ecore.init + evt = FFI::MemoryPointer.new(:int) + evt.write_int 666 + evt_handler = Ecore.event_handler_add Ecore::EVENT_SIGNAL_USER, USER_SIGNAL_CB, KO + evt_handler.null?.should be_false + Ecore.event_handler_data_get(evt_handler).read_string.should eql "ko" + Ecore.event_handler_data_set(evt_handler, OK).address.should eql KO.address + Ecore.event_handler_data_get(evt_handler).read_string.should eql "ok" + ecore_evt = Ecore.event_add Ecore::EVENT_SIGNAL_USER, evt, EVENT_FREE_CB, NONE + ecore_evt.null?.should be_false + Ecore.main_loop_begin # process event + Ecore.shutdown + end + # + it "should be able to create new event type" do + Ecore.init + Ecore.event_type_new.should_not eql 0 + Ecore.event_type_new.should_not eql 0 + Ecore.event_type_new.should_not eql 0 + Ecore.shutdown + end + # + it "should be possible to add and del event filters" do + Ecore.init + loop_data = FFI::MemoryPointer.from_string("loop_data") + event_free_cb = Proc.new do |data,event| + data.read_string.should eql "ko" + event.read_int.should eql 69 + end + start_cb = Proc.new do |data| + data.read_string.should eql "ok" + loop_data + end + count = 0 + filter_cb = Proc.new do |data,loop_data,type,event| + data.read_string.should eql "ok" + loop_data.read_string.should eql "loop_data" + type.should eql Ecore::EVENT_SIGNAL_USER + count += 1 + if event.read_int == 69 + count.should eql 1 + false # drop first event + else + count.should eql 2 + event.read_int.should eql 666 + true + end + end + end_cb = Proc.new do |data,loop_data| + data.read_string.should eql "ok" + loop_data.read_string.should eql "loop_data" + end + filter = Ecore.event_filter_add start_cb, filter_cb, end_cb, OK + Ecore.event_handler_add Ecore::EVENT_SIGNAL_USER, USER_SIGNAL_CB, OK + e1 = FFI::MemoryPointer.new(:int) + e1.write_int 69 + evt1 = Ecore.event_add Ecore::EVENT_SIGNAL_USER, e1, event_free_cb, KO + e2 = FFI::MemoryPointer.new(:int) + e2.write_int 666 + evt2 = Ecore.event_add Ecore::EVENT_SIGNAL_USER, e2, EVENT_FREE_CB, NONE + Ecore.main_loop_begin # process event + Ecore.event_filter_del(filter).address.should eql OK.address + evt2 = Ecore.event_add Ecore::EVENT_SIGNAL_USER, e2, EVENT_FREE_CB, NONE + Ecore.main_loop_begin # process event + Ecore.shutdown + end end |