summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-08-04 00:18:08 +0200
committerSven Gothel <[email protected]>2023-08-04 00:18:08 +0200
commit3e249796e7b42033072aeda438d987601939db44 (patch)
treed60cc75d35a175bf48000e25895e2348d55ca026
parentd4e8ecc3b4f68b86d95ec951971a0fea20217988 (diff)
Fix & Enhance Test4JavaCallback for non-userParam chapter12*: Fix ad-hoc compound equals and add chapter12b for additional parameter with different order
- ad-hoc compound equals must compare value, since native code creates a new class instance from native struct - Add additional case with addition callback argument for further validation
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java111
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test2.c31
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg20
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test2.h18
4 files changed, 142 insertions, 38 deletions
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java b/src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java
index 61a8412..0c1ff93 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java
@@ -42,7 +42,8 @@ import com.jogamp.gluegen.test.junit.generation.Bindingtest2.MessageCallback11aK
import com.jogamp.gluegen.test.junit.generation.Bindingtest2.MessageCallback11bKey;
import com.jogamp.gluegen.test.junit.generation.Bindingtest2.T2_CallbackFunc01;
import com.jogamp.gluegen.test.junit.generation.Bindingtest2.T2_CallbackFunc11;
-import com.jogamp.gluegen.test.junit.generation.Bindingtest2.T2_CallbackFunc12;
+import com.jogamp.gluegen.test.junit.generation.Bindingtest2.T2_CallbackFunc12a;
+import com.jogamp.gluegen.test.junit.generation.Bindingtest2.T2_CallbackFunc12b;
import com.jogamp.gluegen.test.junit.generation.impl.Bindingtest2Impl;
import org.junit.AfterClass;
@@ -1612,53 +1613,127 @@ public class Test4JavaCallback extends BaseClass {
}
/**
- * Test Bindingtest2 with T2_CallbackFunc12 JavaCallback via SetLogCallBack()
+ * Test Bindingtest2 with T2_CallbackFunc12a JavaCallback via SetLogCallBack12a()
*/
@Test
- public void chapter12() throws Exception {
+ public void chapter12a() throws Exception {
final Bindingtest2 bt2 = new Bindingtest2Impl();
- final AtomicReference<LogMessage> messageSupplied = new AtomicReference<>(null);
- final T2_CallbackFunc12 logCallBack = new T2_CallbackFunc12() {
+ final AtomicReference<T2_Callback12LogMessage> messageExpected = new AtomicReference<>(null);
+ final AtomicReference<String> messageReturned = new AtomicReference<>(null);
+ final T2_CallbackFunc12a logCallBack = new T2_CallbackFunc12a() {
@Override
- public void callback(final LogMessage usrParam) {
- Assert.assertEquals(messageSupplied.get(), usrParam);
+ public void callback(final T2_Callback12LogMessage usrParam) {
+ assertEquals(messageExpected.get(), usrParam); // compare value, not object hash value (reference)
+ messageReturned.set("Result-"+usrParam.getMessage());
}
};
- bt2.SetLogCallBack(logCallBack);
+ bt2.SetLogCallBack12a(logCallBack);
+ messageReturned.set(null);
{
- final LogMessage logMessage = LogMessage.create();
+ final T2_Callback12LogMessage logMessage = T2_Callback12LogMessage.create();
logMessage.setCategory("TEST");
logMessage.setMessage("Example");
logMessage.setLevel(Bindingtest2.LOG_Info);
- messageSupplied.set(logMessage);
+ messageExpected.set(logMessage);
- bt2.LogCallBackInject(logMessage);
+ bt2.LogCallBack12aInject(logMessage);
+ Assert.assertEquals(messageReturned.get(), "Result-Example");
}
+ messageReturned.set(null);
{
- final LogMessage logMessage = LogMessage.create();
+ final T2_Callback12LogMessage logMessage = T2_Callback12LogMessage.create();
logMessage.setCategory("IDK");
logMessage.setMessage("John Doe is absent.");
logMessage.setLevel(Bindingtest2.LOG_Warning);
- messageSupplied.set(logMessage);
+ messageExpected.set(logMessage);
- bt2.LogCallBackInject(logMessage);
+ bt2.LogCallBack12aInject(logMessage);
+ Assert.assertEquals(messageReturned.get(), "Result-John Doe is absent.");
}
- bt2.SetLogCallBack(null);
+ bt2.SetLogCallBack12a(null);
+ messageReturned.set(null);
+ {
+ final T2_Callback12LogMessage logMessage = T2_Callback12LogMessage.create();
+ logMessage.setCategory("SANITY");
+ logMessage.setMessage("Callback is now unset");
+ logMessage.setLevel(Bindingtest2.LOG_Fatal);
+ messageExpected.set(logMessage);
+
+ bt2.LogCallBack12aInject(logMessage);
+ Assert.assertEquals(messageReturned.get(), null);
+ }
+ }
+ /**
+ * Test Bindingtest2 with T2_CallbackFunc12a JavaCallback via SetLogCallBack12a()
+ */
+ @Test
+ public void chapter12b() throws Exception {
+ final Bindingtest2 bt2 = new Bindingtest2Impl();
+
+ final AtomicReference<T2_Callback12LogMessage> messageExpected = new AtomicReference<>(null);
+ final AtomicReference<String> messageReturned = new AtomicReference<>(null);
+ final T2_CallbackFunc12b logCallBack = new T2_CallbackFunc12b() {
+ int expParam0 = 1;
+ @Override
+ public void callback(final int param0, final T2_Callback12LogMessage usrParam) {
+ assertEquals(messageExpected.get(), usrParam); // compare value, not object hash value (reference)
+ messageReturned.set("Result-"+usrParam.getMessage());
+ Assert.assertEquals(expParam0++, param0);
+ }
+ };
+ bt2.SetLogCallBack12b(logCallBack);
+ messageReturned.set(null);
{
- final LogMessage logMessage = LogMessage.create();
+ final T2_Callback12LogMessage logMessage = T2_Callback12LogMessage.create();
+ logMessage.setCategory("TEST");
+ logMessage.setMessage("Example");
+ logMessage.setLevel(Bindingtest2.LOG_Info);
+ messageExpected.set(logMessage);
+
+ bt2.LogCallBack12bInject(logMessage, 1);
+ Assert.assertEquals(messageReturned.get(), "Result-Example");
+ }
+
+ messageReturned.set(null);
+ {
+ final T2_Callback12LogMessage logMessage = T2_Callback12LogMessage.create();
+ logMessage.setCategory("IDK");
+ logMessage.setMessage("John Doe is absent.");
+ logMessage.setLevel(Bindingtest2.LOG_Warning);
+ messageExpected.set(logMessage);
+
+ bt2.LogCallBack12bInject(logMessage, 2);
+ Assert.assertEquals(messageReturned.get(), "Result-John Doe is absent.");
+ }
+
+ bt2.SetLogCallBack12b(null);
+ messageReturned.set(null);
+ {
+ final T2_Callback12LogMessage logMessage = T2_Callback12LogMessage.create();
logMessage.setCategory("SANITY");
logMessage.setMessage("Callback is now unset");
logMessage.setLevel(Bindingtest2.LOG_Fatal);
- messageSupplied.set(logMessage);
+ messageExpected.set(logMessage);
- bt2.LogCallBackInject(logMessage);
+ bt2.LogCallBack12bInject(logMessage, 3);
+ Assert.assertEquals(messageReturned.get(), null);
}
}
+ private static void assertEquals(final T2_Callback12LogMessage exp, final T2_Callback12LogMessage has) {
+ if( null == exp ) {
+ Assert.assertNull(has);
+ } else {
+ Assert.assertNotNull(has);
+ }
+ Assert.assertEquals(exp.getCategory(), has.getCategory());
+ Assert.assertEquals(exp.getMessage(), has.getMessage());
+ Assert.assertEquals(exp.getLevel(), has.getLevel());
+ }
static private String toHexString(final int v) { return "0x"+Integer.toHexString(v); }
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.c b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.c
index 66e562f..52b2124 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.c
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.c
@@ -327,17 +327,34 @@ void MessageCallback11bInject(size_t id, long val) {
//
//
-static T2_CallbackFunc12 LogCallBack = NULL;
+static T2_CallbackFunc12a LogCallBack12a = NULL;
-void SetLogCallBack(T2_CallbackFunc12 cbFunc) {
- LogCallBack = cbFunc;
+void SetLogCallBack12a(T2_CallbackFunc12a cbFunc) {
+ LogCallBack12a = cbFunc;
}
-void LogCallBackInject(const LogMessage* message) {
- if ( NULL != LogCallBack ) {
- fprintf(stderr, "XXX LogCallBackInject: func %p, message %p\n", &LogCallBack, &message);
+void LogCallBack12aInject(const T2_Callback12LogMessage* message) {
+ if ( NULL != LogCallBack12a ) {
+ fprintf(stderr, "XXX LogCallBack12aInject: func %p, message %p\n", LogCallBack12a, message);
fflush(NULL);
- (*LogCallBack)(message);
+ (*LogCallBack12a)(message);
+ }
+}
+
+//
+//
+
+static T2_CallbackFunc12b LogCallBack12b = NULL;
+
+void SetLogCallBack12b(T2_CallbackFunc12b cbFunc) {
+ LogCallBack12b = cbFunc;
+}
+
+void LogCallBack12bInject(const T2_Callback12LogMessage* message, int param0) {
+ if ( NULL != LogCallBack12b ) {
+ fprintf(stderr, "XXX LogCallBack12bInject: func %p, message %p\n", LogCallBack12b, message);
+ fflush(NULL);
+ (*LogCallBack12b)(param0, message);
}
}
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg
index 51eb0ae..e1fc193 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg
@@ -180,18 +180,24 @@ JavaCallbackDef MessageCallback11b 2 T2_CallbackFunc11 1
JavaCallbackKey MessageCallback11b 0 T2_CallbackFunc11 0
-ReturnsStringOnly LogMessage.Category
-ReturnsStringOnly LogMessage.Message
+# T2_Callback12LogMessage
+ReturnsStringOnly T2_Callback12LogMessage.Category
+ReturnsStringOnly T2_Callback12LogMessage.Message
# Begin JavaCallback
#
-# typedef void ( * T2_CallbackFunc12)(const LogMessage* usrParam);
-# void SetLogCallBack(T2_CallbackFunc12 cbFunc);
-# void LogCallBackInject(LogMessage message);
-JavaCallbackDef SetLogCallBack -1 T2_CallbackFunc12 -1
+# typedef void ( * T2_CallbackFunc12a)(const T2_Callback12LogMessage* usrParam);
+# void SetLogCallBack12a(T2_CallbackFunc12a cbFunc);
+# void LogCallBack12aInject(const T2_Callback12LogMessage* message);
+JavaCallbackDef SetLogCallBack12a -1 T2_CallbackFunc12a -1
#
# End JavaCallback
+# typedef void ( * T2_CallbackFunc12b)(int param0, const T2_Callback12LogMessage* usrParam1);
+# void SetLogCallBack12b(T2_CallbackFunc12b cbFunc);
+# void LogCallBack12bInject(const T2_Callback12LogMessage* message);
+JavaCallbackDef SetLogCallBack12b -1 T2_CallbackFunc12b -1
+
CustomCCode #include "test2.h"
Import com.jogamp.gluegen.test.junit.generation.Bindingtest2
@@ -200,7 +206,7 @@ Import com.jogamp.gluegen.test.junit.generation.T2_InitializeOptions
Import com.jogamp.gluegen.test.junit.generation.T2_ThreadAffinity
Import com.jogamp.gluegen.test.junit.generation.T2_UserData
Import com.jogamp.gluegen.test.junit.generation.T2_Callback11UserType
-Import com.jogamp.gluegen.test.junit.generation.LogMessage
+Import com.jogamp.gluegen.test.junit.generation.T2_Callback12LogMessage
Import com.jogamp.gluegen.test.junit.generation.Test4JavaCallback.ALCcontext
CustomJavaCode Bindingtest2Impl private static Bindingtest2ProcAddressTable _table = new Bindingtest2ProcAddressTable();
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.h b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.h
index ec46885..235cc14 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.h
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.h
@@ -120,15 +120,21 @@ typedef enum {
LOG_Info = 400,
LOG_Verbose = 500,
LOG_VeryVerbose = 600
-} LogLevel;
+} T2_Callback12LogLevel;
typedef struct {
const char* Category;
const char* Message;
- LogLevel Level;
-} LogMessage;
+ T2_Callback12LogLevel Level;
+} T2_Callback12LogMessage;
-typedef void ( * T2_CallbackFunc12)(const LogMessage* usrParam);
+typedef void ( * T2_CallbackFunc12a)(const T2_Callback12LogMessage* usrParam);
+
+void SetLogCallBack12a(T2_CallbackFunc12a cbFunc);
+void LogCallBack12aInject(const T2_Callback12LogMessage* message);
+
+typedef void ( * T2_CallbackFunc12b)(int param0, const T2_Callback12LogMessage* usrParam1);
+
+void SetLogCallBack12b(T2_CallbackFunc12b cbFunc);
+void LogCallBack12bInject(const T2_Callback12LogMessage* message, int param0);
-void SetLogCallBack(T2_CallbackFunc12 cbFunc);
-void LogCallBackInject(const LogMessage* message);