forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
12
Kha/Backends/Kinc-hxcpp/khacpp/test/native/tests/TestGlobalNamespace.hx
Executable file
12
Kha/Backends/Kinc-hxcpp/khacpp/test/native/tests/TestGlobalNamespace.hx
Executable file
@ -0,0 +1,12 @@
|
||||
package tests;
|
||||
|
||||
class TestGlobalNamespace extends haxe.unit.TestCase
|
||||
{
|
||||
var shortPtr:externs.ShortPtr;
|
||||
|
||||
public function testGen()
|
||||
{
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,65 @@
|
||||
package tests;
|
||||
|
||||
// Uses native enum, which does not play nice with Dynamic - must use @:unreflective
|
||||
@:unreflective
|
||||
@:enum extern abstract SystemMetric(SystemMetricImpl) {
|
||||
@:native("wxSYS_MOUSE_BUTTONS") var MOUSE_BUTTONS;
|
||||
@:native("wxSYS_OS") var OS;
|
||||
}
|
||||
@:unreflective
|
||||
@:native("wxSystemMetric")
|
||||
extern class SystemMetricImpl { }
|
||||
|
||||
|
||||
|
||||
// Wraps enum in struct, which does play nice...
|
||||
@:enum extern abstract SystemMetricStruct(SystemMetricStructImpl) {
|
||||
@:native("wxSYS_MOUSE_BUTTONS") var MOUSE_BUTTONS;
|
||||
@:native("wxSYS_OS") var OS;
|
||||
}
|
||||
@:native("cpp::Struct<wxSystemMetric, cpp::EnumHandler>")
|
||||
extern class SystemMetricStructImpl { }
|
||||
|
||||
@:headerCode('
|
||||
enum wxSystemMetric
|
||||
{
|
||||
wxSYS_OS = 3,
|
||||
wxSYS_MOUSE_BUTTONS = 27,
|
||||
};
|
||||
')
|
||||
class TestNativeEnum extends haxe.unit.TestCase
|
||||
{
|
||||
var x:SystemMetric = SystemMetric.MOUSE_BUTTONS;
|
||||
var xStruct:SystemMetricStruct = SystemMetricStruct.MOUSE_BUTTONS;
|
||||
|
||||
function isX(val:SystemMetric)
|
||||
{
|
||||
return (val==x);
|
||||
}
|
||||
|
||||
function isXStruct(val:SystemMetricStruct)
|
||||
{
|
||||
return (val==xStruct);
|
||||
}
|
||||
|
||||
|
||||
public function test()
|
||||
{
|
||||
assertTrue( isX(SystemMetric.MOUSE_BUTTONS)==true );
|
||||
assertTrue( isX(SystemMetric.OS)==false );
|
||||
assertTrue( isXStruct(SystemMetricStruct.MOUSE_BUTTONS)==true );
|
||||
assertTrue( isXStruct(SystemMetricStruct.OS)==false );
|
||||
var d:Dynamic = this;
|
||||
assertTrue( d.x==null );
|
||||
assertTrue( d.xStruct!=null );
|
||||
assertTrue( d.isX==null );
|
||||
assertTrue( d.isXStruct!=null );
|
||||
var func = d.isXStruct;
|
||||
assertTrue(func!=null);
|
||||
assertTrue(func(SystemMetricStruct.MOUSE_BUTTONS)==true );
|
||||
assertTrue(func(SystemMetricStruct.OS)==false );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,23 @@
|
||||
package tests;
|
||||
|
||||
import NativeGen;
|
||||
|
||||
class TestNativeGen extends haxe.unit.TestCase
|
||||
{
|
||||
@:unreflective var unreflectiveValue:NativeGen;
|
||||
|
||||
@:unreflective public function unreflectiveFunction(inGen:NativeGen)
|
||||
{
|
||||
unreflectiveValue = inGen;
|
||||
return unreflectiveValue.x==22;
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
var nGen:NativeGenStruct = null;
|
||||
nGen.x = 22;
|
||||
assertTrue(nGen.getValue()==22);
|
||||
|
||||
assertTrue(unreflectiveFunction(nGen) );
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package tests;
|
||||
|
||||
class Base
|
||||
{
|
||||
public function new() {}
|
||||
|
||||
@:nonVirtual public function getNvName() return "Base";
|
||||
public function getName() return "Base";
|
||||
}
|
||||
|
||||
|
||||
class Derived extends Base
|
||||
{
|
||||
@:nonVirtual override public function getNvName() return "Derived";
|
||||
override public function getName() return "Derived";
|
||||
}
|
||||
|
||||
|
||||
class TestNonVirtual extends haxe.unit.TestCase
|
||||
{
|
||||
public function testOverride()
|
||||
{
|
||||
var derived = new Derived();
|
||||
|
||||
assertTrue( derived.getName() == "Derived" );
|
||||
assertTrue( derived.getNvName() == "Derived" );
|
||||
var closure:Dynamic = derived.getNvName;
|
||||
assertTrue( closure() == "Derived" );
|
||||
|
||||
var base:Base = derived;
|
||||
|
||||
assertTrue( base.getName() == "Derived" );
|
||||
assertTrue( base.getNvName() == "Base" );
|
||||
var closure:Dynamic = base.getNvName;
|
||||
assertTrue( closure() == "Base" );
|
||||
}
|
||||
}
|
378
Kha/Backends/Kinc-hxcpp/khacpp/test/native/tests/TestPtr.hx
Normal file
378
Kha/Backends/Kinc-hxcpp/khacpp/test/native/tests/TestPtr.hx
Normal file
@ -0,0 +1,378 @@
|
||||
package tests;
|
||||
|
||||
import NativeGen;
|
||||
import cpp.NativeGc;
|
||||
import cpp.Stdlib;
|
||||
import cpp.Pointer;
|
||||
import cpp.RawPointer;
|
||||
import cpp.UInt8;
|
||||
using cpp.NativeArray;
|
||||
using cpp.NativeString;
|
||||
|
||||
@:unreflective
|
||||
@:native("CVec")
|
||||
extern class Vec {
|
||||
public var x:Float;
|
||||
public var y:Float;
|
||||
public var z:Float;
|
||||
}
|
||||
|
||||
|
||||
@:unreflective
|
||||
@:structAccess
|
||||
@:native("CVec")
|
||||
extern class VecStructAccess {
|
||||
public var x:Float;
|
||||
public var y:Float;
|
||||
public var z:Float;
|
||||
|
||||
@:native("new CVec")
|
||||
public static function create(val:Float) : Pointer<VecStructAccess>;
|
||||
|
||||
public function set99(ioVec:VecStructAccess):Void;
|
||||
}
|
||||
|
||||
|
||||
@:unreflective
|
||||
@:native("cpp::Struct<CVec>")
|
||||
extern class VecStruct {
|
||||
public var x:Float;
|
||||
public var y:Float;
|
||||
public var z:Float;
|
||||
}
|
||||
|
||||
@:native("::SomeStruct")
|
||||
extern class Native_SomeStruct {
|
||||
var data:RawPointer<cpp.UInt8>;
|
||||
var dataLength:Int;
|
||||
|
||||
inline function getDataBytes():haxe.io.Bytes {
|
||||
var bdata:haxe.io.BytesData = [];
|
||||
cpp.NativeArray.setData(bdata, cast data, dataLength); // Null Function Pointer
|
||||
return haxe.io.Bytes.ofData(bdata);
|
||||
}
|
||||
|
||||
inline function getUnmanagedDataBytes():haxe.io.Bytes {
|
||||
var bdata:haxe.io.BytesData = [];
|
||||
cpp.NativeArray.setUnmanagedData(bdata, cast data, dataLength); // Null Function Pointer
|
||||
return haxe.io.Bytes.ofData(bdata);
|
||||
}
|
||||
|
||||
}
|
||||
@:native("::cpp::Reference<SomeStruct>")
|
||||
extern class SomeStructRef extends Native_SomeStruct {}
|
||||
@:native("::cpp::Struct<SomeStruct>")
|
||||
extern class SomeStruct extends SomeStructRef {}
|
||||
|
||||
class IntHolder
|
||||
{
|
||||
public var ival:Int;
|
||||
|
||||
public function new(inVal:Int = 1) ival = inVal;
|
||||
}
|
||||
|
||||
@:headerCode('
|
||||
struct CVec{
|
||||
CVec(double inX=0) : x(inX), y(inX), z(inX) { }
|
||||
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
|
||||
void set99(CVec &ioVex) { ioVex.x=99; }
|
||||
};
|
||||
|
||||
struct SomeStruct {
|
||||
SomeStruct() : data((unsigned char *)"Hi!"), dataLength(3) { }
|
||||
|
||||
unsigned char *data;
|
||||
int dataLength;
|
||||
};
|
||||
')
|
||||
@:cppFileCode('
|
||||
int callPointer(CVec *) { return 5; }
|
||||
')
|
||||
class TestPtr extends haxe.unit.TestCase{
|
||||
|
||||
/*
|
||||
Alternate version
|
||||
@:generic
|
||||
public static inline function malloc<T>(size:Int) : cpp.Pointer<T>{
|
||||
var p : cpp.RawPointer<cpp.Void> = untyped __cpp__("malloc({0})",size);
|
||||
return cast cpp.Pointer.fromRaw( cast p );
|
||||
}
|
||||
*/
|
||||
|
||||
public function testMalloc() {
|
||||
var a : Pointer<Vec> = Stdlib.malloc( Stdlib.sizeof(Vec) );
|
||||
assertTrue( a!=null );
|
||||
assertTrue( a.raw!=null );
|
||||
a.ptr.x = 66;
|
||||
assertTrue( a.ptr.x == 66 );
|
||||
Stdlib.free(a);
|
||||
}
|
||||
|
||||
public function testExtened() {
|
||||
var test = NativeGc.allocateExtended( TestPtr, Stdlib.sizeof(Int) * 5 );
|
||||
var a : Pointer<Int> = cast Pointer.endOf(test);
|
||||
for(i in 0...5)
|
||||
a.setAt(i,i);
|
||||
for(i in 0...5)
|
||||
assertTrue( a.postIncRef() == i );
|
||||
}
|
||||
|
||||
function test9194() {
|
||||
// will fail during C++ compile
|
||||
var buffer: cpp.RawPointer<cpp.Void> = null;
|
||||
var floatBuffer: cpp.RawPointer<cpp.Float32> = cast buffer;
|
||||
// generates incorrect: float* floatBuffer = buffer
|
||||
// the lack of native casting means the compiler throws an error here
|
||||
|
||||
var buffer: cpp.Star<cpp.Void> = null;
|
||||
var floatBuffer: cpp.Star<cpp.Float32> = cast buffer;
|
||||
// generates correct: float* floatBuffer = ( (float*) buffer )
|
||||
|
||||
assertTrue(floatBuffer==null);
|
||||
}
|
||||
|
||||
|
||||
public function testNull() {
|
||||
var nullP : Pointer<Vec> = null;
|
||||
var nullRawP = nullP.raw;
|
||||
assertTrue( nullP==null );
|
||||
assertTrue( null==nullP );
|
||||
assertFalse( nullP!=null );
|
||||
assertTrue( nullRawP==null );
|
||||
assertFalse( nullRawP!=null );
|
||||
nullRawP = null;
|
||||
assertTrue( nullRawP==null );
|
||||
}
|
||||
|
||||
private function anonOf(d:Dynamic) : Dynamic return {ptr:d};
|
||||
|
||||
public function testStructAccess() {
|
||||
var e = VecStructAccess.create(1);
|
||||
var tmp = e.ptr;
|
||||
var tmp1 = e.ref;
|
||||
tmp.set99(tmp1);
|
||||
assertTrue(e.ptr.x==99);
|
||||
}
|
||||
|
||||
@:native("callPointer") @:extern
|
||||
private static function callPointer(ptr:cpp.Pointer<Vec>):Int;
|
||||
|
||||
public function testPointerCast() {
|
||||
var map = new Map<Int, cpp.Pointer<Vec> >();
|
||||
map.set(1,null);
|
||||
var result = callPointer( map.get(2) );
|
||||
assertTrue(result==5);
|
||||
}
|
||||
|
||||
public function testDynamic() {
|
||||
var a = [1];
|
||||
var intPtr = a.address(0);
|
||||
var d:Dynamic = intPtr;
|
||||
assertFalse(d==[2].address(0));
|
||||
assertTrue(d==a.address(0));
|
||||
var anon = anonOf(d);
|
||||
assertFalse([2].address(0)==d);
|
||||
assertTrue(a.address(0)==d);
|
||||
assertFalse(intPtr==[2].address(0));
|
||||
assertTrue(intPtr==a.address(0));
|
||||
assertFalse(anon.ptr==[2].address(0));
|
||||
assertTrue(anon.ptr==a.address(0));
|
||||
assertFalse([2].address(0)==anon.ptr);
|
||||
assertTrue(a.address(0)==anon.ptr);
|
||||
}
|
||||
|
||||
function getAnonI(a:Dynamic) : Dynamic
|
||||
{
|
||||
return a.i;
|
||||
}
|
||||
|
||||
|
||||
public function testAnon() {
|
||||
var a = [1];
|
||||
var intPtr = a.address(0);
|
||||
var anon = { i:intPtr };
|
||||
assertTrue( getAnonI(anon)==intPtr );
|
||||
|
||||
var vecPtr = VecStructAccess.create(1);
|
||||
var anon = { i:vecPtr };
|
||||
assertTrue( getAnonI(anon)==vecPtr );
|
||||
|
||||
var vec:VecStruct = null;
|
||||
vec.x = 123;
|
||||
var anon = { i:vec };
|
||||
assertTrue( getAnonI(anon)==vec );
|
||||
}
|
||||
|
||||
static function callMe(x:Int) return 10+x;
|
||||
|
||||
static function notProcAddress(module:String, func:String) return null;
|
||||
|
||||
public function testArrayAccess() {
|
||||
var array = [ 0.0, 1.1, 2.2, 3.3 ];
|
||||
var ptr = cpp.Pointer.arrayElem(array, 0);
|
||||
assertTrue( ptr[1]==1.1 );
|
||||
ptr[1] = 2;
|
||||
assertTrue( ptr[1]==2 );
|
||||
ptr[1]++;
|
||||
assertTrue( ptr[1]==3 );
|
||||
ptr[1]-=2.5;
|
||||
assertTrue( ptr[1]==0.5 );
|
||||
|
||||
var raw = ptr.raw;
|
||||
assertTrue( raw[2]==2.2 );
|
||||
raw[2] = 2;
|
||||
assertTrue( raw[2]==2 );
|
||||
raw[2]++;
|
||||
assertTrue( raw[2]==3 );
|
||||
raw[2]-=2.5;
|
||||
assertTrue( raw[2]==0.5 );
|
||||
|
||||
}
|
||||
|
||||
public function testFromRaw()
|
||||
{
|
||||
var i = new IntHolder(3);
|
||||
var ptr = cpp.Pointer.fromRaw(cpp.Pointer.addressOf(i).rawCast());
|
||||
assertTrue( ptr.ref.ival==i.ival );
|
||||
ptr.ref.ival==23;
|
||||
assertTrue( ptr.ref.ival==i.ival );
|
||||
}
|
||||
|
||||
private static var output:cpp.Pointer<Array<Int>>;
|
||||
|
||||
private static var arrayValue:Array<Int>;
|
||||
private static function makeValue():{ a:cpp.Pointer<Array<Int>> }
|
||||
{
|
||||
arrayValue = [9];
|
||||
return { a: cpp.Pointer.addressOf(arrayValue) };
|
||||
}
|
||||
|
||||
@:analyzer(no_fusion)
|
||||
public function testDynamicOutput()
|
||||
{
|
||||
// Declared as structure (just `var val = ...` works too)
|
||||
var val:{ a:cpp.Pointer<Array<Int>> } = makeValue();
|
||||
|
||||
var a:cpp.Pointer<Array<Int>> = val.a;
|
||||
output = a;
|
||||
output = (val.a:Dynamic);
|
||||
output = val.a;
|
||||
output = (val.a:cpp.Pointer<Array<Int>>);
|
||||
val.a = output;
|
||||
|
||||
// Declared as Dynamic
|
||||
var val2:Dynamic = makeValue();
|
||||
a = val2.a;
|
||||
output = a;
|
||||
output = (val2.a:Dynamic);
|
||||
output = val2.a;
|
||||
output = (val2.a:cpp.Pointer<Array<Int>>);
|
||||
val2.a = output;
|
||||
assertTrue( val2.a==output );
|
||||
assertTrue( output==val.a );
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testAutoCast() {
|
||||
var z = [ 1, 2, 3 ];
|
||||
assertTrue( cpp.NativeArray.address(z, 0).ptr == cpp.NativeArray.address(z, 0).ptr );
|
||||
assertTrue( cpp.NativeArray.address(z, 1).ptr != cpp.NativeArray.address(z, 0).ptr );
|
||||
assertTrue( cpp.NativeArray.address(z, 1).gt(cpp.NativeArray.address(z, 0)) );
|
||||
assertTrue( cpp.NativeArray.address(z, 1).geq(cpp.NativeArray.address(z, 0)) );
|
||||
assertTrue( cpp.NativeArray.address(z, 1).geq(cpp.NativeArray.address(z, 1)) );
|
||||
assertTrue( cpp.NativeArray.address(z, 0).leq(cpp.NativeArray.address(z, 0)) );
|
||||
assertTrue( cpp.NativeArray.address(z, 1).leq(cpp.NativeArray.address(z, 2)) );
|
||||
assertTrue( cpp.NativeArray.address(z, 1).leq(cpp.NativeArray.address(z, 2)) );
|
||||
assertTrue( cpp.NativeArray.address(z, 0) == cpp.Pointer.ofArray(z) );
|
||||
assertTrue( cpp.NativeArray.address(z, 1) == cpp.Pointer.arrayElem(z,1) );
|
||||
assertTrue( cpp.NativeArray.address(z, 1) != cpp.Pointer.fromHandle(null) );
|
||||
assertTrue( cpp.Function.fromStaticFunction(callMe)(1)==11 );
|
||||
try
|
||||
{
|
||||
assertTrue( cpp.Function.fromStaticFunction(notProcAddress)!=cpp.Function.getProcAddress("nomodule","nofunc!") );
|
||||
}
|
||||
catch(e:Dynamic)
|
||||
{
|
||||
// Could not load module - expected
|
||||
}
|
||||
}
|
||||
|
||||
static function functionCaller(fn:cpp.Function<Void->Int,cpp.abi.Abi>) {
|
||||
var a = fn.call();
|
||||
}
|
||||
|
||||
public function testFunctionStructAccess() {
|
||||
assertTrue( functionCaller != null );
|
||||
}
|
||||
|
||||
public function testSetData() {
|
||||
var ss:SomeStruct = null;
|
||||
ss.dataLength = 4;
|
||||
ss.data = cast "bye!".c_str();
|
||||
var b = ss.getDataBytes();
|
||||
assertTrue( b.getString(0, b.length) == "bye!" );
|
||||
|
||||
var ss:SomeStruct = null;
|
||||
var b = ss.getUnmanagedDataBytes();
|
||||
assertTrue( b.getString(0, b.length) == "Hi!" );
|
||||
}
|
||||
|
||||
public function testZero() {
|
||||
var a = [1,2,3];
|
||||
a.zero();
|
||||
assertTrue(a.length==3);
|
||||
assertTrue(a[0]==0);
|
||||
assertTrue(a[1]==0);
|
||||
assertTrue(a[2]==0);
|
||||
}
|
||||
|
||||
public function testMemcmp() {
|
||||
var a = [1,2,3];
|
||||
var b = [2,2,3];
|
||||
assertTrue( a.memcmp(b) == -1 );
|
||||
assertTrue( b.memcmp(a) == 1 );
|
||||
assertTrue( a.memcmp(a) == 0 );
|
||||
}
|
||||
|
||||
public function testCapacity() {
|
||||
var a = [1,2,3];
|
||||
assertTrue( a.capacity() < 1000 );
|
||||
a.reserve(1000);
|
||||
assertTrue( a.capacity() == 1000 );
|
||||
a[1000] = 1;
|
||||
assertTrue( a.capacity() > 1000 );
|
||||
}
|
||||
|
||||
|
||||
public function testElementSize() {
|
||||
var a = [1];
|
||||
assertTrue( a.getElementSize() == cpp.Stdlib.sizeof(Int) );
|
||||
var a = ["hello!"];
|
||||
assertTrue( a.getElementSize() == cpp.Stdlib.sizeof(String) );
|
||||
var a = [7.1];
|
||||
assertTrue( a.getElementSize() == cpp.Stdlib.sizeof(Float) );
|
||||
}
|
||||
|
||||
|
||||
public function testBlit() {
|
||||
var a = [1,2,3,4];
|
||||
var b = [0,0,0,0];
|
||||
b.blit(0,a,0,a.length);
|
||||
for(i in 0...4)
|
||||
assertTrue(b[i] == a[i]);
|
||||
for(i in 0...4)
|
||||
b.blit(i,a,0,1);
|
||||
for(i in 0...4)
|
||||
assertTrue(b[i] == a[0]);
|
||||
for(i in 0...4)
|
||||
b.blit(i,a,2,1);
|
||||
for(i in 0...4)
|
||||
assertTrue(b[i] == a[2]);
|
||||
}
|
||||
}
|
||||
|
107
Kha/Backends/Kinc-hxcpp/khacpp/test/native/tests/TestRectangle.hx
Executable file
107
Kha/Backends/Kinc-hxcpp/khacpp/test/native/tests/TestRectangle.hx
Executable file
@ -0,0 +1,107 @@
|
||||
package tests;
|
||||
import externs.Rectangle;
|
||||
|
||||
class TestRectangle extends haxe.unit.TestCase
|
||||
{
|
||||
static var statRect:Rectangle;
|
||||
static var statRectPtr:RectanglePtr;
|
||||
|
||||
static var statRectProp(get,set):Rectangle;
|
||||
static var statRectPtrProp(get,set):RectanglePtr;
|
||||
|
||||
var memRect:Rectangle;
|
||||
var memRectPtr:RectanglePtr;
|
||||
|
||||
var memRectProp(get,set):Rectangle;
|
||||
var memRectPtrProp(get,set):RectanglePtr;
|
||||
|
||||
static function get_statRectProp() return statRect;
|
||||
static function set_statRectProp(val:Rectangle) return statRect=val;
|
||||
static function get_statRectPtrProp() return statRectPtr;
|
||||
static function set_statRectPtrProp(val:RectanglePtr) return statRectPtr=val;
|
||||
|
||||
|
||||
function get_memRectProp() return memRect;
|
||||
function set_memRectProp(val:Rectangle) return memRect=val;
|
||||
function get_memRectPtrProp() return memRectPtr;
|
||||
function set_memRectPtrProp(val:RectanglePtr) return memRectPtr=val;
|
||||
|
||||
|
||||
public function testRect()
|
||||
{
|
||||
// Struct - copy semantic
|
||||
var rectangle = Rectangle.make(3,4);
|
||||
assertTrue( rectangle.area()==0 );
|
||||
|
||||
var rect2 = rectangle;
|
||||
rect2.width = 2;
|
||||
rect2.height = 4;
|
||||
assertTrue( rect2.area()==8 );
|
||||
assertTrue( rectangle.area()==0 );
|
||||
|
||||
|
||||
// Take address ...
|
||||
var rectPtr:RectanglePtr = rectangle;
|
||||
|
||||
// Pointer-like sysntax
|
||||
rectPtr.width = 3;
|
||||
rectPtr.height = 5;
|
||||
var dynamicPtr:Dynamic = rectPtr;
|
||||
|
||||
assertTrue( rectPtr.area()==15 );
|
||||
// Same object
|
||||
assertTrue( rectangle.area()==15 );
|
||||
|
||||
var dynamicCopy:Dynamic = rectangle; // 3,4 3x5
|
||||
|
||||
rectangle.width = 10;
|
||||
rectangle.height = 10;
|
||||
assertTrue( rectangle.area()==100 );
|
||||
|
||||
// points to original object
|
||||
var fromDynamic:RectanglePtr = rectPtr;
|
||||
assertTrue( fromDynamic.area()==100 );
|
||||
|
||||
// Restore from Dynamic ...
|
||||
rectangle = dynamicCopy;
|
||||
assertTrue( rectangle.area()==15 );
|
||||
}
|
||||
|
||||
public function testReflect()
|
||||
{
|
||||
statRect = Rectangle.make(1,2,3,4);
|
||||
memRect = Rectangle.make(4,5,6,7);
|
||||
// This is not correct in the GC moving case ...
|
||||
//statRectPtr = memRect;
|
||||
statRectPtr = Rectangle.create(1,1,2,2);
|
||||
memRectPtr = statRect;
|
||||
|
||||
assertTrue( statRectProp.area()==12 );
|
||||
assertTrue( memRectProp.area()==42 );
|
||||
assertTrue( statRectPtrProp.area()==4 );
|
||||
assertTrue( memRectPtrProp.area()==12 );
|
||||
|
||||
var d:Dynamic = this;
|
||||
var r:Rectangle = d.memRect;
|
||||
assertTrue( r.area()==42 );
|
||||
var prop:Rectangle = Reflect.getProperty(d,"memRectProp");
|
||||
assertTrue( prop.area()==42 );
|
||||
var propPtr:RectanglePtr = Reflect.getProperty(d,"memRectPtrProp");
|
||||
assertTrue( propPtr.area()==12 );
|
||||
|
||||
var d:Dynamic = TestRectangle;
|
||||
var r:Rectangle = d.statRect;
|
||||
assertTrue( r.area()==12 );
|
||||
var prop:Rectangle = Reflect.getProperty(d,"statRectProp");
|
||||
assertTrue( prop.area()==12 );
|
||||
var propPtr:RectanglePtr = Reflect.getProperty(d,"statRectPtrProp");
|
||||
assertTrue( propPtr.area()==4 );
|
||||
|
||||
|
||||
// No longer valid
|
||||
statRectPtr.delete();
|
||||
statRectPtr = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
53
Kha/Backends/Kinc-hxcpp/khacpp/test/native/tests/TestRgb.hx
Normal file
53
Kha/Backends/Kinc-hxcpp/khacpp/test/native/tests/TestRgb.hx
Normal file
@ -0,0 +1,53 @@
|
||||
package tests;
|
||||
import externs.RGB;
|
||||
|
||||
class TestRgb extends haxe.unit.TestCase
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
// Pointer-like sysntax
|
||||
var rgbPtr = RGB.create(255,0,128);
|
||||
assertTrue( rgbPtr.ptr.toInt() == 0xff0080 );
|
||||
rgbPtr.ptr.deleteMe();
|
||||
|
||||
|
||||
// Structure-like syntax
|
||||
var rgbStruct:RGBStruct = null;
|
||||
rgbStruct.r = 1;
|
||||
rgbStruct = null;
|
||||
rgbStruct.r = 1;
|
||||
rgbStruct.g = 2;
|
||||
rgbStruct.b = 3;
|
||||
assertTrue( rgbStruct.toInt() == 0x010203 );
|
||||
// Store in dynamic
|
||||
var d:Dynamic = rgbStruct;
|
||||
|
||||
// Reference (pointer) like syntax
|
||||
var rgbRef:RGBRef = rgbStruct;
|
||||
rgbRef.g = 255;
|
||||
assertTrue( rgbStruct.toInt() == 0x01ff03 );
|
||||
|
||||
// Get from dynamic
|
||||
rgbStruct = d;
|
||||
assertTrue( rgbStruct.toInt() == 0x010203 );
|
||||
|
||||
var rgbStruct2:RGBStruct = cast rgbRef;
|
||||
assertTrue( rgbStruct2.toInt() == 0x010203 );
|
||||
|
||||
// Reference refers to rgbStruct, not rgbStruct2
|
||||
rgbRef.b = 0;
|
||||
assertTrue( rgbStruct2.toInt() == 0x010203 );
|
||||
assertTrue( rgbStruct.toInt() == 0x010200 );
|
||||
|
||||
|
||||
// TODO - non-dynamic versions
|
||||
var d2:Dynamic = rgbStruct2;
|
||||
// == dynamic
|
||||
assertTrue( d2==d );
|
||||
// != dynamic
|
||||
var d0:Dynamic = rgbStruct;
|
||||
assertTrue( d0!=d );
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package tests;
|
||||
import cpp.Stdio;
|
||||
using cpp.NativeArray;
|
||||
|
||||
class TestStdio extends haxe.unit.TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
var file = Stdio.fopen("test.txt", "wb");
|
||||
var ints = [1];
|
||||
var size:cpp.SizeT = cpp.Stdlib.sizeof(Int);
|
||||
Stdio.fwrite( ints.address(0).raw, size, 1, file );
|
||||
Stdio.fclose(file);
|
||||
|
||||
var bytes = sys.io.File.getBytes("test.txt");
|
||||
var input = new haxe.io.BytesInput(bytes);
|
||||
var val = input.readInt32();
|
||||
|
||||
assertTrue(val==ints[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user