forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
167
Kha/Backends/Kinc-hxcpp/khacpp/test/cppia/Client.hx
Normal file
167
Kha/Backends/Kinc-hxcpp/khacpp/test/cppia/Client.hx
Normal file
@ -0,0 +1,167 @@
|
||||
class ClientOne implements pack.HostInterface
|
||||
{
|
||||
public function new() { }
|
||||
public function getOne() : Int return 1;
|
||||
public function getOneString() : String return "1";
|
||||
}
|
||||
|
||||
class Client
|
||||
{
|
||||
public static var clientBool0 = true;
|
||||
public static var clientBool1 = false;
|
||||
public static var clientBool2 = true;
|
||||
public static var clientBool3 = false;
|
||||
|
||||
public static function main()
|
||||
{
|
||||
Common.status = "running";
|
||||
|
||||
// See if it compiles
|
||||
if (sys.thread.Thread.current()==null)
|
||||
{
|
||||
Common.status = "Cppia Thread.current not working.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (Common.hostImplementation.getOne()!=1)
|
||||
{
|
||||
Common.status = "Bad call to getOne";
|
||||
return;
|
||||
}
|
||||
if (Common.hostImplementation.getOneString()!="1")
|
||||
{
|
||||
Common.status = "Bad call to getOneString";
|
||||
return;
|
||||
}
|
||||
|
||||
var c = new ClientExtends();
|
||||
if (!c.ok())
|
||||
{
|
||||
Common.status = "Bad client extension";
|
||||
return;
|
||||
}
|
||||
if (c.whoStartedYou()!="HostBase")
|
||||
{
|
||||
Common.status = "Bad class fallthrough - got " + c.whoStartedYou();
|
||||
return;
|
||||
}
|
||||
if (c.whoOverridesYou()!="ClientExtends")
|
||||
{
|
||||
Common.status = "Bad class override - got " + c.whoOverridesYou();
|
||||
return;
|
||||
}
|
||||
if (!c.testPointers())
|
||||
{
|
||||
Common.status = "Could not move native pointers";
|
||||
return;
|
||||
}
|
||||
|
||||
var hostInterface:IHostInterface = c;
|
||||
if (hostInterface.whoStartedYou()!="HostBase")
|
||||
{
|
||||
Common.status = "Bad interface fallthrough";
|
||||
return;
|
||||
}
|
||||
if (hostInterface.whoOverridesYou()!="ClientExtends")
|
||||
{
|
||||
Common.status = "Bad interface override";
|
||||
return;
|
||||
}
|
||||
if (hostInterface.hostImplOnly(1,"two",3)!="1two3")
|
||||
{
|
||||
Common.status = "Bad hostImplOnly implementation";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!c.testOne())
|
||||
{
|
||||
Common.status = "Bad ClientExtends getOne";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
var clientInterface:IClientInterface = c;
|
||||
if (clientInterface.whoStartedYou()!="HostBase")
|
||||
{
|
||||
Common.status = "Bad client interface fallthrough";
|
||||
return;
|
||||
}
|
||||
if (clientInterface.uniqueClientFunc()!="uniqueClientFunc")
|
||||
{
|
||||
Common.status = "Bad new client interface call";
|
||||
return;
|
||||
}
|
||||
|
||||
if (clientInterface.whoOverridesYou()!="ClientExtends")
|
||||
{
|
||||
Common.status = "Bad client interface override";
|
||||
return;
|
||||
}
|
||||
|
||||
var clientHostInterface:IClientHostInterface = c;
|
||||
if (clientHostInterface.whoStartedYou()!="HostBase")
|
||||
{
|
||||
Common.status = "Bad client interface fallthrough";
|
||||
return;
|
||||
}
|
||||
if (clientHostInterface.whoOverridesYou()!="ClientExtends")
|
||||
{
|
||||
Common.status = "Bad client interface override";
|
||||
return;
|
||||
}
|
||||
if (clientHostInterface.whoAreYou()!="ClientExtends")
|
||||
{
|
||||
Common.status = "Bad client/host interface";
|
||||
return;
|
||||
}
|
||||
|
||||
var c:ClientIHostImpl = new ClientIHostImpl();
|
||||
if (c.hostImplOnly(0,null,0)!="client" || c.whoStartedYou()!="client" || c.whoOverridesYou()!="client")
|
||||
{
|
||||
Common.status = "Trouble implementing host interface";
|
||||
return;
|
||||
}
|
||||
|
||||
var c:ClientExtends = new ClientExtends2();
|
||||
if (c.getGeneration()!=2)
|
||||
{
|
||||
Common.status = "Error calling cppia super function";
|
||||
return;
|
||||
}
|
||||
|
||||
var c = new ClientExtends2();
|
||||
if (c.testOne())
|
||||
{
|
||||
Common.status = "ClientExtends2 getOne should fail";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!c.testOneExtended())
|
||||
{
|
||||
Common.status = "ClientExtends2 testOneExtended failed";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!c.testFour())
|
||||
{
|
||||
Common.status = "ClientExtends2 testFour error";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
var hostBools = HostBase.hostBool0 + "/" + HostBase.hostBool1+ "/" + HostBase.hostBool2+ "/" + HostBase.hostBool3;
|
||||
var clientBools = clientBool0 + "/" + clientBool1+ "/" + clientBool2+ "/" + clientBool3;
|
||||
if (hostBools!=clientBools)
|
||||
{
|
||||
Common.status = "Error in bool representation:" + hostBools + "!=" + clientBools;
|
||||
return;
|
||||
}
|
||||
|
||||
Common.clientImplementation = new ClientOne();
|
||||
Common.status = "ok";
|
||||
|
||||
Common.callback = () -> Common.callbackSet = 2;
|
||||
}
|
||||
}
|
62
Kha/Backends/Kinc-hxcpp/khacpp/test/cppia/ClientExtends.hx
Normal file
62
Kha/Backends/Kinc-hxcpp/khacpp/test/cppia/ClientExtends.hx
Normal file
@ -0,0 +1,62 @@
|
||||
class ClientExtends extends HostBase implements IClientInterface implements IClientHostInterface
|
||||
{
|
||||
public function new()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function ok():Bool
|
||||
{
|
||||
return getVal()==1.25;
|
||||
}
|
||||
|
||||
public function testOne()
|
||||
{
|
||||
return getOne()==1;
|
||||
}
|
||||
|
||||
public function testOneExtended()
|
||||
{
|
||||
return getOne()==111;
|
||||
}
|
||||
|
||||
|
||||
#if (hxcpp_api_level>=400)
|
||||
public function testPointers() : Bool
|
||||
{
|
||||
pointerDest = pointerSrc;
|
||||
return getDestVal()==4;
|
||||
}
|
||||
|
||||
override public function getGeneration()
|
||||
{
|
||||
return super.getGeneration() + 1;
|
||||
}
|
||||
#else
|
||||
override public function getGeneration()
|
||||
{
|
||||
return super.getGeneration() + 1;
|
||||
}
|
||||
#end
|
||||
|
||||
override public function whoStartedYou() : String return super.whoStartedYou();
|
||||
|
||||
// override IHostInteface
|
||||
override public function whoOverridesYou() return "ClientExtends";
|
||||
|
||||
// new IClientInterface
|
||||
public function uniqueClientFunc() return "uniqueClientFunc";
|
||||
|
||||
// IClientHostInterface
|
||||
public function whoAreYou() return "ClientExtends";
|
||||
|
||||
public function getOne() return 1;
|
||||
|
||||
public function getTwo() return 2;
|
||||
|
||||
public function getThree() return 3;
|
||||
|
||||
override public function update() return "ClientExtends update";
|
||||
}
|
||||
|
||||
|
25
Kha/Backends/Kinc-hxcpp/khacpp/test/cppia/ClientExtends2.hx
Executable file
25
Kha/Backends/Kinc-hxcpp/khacpp/test/cppia/ClientExtends2.hx
Executable file
@ -0,0 +1,25 @@
|
||||
class ClientExtends2 extends ClientExtends
|
||||
{
|
||||
public function new()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
override public function getGeneration()
|
||||
{
|
||||
return super.getGeneration()+1;
|
||||
}
|
||||
|
||||
public function getFour() return 4;
|
||||
|
||||
public function testFour() : Bool
|
||||
{
|
||||
return getFour()==4;
|
||||
}
|
||||
|
||||
override public function getOne() return 111;
|
||||
|
||||
override public function update() return "ClientExtends2 update";
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
class ClientIHostImpl implements IHostInterface
|
||||
{
|
||||
public function new() { }
|
||||
|
||||
public function hostImplOnly(i:Int, s:String, f:Float) : String return "client";
|
||||
public function whoStartedYou() : String return "client";
|
||||
public function whoOverridesYou() : String return "client";
|
||||
}
|
10
Kha/Backends/Kinc-hxcpp/khacpp/test/cppia/Common.hx
Normal file
10
Kha/Backends/Kinc-hxcpp/khacpp/test/cppia/Common.hx
Normal file
@ -0,0 +1,10 @@
|
||||
class Common
|
||||
{
|
||||
public static var status:String = "tests not run";
|
||||
public static var hostImplementation:pack.HostInterface;
|
||||
public static var clientImplementation:pack.HostInterface;
|
||||
|
||||
public static var callbackSet:Int = 0;
|
||||
public static var callback: Void->Void;
|
||||
|
||||
}
|
90
Kha/Backends/Kinc-hxcpp/khacpp/test/cppia/CppiaHost.hx
Normal file
90
Kha/Backends/Kinc-hxcpp/khacpp/test/cppia/CppiaHost.hx
Normal file
@ -0,0 +1,90 @@
|
||||
import cpp.cppia.Host;
|
||||
|
||||
import HostBase;
|
||||
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
59
Kha/Backends/Kinc-hxcpp/khacpp/test/cppia/HostBase.hx
Normal file
59
Kha/Backends/Kinc-hxcpp/khacpp/test/cppia/HostBase.hx
Normal file
@ -0,0 +1,59 @@
|
||||
#if (hxcpp_api_level>=400)
|
||||
import cpp.Native;
|
||||
#end
|
||||
|
||||
class HostBase implements IHostInterface
|
||||
{
|
||||
static var hostInit = 10;
|
||||
public static var hostBool0 = true;
|
||||
public static var hostBool1 = false;
|
||||
public static var hostBool2 = true;
|
||||
public static var hostBool3 = false;
|
||||
|
||||
var floatVal:Float;
|
||||
var pointerSrc:cpp.Star<Int>;
|
||||
var pointerDest:cpp.Star<Int>;
|
||||
|
||||
public function new()
|
||||
{
|
||||
floatVal = 1.25;
|
||||
#if (hxcpp_api_level>=400)
|
||||
pointerSrc = Native.malloc( Native.sizeof(Int) );
|
||||
Native.set(pointerSrc,4);
|
||||
pointerDest = null;
|
||||
#end
|
||||
}
|
||||
|
||||
public function getDestVal() : Int
|
||||
{
|
||||
#if (hxcpp_api_level>=400)
|
||||
if (pointerDest==null)
|
||||
return -1;
|
||||
return Native.get(pointerDest);
|
||||
#else
|
||||
return 4;
|
||||
#end
|
||||
}
|
||||
|
||||
public function getYou() : HostBase
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public function testUpdateOverride() : Bool
|
||||
{
|
||||
return update()=="ClientExtends2 update";
|
||||
}
|
||||
|
||||
|
||||
public function getVal() return floatVal;
|
||||
|
||||
public function getGeneration() return 0;
|
||||
|
||||
public function update() return "HostBase update";
|
||||
|
||||
// IHostInteface
|
||||
public function hostImplOnly(i:Int, s:String, f:Float) : String return i+s+f;
|
||||
public function whoStartedYou() return "HostBase";
|
||||
public function whoOverridesYou() return "No one";
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
// Same as IHostInterface, but not implemented in host
|
||||
interface IClientHostInterface extends IHostInterface
|
||||
{
|
||||
public function whoAreYou() : String;
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
interface IClientInterface
|
||||
{
|
||||
// Same as IHostInterface, but not implemented in host
|
||||
public function whoStartedYou() : String;
|
||||
public function whoOverridesYou() : String;
|
||||
public function uniqueClientFunc() : String;
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
interface IHostInterface
|
||||
{
|
||||
public function hostImplOnly(i:Int, s:String, f:Float) : String;
|
||||
public function whoStartedYou() : String;
|
||||
public function whoOverridesYou() : String;
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
-main Client
|
||||
-D dll_import=host_classes.info
|
||||
-cppia bin/client.cppia
|
||||
-cp ../unit
|
@ -0,0 +1,6 @@
|
||||
-main CppiaHost
|
||||
-D scriptable
|
||||
-D dll_export=host_classes.info
|
||||
-dce no
|
||||
-cpp bin
|
||||
-cp ../unit
|
@ -0,0 +1,7 @@
|
||||
package pack;
|
||||
|
||||
interface HostInterface
|
||||
{
|
||||
public function getOne() : Int;
|
||||
public function getOneString() : String;
|
||||
}
|
Reference in New Issue
Block a user