[D] Improved allprotected test case error messages.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12858 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
David Nadlinger 2011-12-03 19:47:12 +00:00
commit 388484bb77

View file

@ -2,6 +2,8 @@ module allprotected_runme;
import allprotected.Klass; import allprotected.Klass;
import allprotected.ProtectedBase; import allprotected.ProtectedBase;
import std.conv : text;
import std.exception : enforce;
void main() { void main() {
auto mpb = new MyProtectedBase("MyProtectedBase"); auto mpb = new MyProtectedBase("MyProtectedBase");
@ -16,50 +18,46 @@ public:
void accessProtected() { void accessProtected() {
string s = virtualMethod(); string s = virtualMethod();
if (s != "ProtectedBase") enforce(s == "ProtectedBase", "Failed, got '" ~ s ~ "'");
throw new Exception("Failed");
Klass k = instanceMethod(new Klass("xyz")); Klass k;
if (k.getName() != "xyz") void expect(string name) {
throw new Exception("Failed"); auto kName = k.getName();
enforce(kName == name, "Failed, expected '" ~ name ~ "' instead of '" ~
kName ~ "'.");
}
k = instanceMethod(new Klass("xyz"));
expect("xyz");
k = instanceOverloaded(new Klass("xyz")); k = instanceOverloaded(new Klass("xyz"));
if (k.getName() != "xyz") expect("xyz");
throw new Exception("Failed");
k = instanceOverloaded(new Klass("xyz"), "abc"); k = instanceOverloaded(new Klass("xyz"), "abc");
if (k.getName() != "abc") expect("abc");
throw new Exception("Failed");
k = staticMethod(new Klass("abc")); k = staticMethod(new Klass("abc"));
if (k.getName() != "abc") expect("abc");
throw new Exception("Failed");
k = staticOverloaded(new Klass("xyz")); k = staticOverloaded(new Klass("xyz"));
if (k.getName() != "xyz") expect("xyz");
throw new Exception("Failed");
k = staticOverloaded(new Klass("xyz"), "abc"); k = staticOverloaded(new Klass("xyz"), "abc");
if (k.getName() != "abc") expect("abc");
throw new Exception("Failed");
instanceMemberVariable = 30; instanceMemberVariable = 30;
int i = instanceMemberVariable; int i = instanceMemberVariable;
if (i != 30) enforce(i == 30, text("Failed, expected ", 30, "instead of ", i));
throw new Exception("Failed");
staticMemberVariable = 40; staticMemberVariable = 40;
i = staticMemberVariable; i = staticMemberVariable;
if (i != 40) enforce(i == 40, text("Failed, expected ", 40, "instead of ", i));
throw new Exception("Failed");
i = staticConstMemberVariable; i = staticConstMemberVariable;
if (i != 20) enforce(i == 20, text("Failed, expected ", 20, "instead of ", i));
throw new Exception("Failed");
anEnum = ProtectedBase.AnEnum.EnumVal1; anEnum = ProtectedBase.AnEnum.EnumVal1;
ProtectedBase.AnEnum ae = anEnum; ProtectedBase.AnEnum ae = anEnum;
if (ae != ProtectedBase.AnEnum.EnumVal1) enforce(ae == ProtectedBase.AnEnum.EnumVal1);
throw new Exception("Failed");
} }
} }