Skip to content

Commit

Permalink
Add default callback test
Browse files Browse the repository at this point in the history
  • Loading branch information
xpenatan committed Sep 1, 2024
1 parent 4e4ffab commit e1c3442
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.xpenatan.jparser.example.testlib.CallbackClass;
import com.github.xpenatan.jparser.example.testlib.CallbackClassManual;
import com.github.xpenatan.jparser.example.testlib.DefaultCallbackClass;
import com.github.xpenatan.jparser.example.testlib.TestCallbackClass;
import com.github.xpenatan.jparser.example.testlib.TestConstructorClass;
import com.github.xpenatan.jparser.example.testlib.TestMethodClass;
Expand Down Expand Up @@ -317,6 +318,23 @@ public int onIntCallback(int intValue01, int intValue02) {
}
test.dispose();
}
{
TestCallbackClass test = new TestCallbackClass();
try {
test.set_intValue01(10);
test.set_intValue02(3);
CallbackClass callback = new DefaultCallbackClass();
int value = test.callIntCallback(callback);
if(!(value == 7)) {
throw new RuntimeException("value == 7");
}
} catch(Throwable e) {
e.printStackTrace();
test.dispose();
return false;
}
test.dispose();
}
{
TestCallbackClass test = new TestCallbackClass();
try {
Expand Down
8 changes: 4 additions & 4 deletions example/lib/lib-build/src/main/cpp/TestLib.idl
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ interface CallbackClassManualImpl {
};
CallbackClassManualImpl implements CallbackClassManual;

//interface DefaultCallbackClass {
// void DefaultCallbackClass();
//};
//DefaultCallbackClass implements CallbackClass;
interface DefaultCallbackClass {
void DefaultCallbackClass();
};
DefaultCallbackClass implements CallbackClass;

//[JSImplementation="DefaultCallbackClass"]
//interface DefaultCallbackClassImpl {
Expand Down
36 changes: 19 additions & 17 deletions example/lib/lib-build/src/main/cpp/source/TestLib/src/TestLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,23 +278,6 @@ class CallbackClass
}
};

class CallbackClassManual
{
public:
virtual ~CallbackClassManual() {}

virtual void onVoidCallback(TestObjectClass& refData, TestObjectClass* pointerData) const = 0;
virtual int onIntCallback(int intValue01, int intValue02) const = 0;
virtual float onFloatCallback(float floatValue01, float Value02) const = 0;
virtual bool onBoolCallback(bool boolValue01) const = 0;
virtual void onStringCallback(const char* strValue01) const = 0;

int addInt(int a, int b)
{
return a + b;
}
};

class DefaultCallbackClass : public CallbackClass
{
public:
Expand Down Expand Up @@ -324,6 +307,25 @@ class DefaultCallbackClass : public CallbackClass
virtual unsigned short onUnsignedShortCallback(unsigned short unsignedShort) const {
return 20;
}
virtual void onAnyCallback(void * anyPtr) const {
}
};

class CallbackClassManual
{
public:
virtual ~CallbackClassManual() {}

virtual void onVoidCallback(TestObjectClass& refData, TestObjectClass* pointerData) const = 0;
virtual int onIntCallback(int intValue01, int intValue02) const = 0;
virtual float onFloatCallback(float floatValue01, float Value02) const = 0;
virtual bool onBoolCallback(bool boolValue01) const = 0;
virtual void onStringCallback(const char* strValue01) const = 0;

int addInt(int a, int b)
{
return a + b;
}
};

class TestCallbackClass {
Expand Down

0 comments on commit e1c3442

Please sign in to comment.