From 2b61964060ffb79a313030d795ad069fbbe97b88 Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Sat, 27 Mar 2010 00:46:51 +0100
Subject: Add coverage test (signatures and execution) ..

---
 src/junit/com/jogamp/gluegen/test/junit/Test1.java | 141 ++++++++++++---------
 .../jogamp/gluegen/test/junit/test1-gluegen.cfg    |   9 +-
 2 files changed, 87 insertions(+), 63 deletions(-)

(limited to 'src')

diff --git a/src/junit/com/jogamp/gluegen/test/junit/Test1.java b/src/junit/com/jogamp/gluegen/test/junit/Test1.java
index 258256a..03fbaee 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/Test1.java
+++ b/src/junit/com/jogamp/gluegen/test/junit/Test1.java
@@ -32,8 +32,11 @@
 
 package com.jogamp.gluegen.test.junit;
 
+import com.jogamp.gluegen.test.junit.impl.BindingTest1Impl;
+
 import com.sun.gluegen.runtime.BufferFactory;
 import com.sun.gluegen.runtime.PointerBuffer;
+import java.nio.*;
 import java.io.File;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -57,78 +60,92 @@ import static com.jogamp.gluegen.test.junit.BuildEnvironment.*;
  */
 public class Test1 {
 
+    /**
+     * Verifies loading of the new library.
+     */
     @Test
-    public void bindingTest1() throws Exception {
-
+    public void chapter01TestLoadLibrary() throws Exception {
         String nativesPath = testOutput + "/build/natives";
         System.load(nativesPath + "/libtest1.so");
+    }
+
+    /**
+     * Verifies the existence and creation of the generated class.
+     */
+    @Test
+    public void chapter01TestClassExist() throws Exception {
+        Class<?> clazzIf   = Class.forName("com.jogamp.gluegen.test.junit.BindingTest1");
+        Class<?> clazzImpl = Class.forName("com.jogamp.gluegen.test.junit.impl.BindingTest1Impl");
 
-        Class<?> clazz = Class.forName("com.jogamp.gluegen.test.junit.BindingTest1");
+        Assert.assertNotNull("com.jogamp.gluegen.test.junit.BindingTest1 does not exist", clazzIf);
+        Assert.assertNotNull("com.jogamp.gluegen.test.junit.impl.BindingTest1Impl does not exist", clazzImpl);
 
-        Assert.assertNotNull("com.jogamp.gluegen.test.junit.BindingTest1 does not exist", clazz);
-        Assert.assertEquals((int)1,  clazz.getDeclaredField("CONSTANT_ONE").get(null));
+        Assert.assertEquals((int)1,  clazzIf.getDeclaredField("CONSTANT_ONE").get(null));
 
-        Object obj = clazz.newInstance();
+        Object obj = clazzImpl.newInstance();
         Assert.assertTrue("Not of type com.jogamp.gluegen.test.junit.BindingTest1", (obj instanceof com.jogamp.gluegen.test.junit.BindingTest1));
 
-        com.jogamp.gluegen.test.junit.BindingTest1 bindingTest1 = (com.jogamp.gluegen.test.junit.BindingTest1) obj;
+        BindingTest1 bindingTest1 = (BindingTest1) obj;
         Assert.assertTrue("nopTest1 failed", 42==bindingTest1.nopTest());
+    }
+
+    /**
+     * Verifies if all methods / signatures are properly generated,
+     * and can be invoked.
+     * Gluegen Coverage test.
+     * This is a compilation and runtime time test.
+     */
+    @Test
+    public void chapter01TestCoverage() throws Exception {
+          int dummy;
+
+          int array_size = 10;
+          long context = 0;
+          ByteBuffer bb1 = BufferFactory.newDirectByteBuffer(PointerBuffer.elementSize() * array_size);
+          ByteBuffer bb2 = BufferFactory.newDirectByteBuffer(PointerBuffer.elementSize() * array_size);
+
+          PointerBuffer pb1 = PointerBuffer.allocateDirect(array_size);
+          PointerBuffer pb2 = PointerBuffer.allocateDirect(array_size);
+
+          long[] larray1 = new long[array_size];
+          int array1_offset = 0;
+
+          long[] larray2 = new long[array_size];
+          int array2_offset = 0;
+
+          BindingTest1 binding = new BindingTest1Impl();
+
+          /** Interface to C language function: <br> <code> int arrayTest(long context, foo *  array); </code>    */
+          dummy = binding.arrayTest(context, pb1);
+          Assert.assertTrue(42==dummy);
+
+          /** Interface to C language function: <br> <code> int arrayTest(long context, foo *  array); </code>    */
+          dummy = binding.arrayTest(context, larray1, array1_offset);
+          Assert.assertTrue(42==dummy);
+
+          /** Interface to C language function: <br> <code> int bufferTest(void *  object); </code>    */
+          dummy = binding.bufferTest(bb1);
+          Assert.assertTrue(42==dummy);
+
+          /** Interface to C language function: <br> <code> int doubleTest(long context, void *  object1, foo *  array1, void *  object2, foo *  array2); </code>    */
+          dummy = binding.doubleTest(context, bb1, pb1, bb2, pb2);
+          Assert.assertTrue(42==dummy);
+
+          /** Interface to C language function: <br> <code> int doubleTest(long context, void *  object1, foo *  array1, void *  object2, foo *  array2); </code>    */
+          dummy = binding.doubleTest(context, bb1, larray1, array1_offset, bb2, larray2, array2_offset);
+          Assert.assertTrue(42==dummy);
+
+          /** Interface to C language function: <br> <code> int mixedTest(long context, void *  object, foo *  array); </code>    */
+          dummy = binding.mixedTest(context, bb1, pb1);
+          Assert.assertTrue(42==dummy);
+
+          /** Interface to C language function: <br> <code> int mixedTest(long context, void *  object, foo *  array); </code>    */
+          dummy = binding.mixedTest(context, bb1, larray1, array1_offset);
+          Assert.assertTrue(42==dummy);
 
-        // assertEquals((long)0xFFFFFFFF,  clazz.getDeclaredField("GL_INVALID_INDEX").get(null));
-        // assertEquals(-0.5f,             clazz.getDeclaredField("AL_FLANGER_DEFAULT_FEEDBACK").get(null));
-
-        // TODO fix Exception: ...Caused by: java.lang.UnsatisfiedLinkError: test.BindingTest.arrayTest0(JLjava/lang/Object;I)I
-        /*
-        // test values
-        ByteBuffer dbb = BufferFactory.newDirectByteBuffer(32);
-        ByteBuffer bb  = ByteBuffer.allocate(32).order(ByteOrder.nativeOrder());
-
-        PointerBuffer dpb = PointerBuffer.allocateDirect(32);
-        PointerBuffer pb  = PointerBuffer.allocate(32);
-
-        long[] array = new long[] {1,2,3,4,5,6,7,8,9};
-        int offset = 0;
-        long id = 42;
-
-
-        // invoke everything public
-        Object bindingTest = clazz.newInstance();
-        Method[] methods = clazz.getDeclaredMethods();
-
-        for (Method method : methods) {
-
-            // prepare method parameters
-            Class<?>[] paramTypes = method.getParameterTypes();
-            Object[] paramInstances = new Object[paramTypes.length];
-
-            for (int i = 0; i < paramTypes.length; i++) {
-                Class<?> paramType = paramTypes[i];
-                if(paramType.isInstance(dbb)) {
-                    paramInstances[i] = dbb;
-                }else if(paramType.isInstance(bb)) {
-                    paramInstances[i] = bb;
-                }else if(paramType.isInstance(dpb)) {
-                    paramInstances[i] = dpb;
-                }else if(paramType.isInstance(pb)) {
-                    paramInstances[i] = pb;
-                }else if(paramType.isPrimitive()) { // TODO primitive types
-                    paramInstances[i] = offset;
-                }else if(paramType.isArray()) {     // TODO array types
-                    paramInstances[i] = array;
-                }
-            }
-
-            out.println("invoking: "+method);
-            out.println("with params: ");
-            for (Object param : paramInstances)
-                out.print(param+", ");
-            out.println();
-
-            Object result = method.invoke(bindingTest, paramInstances);
-            out.println("result: "+result);
-            out.println("success");
-        }
-        */
+          /** Interface to C language function: <br> <code> int nopTest(); </code>    */
+          dummy = binding.nopTest();
+          Assert.assertTrue(42==dummy);
     }
 
 }
diff --git a/src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.cfg b/src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.cfg
index fe6cb5c..291e6cc 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.cfg
+++ b/src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.cfg
@@ -1,6 +1,6 @@
 Package com.jogamp.gluegen.test.junit
 JavaClass BindingTest1
-Style AllStatic
+Style InterfaceAndImpl
 JavaOutputDir classes
 NativeOutputDir native
 
@@ -19,10 +19,17 @@ NativeOutputDir native
 # pointer typedefs for these routines to MYAPIENTRY
 #LocalProcAddressCallingConvention __ALL__ MYAPIENTRY
 
+#EmitProcAddressTable true
+#ProcAddressTableClassName CLProcAddressTable
+#GetProcAddressTableExpr addressTable
+#ProcAddressNameExpr $UpperCase(arg)
+#ForceProcAddressGen clGetGLContextInfoKHR
+
 CustomCCode #include "test1.h"
 
 # Imports needed by all glue code
 Import java.nio.*
 Import java.util.*
+Import com.jogamp.gluegen.test.junit.BindingTest1
 
 
-- 
cgit v1.2.3