PageRenderTime 63ms CodeModel.GetById 48ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Ruby | 153 lines | 62 code | 22 blank | 69 comment | 0 complexity | 53328cc290059006a13ebd9ab3058cda MD5 | raw file
  1#!/usr/bin/env ruby
  2#
  3# Put description here
  4#
  5# 
  6# 
  7# 
  8#
  9
 10require 'swig_assert'
 11
 12require 'default_constructor'
 13
 14include Default_constructor
 15
 16# Ruby 1.6 raises NameError if you try to call Class.new where no constructor
 17# is defined; Ruby 1.7 changed this to NoMethodError
 18
 19NoConstructorError = Kernel.const_defined?("NoMethodError") ? NoMethodError : NameError
 20
 21# This should be no problem
 22a = A.new
 23
 24# Nor should this
 25aa = AA.new
 26
 27# The default constructor for B is private, so this should raise an exception
 28begin
 29  b = B.new
 30rescue ArgumentError
 31  # pass
 32rescue TypeError
 33  # In Ruby 1.8 the exception raised is:
 34  # TypeError: allocator undefined for Default_constructor::BB
 35	exceptionRaised = true
 36end
 37
 38# The two-argument constructor for B should work
 39b = B.new(3, 4)
 40
 41# BB shouldn't inherit B's default constructor, so this should raise an exception
 42begin
 43  bb = BB.new
 44  puts "Whoa. new BB created."
 45rescue NoConstructorError
 46  # pass
 47rescue TypeError
 48  # In Ruby 1.8 the exception raised is:
 49  # TypeError: allocator undefined for Default_constructor::BB
 50	exceptionRaised = true
 51end
 52
 53# C's constructor is protected, so this should raise an exception
 54begin
 55  c = C.new
 56  print "Whoa. new C created."
 57rescue NoConstructorError
 58  # pass
 59rescue TypeError
 60  # In Ruby 1.8 the exception raised is:
 61  # TypeError: allocator undefined for Default_constructor::C
 62  # pass
 63rescue TypeError
 64  # In Ruby 1.8 the exception raised is:
 65  # TypeError: allocator undefined for Default_constructor::C
 66  # pass
 67end
 68
 69# CC gets a default constructor, so no problem here
 70cc = CC.new
 71
 72# D's constructor is private, so this should fail
 73begin
 74  d = D.new
 75  puts "Whoa. new D created"
 76rescue NoConstructorError
 77  # pass
 78rescue TypeError
 79  # In Ruby 1.8 the exception raised is:
 80  # TypeError: allocator undefined for Default_constructor::D
 81  # pass
 82end
 83
 84# DD shouldn't get a default constructor, so this should fail
 85begin
 86  dd = DD.new
 87  puts "Whoa. new DD created"
 88rescue NoConstructorError
 89  # pass
 90rescue TypeError
 91  # In Ruby 1.8 the exception raised is:
 92  # TypeError: allocator undefined for Default_constructor::DD
 93  # pass
 94rescue TypeError
 95  # In Ruby 1.8 the exception raised is:
 96  # TypeError: allocator undefined for Default_constructor::D
 97  # pass
 98rescue TypeError
 99  # In Ruby 1.8 the exception raised is:
100  # TypeError: allocator undefined for Default_constructor::DD
101  # pass
102end
103
104# AD shouldn't get a default constructor, so this should fail
105begin
106  ad = AD.new
107  puts "Whoa. new AD created"
108rescue NoConstructorError
109  # pass
110rescue TypeError
111  # In Ruby 1.8 the exception raised is:
112  # TypeError: allocator undefined for Default_constructor::AD
113  # pass
114rescue TypeError
115  # In Ruby 1.8 the exception raised is:
116  # TypeError: allocator undefined for Default_constructor::AD
117  # pass
118end
119
120# Both of the arguments to E's constructor have default values,
121# so this should be fine.
122e = E.new
123
124# EE should get a default constructor
125ee = EE.new
126
127# EB should not get a default constructor (because B doesn't have one)
128begin
129  eb = EB.new
130  puts "Whoa. new EB created"
131rescue NoConstructorError
132  # pass
133rescue TypeError
134  # In Ruby 1.8 the exception raised is:
135  # TypeError: allocator undefined for Default_constructor::EB
136  # pass
137rescue TypeError
138  # In Ruby 1.8 the exception raised is:
139  # TypeError: allocator undefined for Default_constructor::EB
140  # pass
141end
142
143# This should work fine
144f = F.new
145
146# This should work fine
147ff = FFF.new
148
149# This should work fine
150g = G.new
151
152# This should work fine
153gg = GG.new