Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for nightly cppia interface issue #1197

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions test/cppia/Client.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
108 changes: 6 additions & 102 deletions test/cppia/CppiaHost.hx
Original file line number Diff line number Diff line change
@@ -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() ]);
}
}

}
3 changes: 3 additions & 0 deletions test/cppia/IFoo.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface IFoo {
function baz() : String;
}
83 changes: 83 additions & 0 deletions test/cppia/cases/TestCommon.hx
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions test/cppia/compile-host.hxml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-m CppiaHost
-D scriptable
-D dll_export=host_classes.info
-L utest
--dce no
--cpp bin
Loading