PageRenderTime 27ms CodeModel.GetById 1ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/ruby/li_std_string_runme.rb

#
Ruby | 144 lines | 94 code | 30 blank | 20 comment | 29 complexity | 097769976e40afdf3bfed1c4a689674f MD5 | raw file
  1#!/usr/bin/env ruby
  2#
  3# Put description here
  4#
  5# 
  6# 
  7# 
  8#
  9
 10require 'swig_assert'
 11
 12require 'li_std_string'
 13
 14include Li_std_string
 15
 16# Checking expected use of %typemap(in) std::string {}
 17test_value("Fee")
 18
 19# Checking expected result of %typemap(out) std::string {}
 20raise RuntimeError unless test_value("Fi") == "Fi"
 21
 22# Verify type-checking for %typemap(in) std::string {}
 23exceptionRaised = false
 24begin
 25  test_value(0)
 26rescue TypeError
 27  exceptionRaised = true
 28ensure
 29  raise RuntimeError unless exceptionRaised
 30end
 31
 32# Checking expected use of %typemap(in) const std::string & {}
 33test_const_reference("Fo")
 34
 35# Checking expected result of %typemap(out) const std::string& {}
 36raise RuntimeError unless test_const_reference("Fum") == "Fum"
 37
 38# Verify type-checking for %typemap(in) const std::string & {}
 39exceptionRaised = false
 40begin
 41  test_const_reference(0)
 42rescue TypeError
 43  exceptionRaised = true
 44ensure
 45  raise RuntimeError unless exceptionRaised
 46end
 47
 48#
 49# Input and output typemaps for pointers and non-const references to
 50# std::string are *not* supported; the following tests confirm
 51# that none of these cases are slipping through.
 52#
 53
 54exceptionRaised = false
 55begin
 56  test_pointer("foo")
 57rescue TypeError
 58  exceptionRaised = true
 59ensure
 60  raise RuntimeError unless exceptionRaised
 61end
 62
 63result = test_pointer_out()
 64raise RuntimeError if result.is_a? String
 65
 66exceptionRaised = false
 67begin
 68  test_const_pointer("bar")
 69rescue TypeError
 70  exceptionRaised = true
 71ensure
 72  raise RuntimeError unless exceptionRaised
 73end
 74
 75result = test_const_pointer_out()
 76raise RuntimeError if result.is_a? String
 77
 78exceptionRaised = false
 79begin
 80  test_reference("foo")
 81rescue TypeError
 82  exceptionRaised = true
 83ensure
 84  raise RuntimeError unless exceptionRaised
 85end
 86
 87result = test_reference_out()
 88raise RuntimeError if result.is_a? String
 89
 90
 91# Member Strings
 92myStructure = Structure.new
 93if (myStructure.MemberString2 != "member string 2")
 94  raise RuntimeError
 95end
 96s = "Hello"
 97myStructure.MemberString2 = s
 98if (myStructure.MemberString2 != s)
 99  raise RuntimeError
100end
101if (myStructure.ConstMemberString != "const member string")
102  raise RuntimeError 
103end
104
105
106if (Structure.StaticMemberString2 != "static member string 2")
107  raise RuntimeError
108end
109Structure.StaticMemberString2 = s
110if (Structure.StaticMemberString2 != s)
111  raise RuntimeError
112end
113if (Structure.ConstStaticMemberString != "const static member string")
114  raise RuntimeError
115end
116
117
118if (test_reference_input("hello") != "hello")
119  raise RuntimeError
120end
121s = test_reference_inout("hello")
122if (s != "hellohello")
123  raise RuntimeError
124end
125
126
127if (stdstring_empty() != "")
128  raise RuntimeError
129end
130
131if (c_empty() != "") 
132  raise RuntimeError
133end
134
135
136if (c_null() != nil) 
137  raise RuntimeError
138end
139
140
141if (get_null(c_null()) != nil) 
142  raise RuntimeError
143end
144