diff --git a/test/cppia/Client.hx b/test/cppia/Client.hx index 85a8b274a..23432d127 100644 --- a/test/cppia/Client.hx +++ b/test/cppia/Client.hx @@ -5,6 +5,15 @@ class ClientOne implements pack.HostInterface public function getOneString() : String return "1"; } +class ClientFoo implements IFoo { + + public function new() {} + + public function baz():String { + return 'foo'; + } +} + class Client { public static var clientBool0 = true; diff --git a/test/cppia/CppiaHost.hx b/test/cppia/CppiaHost.hx index 611a09c2e..155ee01d4 100644 --- a/test/cppia/CppiaHost.hx +++ b/test/cppia/CppiaHost.hx @@ -1,105 +1,9 @@ -import cpp.cppia.Host; +import utest.UTest; +import utest.Test; -import HostBase; -import HostExtendedRoot; - -class HostOne implements pack.HostInterface +class CppiaHost extends Test { - public static var called = 0; - - public function new() - { - } - - public function getOne() : Int - { - called ++; - return 1; - } - public function getOneString() : String - { - called++; - return "1"; - } -} - -class CppiaHost -{ - - public static function main() - { - Common.hostImplementation = new HostOne(); - - Common.callback = () -> Common.callbackSet = 1; - - /* - if (new HostExtends().getYou().extendOnly != 1) - { - Sys.println("extend-overide type failed"); - Sys.exit(-1); - } - */ - - Host.main(); - Sys.println("TestStatus: " + Common.status ); - if (Common.status!="ok") - { - Sys.println("failed"); - Sys.exit(-1); - } - else - { - if (HostOne.called!=2) - { - Sys.println("No client implementation call - failed"); - Sys.exit(-1); - } - - if (Common.clientImplementation==null) - { - Sys.println("No client implementation - failed"); - Sys.exit(-1); - } - if (Common.clientImplementation.getOne()!=1) - { - Sys.println("Bad client Int implementation - failed"); - Sys.exit(-1); - } - if (Common.clientImplementation.getOneString()!="1") - { - Sys.println("Bad client String implementation - failed"); - Sys.exit(-1); - } - - var hostBase:HostBase = Type.createInstance(Type.resolveClass("ClientExtends2"),[]); - - if (!hostBase.testUpdateOverride()) - { - Sys.println("Bad update override"); - Sys.exit(-1); - } - - Common.callback(); - if (Common.callbackSet!=2) - { - Sys.println("Bad cppia closure"); - Sys.exit(-1); - } - - #if (haxe >= version("4.3.6")) - if (Common.clientRoot == null) { - Sys.println("null client root class"); - Sys.exit(-1); - } - switch Common.clientRoot.values { - case [ 0, 1, 2 ]: - // - case _: - Sys.println("Unexpected items in array"); - Sys.exit(-1); - } - #end - } + public static function main() { + UTest.run([ new cases.TestCommon() ]); } -} - +} \ No newline at end of file diff --git a/test/cppia/IFoo.hx b/test/cppia/IFoo.hx new file mode 100644 index 000000000..eedd1a26f --- /dev/null +++ b/test/cppia/IFoo.hx @@ -0,0 +1,3 @@ +interface IFoo { + function baz() : String; +} \ No newline at end of file diff --git a/test/cppia/cases/TestCommon.hx b/test/cppia/cases/TestCommon.hx new file mode 100644 index 000000000..eaacb5a76 --- /dev/null +++ b/test/cppia/cases/TestCommon.hx @@ -0,0 +1,83 @@ +package cases; + +import cpp.cppia.Host; +import utest.Test; +import utest.Assert; + +private class HostOne implements pack.HostInterface +{ + public static var called = 0; + + public function new() {} + + public function getOne() : Int { + called ++; + return 1; + } + + public function getOneString() : String { + called++; + return "1"; + } +} + +class TestCommon extends Test { + function setupClass() { + Common.hostImplementation = new HostOne(); + + Common.callback = () -> Common.callbackSet = 1; + + Host.main(); + } + + function testStatus() { + Assert.equals('ok', Common.status); + } + + @:depends(testStatus) + function testClientImplementation() { + Assert.equals(2, HostOne.called, 'No client implementation call'); + + if (Assert.notNull(Common.clientImplementation, 'No client implementation')) { + Assert.equals(1, Common.clientImplementation.getOne(), 'Bad client Int implementation'); + Assert.equals('1', Common.clientImplementation.getOneString(), 'Bad client String implementation'); + } + } + + @:depends(testStatus) + function testResolvingScriptType() { + var hostBase:HostBase = Type.createInstance(Type.resolveClass("ClientExtends2"),[]); + if (Assert.notNull(hostBase, 'Failed to create client type')) { + Assert.isTrue(hostBase.testUpdateOverride(), 'Bad update override'); + } + } + + @:depends(testStatus) + function testCallback() { + Common.callback(); + + Assert.equals(2, Common.callbackSet, 'Bad cppia closure'); + } + + @:depends(testStatus) + function testInterfaceCalling() { + final obj : IFoo = Type.createInstance(Type.resolveClass('ClientFoo'), []); + + if (Assert.notNull(obj, 'Unable to create client implementation')) { + Assert.equals('foo', obj.baz()); + } + } + +#if (haxe >= version("4.3.6")) + @:depends(testStatus) + function testMultiLevelInheritance() { + if (Assert.notNull(Common.clientRoot, 'Null client root class')) { + if (Assert.equals(3, Common.clientRoot.values.length, 'Expected three items in the array')) { + Assert.equals(0, Common.clientRoot.values[0]); + Assert.equals(1, Common.clientRoot.values[1]); + Assert.equals(2, Common.clientRoot.values[2]); + } + } + } +#end +} \ No newline at end of file diff --git a/test/cppia/compile-host.hxml b/test/cppia/compile-host.hxml index 0c39f79c5..efe8bdf09 100644 --- a/test/cppia/compile-host.hxml +++ b/test/cppia/compile-host.hxml @@ -1,5 +1,6 @@ -m CppiaHost -D scriptable -D dll_export=host_classes.info +-L utest --dce no --cpp bin \ No newline at end of file