summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2011-05-12 15:52:22 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2011-05-12 15:52:22 +0200
commit0d7f365d97ae05cdab23529a03ed2f5468ba382a (patch)
tree6a0a8afe9a63d49ab92ea44d7ca8d84828789bc6
parenta24f87f291e33b94844188fe9893975e44dc5ff2 (diff)
downloadffi-efl-0d7f365d97ae05cdab23529a03ed2f5468ba382a.zip
ffi-efl-0d7f365d97ae05cdab23529a03ed2f5468ba382a.tar.gz
major ecore_getopt rework
-rw-r--r--Changelog1
-rw-r--r--lib/efl/ecore_getopt.rb255
-rw-r--r--spec/ecore_getopt_spec.rb243
3 files changed, 260 insertions, 239 deletions
diff --git a/Changelog b/Changelog
index e629bb5..285110b 100644
--- a/Changelog
+++ b/Changelog
@@ -1,6 +1,7 @@
2011-05-xx Jérémy Zurcher <jeremy@asynk.ch>
* add REinaList#from_a ptrt
* add REinaList#to_a ptrt=nil
+ * rework EcoreGetopt
2011-05-11 Jérémy Zurcher <jeremy@asynk.ch>
* use ditz ass issure tracker
diff --git a/lib/efl/ecore_getopt.rb b/lib/efl/ecore_getopt.rb
index 8e07f92..dfe9275 100644
--- a/lib/efl/ecore_getopt.rb
+++ b/lib/efl/ecore_getopt.rb
@@ -19,6 +19,10 @@ module Efl
:doublep, :double_p,
:listp, :eina_list_p,
:ptrp, :void_p
+
+ def value_ptr idx
+ Native::EcoreGetoptValue.new to_ptr+(idx*Native::EcoreGetoptValue.size)
+ end
end
#
class EcoreGetoptDescStoreDef < FFI::Union
@@ -85,41 +89,92 @@ module Efl
module EcoreGetopt
#
class REcoreGetopt
+ #
def initialize desc
- @ecore_getopt = nil
+ @ecore_getopt_st = nil
+ @ecore_values_st = nil
@desc = desc
@options = [
[ 0 ],
]
- @values = [
- [ :ptrp, FFI::Pointer::NULL ]
- ]
- @refs = [] # to prevent FFI::MemoryPointer.from_string from beeing GC'ed
+ @values = {
+ :sentinel0 => [ :pointer, FFI::Pointer::NULL ]
+ }
+ @values_order = [ :sentinel0 ]
+ @types = {
+ :string => [ :ecore_getopt_type_str, :strv, :strp ],
+ :uchar => [ :ecore_getopt_type_bool, :boolv, :boolp ],
+ :short => [ :ecore_getopt_type_short, :shortv, :shortp ],
+ :int => [ :ecore_getopt_type_int, :intv, :intp ],
+ :long => [ :ecore_getopt_type_long, :longv, :longp ],
+ :ushort => [ :ecore_getopt_type_ushort, :ushortv, :ushortp ],
+ :uint => [ :ecore_getopt_type_uint, :uintv, :uintp ],
+ :ulong => [ :ecore_getopt_type_ulong, :ulongv, :ulongp ],
+ :double => [ :ecore_getopt_type_double, :doublev, :doublep ],
+ :list => [ :list, nil, :listp ],
+ :pointer=> [ :pointer, nil, :ptrp ],
+ :choice => [ :pointer, nil, :ptrp ]
+ }
+# @refs = [] # to prevent FFI::MemoryPointer.from_string from beeing GC'ed
end
def p_from_string r
return r if r==FFI::Pointer::NULL
- p = FFI::MemoryPointer.from_string r
- @refs << p
- p
+ FFI::MemoryPointer.from_string r
end
private :p_from_string
- def << o
+ def set_option o
@options.insert -2, o
end
- def value type, ptr
- @values.insert -2, [ type, ptr ]
+ def set_value key, ptype, val=nil
+ skey = key.to_s
+ r = @values[skey]
+ if r.nil?
+ case ptype
+ when :list
+ p = FFI::MemoryPointer.new :pointer
+ p.write_pointer val[0]
+ r = @values[skey] = [ ptype, p, val[1] ] # add sub_type info
+ when :choice
+ p = FFI::MemoryPointer.new :pointer
+ p.write_pointer FFI::Pointer::NULL
+ r = @values[skey] = [ ptype, p ]
+ else
+ p = FFI::MemoryPointer.new ptype
+ p.send 'write_'+ptype.to_s, val unless val.nil?
+ r = @values[skey] = [ ptype, p ]
+ end
+ end
+ @values_order.insert -2, skey
+ r
+ end
+ def [] k
+ ptype, ptr, sub_type = @values[k.to_s]
+ return nil if ptype.nil?
+ case ptype
+ when:list
+ require 'efl/eina_list'
+ Efl::EinaList::REinaList.new(ptr.read_pointer).to_a sub_type
+ when :choice
+ p = ptr.read_pointer
+ ( p==FFI::Pointer::NULL ? nil : p.read_string )
+ when :pointer
+ p = ptr.read_pointer
+ ( p==FFI::Pointer::NULL ? nil : p )
+ else
+ ptr.send 'read_'+ptype.to_s
+ end
end
def to_ptr
- @ecore_getopt.to_ptr
+ ( @ecore_getopt_st.nil? ? nil : @ecore_getopt_st.to_ptr )
end
def create
- @ecore_getopt = Native::EcoreGetopt.new( FFI::MemoryPointer.new( :uchar, Native::EcoreGetopt.size+Native::EcoreGetoptDesc.size*@options.length) )
+ @ecore_getopt_st = Native::EcoreGetopt.new( FFI::MemoryPointer.new( :uchar, Native::EcoreGetopt.size+Native::EcoreGetoptDesc.size*@options.length) )
[:prog,:usage,:version,:copyright,:license,:description].each do |sym|
- @ecore_getopt[sym] = ( @desc.has_key?(sym) ? FFI::MemoryPointer.from_string(@desc[sym]) : FFI::Pointer::NULL )
+ @ecore_getopt_st[sym] = ( @desc.has_key?(sym) ? FFI::MemoryPointer.from_string(@desc[sym]) : FFI::Pointer::NULL )
end
- @ecore_getopt[:strict] = @desc[:strict] if @desc.has_key? :strict
+ @ecore_getopt_st[:strict] = @desc[:strict] if @desc.has_key? :strict
@options.each_with_index do |o,i|
- d = @ecore_getopt.desc_ptr i
+ d = @ecore_getopt_st.desc_ptr i
if o[0]==0
d[:shortname] = d[:longname] = d[:help] = d[:metavar] = d[:action] = d[:action_param][:dummy] = 0
break
@@ -143,13 +198,7 @@ module Efl
st = d[:action_param][:store]
st[:type] = v[0]
st[:arg_req] = v[1]
- if not v[2].nil?
- if v[2][0]==:strv
- st[:def][:strv] = p_from_string v[2][1]
- else
- st[:def][v[2][0]] = v[2][1]
- end
- end
+ st[:def][v[2]] = (v[2]==:str ? p_from_string(v[3]) : v[3] ) unless v[3].nil?
when :store_const
d[:action_param][:store_const] = v
when :choices
@@ -160,10 +209,13 @@ module Efl
d[:action_param][:dummy] = FFI::Pointer::NULL
end
end
- @values_p = FFI::MemoryPointer.new Native::EcoreGetoptValue, @values.length, false
- @values.each_with_index do |v,i|
- Native::EcoreGetoptValue.new(@values_p+(i*Native::EcoreGetoptValue.size))[v[0]] = v[1]
+ @ecore_values_st = Native::EcoreGetoptValue.new FFI::MemoryPointer.new Native::EcoreGetoptValue, @values_order.length, false
+ @values_order.each_with_index do |k,i|
+ vtype, vpointer, *sub_type = @values[k]
+ etype, vfield, pfield = @types[vtype]
+ @ecore_values_st.value_ptr(i)[pfield] = vpointer
end
+ self
end
def parse argv
ptr = FFI::MemoryPointer.new(:pointer, argv.length+1)
@@ -171,108 +223,119 @@ module Efl
ptr[i].put_pointer 0, p_from_string(s)
end
ptr[argv.length].put_pointer 0, FFI::Pointer::NULL
- Native.ecore_getopt_parse @ecore_getopt, @values_p, argv.length, ptr
+ Native.ecore_getopt_parse @ecore_getopt_st, @ecore_values_st, argv.length, ptr
end
- def store_full short, long, help, meta, type, arg_req, def_val
- self << [ short, long, help, meta, :ecore_getopt_action_store, [:store, [type,arg_req, def_val] ] ]
+ def help short, long, key=nil
+ set_value key||short, :uchar, 0
+ set_option [ short, long, 'show this message.', FFI::Pointer::NULL, :ecore_getopt_action_help, [:dummy,FFI::Pointer::NULL] ]
end
- def store short, long, help, type
- store_full short, long, help, FFI::Pointer::NULL, type, :ecore_getopt_desc_arg_requirement_yes, nil
+ def version short, long, key=nil
+ set_value key||short, :uchar, 0
+ set_option [ short, long, 'show program version.', FFI::Pointer::NULL, :ecore_getopt_action_version, [:dummy,FFI::Pointer::NULL] ]
end
- def store_type type, short, long, help
- store short, long, help, ('ecore_getopt_type_'+type.to_s).to_sym
+ def copyright short, long, key=nil
+ set_value key||short, :uchar, 0
+ set_option [ short, long, 'show copyright.', FFI::Pointer::NULL, :ecore_getopt_action_copyright, [:dummy,FFI::Pointer::NULL] ]
end
- def store_metavar short, long, help, meta, type
- store_full short, long, help, meta, type, :ecore_getopt_desc_arg_requirement_yes, nil
+ def license short, long, key=nil
+ set_value key||short, :uchar, 0
+ set_option [ short, long, 'show license.', FFI::Pointer::NULL, :ecore_getopt_action_license, [:dummy,FFI::Pointer::NULL] ]
end
- def store_meta_type type, short, long, help, meta
- store_metavar short, long, help, meta, ('ecore_getopt_type_'+type.to_s).to_sym
+ def store_full short, long, help, meta, arg_req, type, def_val
+ vtype, vpointer = set_value short, type, def_val
+ etype, vfield, pfield = @types[vtype]
+ set_option [ short, long, help, meta, :ecore_getopt_action_store, [:store, [etype, arg_req, vfield, def_val] ] ]
end
- def store_def short, long, help, type, def_val
- store_full short, long, help, FFI::Pointer::NULL, type, :ecore_getopt_desc_arg_requirement_optional, def_val
+ def store short, long, help, type, def_val=nil
+ store_full short, long, help, FFI::Pointer::NULL, :ecore_getopt_desc_arg_requirement_yes, type, def_val
end
- def store_def_type type, short, long, help, def_val
- store_def short, long, help, ('ecore_getopt_type_'+type.to_s).to_sym, [ (type.to_s+'v').to_sym, def_val ]
+ def store_meta short, long, help, meta, type, def_val=nil
+ store_full short, long, help, meta, :ecore_getopt_desc_arg_requirement_yes, type, def_val
end
- def store_full_type type, short, long, help, meta, arg_req, def_val
- store_full short, long, help, meta, ('ecore_getopt_type_'+type.to_s).to_sym, arg_req, [ (type.to_s+'v').to_sym, def_val ]
+ def store_def short, long, help, type, def_val
+ store_full short, long, help, FFI::Pointer::NULL, :ecore_getopt_desc_arg_requirement_optional, type, def_val
end
- def store_const short, long, help, value
- self << [ short, long, help, FFI::Pointer::NULL, :ecore_getopt_action_store_const, [:store_const, value] ]
+ def store_const short, long, help, def_val, value
+ set_value short, :int, def_val
+ set_option [ short, long, help, FFI::Pointer::NULL, :ecore_getopt_action_store_const, [:store_const, value] ]
end
def store_true short, long, help
- self << [ short, long, help, FFI::Pointer::NULL, :ecore_getopt_action_store_true, [:dummy,FFI::MemoryPointer::NULL] ]
+ set_value short, :uchar, 0
+ set_option [ short, long, help, FFI::Pointer::NULL, :ecore_getopt_action_store_true, [:dummy,FFI::MemoryPointer::NULL] ]
end
def store_false short, long, help
- self << [ short, long, help, FFI::Pointer::NULL, :ecore_getopt_action_store_false, [:dummy,FFI::MemoryPointer::NULL] ]
- end
- def choice short, long, help, choices
- ptr = FFI::MemoryPointer.new(:pointer, choices.length+1)
- choices.each_with_index do |s, i|
- ptr[i].put_pointer 0, p_from_string(s)
+ set_value short, :uchar, 1
+ set_option [ short, long, help, FFI::Pointer::NULL, :ecore_getopt_action_store_false, [:dummy,FFI::MemoryPointer::NULL] ]
+ end
+ def count short, long, help, def_val
+ set_value short, :int, def_val
+ set_option [ short, long, help, FFI::Pointer::NULL, :ecore_getopt_action_count, [:dummy,FFI::Pointer::NULL] ]
+ end
+ def append_meta short, long, help, meta, sub_type, def_val=nil
+ if def_val.nil?
+ p = FFI::Pointer::NULL
+ else
+ require 'efl/eina_list'
+ p = Efl::EinaList::REinaList.from_a def_val, sub_type
end
- ptr[choices.length].put_pointer 0, FFI::Pointer::NULL
- self << [ short, long, help, FFI::Pointer::NULL, :ecore_getopt_action_choice, [:choices,ptr] ]
+ set_value short, :list, [p,sub_type]
+ set_option [ short, long, help, meta, :ecore_getopt_action_append, [:append,@types[sub_type][0]] ]
+ end
+ def append short, long, help, sub_type, def_val=nil
+ append_meta short, long, help, FFI::Pointer::NULL, sub_type, def_val
end
- def choice_metavar short, long, help, meta, choices
- ptr = FFI::MemoryPointer.new(:pointer, choices.length+1)
+ def choice_meta short, long, help, meta, choices
+ p = FFI::MemoryPointer.new(:pointer, choices.length+1)
choices.each_with_index do |s, i|
- ptr[i].put_pointer 0, p_from_string(s)
+ p[i].put_pointer 0, p_from_string(s)
end
- ptr[choices.length].put_pointer 0, FFI::Pointer::NULL
- self << [ short, long, help, meta, :ecore_getopt_action_choice, [:choices,ptr] ]
- end
- def append short, long, help, sub_type
- self << [ short, long, help, FFI::Pointer::NULL, :ecore_getopt_action_append, [:append,sub_type] ]
- end
- def append_metavar short, long, help, meta, sub_type
- self << [ short, long, help, meta, :ecore_getopt_action_append, [:append,sub_type] ]
+ p[choices.length].put_pointer 0, FFI::Pointer::NULL
+ set_value short, :choice
+ set_option [ short, long, help, meta, :ecore_getopt_action_choice, [:choices,p] ]
end
- def count short, long, help
- self << [ short, long, help, FFI::Pointer::NULL, :ecore_getopt_action_count, [:dummy,FFI::Pointer::NULL] ]
+ def choice short, long, help, choices
+ choice_meta short, long, help, FFI::Pointer::NULL, choices
end
- def callback_full short, long, help, meta, cb, data, arg_req, def_val
- self << [ short, long, help, meta, :ecore_getopt_action_callback, [:callback, [cb, data, arg_req, def_val] ] ]
+ def callback_full short, long, help, meta, cb, data, arg_req, type, def_val
+ pt, ptr = set_value short, type, def_val
+ arg_req = ( arg_req ? :ecore_getopt_desc_arg_requirement_yes : :ecore_getopt_desc_arg_requirement_no )
+ set_option [ short, long, help, meta, :ecore_getopt_action_callback, [:callback, [cb, data, arg_req, ptr ] ] ]
end
def callback_noargs short, long, help, cb, data=nil
- callback_full short, long, help, FFI::Pointer::NULL, cb, data, :ecore_getopt_desc_arg_requirement_no, FFI::Pointer::NULL
- end
- def callback_args short, long, help, meta, cb, data=nil
- callback_full short, long, help, meta, cb, data, :ecore_getopt_desc_arg_requirement_yes, FFI::Pointer::NULL
- end
- def help short, long
- self << [ short, long, 'show this message.', FFI::Pointer::NULL, :ecore_getopt_action_help, [:dummy,FFI::Pointer::NULL] ]
+ callback_full short, long, help, FFI::Pointer::NULL, cb, data, false, :uchar, 0
end
- def version short, long
- self << [ short, long, 'show program version.', FFI::Pointer::NULL, :ecore_getopt_action_version, [:dummy,FFI::Pointer::NULL] ]
+ def callback_args short, long, help, meta, cb, data, type, def_val
+ callback_full short, long, help, meta, cb, data, true, type, def_val
end
- def copyright short, long
- self << [ short, long, 'show copyright.', FFI::Pointer::NULL, :ecore_getopt_action_copyright, [:dummy,FFI::Pointer::NULL] ]
- end
- def license short, long
- self << [ short, long, 'show license.', FFI::Pointer::NULL, :ecore_getopt_action_license, [:dummy,FFI::Pointer::NULL] ]
- end
-# def sentinel
-# self << [ 0, FFI::Pointer::NULL, FFI::Pointer::NULL, FFI::Pointer::NULL, 0, {:dummy=>FFI::Pointer::NULL} ]
-# end
#
def debug
r = ''
- r << "#{self.class} : #{@ecore_getopt.to_ptr}\n"
+ r << "#{self.class} : #{@ecore_getopt_st.to_ptr}\n"
[:prog,:usage,:version,:copyright,:license,:description].each do |sym|
- r<< " #{sym.to_s} : #{@ecore_getopt[sym]==FFI::Pointer::NULL ? 'NULL' : @ecore_getopt[sym].read_string}\n"
+ r<< " #{sym.to_s} : #{@ecore_getopt_st[sym]==FFI::Pointer::NULL ? 'NULL' : @ecore_getopt_st[sym].read_string}\n"
end
- r << " strict : #{@ecore_getopt[:strict]}\n"
+ r << " strict : #{@ecore_getopt_st[:strict]}\n"
i=0
+ r << " Descriptions\n"
while true
- d = @ecore_getopt.desc_ptr i
- break if d[:shortname]==0 and d[:longname] == FFI::Pointer::NULL
- r << " desc #{d.to_ptr}\n"
- r << " short: #{d[:shortname].chr}\n" unless d[:shortname]==0
- r << " long: #{d[:longname].read_string}\n" unless d[:longname]==FFI::Pointer::NULL
- r << " help: #{d[:help].read_string}\n" unless d[:help]==FFI::Pointer::NULL
+ st = @ecore_getopt_st.desc_ptr i
+ break if st[:shortname]==0 and st[:longname] == FFI::Pointer::NULL
+ r << " desc #{st.to_ptr}\n"
+ r << " short: #{st[:shortname].chr}\n" unless st[:shortname]==0
+ r << " long: #{st[:longname].read_string}\n" unless st[:longname]==FFI::Pointer::NULL
+ r << " help: #{st[:help].read_string}\n" unless st[:help]==FFI::Pointer::NULL
i+=1
end
+ r << " Values\n"
+ @values_order.each_with_index do |k,i|
+ st = @ecore_values_st.value_ptr i
+ vtype, vpointer = @values[k]
+ etype, vfield, pfield = @types[vtype]
+ r << " value #{st.to_ptr}\n"
+ r << " key: #{k}\n"
+ r << " type: #{vtype}\n"
+ r << " value: #{self[k]}\n"
+ end
r
end
end
diff --git a/spec/ecore_getopt_spec.rb b/spec/ecore_getopt_spec.rb
index a3c3a30..3eb38b6 100644
--- a/spec/ecore_getopt_spec.rb
+++ b/spec/ecore_getopt_spec.rb
@@ -8,252 +8,209 @@ require 'efl/ecore_getopt'
#
describe Efl::EcoreGetopt do
#
- after(:all) do
+ after(:all) {
Efl::Ecore.shutdown
- end
- before(:all) do
+ }
+ before(:all) {
Efl::Ecore.init
#
+ }
+ before(:each) do
+ #
@p = Efl::EcoreGetopt::REcoreGetopt.new :prog =>"Prog", :usage => "Usage", :version => "0.0.0", :copyright => "less", :license => "MIT", :description => "description", :strict => 1
- @callback = Proc.new do |parser, desc, string, data, value|
+ #
+ @callback = Proc.new do |parser, desc, string, data, storage|
parser.address.should == @p.to_ptr.address
- string.should == "my_data"
+ Efl::Native::EcoreGetoptDesc.new(desc)[:shortname].chr.should == 'b'
+ string.should == "user_arg"
data.read_string.should == "cb_data"
- value.read_pointer.read_int.should == 99
+ storage.read_pointer.read_int == 69
+ storage.read_pointer.write_int 666
true
end
#
- @values = {
- :license => FFI::MemoryPointer.new(:uchar),
- :copyright => FFI::MemoryPointer.new(:uchar),
- :version => FFI::MemoryPointer.new(:uchar),
- :help => FFI::MemoryPointer.new(:uchar),
- :engines => FFI::MemoryPointer.new(:uchar),
- :int => FFI::MemoryPointer.new(:int),
- :double => FFI::MemoryPointer.new(:double),
- :short => FFI::MemoryPointer.new(:short),
- :long => FFI::MemoryPointer.new(:long),
- :const => FFI::MemoryPointer.new(:int),
- :true => FFI::MemoryPointer.new(:uchar),
- :false => FFI::MemoryPointer.new(:uchar),
- :choice => FFI::MemoryPointer.new(:pointer),
- :append => FFI::MemoryPointer.new(:pointer),
- :count => FFI::MemoryPointer.new(:int),
- :callback => FFI::MemoryPointer.new(:int),
- }
- @meta1 = FFI::MemoryPointer.from_string "My pretty"
- @meta2 = FFI::MemoryPointer.from_string "My precious"
+ @meta1 = FFI::MemoryPointer.from_string "My pretty meta"
+ @meta2 = FFI::MemoryPointer.from_string "My precious meta"
@cb_data = FFI::MemoryPointer.from_string "cb_data"
#
- @p.license 'L', 'license'
- @p.value :boolp, @values[:license]
- @p.copyright 'C', 'copyright'
- @p.value :boolp, @values[:copyright]
+ # license and copyright share the same flag named quit
+ @p.license 'L', 'license', 'quit'
+ @p.copyright 'C', 'copyright', 'quit'
@p.version 'V', 'version'
- @p.value :boolp, @values[:version]
@p.help 'H', 'help'
- @p.value :boolp, @values[:help]
- # FIXME debug callback : ecore_getopt_callback_ecore_evas_list_engines
-# @p.callback_noargs 'E', 'list-engines', 'list ecore-evas available engines', @engines_cb, FFI::Pointer::NULL
- @p.callback_noargs 'E', 'list-engines', 'list ecore-evas available engines', Efl::Native.method(:ecore_getopt_callback_ecore_evas_list_engines), FFI::Pointer::NULL
- @p.value :boolp, @values[:engines]
- @p.store_type :int, 'i', 'int', 'store an integer'
- @p.value :intp, @values[:int]
- @p.store_meta_type :double, 'd', 'double', 'store an double+meta', @meta1
- @p.value :doublep, @values[:double]
- @p.store_def_type :short, 's', 'short', 'store an short+default', 6
- @p.value :shortp, @values[:short]
- @p.store_full_type :long, 'l', 'long', 'store a long+full', @meta2, :ecore_getopt_desc_arg_requirement_yes, 666
- @p.value :longp, @values[:long]
- @p.store_const 'c', 'const', 'store a constant', 123456
- @p.value :intp, @values[:const]
+ @p.store 'i', 'int', 'store an integer', :int, 2
+ @p.store_meta 'd', 'double', 'store an double+meta', @meta1, :double, 3.1415926
+ @p.store_def 's', 'short', 'store an short+default', :short, 9
+ @p.store_full 'l', 'long', 'store a long+full', @meta2, :ecore_getopt_desc_arg_requirement_yes, :long, 666
+ @p.store_const 'c', 'const', 'store a constant', -666, 123456
@p.store_true 't', 'true', 'store true'
- @p.value :boolp, @values[:false]
@p.store_false 'f', 'false', 'store false'
- @p.value :boolp, @values[:true]
+ @p.count 'k', 'count', 'store count', 664
+ @p.append 'a', 'append', 'store append', :int, [1,2,3]
@p.choice 'm', 'many', 'store choice', ['ch1','ch2','ch3']
- @p.value :strp, @values[:choice]
- @p.append 'a', 'append', 'store append', :ecore_getopt_type_int
- @p.value :listp, @values[:append]
- @p.count 'k', 'count', 'store count'
- @p.value :intp, @values[:count]
- @p.callback_args 'b', 'callback', 'callback full', @meta1, @callback, @cb_data
- @p.value :intp, @values[:callback]
+ @p.callback_noargs 'E', 'list-engines', 'list ecore-evas available engines', Efl::Native.method(:ecore_getopt_callback_ecore_evas_list_engines)
+ @p.callback_args 'b', 'callback', 'callback full', @meta1, @callback, @cb_data, :int, 69
@p.create
-# puts @p.debug
#
end
- before(:each) do
- [ :license, :copyright, :version, :help, :engines ].each do |sym|
- @values[sym].write_char 0
- end
- @values[:int].write_int 0
- @values[:double].write_double 3.1415926
- @values[:short].write_short 9
- @values[:long].write_long 666
- @values[:const].write_int -666
- @values[:true].write_uchar 1
- @values[:false].write_uchar 0
- @values[:choice].write_pointer FFI::Pointer::NULL
- @values[:append].write_pointer FFI::Pointer::NULL
- @values[:count].write_int 664
- @values[:callback].write_int 99
- end
#
describe "license copyright version help" do
+# it "DEBUG" do
+# puts @p.debug
+# end
it "should handle -L" do
args = @p.parse ["My lovely prog name","-L"]
- @values[:license].read_char.should == 1
+ @p['quit'].should == 1
end
it "should handle --license" do
args = @p.parse ["My lovely prog name","--license"]
- @values[:license].read_char.should == 1
+ @p['quit'].should == 1
end
it "should handle -C" do
args = @p.parse ["progname","-C"]
- @values[:copyright].read_char.should == 1
+ @p['quit'].should == 1
end
it "should handle --copyright" do
args = @p.parse ["My lovely prog name","--copyright"]
- @values[:copyright].read_char.should == 1
+ @p['quit'].should == 1
end
it "should handle -V" do
args = @p.parse ["My lovely prog name","-V"]
- @values[:version].read_char.should == 1
+ @p['V'].should == 1
end
it "should handle --version" do
args = @p.parse ["progname","--version"]
- @values[:version].read_char.should == 1
+ @p['V'].should == 1
end
it "should handle -H" do
args = @p.parse ["My lovely prog name","-H"]
- @values[:help].read_char.should == 1
+ @p['H'].should == 1
end
it "should handle --help" do
args = @p.parse ["progname","--help"]
- @values[:help].read_char.should == 1
- end
- it "should handle -E" do
- args = @p.parse ["My lovely prog name","-E"]
- @values[:engines].read_char.should == 1
- end
- it "should handle --list-engines" do
- args = @p.parse ["My lovely prog name","--list-engines"]
- @values[:engines].read_char.should == 1
+ @p['H'].should == 1
end
end
describe "simple short options" do
it "should handle -i" do
- @values[:int].read_int.should == 0
+ @p['i'].should == 2
args = @p.parse ["progname","-i 666"]
- @values[:int].read_int.should == 666
+ @p['i'].should == 666
end
it "should handle -d" do
- @values[:double].read_double.should == 3.1415926
+ @p['d'].should == 3.1415926
args = @p.parse ["progname","-d 6.66"]
- @values[:double].read_double.should == 6.66
+ @p['d'].should == 6.66
end
it "should handle -s" do
- @values[:short].read_short.should == 9
+ @p['s'].should == 9
args = @p.parse ["progname","-s 125"]
- @values[:short].read_short.should == 125
+ @p['s'].should == 125
end
it "should handle -l" do
- @values[:long].read_long.should == 666
+ @p['l'].should == 666
args = @p.parse ["progname","-l 69"]
- @values[:long].read_long.should == 69
+ @p['l'].should == 69
end
it "should handle -c" do
- @values[:const].read_int.should == -666
+ @p['c'].should == -666
args = @p.parse ["progname","-c"]
- @values[:const].read_int.should == 123456
+ @p['c'].should == 123456
end
it "should handle -t" do
- @values[:false].read_uchar.should == 0
+ @p['t'].should == 0
args = @p.parse ["progname","-t"]
- @values[:false].read_uchar.should == 1
+ @p['t'].should == 1
end
it "should handle -f" do
- @values[:true].read_uchar.should == 1
+ @p['f'].should == 1
args = @p.parse ["progname","-f"]
- @values[:true].read_uchar.should == 0
+ @p['f'].should == 0
end
- it "should handle -m" do
- @values[:choice].read_pointer.should == FFI::Pointer::NULL
- args = @p.parse ["progname","-mch2"]
- @values[:choice].read_pointer.read_string.should == "ch2"
+ it "should handle -k" do
+ @p['k'].should == 664
+ args = @p.parse ["progname","-kk"]
+ @p['k'].should == 666
end
it "should handle -a" do
- @values[:append].read_pointer.should == FFI::Pointer::NULL
+ @p['a'].should == [1,2,3]
args = @p.parse ["progname","-a10", "-a20"]
- l = Efl::EinaList::REinaList.new(@values[:append].read_pointer).to_a
- l[0].read_int.should==10
- l[1].read_int.should==20
+ @p['a'].should == [1,2,3,10,20]
end
- it "should handle -k" do
- @values[:count].read_int.should == 664
- args = @p.parse ["progname","-kk"]
- @values[:count].read_int.should == 666
+ it "should handle -m" do
+ @p['m'].should == nil
+ args = @p.parse ["progname","-mch2"]
+ @p['m'].should == "ch2"
+ end
+ it "should handle -E" do
+ args = @p.parse ["My lovely prog name","-E"]
+ @p['E'].should == 1
end
it "should handle -b" do
- args = @p.parse ["progname","-bmy_data"]
+ @p['b'].should == 69
+ args = @p.parse ["progname","-buser_arg"]
+ @p['b'].should == 666
end
end
describe "simple long options" do
it "should handle --int" do
- @values[:int].read_int.should == 0
+ @p['i'].should == 2
args = @p.parse ["progname","--int=666"]
- @values[:int].read_int.should == 666
+ @p['i'].should == 666
end
it "should handle --double" do
- @values[:double].read_double.should == 3.1415926
+ @p['d'].should == 3.1415926
args = @p.parse ["progname","--double=6.66"]
- @values[:double].read_double.should == 6.66
+ @p['d'].should == 6.66
end
it "should handle --short" do
- @values[:short].read_short.should == 9
+ @p['s'].should == 9
args = @p.parse ["progname","--short=125"]
- @values[:short].read_short.should == 125
+ @p['s'].should == 125
end
it "should handle --long" do
- @values[:long].read_long.should == 666
+ @p['l'].should == 666
args = @p.parse ["progname","--long=69"]
- @values[:long].read_long.should == 69
+ @p['l'].should == 69
end
it "should handle --const" do
- @values[:const].read_int.should == -666
+ @p['c'].should == -666
args = @p.parse ["progname","--const"]
- @values[:const].read_int.should == 123456
+ @p['c'].should == 123456
end
it "should handle --true" do
- @values[:false].read_uchar.should == 0
+ @p['t'].should == 0
args = @p.parse ["progname","--true"]
- @values[:false].read_uchar.should == 1
+ @p['t'].should == 1
end
it "should handle --false" do
- @values[:true].read_uchar.should == 1
+ @p['f'].should == 1
args = @p.parse ["progname","--false"]
- @values[:true].read_uchar.should == 0
+ @p['f'].should == 0
end
- it "should handle --many" do
- @values[:choice].read_pointer.should == FFI::Pointer::NULL
- args = @p.parse ["progname","--many=ch3"]
- @values[:choice].read_pointer.read_string.should == "ch3"
+ it "should handle --count" do
+ @p['k'].should == 664
+ args = @p.parse ["progname","--count","--count"]
+ @p['k'].should == 666
end
- it "should handle -append" do
- @values[:append].read_pointer.should == FFI::Pointer::NULL
+ it "should handle -a" do
+ @p['a'].should == [1,2,3]
args = @p.parse ["progname","--append=10", "--append=20"]
- l = Efl::EinaList::REinaList.new(@values[:append].read_pointer).to_a
- l[0].read_int.should==10
- l[1].read_int.should==20
+ @p['a'].should == [1,2,3,10,20]
end
- it "should handle --count" do
- @values[:count].read_int.should == 664
- args = @p.parse ["progname","--count","--count"]
- @values[:count].read_int.should == 666
+ it "should handle --many" do
+ @p['m'].should == nil
+ args = @p.parse ["progname","--many=ch3"]
+ @p['m'].should == "ch3"
+ end
+ it "should handle --list-engines" do
+ args = @p.parse ["My lovely prog name","--list-engines"]
+ @p['E'].should == 1
end
it "should handle --callback" do
- args = @p.parse ["progname","--callback=my_data"]
+ @p['b'].should == 69
+ args = @p.parse ["progname","--callback=user_arg"]
+ @p['b'].should == 666
end
end
end