diff options
Diffstat (limited to 'src/junit/com/jogamp/gluegen/test')
9 files changed, 258 insertions, 2 deletions
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java index c57a288..df3df83 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java @@ -532,5 +532,80 @@ public class BaseClass { i = binding.intArrayRead(iarray, 0, 3); Assert.assertTrue("Wrong result: "+i, 6==i); } + + void assertAPTR(final long expected, final long actual) { + System.err.println("0x"+Long.toHexString(expected)+" == 0x"+Long.toHexString(actual)); + if (Platform.is32Bit()) { + int exp32; + int act32; + // if(Platform.isLittleEndian()) { + exp32 = (int) ( expected ) ; + act32 = (int) ( actual ) ; + /* } else { + exp32 = (int) ( expected >> 32 ) ; + act32 = (int) ( actual >> 32 ) ; + } */ + System.err.println("0x"+Integer.toHexString(exp32)+" == 0x"+Integer.toHexString(act32)); + Assert.assertEquals(exp32, act32); + } else { + Assert.assertEquals(expected, actual); + } + } + + public void chapter09TestCompoundAndAlignment(Bindingtest1 binding) throws Exception { + TK_ComplicatedSuperSet cs = binding.createComplicatedSuperSet(); + Assert.assertEquals((byte)0xA0, cs.getBits1()); + + TK_ComplicatedSubSet sub1 = cs.getSub1(); + Assert.assertEquals((byte)0xA1, sub1.getBits1()); + Assert.assertEquals(0x12345678, sub1.getId()); + Assert.assertEquals((byte)0xA2, sub1.getBits2()); + Assert.assertEquals(0x123456789abcdef0L, sub1.getLong0()); + Assert.assertEquals((byte)0xA3, sub1.getBits3()); + Assert.assertEquals(3.1415926535897932384626433832795, sub1.getReal0(), 0.0); + Assert.assertEquals((byte)0xA4, sub1.getBits4()); + + Assert.assertEquals((byte)0xB0, cs.getBits2()); + + TK_ComplicatedSubSet sub2 = cs.getSub2(); + Assert.assertEquals((byte)0xB1, sub2.getBits1()); + Assert.assertEquals(0x12345678, sub2.getId()); + Assert.assertEquals((byte)0xB2, sub2.getBits2()); + Assert.assertEquals(0x123456789abcdef0L, sub2.getLong0()); + Assert.assertEquals((byte)0xB3, sub2.getBits3()); + Assert.assertEquals(3.1415926535897932384626433832795, sub2.getReal0(), 0.0); + Assert.assertEquals((byte)0xB4, sub2.getBits4()); + + Assert.assertEquals((byte)0xC0, cs.getBits3()); + + binding.destroyComplicatedSuperSet(cs); + + /********************************************************************************/ + + TK_Surface surface = binding.createSurface(); + + assertAPTR(0x123456789abcdef0L, surface.getCtx()); + + TK_Engine engine = surface.getEngine(); + assertAPTR(0x123456789abcdef0L, engine.getCtx()); + Assert.assertEquals(0x0111, engine.render(0x0100, 0x0010, 0x0001)); + + TK_Dimension dimension = surface.getBounds(); + Assert.assertEquals(0x11111111, dimension.getX()); + Assert.assertEquals(0x22222222, dimension.getY()); + Assert.assertEquals(0x33333333, dimension.getWidth()); + Assert.assertEquals(0x44444444, dimension.getHeight()); + + Assert.assertEquals(2, surface.getClipSize()); + + for(int i=0; i<surface.getClipSize(); i++) { + TK_Dimension clip = surface.getClip(i); + Assert.assertEquals(0x44444444 * (i+1) + 0x11111111, clip.getX()); + Assert.assertEquals(0x44444444 * (i+1) + 0x22222222, clip.getY()); + Assert.assertEquals(0x44444444 * (i+1) + 0x33333333, clip.getWidth()); + Assert.assertEquals(0x44444444 * (i+1) + 0x44444444, clip.getHeight()); + } + binding.destroySurface(surface); + } } diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/BuildEnvironment.java b/src/junit/com/jogamp/gluegen/test/junit/generation/BuildEnvironment.java index 73950eb..3b883aa 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/BuildEnvironment.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/BuildEnvironment.java @@ -31,6 +31,8 @@ package com.jogamp.gluegen.test.junit.generation; import java.io.File; import java.net.URISyntaxException; +import com.jogamp.common.util.VersionUtil; + import static java.lang.System.*; /** @@ -46,7 +48,7 @@ public final class BuildEnvironment { static { out.println(" - - - System info - - - "); - out.println("OS: " + System.getProperty("os.name")); + out.println(VersionUtil.getPlatformInfo()); out.println("VM: " + System.getProperty("java.vm.name")); String rootrel_build_tmp = System.getProperty("rootrel.build"); diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java index 83faa9b..35907de 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java @@ -105,6 +105,14 @@ public class Test1p1JavaEmitter extends BaseClass { chapter05TestSomeFunctionsAllIndirect(new Bindingtest1p1Impl()); } + /** + * This covers compounds (structs) and data alignment + */ + @Test + public void chapter09TestCompoundAndAlignment() throws Exception { + chapter09TestCompoundAndAlignment(new Bindingtest1p1Impl()); + } + public static void main(String args[]) throws IOException { String tstname = Test1p1JavaEmitter.class.getName(); org.junit.runner.JUnitCore.main(tstname); diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java index 8fe4f86..cd6e85d 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java @@ -115,6 +115,14 @@ public class Test1p2ProcAddressEmitter extends BaseClass { chapter05TestSomeFunctionsAllIndirect(new Bindingtest1p2Impl()); } + /** + * This covers compounds (structs) and data alignment + */ + @Test + public void chapter09TestCompoundAndAlignment() throws Exception { + chapter09TestCompoundAndAlignment(new Bindingtest1p1Impl()); + } + public static void main(String args[]) throws IOException { String tstname = Test1p2ProcAddressEmitter.class.getName(); org.junit.runner.JUnitCore.main(tstname); diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1-common.cfg b/src/junit/com/jogamp/gluegen/test/junit/generation/test1-common.cfg index 30cdd96..c6e5415 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1-common.cfg +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1-common.cfg @@ -25,11 +25,31 @@ Opaque long MYAPIConfig CustomCCode #include "test1.h" +Opaque long TK_Context + +StructPackage TK_Surface com.jogamp.gluegen.test.junit.generation +EmitStruct TK_Surface +# Implements TK_Surface TḴ_??? + +StructPackage TK_ComplicatedSuperSet com.jogamp.gluegen.test.junit.generation +EmitStruct TK_ComplicatedSuperSet +# Implements TK_ComplicatedSuperSet TḴ_??? + +ReturnValueCapacity createSurface sizeof(TK_Surface) +ReturnValueCapacity getClip sizeof(TK_Dimension) + +ReturnValueCapacity createComplicatedSuperSet sizeof(TK_ComplicatedSuperSet) + # Imports needed by all glue code Import java.nio.* Import java.util.* Import com.jogamp.common.os.* Import com.jogamp.common.nio.* +Import com.jogamp.gluegen.test.junit.generation.TK_Surface +Import com.jogamp.gluegen.test.junit.generation.TK_Dimension +Import com.jogamp.gluegen.test.junit.generation.TK_Engine +Import com.jogamp.gluegen.test.junit.generation.TK_ComplicatedSuperSet +Import com.jogamp.gluegen.test.junit.generation.TK_ComplicatedSubSet diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1-gluegen.cfg b/src/junit/com/jogamp/gluegen/test/junit/generation/test1-gluegen.cfg index 197b081..bb5eb80 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1-gluegen.cfg +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1-gluegen.cfg @@ -3,6 +3,7 @@ Style AllStatic JavaClass Bindingtest1 Style InterfaceOnly JavaOutputDir classes +NativeOutputDir native Include test1-common.cfg diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c index 05a9889..0876403 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c @@ -234,4 +234,85 @@ MYAPI uintptr_t MYAPIENTRY typeTestUIntPtrT(const uintptr_t ptr1, uintptr_t ptr2 return ptr1 + ptr2; } +static TK_Dimension * _TK_getClip(TK_Surface * surface, int idx) { + return & ( surface->clips[idx] ) ; +} + +static int32_t _TK_render (int x, int y, int ps) { + return x + y + ps ; +} + +MYAPI TK_Surface * MYAPIENTRY createSurface() { + TK_Surface * s = calloc(1, sizeof(TK_Surface)); + + s->getClip = _TK_getClip; + + s->ctx = (void *) 0x123456789abcdef0UL; + //s->engine = (TK_Engine *) calloc(1, sizeof(TK_Engine)); + //s->engine->ctx = (void *) 0x123456789abcdef0UL; + //s->engine->render = _TK_render; + s->engine.ctx = (void *) 0x123456789abcdef0UL; + s->engine.render = _TK_render; + + s->bounds.x = 0x11111111U; + s->bounds.y = 0x22222222U; + s->bounds.width = 0x33333333U; + s->bounds.height = 0x44444444U; + + s->clipSize = 2; + s->clips = (TK_Dimension *) calloc(2, sizeof(TK_Dimension)); + s->clips[0].x = 0x55555555U; + s->clips[0].y = 0x66666666U; + s->clips[0].width = 0x77777777U; + s->clips[0].height = 0x88888888U; + s->clips[1].x = 0x99999999U; + s->clips[1].y = 0xaaaaaaaaU; + s->clips[1].width = 0xbbbbbbbbU; + s->clips[1].height = 0xccccccccU; + + return s; +} + +MYAPI void MYAPIENTRY destroySurface(TK_Surface * surface) { + free(surface->clips); + // free(surface->engine); + free(surface); +} + +MYAPI TK_ComplicatedSuperSet * MYAPIENTRY createComplicatedSuperSet() { + TK_ComplicatedSuperSet * s = calloc(1, sizeof(TK_ComplicatedSuperSet)); + + s->bits1 = 0xA0U; + s->sub1.bits1 = 0xA1U; + s->sub1.id = 0x12345678U; + s->sub1.bits2 = 0xA2U; + s->sub1.long0 = 0x123456789abcdef0UL; + s->sub1.bits3 = 0xA3U; + s->sub1.real0 = 3.1415926535897932384626433832795L; + s->sub1.bits4 = 0xA4U; + s->bits2 = 0xB0U; + s->sub2.bits1 = 0xB1U; + s->sub2.id = 0x12345678U; + s->sub2.bits2 = 0xB2U; + s->sub2.long0 = 0x123456789abcdef0UL; + s->sub2.bits3 = 0xB3U; + s->sub2.real0 = 3.1415926535897932384626433832795L; + s->sub2.bits4 = 0xB4U; + s->bits3 = 0xC0U; + + fprintf(stderr, "TK_ComplicatedSubSet: sizeof(): %ld\n", (long) sizeof(TK_ComplicatedSubSet)); + fprintf(stderr, "TK_ComplicatedSubSet: bits2-s offset: %ld\n", (long) ((void *)(&s->sub1.bits2) - (void *)(&s->sub1)) ); + fprintf(stderr, "TK_ComplicatedSubSet: bits3-s offset: %ld\n", (long) ((void *)(&s->sub1.bits3) - (void *)(&s->sub1)) ); + fprintf(stderr, "TK_ComplicatedSubSet: bits4-s offset: %ld\n", (long) ((void *)(&s->sub1.bits4) - (void *)(&s->sub1)) ); + + fprintf(stderr, "TK_ComplicatedSuperSet: sizeof(): %ld\n", (long) sizeof(TK_ComplicatedSuperSet)); + fprintf(stderr, "TK_ComplicatedSuperSet: bits2-s offset: %ld\n", (long) ((void *)(&s->bits2) - (void *)(s)) ); + fprintf(stderr, "TK_ComplicatedSuperSet: bits3-s offset: %ld\n", (long) ((void *)(&s->bits3) - (void *)(s)) ); + + return s; +} + +MYAPI void MYAPIENTRY destroyComplicatedSuperSet(TK_ComplicatedSuperSet * s) { + free(s); +} diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h index 5b1c241..041a8d2 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h @@ -125,3 +125,65 @@ MYAPI uintptr_t MYAPIENTRY typeTestUIntPtrT(const uintptr_t ptr1, uintptr_t ptr2 #warning "Hello Native Compiler" #endif +typedef struct { + int32_t x; + int32_t y; + int32_t width; + int32_t height; +} TK_Dimension; + +typedef struct _TK_Context * TK_Context; // anonymous + +typedef struct { + TK_Context ctx; + int32_t (MYAPIENTRY *render) (int x, int y, int ps); +} TK_Engine; + +typedef struct tk_Surface { + TK_Context ctx; + // const TK_Engine * engine; + TK_Engine engine; + TK_Dimension bounds; + int32_t clipSize; + TK_Dimension * clips; + TK_Dimension * (MYAPIENTRY *getClip) (struct tk_Surface * ds, int idx); +} TK_Surface; + +typedef struct { + int8_t bits1; // +1 + // +3 (p64) + int32_t id; // +4 + int8_t bits2; // +1 + // +7 (p64) + int64_t long0; // +8 + int8_t bits3; // +1 + // +7 (p64) + double real0; // +8 + int8_t bits4; // +1 + // +7 (p64) (for next struct ..) + + // 24 net + + // 48 gross 64bit/linux +} TK_ComplicatedSubSet; + +typedef struct { + int8_t bits1; // + 1 + // + 7 (p64) + TK_ComplicatedSubSet sub1; // +48 (64bit) + int8_t bits2; // + 1 + // + 7 (p64) + TK_ComplicatedSubSet sub2; // +48 (64bit) + int8_t bits3; // + 1 + // + 7 (p64) + + // 51 net + + // 120 gross 64bit/linux +} TK_ComplicatedSuperSet; + +MYAPI TK_Surface * MYAPIENTRY createSurface(); +MYAPI void MYAPIENTRY destroySurface(TK_Surface * surface); + +MYAPI TK_ComplicatedSuperSet * MYAPIENTRY createComplicatedSuperSet(); +MYAPI void MYAPIENTRY destroyComplicatedSuperSet(TK_ComplicatedSuperSet * s); diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1p2-gluegen.cfg b/src/junit/com/jogamp/gluegen/test/junit/generation/test1p2-gluegen.cfg index 649499d..708bd26 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1p2-gluegen.cfg +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1p2-gluegen.cfg @@ -22,7 +22,6 @@ ForceProcAddressGen __ALL__ LocalProcAddressCallingConvention __ALL__ MYAPIENTRY Include test1-common.cfg -Include ../../../../../../../../make/config/intptr.cfg Import com.jogamp.gluegen.test.junit.generation.Bindingtest1 Import com.jogamp.gluegen.test.junit.generation.Bindingtest1p2 |