Director smartptr testing

- Enhance Java and C# test
- Add Ruby test
This commit is contained in:
William S Fulton 2015-09-30 07:53:19 +01:00
commit 350eff3687
4 changed files with 107 additions and 25 deletions

View file

@ -1,13 +1,13 @@
using director_smartptrNamespace; using director_smartptrNamespace;
using System;
public class runme public class runme
{ {
private class director_smartptr_MyBarFoo : Foo private class director_smartptr_MyBarFoo : Foo
{ {
public override string ping() public override string ping()
{ {
return "director_smartptr_MyBarFoo.ping();"; return "director_smartptr_MyBarFoo.ping()";
} }
public override string pong() public override string pong()
@ -15,27 +15,39 @@ public class runme
return "director_smartptr_MyBarFoo.pong();" + ping(); 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() public override Foo makeFoo()
{ {
return new Foo(); return new Foo();
} }
}
public override FooBar makeFooBar() private static void check(string got, string expected)
{ {
return new FooBar(); if (got != expected)
} throw new ApplicationException("Failed, got: " + got + " expected: " + expected);
} }
static void Main() static void Main()
{ {
director_smartptr_MyBarFoo myBarFoo = FooBar fooBar = new FooBar();
new director_smartptr_MyBarFoo();
myBarFoo.ping(); 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()");
Foo myFoo2 = new Foo().makeFoo();
check(myFoo2.pong(), "Foo::pong();Foo::ping()");
check(Foo.callPong(myFoo2), "Foo::pong();Foo::ping()");
} }
} }

View file

@ -23,10 +23,12 @@ public:
virtual ~Foo() {} virtual ~Foo() {}
virtual std::string ping() { return "Foo::ping()"; } virtual std::string ping() { return "Foo::ping()"; }
virtual std::string pong() { return "Foo::pong();" + 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 Foo makeFoo() { return Foo(); }
virtual FooBar makeFooBar() { return FooBar(); } 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_;} static Foo* get_self(Foo *self_) {return self_;}
}; };
@ -61,10 +63,12 @@ public:
virtual ~Foo(); virtual ~Foo();
virtual std::string ping(); virtual std::string ping();
virtual std::string pong(); virtual std::string pong();
virtual std::string fooBar(FooBar* fooBarPtr); virtual std::string upcall(FooBar* fooBarPtr);
virtual Foo makeFoo(); virtual Foo makeFoo();
virtual FooBar makeFooBar(); virtual FooBar makeFooBar();
static std::string callPong(Foo &foo);
static std::string callUpcall(Foo &foo, FooBar* fooBarPtr);
static Foo* get_self(Foo *self_); static Foo* get_self(Foo *self_);
}; };

View file

@ -12,18 +12,35 @@ public class director_smartptr_runme {
} }
} }
public static void main(String argv[]) { private static void check(String got, String expected) {
director_smartptr_MyBarFoo myBarFoo = if (!got.equals(expected))
new director_smartptr_MyBarFoo(); 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 { class director_smartptr_MyBarFoo extends director_smartptr.Foo {
@Override @Override
public String ping() { public String ping() {
return "director_smartptr_MyBarFoo.ping();"; return "director_smartptr_MyBarFoo.ping()";
} }
@Override @Override
@ -32,17 +49,12 @@ class director_smartptr_MyBarFoo extends director_smartptr.Foo {
} }
@Override @Override
public String fooBar(director_smartptr.FooBar fooBar) { public String upcall(director_smartptr.FooBar fooBarPtr) {
return fooBar.FooBarDo(); return "override;" + fooBarPtr.FooBarDo();
} }
@Override @Override
public director_smartptr.Foo makeFoo() { public director_smartptr.Foo makeFoo() {
return new director_smartptr.Foo(); return new director_smartptr.Foo();
} }
@Override
public director_smartptr.FooBar makeFooBar() {
return new director_smartptr.FooBar();
}
} }

View file

@ -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()")