Class: Genprovider::Testcase
- Inherits:
-
Object
- Object
- Genprovider::Testcase
- Defined in:
- lib/genprovider/testcase.rb
Instance Method Summary collapse
-
#initialize(c, namespace, out) ⇒ Testcase
constructor
A new instance of Testcase.
-
#rubytype(type) ⇒ Object
return Ruby type equivalent.
Constructor Details
#initialize(c, namespace, out) ⇒ Testcase
Returns a new instance of Testcase.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/genprovider/testcase.rb', line 31 def initialize c, namespace, out out.comment.comment "Testcase for #{namespace}:#{c.name}" out.comment.comment "Generated by 'genprovider' for use with cmpi-bindings-ruby" out.puts "require 'rubygems'" out.puts "require 'sfcc'" out.puts "require 'test/unit'" out.puts out.puts "class Test_#{c.name} < Test::Unit::TestCase" out.inc out.def "setup" out.puts "@client = Sfcc::Cim::Client.connect(:uri => 'http://localhost:12345', :verify => false)" out.puts "@op = Sfcc::Cim::ObjectPath.new('#{namespace}', '#{c.name}')" out.end out.puts out.def "test_registered" out.puts "cimclass = @client.get_class(@op)" out.puts "assert cimclass" out.end # test_registered out.puts out.def "test_instance_names" out.puts "names = @client.instance_names(@op)" out.puts "assert names.size > 0" out.puts "names.each do |ref|" out.inc out.puts "ref.namespace = @op.namespace" out.puts "instance = @client.get_instance ref" out.puts "assert instance" out.puts # # Properties # c.features.each do |p| next unless p.property? element = "instance.#{p.name}" out.puts "assert #{element}" if p.type.array? out.puts "assert_kind_of Array, #{element} # #{p.type}" out.puts "tmp = #{element}[0]" element = "tmp" end rtype = rubytype p.type raise "Unsupported type #{p.type} [#{rtype.class}]" if rtype.nil? out.puts "if #{element}" out.inc if rtype.empty? out.puts "assert #{element}.is_a?(TrueClass) || #{element}.is_a?(FalseClass)" else out.puts "assert_kind_of #{rubytype p.type}, #{element} # #{p.type}" end out.end end out.end # names.each out.end # test_instance_names # # References # out.puts c.features.each do |r| next unless r.reference? end # # Methods # out.puts c.features.each do |m| next unless m.method? out.puts out.def "test_method_#{m.name}" if m.static? # class-level method else # instance level method out.puts "@client.instances(@op).each do |inst|" out.inc m.parameters.each do |p| desc = p.description out.comment desc if desc if p.out? out.puts "p_out_#{p.name} = {} # #{p.type}" else out.puts "p_in_#{p.name} = nil # #{p.type}" end end s = "res = inst.#{m.name}(" first = true m.parameters.each do |p| if first first = false else s << ", " end if p.includes? :out s << "p_out_#{p.name}" else s << "p_in_#{p.name}" end end s << ")" out.puts s out.puts "assert_kind_of #{rubytype m.type}, res" out.end end out.end # test_method_<name> end out.puts out.end # class end |
Instance Method Details
#rubytype(type) ⇒ Object
return Ruby type equivalent
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/genprovider/testcase.rb', line 8 def rubytype type case type.to_sym when :boolean then return "" when :string then return "String" when :char16 then return "Integer" when :uint8 then return "Integer" when :uint16 then return "Integer" when :uint32 then return "Integer" when :uint64 then return "Integer" when :sint8 then return "Integer" when :sint16 then return "Integer" when :sint32 then return "Integer" when :sint64 then return "Integer" when :real32 then return "Float" when :real64 then return "Float" when :dateTime then return "Time" when :reference then return "Sfcc::Cim::ObjectPath" when :class then return "Sfcc::Cim::Class" else STDERR.puts "Unhandled type #{type}" end end |