Skip to content

Commit be84265

Browse files
committed
BridJ: unsuccessful attempt to reproduce issue #530
1 parent 6873d82 commit be84265

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

src/test/cpp/test/test.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,3 +617,18 @@ TEST_API int deleteMyUnknownStruct(MyUnknownStruct *s) {
617617
TEST_API double callCallback(float (*cb)(int, long long), short a, char b) {
618618
return cb(a, b);
619619
}
620+
621+
Hello::Hello(const int& a, const int& b) {
622+
this->a = a;
623+
this->b = b;
624+
}
625+
int Hello::Sum() {
626+
return a + b;
627+
}
628+
629+
TEST_API Hello* NewHello(int a, int b) {
630+
return new Hello(a, b);
631+
}
632+
TEST_API int Sum(Hello* h) {
633+
return h->Sum();
634+
}

src/test/cpp/test/test.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,17 @@ TEST_API int deleteMyUnknownStruct(MyUnknownStruct *s);
177177

178178
TEST_API char* incrPointer(char* ptr);
179179

180+
class TEST_API Hello
181+
{
182+
public:
183+
Hello(const int& a, const int& b);
184+
~Hello();
185+
186+
int Sum();
187+
private:
188+
int a;
189+
int b;
190+
};
191+
192+
180193
#endif // _TEST_H

src/test/java/org/bridj/CPPTest2.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@
3030
*/
3131
package org.bridj;
3232
import java.io.File;
33+
import org.bridj.ann.Constructor;
3334
import org.bridj.ann.Library;
3435
import org.bridj.ann.Virtual;
3536
import org.bridj.cpp.CPPObject;
3637

3738
import org.bridj.*;
3839
import static org.bridj.Pointer.*;
40+
import org.bridj.ann.Field;
3941
import org.junit.Test;
4042
import static org.junit.Assert.*;
4143
import org.junit.Ignore;
@@ -109,4 +111,28 @@ public int add(int a, int b) {
109111
};
110112
assertEquals(210, testIVirtualAdd(getPointer(v), 1, 2));
111113
}
114+
115+
public static class Hello extends CPPObject {
116+
@Constructor(0)
117+
public Hello(Pointer<Integer> a, Pointer<Integer> b) {
118+
super((Void)null, 0, a, b);
119+
}
120+
public native int Sum();
121+
@Field(0)
122+
public int a() {
123+
return io.getIntField(this, 0);
124+
}
125+
@Field(1)
126+
public int b() {
127+
return io.getIntField(this, 1);
128+
}
129+
}
130+
131+
@Test
132+
public void testHello() {
133+
Hello h = new Hello(pointerToInt(1), pointerToInt(2));
134+
assertEquals(1, h.a());
135+
assertEquals(2, h.b());
136+
assertEquals(3, h.Sum());
137+
}
112138
}

0 commit comments

Comments
 (0)