From 350eff36877acfe21c60a2e7bf8e8c2871733b84 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 30 Sep 2015 07:53:19 +0100 Subject: [PATCH] Director smartptr testing - Enhance Java and C# test - Add Ruby test --- .../csharp/director_smartptr_runme.cs | 34 ++++++++---- Examples/test-suite/director_smartptr.i | 8 ++- .../java/director_smartptr_runme.java | 36 ++++++++----- .../ruby/director_smartptr_runme.rb | 54 +++++++++++++++++++ 4 files changed, 107 insertions(+), 25 deletions(-) create mode 100644 Examples/test-suite/ruby/director_smartptr_runme.rb diff --git a/Examples/test-suite/csharp/director_smartptr_runme.cs b/Examples/test-suite/csharp/director_smartptr_runme.cs index ad33c4d3420..559dff7a0c7 100644 --- a/Examples/test-suite/csharp/director_smartptr_runme.cs +++ b/Examples/test-suite/csharp/director_smartptr_runme.cs @@ -1,13 +1,13 @@ using director_smartptrNamespace; +using System; public class runme { - private class director_smartptr_MyBarFoo : Foo { public override string ping() { - return "director_smartptr_MyBarFoo.ping();"; + return "director_smartptr_MyBarFoo.ping()"; } public override string pong() @@ -15,27 +15,39 @@ public override string pong() return "director_smartptr_MyBarFoo.pong();" + ping(); } - public override string fooBar(FooBar fooBar) + public override string upcall(FooBar fooBarPtr) { - return fooBar.FooBarDo(); + return "override;" + fooBarPtr.FooBarDo(); } public override Foo makeFoo() { return new Foo(); } + } - public override FooBar makeFooBar() - { - return new FooBar(); - } + private static void check(string got, string expected) + { + if (got != expected) + throw new ApplicationException("Failed, got: " + got + " expected: " + expected); } static void Main() { - director_smartptr_MyBarFoo myBarFoo = - new director_smartptr_MyBarFoo(); + FooBar fooBar = new FooBar(); + + Foo myBarFoo = new director_smartptr_MyBarFoo(); + check(myBarFoo.ping(), "director_smartptr_MyBarFoo.ping()"); + check(Foo.callPong(myBarFoo), "director_smartptr_MyBarFoo.pong();director_smartptr_MyBarFoo.ping()"); + check(Foo.callUpcall(myBarFoo, fooBar), "override;Bar::Foo2::Foo2Bar()"); + + Foo myFoo = myBarFoo.makeFoo(); + check(myFoo.pong(), "Foo::pong();Foo::ping()"); + check(Foo.callPong(myFoo), "Foo::pong();Foo::ping()"); + check(myFoo.upcall(new FooBar()), "Bar::Foo2::Foo2Bar()"); - myBarFoo.ping(); + Foo myFoo2 = new Foo().makeFoo(); + check(myFoo2.pong(), "Foo::pong();Foo::ping()"); + check(Foo.callPong(myFoo2), "Foo::pong();Foo::ping()"); } } diff --git a/Examples/test-suite/director_smartptr.i b/Examples/test-suite/director_smartptr.i index bb44baaa19e..9d0be80f0fa 100644 --- a/Examples/test-suite/director_smartptr.i +++ b/Examples/test-suite/director_smartptr.i @@ -23,10 +23,12 @@ public: virtual ~Foo() {} virtual std::string ping() { return "Foo::ping()"; } virtual std::string pong() { return "Foo::pong();" + ping(); } - virtual std::string fooBar(FooBar* fooBarPtr) { return fooBarPtr->FooBarDo(); } + virtual std::string upcall(FooBar* fooBarPtr) { return fooBarPtr->FooBarDo(); } virtual Foo makeFoo() { return Foo(); } virtual FooBar makeFooBar() { return FooBar(); } + static std::string callPong(Foo &foo) { return foo.pong(); } + static std::string callUpcall(Foo &foo, FooBar* fooBarPtr) { return foo.upcall(fooBarPtr); } static Foo* get_self(Foo *self_) {return self_;} }; @@ -61,10 +63,12 @@ public: virtual ~Foo(); virtual std::string ping(); virtual std::string pong(); - virtual std::string fooBar(FooBar* fooBarPtr); + virtual std::string upcall(FooBar* fooBarPtr); virtual Foo makeFoo(); virtual FooBar makeFooBar(); + static std::string callPong(Foo &foo); + static std::string callUpcall(Foo &foo, FooBar* fooBarPtr); static Foo* get_self(Foo *self_); }; diff --git a/Examples/test-suite/java/director_smartptr_runme.java b/Examples/test-suite/java/director_smartptr_runme.java index 8c4ddc5d3af..710ece7107b 100644 --- a/Examples/test-suite/java/director_smartptr_runme.java +++ b/Examples/test-suite/java/director_smartptr_runme.java @@ -12,18 +12,35 @@ public class director_smartptr_runme { } } - public static void main(String argv[]) { - director_smartptr_MyBarFoo myBarFoo = - new director_smartptr_MyBarFoo(); + private static void check(String got, String expected) { + if (!got.equals(expected)) + throw new RuntimeException("Failed, got: " + got + " expected: " + expected); } + public static void main(String argv[]) { + director_smartptr.FooBar fooBar = new director_smartptr.FooBar(); + + director_smartptr.Foo myBarFoo = new director_smartptr_MyBarFoo(); + check(myBarFoo.ping(), "director_smartptr_MyBarFoo.ping()"); + check(director_smartptr.Foo.callPong(myBarFoo), "director_smartptr_MyBarFoo.pong();director_smartptr_MyBarFoo.ping()"); + check(director_smartptr.Foo.callUpcall(myBarFoo, fooBar), "override;Bar::Foo2::Foo2Bar()"); + + director_smartptr.Foo myFoo = myBarFoo.makeFoo(); + check(myFoo.pong(), "Foo::pong();Foo::ping()"); + check(director_smartptr.Foo.callPong(myFoo), "Foo::pong();Foo::ping()"); + check(myFoo.upcall(fooBar), "Bar::Foo2::Foo2Bar()"); + + director_smartptr.Foo myFoo2 = new director_smartptr.Foo().makeFoo(); + check(myFoo2.pong(), "Foo::pong();Foo::ping()"); + check(director_smartptr.Foo.callPong(myFoo2), "Foo::pong();Foo::ping()"); + } } class director_smartptr_MyBarFoo extends director_smartptr.Foo { @Override public String ping() { - return "director_smartptr_MyBarFoo.ping();"; + return "director_smartptr_MyBarFoo.ping()"; } @Override @@ -32,17 +49,12 @@ public String pong() { } @Override - public String fooBar(director_smartptr.FooBar fooBar) { - return fooBar.FooBarDo(); + public String upcall(director_smartptr.FooBar fooBarPtr) { + return "override;" + fooBarPtr.FooBarDo(); } @Override public director_smartptr.Foo makeFoo() { return new director_smartptr.Foo(); } - - @Override - public director_smartptr.FooBar makeFooBar() { - return new director_smartptr.FooBar(); - } -} \ No newline at end of file +} diff --git a/Examples/test-suite/ruby/director_smartptr_runme.rb b/Examples/test-suite/ruby/director_smartptr_runme.rb new file mode 100644 index 00000000000..8b4bd3d6d14 --- /dev/null +++ b/Examples/test-suite/ruby/director_smartptr_runme.rb @@ -0,0 +1,54 @@ +#!/usr/bin/env ruby +# +# Put description here +# +# +# +# +# + +require 'director_smartptr' + +include Director_smartptr + +class Director_smartptr_MyBarFoo < Foo + + def ping() + return "director_smartptr_MyBarFoo.ping()" + end + + def pong() + return "director_smartptr_MyBarFoo.pong();" + ping() + end + + def upcall(fooBarPtr) + return "override;" + fooBarPtr.FooBarDo() + end + + def makeFoo() + return Foo.new() + end +end + +def check(got, expected) + if (got != expected) + raise RuntimeError, "Failed, got: #{got} expected: #{expected}" + end +end + +fooBar = Director_smartptr::FooBar.new() + +myBarFoo = Director_smartptr_MyBarFoo.new() +check(myBarFoo.ping(), "director_smartptr_MyBarFoo.ping()") +check(Foo.callPong(myBarFoo), "director_smartptr_MyBarFoo.pong();director_smartptr_MyBarFoo.ping()") +check(Foo.callUpcall(myBarFoo, fooBar), "override;Bar::Foo2::Foo2Bar()") + +myFoo = myBarFoo.makeFoo() +check(myFoo.pong(), "Foo::pong();Foo::ping()") +check(Foo.callPong(myFoo), "Foo::pong();Foo::ping()") +check(myFoo.upcall(FooBar.new()), "Bar::Foo2::Foo2Bar()") + +myFoo2 = Foo.new().makeFoo() +check(myFoo2.pong(), "Foo::pong();Foo::ping()") +check(Foo.callPong(myFoo2), "Foo::pong();Foo::ping()") +check(myFoo2.upcall(FooBar.new()), "Bar::Foo2::Foo2Bar()")