diff options
Diffstat (limited to 'src/junit/com')
5 files changed, 124 insertions, 13 deletions
diff --git a/src/junit/com/jogamp/gluegen/test/junit/structgen/BuildStruct01.java b/src/junit/com/jogamp/gluegen/test/junit/structgen/BuildStruct01.java new file mode 100644 index 0000000..7824e55 --- /dev/null +++ b/src/junit/com/jogamp/gluegen/test/junit/structgen/BuildStruct01.java @@ -0,0 +1,34 @@ +package com.jogamp.gluegen.test.junit.structgen; + +import com.jogamp.gluegen.structgen.CStruct; + +/** + * Class simply triggering CStruct annotation processor to generate the types 'RenderingConfig' etc. + * <p> + * Due to Java8 issues, see Bug 923, + * using {@link package-info} is more elegant to kick-off the annotation processor. + * </p> + */ +public class BuildStruct01 { + + // APT is only triggered for fields, + // hence we use unused fields in this unit test! + + // @CStruct(name="RenderingConfig", header="TestStruct01.h") + // MyRenderingConfig config; + + // @CStruct(header="TestStruct01.h") + // MyRenderingConfig config; + + /** + * Java8: We cannot use type 'RenderingConfig' yet (bug?) even if not compiling. + * Hence we force the type-name via 'jname' and use a dummy variable! + */ + @CStruct(name="RenderingConfig", jname="RenderingConfig", header="TestStruct01.h") + boolean dummy1; + + @CStruct(name="Pixel", jname="Pixel", header="TestStruct02.h") + boolean dummy2; + + public static void initSingleton() {} +} diff --git a/src/junit/com/jogamp/gluegen/test/junit/structgen/TestStruct02.h b/src/junit/com/jogamp/gluegen/test/junit/structgen/TestStruct02.h new file mode 100644 index 0000000..64fda78 --- /dev/null +++ b/src/junit/com/jogamp/gluegen/test/junit/structgen/TestStruct02.h @@ -0,0 +1,14 @@ +// +// TestStruct02.h +// + +#include "TestStruct01.h" + +typedef struct { + float r, g, b, a; +} Col4f; + +typedef struct { + Col4f color; + Vec3f pos; +} Pixel; diff --git a/src/junit/com/jogamp/gluegen/test/junit/structgen/TestStructGen01.java b/src/junit/com/jogamp/gluegen/test/junit/structgen/TestStructGen01.java index 23b1624..74f0552 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/structgen/TestStructGen01.java +++ b/src/junit/com/jogamp/gluegen/test/junit/structgen/TestStructGen01.java @@ -1,26 +1,23 @@ package com.jogamp.gluegen.test.junit.structgen; -import com.jogamp.gluegen.structgen.CStruct; import com.jogamp.junit.util.JunitTracer; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; - import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestStructGen01 extends JunitTracer { - // APT is only triggered for fields, - // hence we use unused fields in this unit test! - - // @CStruct(name="RenderingConfig", header="TestStruct01.h") - // MyRenderingConfig config; - - @CStruct(header="TestStruct01.h") - RenderingConfig config0; - + @BeforeClass + public static void init() { + // Enforce dependency, + // i.e. CStruct annotation processor to generate the types 'RenderingConfig' etc. + BuildStruct01.initSingleton(); + } + @Test public void test01() { RenderingConfig config = RenderingConfig.create(); @@ -46,10 +43,10 @@ public class TestStructGen01 extends JunitTracer { cam_orig.setY(1); cam_orig.setZ(2); } - + public static void main(String args[]) { String tstname = TestStructGen01.class.getName(); org.junit.runner.JUnitCore.main(tstname); } - + } diff --git a/src/junit/com/jogamp/gluegen/test/junit/structgen/TestStructGen02.java b/src/junit/com/jogamp/gluegen/test/junit/structgen/TestStructGen02.java new file mode 100644 index 0000000..a8f0e52 --- /dev/null +++ b/src/junit/com/jogamp/gluegen/test/junit/structgen/TestStructGen02.java @@ -0,0 +1,51 @@ +package com.jogamp.gluegen.test.junit.structgen; + +import com.jogamp.junit.util.JunitTracer; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestStructGen02 extends JunitTracer { + + @BeforeClass + public static void init() { + // Enforce dependency, + // i.e. CStruct annotation processor to generate the types 'RenderingConfig' etc. + BuildStruct01.initSingleton(); + } + + @Test + public void test01() { + final Pixel pixel = Pixel.create(); + final Col4f color = pixel.getColor(); + color.setR(1f); + color.setG(2f); + color.setB(3f); + color.setA(4f); + final Vec3f pos = pixel.getPos(); + pos.setX(0.5f); + pos.setY(0.6f); + pos.setZ(0.7f); + + Pixel pixel2 = Pixel.create(pixel.getBuffer()); + final Col4f color2 = pixel2.getColor(); + Assert.assertEquals(color.getR(), color2.getR(), 0.0001f); + Assert.assertEquals(color.getG(), color2.getG(), 0.0001f); + Assert.assertEquals(color.getB(), color2.getB(), 0.0001f); + Assert.assertEquals(color.getA(), color2.getA(), 0.0001f); + final Vec3f pos2 = pixel2.getPos(); + Assert.assertEquals(pos.getX(), pos2.getX(), 0.0001f); + Assert.assertEquals(pos.getY(), pos2.getY(), 0.0001f); + Assert.assertEquals(pos.getZ(), pos2.getZ(), 0.0001f); + } + + public static void main(String args[]) { + String tstname = TestStructGen02.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/junit/com/jogamp/gluegen/test/junit/structgen/package-info.java b/src/junit/com/jogamp/gluegen/test/junit/structgen/package-info.java new file mode 100644 index 0000000..d009c5f --- /dev/null +++ b/src/junit/com/jogamp/gluegen/test/junit/structgen/package-info.java @@ -0,0 +1,15 @@ +/** + * Package scope generation of {@link CStruct}s + * avoiding Java8 issues w/ annotation processing + * where the generated class is not yet available. + * <p> + * See Bug 923. + * </p> + * @see BuildStruct01 + */ +@CStructs({@CStruct(name="RenderingConfig", header="TestStruct01.h"), @CStruct(name="Pixel", header="TestStruct02.h")}) +package com.jogamp.gluegen.test.junit.structgen; + +import com.jogamp.gluegen.structgen.CStructs; +import com.jogamp.gluegen.structgen.CStruct; + |