GlueGen: src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass4JavaCallback.java Source File

GlueGen v2.6.0 GlueGen, Native Binding Generator for Java™ (public API).

BaseClass4JavaCallback.java
Go to the documentation of this file.
1/**
2 * Copyright 2023 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.gluegen.test.junit.generation;
30
31import java.util.Set;
32import java.util.concurrent.atomic.AtomicReference;
33
34import com.jogamp.gluegen.test.junit.generation.Bindingtest2.ALBUFFERCALLBACKTYPESOFT;
35import com.jogamp.gluegen.test.junit.generation.Bindingtest2.ALEVENTPROCSOFT;
36import com.jogamp.gluegen.test.junit.generation.Bindingtest2.AlBufferCallback0Key;
37import com.jogamp.gluegen.test.junit.generation.Bindingtest2.AlEventCallback0Key;
38import com.jogamp.gluegen.test.junit.generation.Bindingtest2.AlEventCallback1Key;
39import com.jogamp.gluegen.test.junit.generation.Bindingtest2.MessageCallback11aKey;
40import com.jogamp.gluegen.test.junit.generation.Bindingtest2.MessageCallback11bKey;
41import com.jogamp.gluegen.test.junit.generation.Bindingtest2.MessageCallback13Key;
42import com.jogamp.gluegen.test.junit.generation.Bindingtest2.T2_CallbackFunc01;
43import com.jogamp.gluegen.test.junit.generation.Bindingtest2.T2_CallbackFunc11;
44import com.jogamp.gluegen.test.junit.generation.Bindingtest2.T2_CallbackFunc12a;
45import com.jogamp.gluegen.test.junit.generation.Bindingtest2.T2_CallbackFunc12b;
46import com.jogamp.gluegen.test.junit.generation.Bindingtest2.T2_CallbackFunc13;
47
48import org.junit.Assert;
49
50/**
51 * Test {@link Bindingtest2} with {@link T2_PointerStorage} instance and pointer pointer..
52 */
53 public class BaseClass4JavaCallback extends BaseClass {
54
55 private static class MyUserParam01 {
56 final long i;
57 long j;
58 public MyUserParam01(final long i) { this.i = i; j=0; }
59
60 @Override
61 public boolean equals(final Object o) {
62 if( this == o ) {
63 return true;
64 }
65 if( !(o instanceof MyUserParam01) ) {
66 return false;
67 }
68 return false; // we require identity!
69 }
70 @Override
71 public int hashCode() {
72 return System.identityHashCode(this); // we require identity!
73 }
74 }
75
76 /**
77 * Test Bindingtest2 with T2_CallbackFunc JavaCallback
78 */
79 public void chapter01(final Bindingtest2 bt2) throws Exception {
80 final long[] id_res = { -1 };
81 final String[] msg_res = { null };
82 final T2_CallbackFunc01 myCallback01 = new T2_CallbackFunc01() {
83 @Override
84 public void callback(final long id, final String msg, final Object userParam) {
85 final MyUserParam01 myUserParam = (MyUserParam01)userParam;
86 id_res[0] = id + myUserParam.i;
87 msg_res[0] = msg;
88 myUserParam.j += id_res[0];
89 System.err.println("chapter01.myCallback01: "+id+", '"+msg+"'");
90 }
91 };
92 final T2_CallbackFunc01 myCallback02 = new T2_CallbackFunc01() {
93 @Override
94 public void callback(final long id, final String msg, final Object userParam) {
95 final MyUserParam01 myUserParam = (MyUserParam01)userParam;
96 id_res[0] = id;
97 msg_res[0] = msg;
98 myUserParam.j += id_res[0];
99 System.err.println("chapter01.myCallback02: "+id+", '"+msg+"'");
100 }
101 };
102 final MyUserParam01 myUserParam01 = new MyUserParam01(10);
103 Assert.assertEquals(10, myUserParam01.i);
104 Assert.assertEquals( 0, myUserParam01.j);
105 Assert.assertEquals(false, bt2.isMessageCallback01Mapped());
106
107 bt2.MessageCallback01(myCallback01, myUserParam01);
108 Assert.assertEquals(true, bt2.isMessageCallback01Mapped());
109 Assert.assertEquals(-1, id_res[0]);
110 Assert.assertEquals(null, msg_res[0]);
111 Assert.assertEquals(10, myUserParam01.i);
112 Assert.assertEquals( 0, myUserParam01.j);
113
114 {
115 final String msgNo1 = "My First JavaCallback message";
116 bt2.InjectMessageCallback01(404, msgNo1);
117 Assert.assertEquals(404+10, id_res[0]);
118 Assert.assertEquals(msgNo1, msg_res[0]);
119 Assert.assertEquals( 10, myUserParam01.i);
120 Assert.assertEquals(404+10, myUserParam01.j);
121 }
122 final String msgNo2 = "My Second JavaCallback message";
123 {
124 bt2.InjectMessageCallback01( 42, msgNo2);
125 Assert.assertEquals( 42+10, id_res[0]);
126 Assert.assertEquals( msgNo2, msg_res[0]);
127 Assert.assertEquals( 10, myUserParam01.i);
128 Assert.assertEquals(42+10+404+10, myUserParam01.j);
129 }
130
131 // Switch the callback function
132 // The previously mapped myUserParam01 gets released and remapped to new callback
133 bt2.MessageCallback01(myCallback02, myUserParam01);
134 Assert.assertEquals(true, bt2.isMessageCallback01Mapped());
135 Assert.assertEquals( 42+10, id_res[0]);
136 Assert.assertEquals( msgNo2, msg_res[0]);
137 Assert.assertEquals( 10, myUserParam01.i);
138 Assert.assertEquals(42+10+404+10, myUserParam01.j);
139
140 final String msgNo3 = "My Third JavaCallback message";
141 {
142 bt2.InjectMessageCallback01( 1, msgNo3);
143 Assert.assertEquals( 1, id_res[0]);
144 Assert.assertEquals( msgNo3, msg_res[0]);
145 Assert.assertEquals( 10, myUserParam01.i);
146 Assert.assertEquals(1+42+10+404+10, myUserParam01.j);
147 }
148
149 // Just release the callback and mapped myUserParam01
150 bt2.MessageCallback01(null, myUserParam01);
151 Assert.assertEquals(false, bt2.isMessageCallback01Mapped());
152 {
153 final String msgNo4 = "My Fourth JavaCallback message";
154 bt2.InjectMessageCallback01( 21, msgNo4);
155 // No callback shall be received, hence old values
156 Assert.assertEquals( 1, id_res[0]);
157 Assert.assertEquals( msgNo3, msg_res[0]);
158 Assert.assertEquals( 10, myUserParam01.i);
159 Assert.assertEquals(1+42+10+404+10, myUserParam01.j);
160 }
161 }
162
163 public static class ALCcontext {
164 final long i;
165 long j;
166 int buffer;
167 boolean throwPreAction, throwPostAction;
168 public ALCcontext(final long i) { this.i = i; j=0; buffer=0; throwPreAction=false; throwPostAction=false; }
169 public ALCcontext() { this.i = 0; j=0; buffer=0; throwPreAction=false; throwPostAction=false; }
170
171 @Override
172 public boolean equals(final Object o) {
173 if( this == o ) {
174 return true;
175 }
176 if( !(o instanceof ALCcontext) ) {
177 return false;
178 }
179 return false; // we require identity!
180 }
181 @Override
182 public int hashCode() {
183 return System.identityHashCode(this); // we require identity!
184 }
185 }
186
187
188 /**
189 * Test Bindingtest2 with ALBUFFERCALLBACKTYPESOFT JavaCallback via alBufferCallback1()
190 * using the default AlBufferCallback1Key class.
191 */
192 public void chapter02(final Bindingtest2 bt2) throws Exception {
193 final long[] id_res = { -1 };
194 final ALBUFFERCALLBACKTYPESOFT myCallback01 = new ALBUFFERCALLBACKTYPESOFT() {
195 @Override
196 public void callback(final int buffer, final ALCcontext context, final int sampledata, final int numbytes) {
197 final long res = sampledata + numbytes + context.i;
198 id_res[0] = res;
199 context.j = res;
200 context.buffer = buffer;
201 System.err.println("chapter02.myCallback01: buffer "+buffer+", sampledata "+sampledata+", numbytes "+numbytes);
202 }
203 };
204 final ALBUFFERCALLBACKTYPESOFT myCallback02 = new ALBUFFERCALLBACKTYPESOFT() {
205 @Override
206 public void callback(final int buffer, final ALCcontext context, final int sampledata, final int numbytes) {
207 final long res = sampledata * numbytes + context.i;
208 id_res[0] = res;
209 context.j = res;
210 context.buffer = buffer;
211 System.err.println("chapter02.myCallback02: buffer "+buffer+", sampledata "+sampledata+", numbytes "+numbytes);
212 }
213 };
214 final int buffer1 = 1;
215 final int buffer2 = 2;
216 final int buffer3 = 3;
217 final AlBufferCallback0Key buffer1Key = new AlBufferCallback0Key(buffer1);
218 final AlBufferCallback0Key buffer2Key = new AlBufferCallback0Key(buffer2);
219 final AlBufferCallback0Key buffer3Key = new AlBufferCallback0Key(buffer3);
220 final ALCcontext context01 = new ALCcontext( 1);
221 final ALCcontext context02 = new ALCcontext( 2);
222 Assert.assertEquals( 1, context01.i);
223 Assert.assertEquals( 0, context01.j);
224 Assert.assertEquals( 0, context01.buffer);
225 Assert.assertEquals( 2, context02.i);
226 Assert.assertEquals( 0, context02.j);
227 Assert.assertEquals( 0, context02.buffer);
228
229 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer1Key));
230 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key));
231 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
232 Assert.assertEquals(0, bt2.getAlBufferCallback0Keys().size());
233
234 // 1st mapping: buffer1 -> myCallback01, context01
235 bt2.alBufferCallback0(buffer1, 0, 0, myCallback01, context01);
236 Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key));
237 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key));
238 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
239 Assert.assertEquals(context01, bt2.getAlBufferCallback0UserParam(buffer1Key));
240 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key));
241 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key));
242 Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key));
243 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer2Key));
244 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key));
245 Assert.assertEquals(1, bt2.getAlBufferCallback0Keys().size());
246 {
247 final Set<AlBufferCallback0Key> keys = bt2.getAlBufferCallback0Keys();
248 Assert.assertEquals(true, keys.contains(buffer1Key));
249 Assert.assertEquals(false, keys.contains(buffer2Key));
250 Assert.assertEquals(false, keys.contains(buffer3Key));
251 }
252
253 // 2nd mapping: buffer2 -> myCallback02, context02
254 bt2.alBufferCallback0(buffer2, 0, 0, myCallback02, context02);
255 Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key));
256 Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer2Key));
257 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
258 Assert.assertEquals(context01, bt2.getAlBufferCallback0UserParam(buffer1Key));
259 Assert.assertEquals(context02, bt2.getAlBufferCallback0UserParam(buffer2Key));
260 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key));
261 Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key));
262 Assert.assertEquals(myCallback02, bt2.getAlBufferCallback0(buffer2Key));
263 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key));
264 Assert.assertEquals(2, bt2.getAlBufferCallback0Keys().size());
265 {
266 final Set<AlBufferCallback0Key> keys = bt2.getAlBufferCallback0Keys();
267 Assert.assertEquals(true, keys.contains(buffer1Key));
268 Assert.assertEquals(true, keys.contains(buffer2Key));
269 Assert.assertEquals(false, keys.contains(buffer3Key));
270 }
271
272 {
273 final Thread thread = new Thread(new Runnable() {
274 @Override
275 public void run() {
276 bt2.alBufferCallback0Inject(buffer1, 10, 100); // buffer1 -> myCallback01, context01
277 }
278 });
279 thread.start();
280 thread.join();
281 Assert.assertEquals(10+100+1, id_res[0]);
282 Assert.assertEquals( 1, context01.i);
283 Assert.assertEquals(10+100+1, context01.j);
284 Assert.assertEquals( 1, context01.buffer);
285 Assert.assertEquals( 2, context02.i);
286 Assert.assertEquals( 0, context02.j);
287 Assert.assertEquals( 0, context02.buffer);
288 }
289 {
290 bt2.alBufferCallback0Inject(buffer2, 10, 100); // buffer2 -> myCallback02, context02
291 Assert.assertEquals(10*100+2, id_res[0]);
292 Assert.assertEquals( 1, context01.i);
293 Assert.assertEquals(10+100+1, context01.j);
294 Assert.assertEquals( 1, context01.buffer);
295 Assert.assertEquals( 2, context02.i);
296 Assert.assertEquals(10*100+2, context02.j);
297 Assert.assertEquals( 2, context02.buffer);
298 }
299
300 // Switch the callback function for buffer2 -> myCallback01, context02
301 bt2.alBufferCallback0(buffer2, 0, 0, myCallback01, context02);
302 Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key));
303 Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer2Key));
304 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
305 Assert.assertEquals(context01, bt2.getAlBufferCallback0UserParam(buffer1Key));
306 Assert.assertEquals(context02, bt2.getAlBufferCallback0UserParam(buffer2Key));
307 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key));
308 Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key));
309 Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer2Key));
310 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key));
311
312 {
313 bt2.alBufferCallback0Inject(buffer1, 11, 101); // buffer1 -> myCallback01, context01
314 Assert.assertEquals(11+101+1, id_res[0]);
315 Assert.assertEquals( 1, context01.i);
316 Assert.assertEquals(11+101+1, context01.j);
317 Assert.assertEquals( 1, context01.buffer);
318 Assert.assertEquals( 2, context02.i);
319 Assert.assertEquals(10*100+2, context02.j);
320 Assert.assertEquals( 2, context02.buffer);
321 }
322 {
323 final Thread thread = new Thread(new Runnable() {
324 @Override
325 public void run() {
326 bt2.alBufferCallback0Inject(buffer2, 1, 10); // buffer2 -> myCallback01, context02
327 }
328 });
329 thread.start();
330 thread.join();
331 Assert.assertEquals( 1+ 10+2, id_res[0]);
332 Assert.assertEquals( 1, context01.i);
333 Assert.assertEquals(11+101+1, context01.j);
334 Assert.assertEquals( 1, context01.buffer);
335 Assert.assertEquals( 2, context02.i);
336 Assert.assertEquals( 1+ 10+2, context02.j);
337 Assert.assertEquals( 2, context02.buffer);
338 }
339
340 // Just release the buffer2 callback and mapped resources
341 bt2.alBufferCallback0(buffer2, 0, 0, null, context02); // usrptr is not key, only buffer is key!
342 Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key));
343 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key));
344 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
345 Assert.assertEquals(context01, bt2.getAlBufferCallback0UserParam(buffer1Key));
346 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key));
347 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key));
348 Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key));
349 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer2Key));
350 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key));
351 Assert.assertEquals(1, bt2.getAlBufferCallback0Keys().size());
352 {
353 final Set<AlBufferCallback0Key> keys = bt2.getAlBufferCallback0Keys();
354 Assert.assertEquals(true, keys.contains(buffer1Key));
355 Assert.assertEquals(false, keys.contains(buffer2Key));
356 Assert.assertEquals(false, keys.contains(buffer3Key));
357 }
358
359 // Switch the callback function for buffer2 -> myCallback01, context02
360 {
361 // pre-condition
362 Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key));
363 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key));
364 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
365 Assert.assertEquals(context01, bt2.getAlBufferCallback0UserParam(buffer1Key));
366 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key));
367 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key));
368 Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key));
369 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer2Key));
370 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key));
371 Assert.assertEquals(1, bt2.getAlBufferCallback0Keys().size());
372 }
373 bt2.alBufferCallback0(buffer1, 0, 0, myCallback02, context02);
374 {
375 // post-state
376 Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key));
377 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key));
378 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
379 Assert.assertEquals(context02, bt2.getAlBufferCallback0UserParam(buffer1Key));
380 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key));
381 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key));
382 Assert.assertEquals(myCallback02, bt2.getAlBufferCallback0(buffer1Key));
383 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer2Key));
384 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key));
385 }
386 {
387 context01.j = 0;
388 context01.buffer = 0;
389 context02.j = 0;
390 context02.buffer = 0;
391 bt2.alBufferCallback0Inject(buffer1, 2, 10); // buffer1 -> myCallback01, context01
392 Assert.assertEquals( 2*10+2, id_res[0]);
393 Assert.assertEquals( 1, context01.i);
394 Assert.assertEquals( 0, context01.j);
395 Assert.assertEquals( 0, context01.buffer);
396 Assert.assertEquals( 2, context02.i);
397 Assert.assertEquals( 2*10+2, context02.j);
398 Assert.assertEquals( 1, context02.buffer);
399 }
400
401 // Just release the buffer1 callback and mapped resources
402 bt2.alBufferCallback0(buffer1, 0, 0, null, null); // usrptr is not key, only buffer is key!
403 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer1Key));
404 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key));
405 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
406 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer1Key));
407 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key));
408 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key));
409 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer1Key));
410 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer2Key));
411 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key));
412 Assert.assertEquals(0, bt2.getAlBufferCallback0Keys().size());
413 {
414 final Set<AlBufferCallback0Key> keys = bt2.getAlBufferCallback0Keys();
415 Assert.assertEquals(false, keys.contains(buffer1Key));
416 Assert.assertEquals(false, keys.contains(buffer2Key));
417 Assert.assertEquals(false, keys.contains(buffer3Key));
418 }
419
420 {
421 id_res[0] = 0;
422 context01.j = 0;
423 context01.buffer = 0;
424 context02.j = 0;
425 context02.buffer = 0;
426 bt2.alBufferCallback0Inject(buffer2, 1, 10); // unmapped, no change in data
427 Assert.assertEquals( 0, id_res[0]);
428 Assert.assertEquals( 1, context01.i);
429 Assert.assertEquals( 0, context01.j);
430 Assert.assertEquals( 0, context01.buffer);
431 Assert.assertEquals( 2, context02.i);
432 Assert.assertEquals( 0, context02.j);
433 Assert.assertEquals( 0, context02.buffer);
434 }
435 }
436
437 /**
438 * Test Bindingtest2 with ALBUFFERCALLBACKTYPESOFT JavaCallback via alBufferCallback1()
439 * using our custom CustomAlBufferCallback1Key class.
440 */
441 public void chapter03(final Bindingtest2 bt2) throws Exception {
442 final long[] id_res = { -1 };
443 final ALBUFFERCALLBACKTYPESOFT myCallback01 = new ALBUFFERCALLBACKTYPESOFT() {
444 @Override
445 public void callback(final int buffer, final ALCcontext context, final int sampledata, final int numbytes) {
446 final long res = sampledata + numbytes + context.i;
447 id_res[0] = res;
448 context.j = res;;
449 context.buffer = buffer;
450 System.err.println("chapter03.myCallback01: buffer "+buffer+", sampledata "+sampledata+", numbytes "+numbytes);
451 }
452 };
453 final ALBUFFERCALLBACKTYPESOFT myCallback02 = new ALBUFFERCALLBACKTYPESOFT() {
454 @Override
455 public void callback(final int buffer, final ALCcontext context, final int sampledata, final int numbytes) {
456 final long res = sampledata * numbytes + context.i;
457 id_res[0] = res;
458 context.j = res;
459 context.buffer = buffer;
460 System.err.println("chapter03.myCallback02: buffer "+buffer+", sampledata "+sampledata+", numbytes "+numbytes);
461 }
462 };
463 final int buffer1 = 1;
464 final int buffer2 = 2;
465 final int buffer3 = 3;
466 final CustomAlBufferCallback1Key buffer1Key = new CustomAlBufferCallback1Key(buffer1);
467 final CustomAlBufferCallback1Key buffer2Key = new CustomAlBufferCallback1Key(buffer2);
468 final CustomAlBufferCallback1Key buffer3Key = new CustomAlBufferCallback1Key(buffer3);
469 final ALCcontext context01 = new ALCcontext( 1);
470 final ALCcontext context02 = new ALCcontext( 2);
471 Assert.assertEquals( 1, context01.i);
472 Assert.assertEquals( 0, context01.j);
473 Assert.assertEquals( 0, context01.buffer);
474 Assert.assertEquals( 2, context02.i);
475 Assert.assertEquals( 0, context02.j);
476 Assert.assertEquals( 0, context02.buffer);
477
478 Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer1Key));
479 Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer2Key));
480 Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key));
481 Assert.assertEquals(0, bt2.getAlBufferCallback1Keys().size());
482
483 // 1st mapping: buffer1 -> myCallback01, context01
484 bt2.alBufferCallback1(context01, buffer1, 0, 0, myCallback01);
485 Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer1Key));
486 Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer2Key));
487 Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key));
488 Assert.assertEquals(context01, bt2.getAlBufferCallback1UserParam(buffer1Key));
489 Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer2Key));
490 Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer3Key));
491 Assert.assertEquals(myCallback01, bt2.getAlBufferCallback1(buffer1Key));
492 Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer2Key));
493 Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer3Key));
494 Assert.assertEquals(1, bt2.getAlBufferCallback1Keys().size());
495 {
496 final Set<CustomAlBufferCallback1Key> keys = bt2.getAlBufferCallback1Keys();
497 Assert.assertEquals(true, keys.contains(buffer1Key));
498 Assert.assertEquals(false, keys.contains(buffer2Key));
499 Assert.assertEquals(false, keys.contains(buffer3Key));
500 }
501
502 // 2nd mapping: buffer2 -> myCallback02, context02
503 bt2.alBufferCallback1(context02, buffer2, 0, 0, myCallback02);
504 Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer1Key));
505 Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer2Key));
506 Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key));
507 Assert.assertEquals(context01, bt2.getAlBufferCallback1UserParam(buffer1Key));
508 Assert.assertEquals(context02, bt2.getAlBufferCallback1UserParam(buffer2Key));
509 Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer3Key));
510 Assert.assertEquals(myCallback01, bt2.getAlBufferCallback1(buffer1Key));
511 Assert.assertEquals(myCallback02, bt2.getAlBufferCallback1(buffer2Key));
512 Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer3Key));
513 Assert.assertEquals(2, bt2.getAlBufferCallback1Keys().size());
514 {
515 final Set<CustomAlBufferCallback1Key> keys = bt2.getAlBufferCallback1Keys();
516 Assert.assertEquals(true, keys.contains(buffer1Key));
517 Assert.assertEquals(true, keys.contains(buffer2Key));
518 Assert.assertEquals(false, keys.contains(buffer3Key));
519 }
520
521 {
522 bt2.alBufferCallback1Inject(buffer1, 10, 100); // buffer1 -> myCallback01, context01
523 Assert.assertEquals(10+100+1, id_res[0]);
524 Assert.assertEquals( 1, context01.i);
525 Assert.assertEquals(10+100+1, context01.j);
526 Assert.assertEquals( 1, context01.buffer);
527 Assert.assertEquals( 2, context02.i);
528 Assert.assertEquals( 0, context02.j);
529 Assert.assertEquals( 0, context02.buffer);
530 }
531 {
532 final Thread thread = new Thread(new Runnable() {
533 @Override
534 public void run() {
535 bt2.alBufferCallback1Inject(buffer2, 10, 100); // buffer2 -> myCallback02, context02
536 }
537 });
538 thread.start();
539 thread.join();
540 Assert.assertEquals(10*100+2, id_res[0]);
541 Assert.assertEquals( 1, context01.i);
542 Assert.assertEquals(10+100+1, context01.j);
543 Assert.assertEquals( 1, context01.buffer);
544 Assert.assertEquals( 2, context02.i);
545 Assert.assertEquals(10*100+2, context02.j);
546 Assert.assertEquals( 2, context02.buffer);
547 }
548
549 // Switch the callback function for buffer2 -> myCallback01, context02
550 bt2.alBufferCallback1(context02, buffer2, 0, 0, myCallback01);
551 Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer1Key));
552 Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer2Key));
553 Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key));
554 Assert.assertEquals(context01, bt2.getAlBufferCallback1UserParam(buffer1Key));
555 Assert.assertEquals(context02, bt2.getAlBufferCallback1UserParam(buffer2Key));
556 Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer3Key));
557 Assert.assertEquals(myCallback01, bt2.getAlBufferCallback1(buffer1Key));
558 Assert.assertEquals(myCallback01, bt2.getAlBufferCallback1(buffer2Key));
559 Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer3Key));
560
561 {
562 final Thread thread = new Thread(new Runnable() {
563 @Override
564 public void run() {
565 bt2.alBufferCallback1Inject(buffer1, 11, 101); // buffer1 -> myCallback01, context01
566 }
567 });
568 thread.start();
569 thread.join();
570 Assert.assertEquals(11+101+1, id_res[0]);
571 Assert.assertEquals( 1, context01.i);
572 Assert.assertEquals(11+101+1, context01.j);
573 Assert.assertEquals( 1, context01.buffer);
574 Assert.assertEquals( 2, context02.i);
575 Assert.assertEquals(10*100+2, context02.j);
576 Assert.assertEquals( 2, context02.buffer);
577 }
578 {
579 bt2.alBufferCallback1Inject(buffer2, 1, 10); // buffer2 -> myCallback01, context02
580 Assert.assertEquals( 1+ 10+2, id_res[0]);
581 Assert.assertEquals( 1, context01.i);
582 Assert.assertEquals(11+101+1, context01.j);
583 Assert.assertEquals( 1, context01.buffer);
584 Assert.assertEquals( 2, context02.i);
585 Assert.assertEquals( 1+ 10+2, context02.j);
586 Assert.assertEquals( 2, context02.buffer);
587 }
588
589 // Just release the buffer2 callback and mapped resources
590 bt2.alBufferCallback1(context02, buffer2, 0, 0, null); // usrptr is not key, only buffer is key!
591 Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer1Key));
592 Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer2Key));
593 Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key));
594 Assert.assertEquals(context01, bt2.getAlBufferCallback1UserParam(buffer1Key));
595 Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer2Key));
596 Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer3Key));
597 Assert.assertEquals(myCallback01, bt2.getAlBufferCallback1(buffer1Key));
598 Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer2Key));
599 Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer3Key));
600 Assert.assertEquals(1, bt2.getAlBufferCallback1Keys().size());
601 {
602 final Set<CustomAlBufferCallback1Key> keys = bt2.getAlBufferCallback1Keys();
603 Assert.assertEquals(true, keys.contains(buffer1Key));
604 Assert.assertEquals(false, keys.contains(buffer2Key));
605 Assert.assertEquals(false, keys.contains(buffer3Key));
606 }
607
608 // Just release the buffer1 callback and mapped resources
609 bt2.alBufferCallback1(null, buffer1, 0, 0, null); // usrptr is not key, only buffer is key!
610 Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer1Key));
611 Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer2Key));
612 Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key));
613 Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer1Key));
614 Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer2Key));
615 Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer3Key));
616 Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer1Key));
617 Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer2Key));
618 Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer3Key));
619 Assert.assertEquals(0, bt2.getAlBufferCallback1Keys().size());
620 {
621 final Set<CustomAlBufferCallback1Key> keys = bt2.getAlBufferCallback1Keys();
622 Assert.assertEquals(false, keys.contains(buffer1Key));
623 Assert.assertEquals(false, keys.contains(buffer2Key));
624 Assert.assertEquals(false, keys.contains(buffer3Key));
625 }
626
627 {
628 bt2.alBufferCallback1Inject(buffer2, 1, 10); // unmapped, no change in data
629 Assert.assertEquals( 1+ 10+2, id_res[0]);
630 Assert.assertEquals( 1, context01.i);
631 Assert.assertEquals(11+101+1, context01.j);
632 Assert.assertEquals( 1, context01.buffer);
633 Assert.assertEquals( 2, context02.i);
634 Assert.assertEquals( 1+ 10+2, context02.j);
635 Assert.assertEquals( 2, context02.buffer);
636 }
637 }
638
639 /**
640 * Test in depth lifecycle of Bindingtest2 with ALBUFFERCALLBACKTYPESOFT JavaCallback via alBufferCallback1()
641 * using the default AlBufferCallback1Key class.
642 */
643 public void chapter04(final Bindingtest2 bt2) throws Exception {
644 final long[] id_res = { -1 };
645 final ALBUFFERCALLBACKTYPESOFT myCallback01 = new ALBUFFERCALLBACKTYPESOFT() {
646 @Override
647 public void callback(final int buffer, final ALCcontext context, final int sampledata, final int numbytes) {
648 if( context.throwPreAction ) {
649 context.throwPreAction = false;
650 throw new RuntimeException("Exception test.pre: chapter04.myCallback01");
651 }
652 final long res = sampledata + numbytes + context.i;
653 id_res[0] = res;
654 context.j = res;
655 context.buffer = buffer;
656 System.err.println("chapter04.myCallback01: buffer "+buffer+", sampledata "+sampledata+", numbytes "+numbytes);
657 if( context.throwPostAction ) {
658 context.throwPostAction = false;
659 throw new RuntimeException("Exception test.post: chapter04.myCallback01");
660 }
661 }
662 };
663 final ALBUFFERCALLBACKTYPESOFT myCallback02 = new ALBUFFERCALLBACKTYPESOFT() {
664 @Override
665 public void callback(final int buffer, final ALCcontext context, final int sampledata, final int numbytes) {
666 if( context.throwPreAction ) {
667 context.throwPreAction = false;
668 throw new RuntimeException("Exception test.pre: chapter04.myCallback02");
669 }
670 final long res = sampledata * numbytes + context.i;
671 id_res[0] = res;
672 context.j = res;
673 context.buffer = buffer;
674 System.err.println("chapter04.myCallback02: buffer "+buffer+", sampledata "+sampledata+", numbytes "+numbytes);
675 if( context.throwPostAction ) {
676 context.throwPostAction = false;
677 throw new RuntimeException("Exception test.post: chapter04.myCallback02");
678 }
679 }
680 };
681 final int buffer1 = 1;
682 final int buffer2 = 2;
683 final int buffer3 = 3;
684 final AlBufferCallback0Key buffer1Key = new AlBufferCallback0Key(buffer1);
685 final AlBufferCallback0Key buffer2Key = new AlBufferCallback0Key(buffer2);
686 final AlBufferCallback0Key buffer3Key = new AlBufferCallback0Key(buffer3);
687 final ALCcontext context01 = new ALCcontext( 1);
688 final ALCcontext context02 = new ALCcontext( 2);
689 Assert.assertEquals( 1, context01.i);
690 Assert.assertEquals( 0, context01.j);
691 Assert.assertEquals( 0, context01.buffer);
692 Assert.assertEquals( 2, context02.i);
693 Assert.assertEquals( 0, context02.j);
694 Assert.assertEquals( 0, context02.buffer);
695
696 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer1Key));
697 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key));
698 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
699 Assert.assertEquals(0, bt2.getAlBufferCallback0Keys().size());
700
701 // 1st mapping: buffer1 -> myCallback01, context01
702 bt2.alBufferCallback0(buffer1, 0, 0, myCallback01, context01);
703 Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key));
704 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key));
705 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
706 Assert.assertEquals(context01, bt2.getAlBufferCallback0UserParam(buffer1Key));
707 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key));
708 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key));
709 Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key));
710 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer2Key));
711 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key));
712 Assert.assertEquals(1, bt2.getAlBufferCallback0Keys().size());
713 {
714 final Set<AlBufferCallback0Key> keys = bt2.getAlBufferCallback0Keys();
715 Assert.assertEquals(true, keys.contains(buffer1Key));
716 Assert.assertEquals(false, keys.contains(buffer2Key));
717 Assert.assertEquals(false, keys.contains(buffer3Key));
718 }
719
720 // 2nd mapping: buffer2 -> myCallback02, context02
721 bt2.alBufferCallback0(buffer2, 0, 0, myCallback02, context02);
722 Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key));
723 Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer2Key));
724 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
725 Assert.assertEquals(context01, bt2.getAlBufferCallback0UserParam(buffer1Key));
726 Assert.assertEquals(context02, bt2.getAlBufferCallback0UserParam(buffer2Key));
727 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key));
728 Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key));
729 Assert.assertEquals(myCallback02, bt2.getAlBufferCallback0(buffer2Key));
730 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key));
731 Assert.assertEquals(2, bt2.getAlBufferCallback0Keys().size());
732 {
733 final Set<AlBufferCallback0Key> keys = bt2.getAlBufferCallback0Keys();
734 Assert.assertEquals(true, keys.contains(buffer1Key));
735 Assert.assertEquals(true, keys.contains(buffer2Key));
736 Assert.assertEquals(false, keys.contains(buffer3Key));
737 }
738
739 // Exception text post action, i.e. result as expected
740 // Continuous program flow
741 id_res[0] = -1;
742 {
743 context01.throwPostAction = true;
744 bt2.alBufferCallback0Inject(buffer1, 10, 100); // buffer1 -> myCallback01, context01
745 Assert.assertEquals(10+100+1, id_res[0]);
746 Assert.assertEquals( 1, context01.i);
747 Assert.assertEquals(10+100+1, context01.j);
748 Assert.assertEquals( 1, context01.buffer);
749 Assert.assertEquals( 2, context02.i);
750 Assert.assertEquals( 0, context02.j);
751 Assert.assertEquals( 0, context02.buffer);
752 }
753 {
754 context02.throwPostAction = true;
755 final Thread thread = new Thread(new Runnable() {
756 @Override
757 public void run() {
758 bt2.alBufferCallback0Inject(buffer2, 10, 100); // buffer2 -> myCallback02, context02
759 }
760 });
761 thread.start();
762 thread.join();
763 Assert.assertEquals(10*100+2, id_res[0]);
764 Assert.assertEquals( 1, context01.i);
765 Assert.assertEquals(10+100+1, context01.j);
766 Assert.assertEquals( 1, context01.buffer);
767 Assert.assertEquals( 2, context02.i);
768 Assert.assertEquals(10*100+2, context02.j);
769 Assert.assertEquals( 2, context02.buffer);
770 }
771
772 // Exception text pre action, i.e. result NOT as expected (unchanged)
773 // Continuous program flow
774 id_res[0] = -1;
775 {
776 context01.throwPreAction = true;
777 bt2.alBufferCallback0Inject(buffer1, 20, 200); // buffer1 -> myCallback01, context01
778 Assert.assertEquals( -1, id_res[0]);
779 Assert.assertEquals( 1, context01.i);
780 Assert.assertEquals(10+100+1, context01.j);
781 Assert.assertEquals( 1, context01.buffer);
782 Assert.assertEquals( 2, context02.i);
783 Assert.assertEquals(10*100+2, context02.j);
784 Assert.assertEquals( 2, context02.buffer);
785 }
786 {
787 context02.throwPreAction = true;
788 final Thread thread = new Thread(new Runnable() {
789 @Override
790 public void run() {
791 bt2.alBufferCallback0Inject(buffer2, 20, 200); // buffer2 -> myCallback02, context02
792 }
793 });
794 thread.start();
795 thread.join();
796 Assert.assertEquals( -1, id_res[0]);
797 Assert.assertEquals( 1, context01.i);
798 Assert.assertEquals(10+100+1, context01.j);
799 Assert.assertEquals( 1, context01.buffer);
800 Assert.assertEquals( 2, context02.i);
801 Assert.assertEquals(10*100+2, context02.j);
802 Assert.assertEquals( 2, context02.buffer);
803 }
804
805 // Just release the buffer2 callback and mapped resources
806 bt2.releaseAlBufferCallback0(buffer2Key);
807 // bt2.alBufferCallback0(buffer2, 0, 0, null, context02); // usrptr is not key, only buffer is key!
808 Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key));
809 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key));
810 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
811 Assert.assertEquals(context01, bt2.getAlBufferCallback0UserParam(buffer1Key));
812 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key));
813 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key));
814 Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key));
815 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer2Key));
816 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key));
817 Assert.assertEquals(1, bt2.getAlBufferCallback0Keys().size());
818 {
819 final Set<AlBufferCallback0Key> keys = bt2.getAlBufferCallback0Keys();
820 Assert.assertEquals(true, keys.contains(buffer1Key));
821 Assert.assertEquals(false, keys.contains(buffer2Key));
822 Assert.assertEquals(false, keys.contains(buffer3Key));
823 }
824
825 // Just release the buffer1 callback and mapped resources
826 bt2.releaseAlBufferCallback0(buffer1Key);
827 // bt2.alBufferCallback0(buffer1, 0, 0, null, null); // usrptr is not key, only buffer is key!
828 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer1Key));
829 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key));
830 Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
831 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer1Key));
832 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key));
833 Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key));
834 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer1Key));
835 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer2Key));
836 Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key));
837 Assert.assertEquals(0, bt2.getAlBufferCallback0Keys().size());
838 {
839 final Set<AlBufferCallback0Key> keys = bt2.getAlBufferCallback0Keys();
840 Assert.assertEquals(false, keys.contains(buffer1Key));
841 Assert.assertEquals(false, keys.contains(buffer2Key));
842 Assert.assertEquals(false, keys.contains(buffer3Key));
843 }
844
845 // The native callback is still registered,
846 // we 'just' pulled the resource via release*()!
847 //
848 // So we no only test no-change in data
849 // but also whether the native callback handles this case well,
850 // i.e. detects the released data-resource and *NOT* issuing the java callback.
851 // The latter would end up in a SIGSEGV otherwise!
852 //
853 // Note: After successfully checking a correct jobject reference,
854 // the native callback also enters and leaves the monitor (Object sync/lock).
855 id_res[0] = -1;
856 bt2.alBufferCallback0Inject(buffer2, 1, 10);
857 Assert.assertEquals( -1, id_res[0]);
858 Assert.assertEquals( 1, context01.i);
859 Assert.assertEquals(10+100+1, context01.j);
860 Assert.assertEquals( 1, context01.buffer);
861 Assert.assertEquals( 2, context02.i);
862 Assert.assertEquals(10*100+2, context02.j);
863 Assert.assertEquals( 2, context02.buffer);
864 }
865
866 public static class CustomAlBufferCallback1Key {
867 private final int buffer;
868 public CustomAlBufferCallback1Key(final int buffer) {
869 this.buffer = buffer;
870 }
871 @Override
872 public boolean equals(final Object o) {
873 if( this == o ) {
874 return true;
875 }
876 if( !(o instanceof CustomAlBufferCallback1Key) ) {
877 return false;
878 }
879 final CustomAlBufferCallback1Key o2 = (CustomAlBufferCallback1Key)o;
880 return buffer == o2.buffer;
881 }
882 @Override
883 public int hashCode() {
884 return buffer;
885 }
886 @Override
887 public String toString() {
888 return "CustomALKey[this "+toHexString(System.identityHashCode(this))+", buffer "+buffer+"]";
889 }
890 }
891
892 /**
893 * Test Bindingtest2 with ALEVENTPROCSOFT JavaCallback
894 * on alEventCallback0(..) having the 'Object userParam` as single key.
895 */
896 public void chapter05a(final Bindingtest2 bt2) throws Exception {
897 final int[] id_res = { -1 };
898 final String[] msg_res = { null };
899 final ALEVENTPROCSOFT myCallback01 = new ALEVENTPROCSOFT() {
900 @Override
901 public void callback(final int eventType, final int object, final int param, final String message, final ALCcontext context) {
902 id_res[0] = object;
903 msg_res[0] = message;
904 System.err.println("chapter05a.myCallback01: type "+eventType+", obj "+object+", param "+param+", '"+message+"', userParam 0x"+
905 Integer.toHexString(System.identityHashCode(context)));
906 }
907 };
908 final ALEVENTPROCSOFT myCallback02 = new ALEVENTPROCSOFT() {
909 @Override
910 public void callback(final int eventType, final int object, final int param, final String message, final ALCcontext context) {
911 id_res[0] = 1000 * object;
912 msg_res[0] = message;
913 System.err.println("chapter05a.myCallback02: type "+eventType+", obj "+object+", param "+param+", '"+message+"', userParam 0x"+
914 Integer.toHexString(System.identityHashCode(context)));
915 }
916 };
917 final ALCcontext context01 = new ALCcontext();
918 final ALCcontext context02 = new ALCcontext();
919 final AlEventCallback0Key myKey01 = new AlEventCallback0Key(context01);
920 final AlEventCallback0Key myKey02 = new AlEventCallback0Key(context02);
921 Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey01));
922 Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey02));
923
924 bt2.alEventCallback0(myCallback01, context01);
925 Assert.assertEquals(true, bt2.isAlEventCallback0Mapped(myKey01));
926 Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey02));
927 {
928 final Set<AlEventCallback0Key> keys = bt2.getAlEventCallback0Keys();
929 Assert.assertEquals(1, keys.size());
930 Assert.assertEquals(true, keys.contains(myKey01));
931 Assert.assertEquals(false, keys.contains(myKey02));
932 }
933 Assert.assertEquals(myCallback01, bt2.getAlEventCallback0(myKey01));
934 Assert.assertEquals(null, bt2.getAlEventCallback0(myKey02));
935 Assert.assertEquals(-1, id_res[0]);
936 Assert.assertEquals(null, msg_res[0]);
937
938 {
939 final String msgNo1 = "First message";
940 id_res[0] = -1;
941 msg_res[0] = null;
942 bt2.alEventCallback0Inject(context01, 0, 1, 0, msgNo1);
943 Assert.assertEquals( 1, id_res[0]);
944 Assert.assertEquals(msgNo1, msg_res[0]);
945 }
946 {
947 final String msgNo2 = "Second message";
948 id_res[0] = -1;
949 msg_res[0] = null;
950 bt2.alEventCallback0Inject(context02, 0, 2, 0, msgNo2);
951 Assert.assertEquals( -1, id_res[0]);
952 Assert.assertEquals( null, msg_res[0]);
953
954 bt2.alEventCallback0Inject(context01, 0, 2, 0, msgNo2);
955 Assert.assertEquals( 2, id_res[0]);
956 Assert.assertEquals( msgNo2, msg_res[0]);
957 }
958
959 // Switch the callback function
960 // The previously mapped myCallback01 (context01) gets released
961 // and remapped to myCallback02 + ( context01 )(key)
962 bt2.alEventCallback0(myCallback02, context01);
963 Assert.assertEquals(true, bt2.isAlEventCallback0Mapped(myKey01));
964 Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey02));
965 {
966 final Set<AlEventCallback0Key> keys = bt2.getAlEventCallback0Keys();
967 Assert.assertEquals(1, keys.size());
968 Assert.assertEquals(true, keys.contains(myKey01));
969 Assert.assertEquals(false, keys.contains(myKey02));
970 }
971 Assert.assertEquals(myCallback02, bt2.getAlEventCallback0(myKey01));
972 Assert.assertEquals(null, bt2.getAlEventCallback0(myKey02));
973
974 {
975 final String msgNo3 = "Third message";
976 id_res[0] = -1;
977 msg_res[0] = null;
978 bt2.alEventCallback0Inject(context02, 0, 3, 0, msgNo3);
979 Assert.assertEquals( -1, id_res[0]);
980 Assert.assertEquals( null, msg_res[0]);
981
982 bt2.alEventCallback0Inject(context01, 0, 3, 0, msgNo3);
983 Assert.assertEquals( 3000, id_res[0]);
984 Assert.assertEquals( msgNo3, msg_res[0]);
985 }
986
987 // Fake release (wrong key)
988 bt2.alEventCallback0(null, context02);
989 Assert.assertEquals(true, bt2.isAlEventCallback0Mapped(myKey01));
990 Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey02));
991
992 // Just release the callback and mapped context01
993 bt2.alEventCallback0(null, context01);
994 Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey01));
995 Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey02));
996 Assert.assertEquals(0, bt2.getAlEventCallback0Keys().size());
997
998 {
999 final String msgNo4 = "Forth message";
1000 id_res[0] = -1;
1001 msg_res[0] = null;
1002 bt2.alEventCallback0Inject(context01, 0, 4, 0, msgNo4);
1003 Assert.assertEquals( -1, id_res[0]);
1004 Assert.assertEquals( null, msg_res[0]);
1005
1006 bt2.alEventCallback0Inject(context02, 0, 4, 0, msgNo4);
1007 Assert.assertEquals( -1, id_res[0]);
1008 Assert.assertEquals( null, msg_res[0]);
1009 }
1010 }
1011
1012 /**
1013 * Test Bindingtest2 with ALEVENTPROCSOFT JavaCallback
1014 * on alEventCallback0(..) having the 'Object userParam` and `int object` as keys.
1015 */
1016 public void chapter05b(final Bindingtest2 bt2) throws Exception {
1017 final int[] id_res = { -1 };
1018 final String[] msg_res = { null };
1019 final ALEVENTPROCSOFT myCallback01 = new ALEVENTPROCSOFT() {
1020 @Override
1021 public void callback(final int eventType, final int object, final int param, final String message, final ALCcontext context) {
1022 id_res[0] = object;
1023 msg_res[0] = message;
1024 System.err.println("chapter05.myCallback01: type "+eventType+", obj "+object+", param "+param+", '"+message+"', userParam 0x"+
1025 Integer.toHexString(System.identityHashCode(context)));
1026 }
1027 };
1028 final ALEVENTPROCSOFT myCallback02 = new ALEVENTPROCSOFT() {
1029 @Override
1030 public void callback(final int eventType, final int object, final int param, final String message, final ALCcontext context) {
1031 id_res[0] = 1000 * object;
1032 msg_res[0] = message;
1033 System.err.println("chapter05.myCallback02: type "+eventType+", obj "+object+", param "+param+", '"+message+"', userParam 0x"+
1034 Integer.toHexString(System.identityHashCode(context)));
1035 }
1036 };
1037 final ALCcontext context01 = new ALCcontext();
1038 final ALCcontext context02 = new ALCcontext();
1039 final AlEventCallback1Key myKey01 = new AlEventCallback1Key(1, context01);
1040 final AlEventCallback1Key myKey02 = new AlEventCallback1Key(2, context02);
1041 Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey01));
1042 Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey02));
1043
1044 bt2.alEventCallback1(1, myCallback01, context01);
1045 Assert.assertEquals(true, bt2.isAlEventCallback1Mapped(myKey01));
1046 Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey02));
1047 {
1048 final Set<AlEventCallback1Key> keys = bt2.getAlEventCallback1Keys();
1049 Assert.assertEquals(1, keys.size());
1050 Assert.assertEquals(true, keys.contains(myKey01));
1051 Assert.assertEquals(false, keys.contains(myKey02));
1052 }
1053 Assert.assertEquals(myCallback01, bt2.getAlEventCallback1(myKey01));
1054 Assert.assertEquals(null, bt2.getAlEventCallback1(myKey02));
1055 Assert.assertEquals(-1, id_res[0]);
1056 Assert.assertEquals(null, msg_res[0]);
1057
1058 {
1059 final String msgNo1 = "First message";
1060 id_res[0] = -1;
1061 msg_res[0] = null;
1062 bt2.alEventCallback1Inject(context01, 0, 1, 0, msgNo1);
1063 Assert.assertEquals( 1, id_res[0]);
1064 Assert.assertEquals(msgNo1, msg_res[0]);
1065 }
1066 {
1067 final String msgNo2 = "Second message";
1068 id_res[0] = -1;
1069 msg_res[0] = null;
1070 bt2.alEventCallback1Inject(context02, 0, 2, 0, msgNo2);
1071 Assert.assertEquals( -1, id_res[0]);
1072 Assert.assertEquals( null, msg_res[0]);
1073
1074 bt2.alEventCallback1Inject(context01, 0, 2, 0, msgNo2);
1075 Assert.assertEquals( -1, id_res[0]);
1076 Assert.assertEquals( null, msg_res[0]);
1077
1078 bt2.alEventCallback1Inject(context01, 0, 1, 0, msgNo2);
1079 Assert.assertEquals( 1, id_res[0]);
1080 Assert.assertEquals( msgNo2, msg_res[0]);
1081 }
1082
1083 // Switch the callback function
1084 // The previously mapped myCallback01 (1, context01) gets released
1085 // and remapped to myCallback02 + ( 1, context01 )(key)
1086 bt2.alEventCallback1(1, myCallback02, context01);
1087 Assert.assertEquals(true, bt2.isAlEventCallback1Mapped(myKey01));
1088 Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey02));
1089 {
1090 final Set<AlEventCallback1Key> keys = bt2.getAlEventCallback1Keys();
1091 Assert.assertEquals(1, keys.size());
1092 Assert.assertEquals(true, keys.contains(myKey01));
1093 Assert.assertEquals(false, keys.contains(myKey02));
1094 }
1095 Assert.assertEquals(myCallback02, bt2.getAlEventCallback1(myKey01));
1096 Assert.assertEquals(null, bt2.getAlEventCallback1(myKey02));
1097
1098 {
1099 final String msgNo3 = "Third message";
1100 id_res[0] = -1;
1101 msg_res[0] = null;
1102 bt2.alEventCallback1Inject(context02, 0, 2, 0, msgNo3);
1103 Assert.assertEquals( -1, id_res[0]);
1104 Assert.assertEquals( null, msg_res[0]);
1105
1106 bt2.alEventCallback1Inject(context01, 0, 2, 0, msgNo3);
1107 Assert.assertEquals( -1, id_res[0]);
1108 Assert.assertEquals( null, msg_res[0]);
1109
1110 bt2.alEventCallback1Inject(context01, 0, 1, 0, msgNo3);
1111 Assert.assertEquals( 1000, id_res[0]);
1112 Assert.assertEquals( msgNo3, msg_res[0]);
1113 }
1114
1115 // Fake release (wrong key)
1116 bt2.alEventCallback1(2, null, context02);
1117 Assert.assertEquals(true, bt2.isAlEventCallback1Mapped(myKey01));
1118 Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey02));
1119
1120 bt2.alEventCallback1(2, null, context01);
1121 Assert.assertEquals(true, bt2.isAlEventCallback1Mapped(myKey01));
1122 Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey02));
1123
1124 // Just release the callback and mapped context01
1125 bt2.alEventCallback1(1, null, context01);
1126 Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey01));
1127 Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey02));
1128 Assert.assertEquals(0, bt2.getAlEventCallback1Keys().size());
1129
1130 {
1131 final String msgNo4 = "Forth message";
1132 id_res[0] = -1;
1133 msg_res[0] = null;
1134 bt2.alEventCallback1Inject(context01, 0, 4, 0, msgNo4);
1135 Assert.assertEquals( -1, id_res[0]);
1136 Assert.assertEquals( null, msg_res[0]);
1137
1138 bt2.alEventCallback1Inject(context02, 0, 4, 0, msgNo4);
1139 Assert.assertEquals( -1, id_res[0]);
1140 Assert.assertEquals( null, msg_res[0]);
1141 }
1142 }
1143
1144 /**
1145 * Test Bindingtest2 with T2_CallbackFunc11 JavaCallback via MessageCallback11a()
1146 * using the default MessageCallback11aKey class.
1147 */
1148 public void chapter11a(final Bindingtest2 bt2) throws Exception {
1149 final long userParam01Ptr = 0xAFFEBEAFC0FFEEL;
1150 final long userParam02Ptr = 0xC0FFEEDEADBEAFL;
1151
1152 final long[] id_res = { -1 };
1153 final T2_CallbackFunc11 myCallback01 = new T2_CallbackFunc11() {
1154 @Override
1155 public void callback(final long id, final T2_Callback11UserType usrParam, final long val) {
1156 Assert.assertEquals(42, usrParam.getApiVersion()); // native toolkit should have set API version
1157 if( 1 == id ) {
1158 BaseClass.assertAPTR(userParam01Ptr, usrParam.getData());
1159 } else if( 2 == id ) {
1160 BaseClass.assertAPTR(userParam02Ptr, usrParam.getData());
1161 }
1162 final long res = val + usrParam.getI();
1163 id_res[0] = res;
1164 usrParam.setR(res);
1165 usrParam.setId(id);
1166 System.err.println("chapter11a.myCallback01: id "+id+", val "+val);
1167 }
1168 };
1169 final T2_CallbackFunc11 myCallback02 = new T2_CallbackFunc11() {
1170 @Override
1171 public void callback(final long id, final T2_Callback11UserType usrParam, final long val) {
1172 Assert.assertEquals(42, usrParam.getApiVersion()); // native toolkit should have set API version
1173 if( 1 == id ) {
1174 BaseClass.assertAPTR(userParam01Ptr, usrParam.getData());
1175 } else if( 2 == id ) {
1176 BaseClass.assertAPTR(userParam02Ptr, usrParam.getData());
1177 }
1178 final long res = val * usrParam.getI();
1179 id_res[0] = res;
1180 usrParam.setR(res);
1181 usrParam.setId(id);
1182 System.err.println("chapter11a.myCallback02: id "+id+", val "+val);
1183 }
1184 };
1185 final int id1 = 1;
1186 final int id2 = 2;
1187 final int id3 = 3;
1188 final MessageCallback11aKey id1Key = new MessageCallback11aKey(id1);
1189 final MessageCallback11aKey id2Key = new MessageCallback11aKey(id2);
1190 final MessageCallback11aKey id3Key = new MessageCallback11aKey(id3);
1191 final T2_Callback11UserType userParam01 = T2_Callback11UserType.create(); // native toolkit should set API version
1192 userParam01.setData(userParam01Ptr);
1193 userParam01.setI(1);
1194 final T2_Callback11UserType userParam02 = T2_Callback11UserType.create(); // native toolkit should set API version
1195 userParam02.setData(userParam02Ptr);
1196 userParam02.setI(2);
1197 Assert.assertEquals( 1, userParam01.getI());
1198 Assert.assertEquals( 0, userParam01.getR());
1199 Assert.assertEquals( 0, userParam01.getId());
1200 Assert.assertEquals( 2, userParam02.getI());
1201 Assert.assertEquals( 0, userParam02.getR());
1202 Assert.assertEquals( 0, userParam02.getId());
1203
1204 Assert.assertEquals(false, bt2.isMessageCallback11aMapped(id1Key));
1205 Assert.assertEquals(false, bt2.isMessageCallback11aMapped(id2Key));
1206 Assert.assertEquals(false, bt2.isMessageCallback11aMapped(id3Key));
1207 Assert.assertEquals(0, bt2.getMessageCallback11aKeys().size());
1208
1209 // 1st mapping: buffer1 -> myCallback01, userParam01
1210 bt2.MessageCallback11a(id1, myCallback01, userParam01);
1211 Assert.assertEquals(true, bt2.isMessageCallback11aMapped(id1Key));
1212 Assert.assertEquals(false, bt2.isMessageCallback11aMapped(id2Key));
1213 Assert.assertEquals(false, bt2.isMessageCallback11aMapped(id3Key));
1214 Assert.assertEquals(userParam01, bt2.getMessageCallback11aUserParam(id1Key));
1215 Assert.assertEquals(null, bt2.getMessageCallback11aUserParam(id2Key));
1216 Assert.assertEquals(null, bt2.getMessageCallback11aUserParam(id3Key));
1217 Assert.assertEquals(myCallback01, bt2.getMessageCallback11a(id1Key));
1218 Assert.assertEquals(null, bt2.getMessageCallback11a(id2Key));
1219 Assert.assertEquals(null, bt2.getMessageCallback11a(id3Key));
1220 Assert.assertEquals(1, bt2.getMessageCallback11aKeys().size());
1221 {
1222 final Set<MessageCallback11aKey> keys = bt2.getMessageCallback11aKeys();
1223 Assert.assertEquals(true, keys.contains(id1Key));
1224 Assert.assertEquals(false, keys.contains(id2Key));
1225 Assert.assertEquals(false, keys.contains(id3Key));
1226 }
1227
1228 // 2nd mapping: buffer2 -> myCallback02, userParam02
1229 bt2.MessageCallback11a(id2, myCallback02, userParam02);
1230 Assert.assertEquals(true, bt2.isMessageCallback11aMapped(id1Key));
1231 Assert.assertEquals(true, bt2.isMessageCallback11aMapped(id2Key));
1232 Assert.assertEquals(false, bt2.isMessageCallback11aMapped(id3Key));
1233 Assert.assertEquals(userParam01, bt2.getMessageCallback11aUserParam(id1Key));
1234 Assert.assertEquals(userParam02, bt2.getMessageCallback11aUserParam(id2Key));
1235 Assert.assertEquals(null, bt2.getMessageCallback11aUserParam(id3Key));
1236 Assert.assertEquals(myCallback01, bt2.getMessageCallback11a(id1Key));
1237 Assert.assertEquals(myCallback02, bt2.getMessageCallback11a(id2Key));
1238 Assert.assertEquals(null, bt2.getMessageCallback11a(id3Key));
1239 Assert.assertEquals(2, bt2.getMessageCallback11aKeys().size());
1240 {
1241 final Set<MessageCallback11aKey> keys = bt2.getMessageCallback11aKeys();
1242 Assert.assertEquals(true, keys.contains(id1Key));
1243 Assert.assertEquals(true, keys.contains(id2Key));
1244 Assert.assertEquals(false, keys.contains(id3Key));
1245 }
1246
1247 {
1248 final Thread thread = new Thread(new Runnable() {
1249 @Override
1250 public void run() {
1251 bt2.MessageCallback11aInject(id1, 10); // buffer1 -> myCallback01, userParam01
1252 }
1253 });
1254 thread.start();
1255 thread.join();
1256 Assert.assertEquals( 10+1, id_res[0]);
1257 Assert.assertEquals( 1, userParam01.getI());
1258 Assert.assertEquals( 10+1, userParam01.getR());
1259 Assert.assertEquals( 1, userParam01.getId());
1260 Assert.assertEquals( 2, userParam02.getI());
1261 Assert.assertEquals( 0, userParam02.getR());
1262 Assert.assertEquals( 0, userParam02.getId());
1263 }
1264 {
1265 bt2.MessageCallback11aInject(id2, 10); // buffer2 -> myCallback02, userParam02
1266 Assert.assertEquals( 10*2, id_res[0]);
1267 Assert.assertEquals( 1, userParam01.getI());
1268 Assert.assertEquals( 10+1, userParam01.getR());
1269 Assert.assertEquals( 1, userParam01.getId());
1270 Assert.assertEquals( 2, userParam02.getI());
1271 Assert.assertEquals( 10*2, userParam02.getR());
1272 Assert.assertEquals( 2, userParam02.getId());
1273 }
1274
1275 // Switch the callback function for buffer2 -> myCallback01, userParam02
1276 bt2.MessageCallback11a(id2, myCallback01, userParam02);
1277 Assert.assertEquals(true, bt2.isMessageCallback11aMapped(id1Key));
1278 Assert.assertEquals(true, bt2.isMessageCallback11aMapped(id2Key));
1279 Assert.assertEquals(false, bt2.isMessageCallback11aMapped(id3Key));
1280 Assert.assertEquals(userParam01, bt2.getMessageCallback11aUserParam(id1Key));
1281 Assert.assertEquals(userParam02, bt2.getMessageCallback11aUserParam(id2Key));
1282 Assert.assertEquals(null, bt2.getMessageCallback11aUserParam(id3Key));
1283 Assert.assertEquals(myCallback01, bt2.getMessageCallback11a(id1Key));
1284 Assert.assertEquals(myCallback01, bt2.getMessageCallback11a(id2Key));
1285 Assert.assertEquals(null, bt2.getMessageCallback11a(id3Key));
1286
1287 {
1288 bt2.MessageCallback11aInject(id1, 11); // buffer1 -> myCallback01, userParam01
1289 Assert.assertEquals( 11+1, id_res[0]);
1290 Assert.assertEquals( 1, userParam01.getI());
1291 Assert.assertEquals( 11+1, userParam01.getR());
1292 Assert.assertEquals( 1, userParam01.getId());
1293 Assert.assertEquals( 2, userParam02.getI());
1294 Assert.assertEquals( 10*2, userParam02.getR());
1295 Assert.assertEquals( 2, userParam02.getId());
1296 }
1297 {
1298 final Thread thread = new Thread(new Runnable() {
1299 @Override
1300 public void run() {
1301 bt2.MessageCallback11aInject(id2, 22); // buffer2 -> myCallback01, userParam02
1302 }
1303 });
1304 thread.start();
1305 thread.join();
1306 Assert.assertEquals( 22+2, id_res[0]);
1307 Assert.assertEquals( 1, userParam01.getI());
1308 Assert.assertEquals( 11+1, userParam01.getR());
1309 Assert.assertEquals( 1, userParam01.getId());
1310 Assert.assertEquals( 2, userParam02.getI());
1311 Assert.assertEquals( 22+2, userParam02.getR());
1312 Assert.assertEquals( 2, userParam02.getId());
1313 }
1314
1315 // Just release the buffer2 callback and mapped resources
1316 bt2.MessageCallback11a(id2, null, userParam02); // usrptr is not key, only id is key!
1317 Assert.assertEquals(true, bt2.isMessageCallback11aMapped(id1Key));
1318 Assert.assertEquals(false, bt2.isMessageCallback11aMapped(id2Key));
1319 Assert.assertEquals(false, bt2.isMessageCallback11aMapped(id3Key));
1320 Assert.assertEquals(userParam01, bt2.getMessageCallback11aUserParam(id1Key));
1321 Assert.assertEquals(null, bt2.getMessageCallback11aUserParam(id2Key));
1322 Assert.assertEquals(null, bt2.getMessageCallback11aUserParam(id3Key));
1323 Assert.assertEquals(myCallback01, bt2.getMessageCallback11a(id1Key));
1324 Assert.assertEquals(null, bt2.getMessageCallback11a(id2Key));
1325 Assert.assertEquals(null, bt2.getMessageCallback11a(id3Key));
1326 Assert.assertEquals(1, bt2.getMessageCallback11aKeys().size());
1327 {
1328 final Set<MessageCallback11aKey> keys = bt2.getMessageCallback11aKeys();
1329 Assert.assertEquals(true, keys.contains(id1Key));
1330 Assert.assertEquals(false, keys.contains(id2Key));
1331 Assert.assertEquals(false, keys.contains(id3Key));
1332 }
1333
1334 // Just release the buffer1 callback and mapped resources
1335 bt2.MessageCallback11a(id1, null, null); // usrptr is not key, only id is key!
1336 Assert.assertEquals(false, bt2.isMessageCallback11aMapped(id1Key));
1337 Assert.assertEquals(false, bt2.isMessageCallback11aMapped(id2Key));
1338 Assert.assertEquals(false, bt2.isMessageCallback11aMapped(id3Key));
1339 Assert.assertEquals(null, bt2.getMessageCallback11aUserParam(id1Key));
1340 Assert.assertEquals(null, bt2.getMessageCallback11aUserParam(id2Key));
1341 Assert.assertEquals(null, bt2.getMessageCallback11aUserParam(id3Key));
1342 Assert.assertEquals(null, bt2.getMessageCallback11a(id1Key));
1343 Assert.assertEquals(null, bt2.getMessageCallback11a(id2Key));
1344 Assert.assertEquals(null, bt2.getMessageCallback11a(id3Key));
1345 Assert.assertEquals(0, bt2.getMessageCallback11aKeys().size());
1346 {
1347 final Set<MessageCallback11aKey> keys = bt2.getMessageCallback11aKeys();
1348 Assert.assertEquals(false, keys.contains(id1Key));
1349 Assert.assertEquals(false, keys.contains(id2Key));
1350 Assert.assertEquals(false, keys.contains(id3Key));
1351 }
1352
1353 {
1354 bt2.MessageCallback11aInject(id2, 5); // unmapped, no change in data
1355 Assert.assertEquals( 22+2, id_res[0]);
1356 Assert.assertEquals( 1, userParam01.getI());
1357 Assert.assertEquals( 11+1, userParam01.getR());
1358 Assert.assertEquals( 1, userParam01.getId());
1359 Assert.assertEquals( 2, userParam02.getI());
1360 Assert.assertEquals( 22+2, userParam02.getR());
1361 Assert.assertEquals( 2, userParam02.getId());
1362 }
1363 }
1364
1365 /**
1366 * Test Bindingtest2 with T2_CallbackFunc11 JavaCallback via MessageCallback11b()
1367 * using the default MessageCallback11bKey class.
1368 */
1369 public void chapter11b(final Bindingtest2 bt2) throws Exception {
1370 final long userParam01Ptr = 0xAFFEBEAFC0FFEEL;
1371 final long userParam02Ptr = 0xC0FFEEDEADBEAFL;
1372
1373 final long[] id_res = { -1 };
1374 final T2_CallbackFunc11 myCallback01 = new T2_CallbackFunc11() {
1375 @Override
1376 public void callback(final long id, final T2_Callback11UserType usrParam, final long val) {
1377 Assert.assertEquals(42, usrParam.getApiVersion()); // native toolkit should have set API version
1378 if( 1 == id ) {
1379 BaseClass.assertAPTR(userParam01Ptr, usrParam.getData());
1380 } else if( 2 == id ) {
1381 BaseClass.assertAPTR(userParam02Ptr, usrParam.getData());
1382 }
1383 final long res = val + id;
1384 id_res[0] = res;
1385 usrParam.setR(res);
1386 usrParam.setId(id);
1387 System.err.println("chapter11b.myCallback01: id "+id+", val "+val);
1388 }
1389 };
1390 final T2_CallbackFunc11 myCallback02 = new T2_CallbackFunc11() {
1391 @Override
1392 public void callback(final long id, final T2_Callback11UserType usrParam, final long val) {
1393 Assert.assertEquals(42, usrParam.getApiVersion()); // native toolkit should have set API version
1394 if( 1 == id ) {
1395 BaseClass.assertAPTR(userParam01Ptr, usrParam.getData());
1396 } else if( 2 == id ) {
1397 BaseClass.assertAPTR(userParam02Ptr, usrParam.getData());
1398 }
1399 final long res = val * id;
1400 id_res[0] = res;
1401 usrParam.setR(res);
1402 usrParam.setId(id);
1403 System.err.println("chapter11b.myCallback02: id "+id+", val "+val);
1404 }
1405 };
1406 final int id1 = 1;
1407 final int id2 = 2;
1408 final int id3 = 3;
1409 final MessageCallback11bKey id1Key = new MessageCallback11bKey(id1);
1410 final MessageCallback11bKey id2Key = new MessageCallback11bKey(id2);
1411 final MessageCallback11bKey id3Key = new MessageCallback11bKey(id3);
1412
1413 Assert.assertEquals(false, bt2.isMessageCallback11bMapped(id1Key));
1414 Assert.assertEquals(false, bt2.isMessageCallback11bMapped(id2Key));
1415 Assert.assertEquals(false, bt2.isMessageCallback11bMapped(id3Key));
1416 Assert.assertEquals(0, bt2.getMessageCallback11bKeys().size());
1417
1418 // 1st mapping: buffer1 -> myCallback01, userParam01Ptr
1419 bt2.MessageCallback11b(id1, myCallback01, userParam01Ptr);
1420 Assert.assertEquals(true, bt2.isMessageCallback11bMapped(id1Key));
1421 Assert.assertEquals(false, bt2.isMessageCallback11bMapped(id2Key));
1422 Assert.assertEquals(false, bt2.isMessageCallback11bMapped(id3Key));
1423 Assert.assertEquals(null, bt2.getMessageCallback11bUserParam(id2Key));
1424 Assert.assertEquals(null, bt2.getMessageCallback11bUserParam(id3Key));
1425 Assert.assertEquals(myCallback01, bt2.getMessageCallback11b(id1Key));
1426 Assert.assertEquals(null, bt2.getMessageCallback11b(id2Key));
1427 Assert.assertEquals(null, bt2.getMessageCallback11b(id3Key));
1428 Assert.assertEquals(1, bt2.getMessageCallback11bKeys().size());
1429 {
1430 final Set<MessageCallback11bKey> keys = bt2.getMessageCallback11bKeys();
1431 Assert.assertEquals(true, keys.contains(id1Key));
1432 Assert.assertEquals(false, keys.contains(id2Key));
1433 Assert.assertEquals(false, keys.contains(id3Key));
1434 }
1435
1436 // 2nd mapping: buffer2 -> myCallback02, userParam02Ptr
1437 bt2.MessageCallback11b(id2, myCallback02, userParam02Ptr);
1438 Assert.assertEquals(true, bt2.isMessageCallback11bMapped(id1Key));
1439 Assert.assertEquals(true, bt2.isMessageCallback11bMapped(id2Key));
1440 Assert.assertEquals(false, bt2.isMessageCallback11bMapped(id3Key));
1441 Assert.assertEquals(null, bt2.getMessageCallback11bUserParam(id3Key));
1442 Assert.assertEquals(null, bt2.getMessageCallback11b(id3Key));
1443 Assert.assertEquals(2, bt2.getMessageCallback11bKeys().size());
1444 {
1445 final Set<MessageCallback11bKey> keys = bt2.getMessageCallback11bKeys();
1446 Assert.assertEquals(true, keys.contains(id1Key));
1447 Assert.assertEquals(true, keys.contains(id2Key));
1448 Assert.assertEquals(false, keys.contains(id3Key));
1449 }
1450
1451 {
1452 final Thread thread = new Thread(new Runnable() {
1453 @Override
1454 public void run() {
1455 bt2.MessageCallback11bInject(id1, 10); // buffer1 -> myCallback01, userParam01
1456 }
1457 });
1458 thread.start();
1459 thread.join();
1460 Assert.assertEquals( 10+1, id_res[0]);
1461 }
1462 {
1463 bt2.MessageCallback11bInject(id2, 10); // buffer2 -> myCallback02, userParam02
1464 Assert.assertEquals( 10*2, id_res[0]);
1465 }
1466
1467 // Switch the callback function for buffer2 -> myCallback01, userParam02Ptr
1468 bt2.MessageCallback11b(id2, myCallback01, userParam02Ptr);
1469 Assert.assertEquals(true, bt2.isMessageCallback11bMapped(id1Key));
1470 Assert.assertEquals(true, bt2.isMessageCallback11bMapped(id2Key));
1471 Assert.assertEquals(false, bt2.isMessageCallback11bMapped(id3Key));
1472 Assert.assertEquals(null, bt2.getMessageCallback11bUserParam(id3Key));
1473 Assert.assertEquals(myCallback01, bt2.getMessageCallback11b(id1Key));
1474 Assert.assertEquals(myCallback01, bt2.getMessageCallback11b(id2Key));
1475 Assert.assertEquals(null, bt2.getMessageCallback11b(id3Key));
1476
1477 {
1478 bt2.MessageCallback11bInject(id1, 11); // buffer1 -> myCallback01, userParam01
1479 Assert.assertEquals( 11+1, id_res[0]);
1480 }
1481 {
1482 final Thread thread = new Thread(new Runnable() {
1483 @Override
1484 public void run() {
1485 bt2.MessageCallback11bInject(id2, 22); // buffer2 -> myCallback01, userParam02
1486 }
1487 });
1488 thread.start();
1489 thread.join();
1490 Assert.assertEquals( 22+2, id_res[0]);
1491 }
1492
1493 // Just release the buffer2 callback and mapped resources
1494 bt2.MessageCallback11b(id2, null, userParam02Ptr); // usrptr is not key, only id is key!
1495 Assert.assertEquals(true, bt2.isMessageCallback11bMapped(id1Key));
1496 Assert.assertEquals(false, bt2.isMessageCallback11bMapped(id2Key));
1497 Assert.assertEquals(false, bt2.isMessageCallback11bMapped(id3Key));
1498 Assert.assertEquals(null, bt2.getMessageCallback11bUserParam(id2Key));
1499 Assert.assertEquals(null, bt2.getMessageCallback11bUserParam(id3Key));
1500 Assert.assertEquals(myCallback01, bt2.getMessageCallback11b(id1Key));
1501 Assert.assertEquals(null, bt2.getMessageCallback11b(id2Key));
1502 Assert.assertEquals(null, bt2.getMessageCallback11b(id3Key));
1503 Assert.assertEquals(1, bt2.getMessageCallback11bKeys().size());
1504 {
1505 final Set<MessageCallback11bKey> keys = bt2.getMessageCallback11bKeys();
1506 Assert.assertEquals(true, keys.contains(id1Key));
1507 Assert.assertEquals(false, keys.contains(id2Key));
1508 Assert.assertEquals(false, keys.contains(id3Key));
1509 }
1510
1511 // Just release the buffer1 callback and mapped resources
1512 bt2.MessageCallback11b(id1, null, 0); // usrptr is not key, only id is key!
1513 Assert.assertEquals(false, bt2.isMessageCallback11bMapped(id1Key));
1514 Assert.assertEquals(false, bt2.isMessageCallback11bMapped(id2Key));
1515 Assert.assertEquals(false, bt2.isMessageCallback11bMapped(id3Key));
1516 Assert.assertEquals(null, bt2.getMessageCallback11bUserParam(id1Key));
1517 Assert.assertEquals(null, bt2.getMessageCallback11bUserParam(id2Key));
1518 Assert.assertEquals(null, bt2.getMessageCallback11bUserParam(id3Key));
1519 Assert.assertEquals(null, bt2.getMessageCallback11b(id1Key));
1520 Assert.assertEquals(null, bt2.getMessageCallback11b(id2Key));
1521 Assert.assertEquals(null, bt2.getMessageCallback11b(id3Key));
1522 Assert.assertEquals(0, bt2.getMessageCallback11bKeys().size());
1523 {
1524 final Set<MessageCallback11bKey> keys = bt2.getMessageCallback11bKeys();
1525 Assert.assertEquals(false, keys.contains(id1Key));
1526 Assert.assertEquals(false, keys.contains(id2Key));
1527 Assert.assertEquals(false, keys.contains(id3Key));
1528 }
1529
1530 {
1531 bt2.MessageCallback11bInject(id2, 5); // unmapped, no change in data
1532 Assert.assertEquals( 22+2, id_res[0]);
1533 }
1534 }
1535
1536 public static class CustomMessageCallback11Key {
1537 public CustomMessageCallback11Key() {
1538 }
1539 @Override
1540 public boolean equals(final Object o) {
1541 if( this == o ) {
1542 return true;
1543 }
1544 if( !(o instanceof CustomAlBufferCallback1Key) ) {
1545 return false;
1546 }
1547 final CustomAlBufferCallback1Key o2 = (CustomAlBufferCallback1Key)o;
1548 return true;
1549 }
1550 @Override
1551 public int hashCode() {
1552 return 0;
1553 }
1554 @Override
1555 public String toString() {
1556 return "CustomMessageCallback11Key[this "+toHexString(System.identityHashCode(this))+"]";
1557 }
1558 }
1559
1560 /**
1561 * Test Bindingtest2 with T2_CallbackFunc12a JavaCallback via SetLogCallBack12a()
1562 */
1563 public void chapter12a(final Bindingtest2 bt2) throws Exception {
1564 final AtomicReference<T2_Callback12LogMessage> messageExpected = new AtomicReference<>(null);
1565 final AtomicReference<String> messageReturned = new AtomicReference<>(null);
1566 final T2_CallbackFunc12a logCallBack = new T2_CallbackFunc12a() {
1567 @Override
1568 public void callback(final T2_Callback12LogMessage usrParam) {
1569 assertEquals(messageExpected.get(), usrParam); // compare value, not object hash value (reference)
1570 messageReturned.set("Result-"+usrParam.getMessage());
1571 }
1572 };
1573
1574 bt2.SetLogCallBack12a(logCallBack);
1575 messageReturned.set(null);
1576 {
1577 final T2_Callback12LogMessage logMessage = T2_Callback12LogMessage.create();
1578 logMessage.setCategory("TEST");
1579 logMessage.setMessage("Example");
1580 logMessage.setLevel(Bindingtest2.LOG_Info);
1581 messageExpected.set(logMessage);
1582
1583 bt2.LogCallBack12aInject(logMessage);
1584 Assert.assertEquals(messageReturned.get(), "Result-Example");
1585 }
1586
1587 messageReturned.set(null);
1588 {
1589 final T2_Callback12LogMessage logMessage = T2_Callback12LogMessage.create();
1590 logMessage.setCategory("IDK");
1591 logMessage.setMessage("John Doe is absent.");
1592 logMessage.setLevel(Bindingtest2.LOG_Warning);
1593 messageExpected.set(logMessage);
1594
1595 bt2.LogCallBack12aInject(logMessage);
1596 Assert.assertEquals(messageReturned.get(), "Result-John Doe is absent.");
1597 }
1598
1599 bt2.SetLogCallBack12a(null);
1600 messageReturned.set(null);
1601 {
1602 final T2_Callback12LogMessage logMessage = T2_Callback12LogMessage.create();
1603 logMessage.setCategory("SANITY");
1604 logMessage.setMessage("Callback is now unset");
1605 logMessage.setLevel(Bindingtest2.LOG_Fatal);
1606 messageExpected.set(logMessage);
1607
1608 bt2.LogCallBack12aInject(logMessage);
1609 Assert.assertEquals(messageReturned.get(), null);
1610 }
1611 }
1612 /**
1613 * Test Bindingtest2 with T2_CallbackFunc12a JavaCallback via SetLogCallBack12a()
1614 */
1615 public void chapter12b(final Bindingtest2 bt2) throws Exception {
1616 final AtomicReference<T2_Callback12LogMessage> expMessage = new AtomicReference<>(null);
1617 final AtomicReference<String> hasReturnedMsg = new AtomicReference<>(null);
1618 final T2_CallbackFunc12b logCallBack = new T2_CallbackFunc12b() {
1619 int expParam0 = 1;
1620 @Override
1621 public void callback(final int param0, final T2_Callback12LogMessage usrParam) {
1622 assertEquals(expMessage.get(), usrParam); // compare value, not object hash value (reference)
1623 hasReturnedMsg.set("Result-"+usrParam.getMessage());
1624 Assert.assertEquals(expParam0++, param0);
1625 }
1626 };
1627
1628 bt2.SetLogCallBack12b(logCallBack);
1629 hasReturnedMsg.set(null);
1630 {
1631 final T2_Callback12LogMessage logMessage = T2_Callback12LogMessage.create();
1632 logMessage.setCategory("TEST");
1633 logMessage.setMessage("Example");
1634 logMessage.setLevel(Bindingtest2.LOG_Info);
1635 expMessage.set(logMessage);
1636
1637 bt2.LogCallBack12bInject(logMessage, 1);
1638 Assert.assertEquals("Result-Example", hasReturnedMsg.get());
1639 }
1640
1641 hasReturnedMsg.set(null);
1642 {
1643 final T2_Callback12LogMessage logMessage = T2_Callback12LogMessage.create();
1644 logMessage.setCategory("IDK");
1645 logMessage.setMessage("John Doe is absent.");
1646 logMessage.setLevel(Bindingtest2.LOG_Warning);
1647 expMessage.set(logMessage);
1648
1649 bt2.LogCallBack12bInject(logMessage, 2);
1650 Assert.assertEquals("Result-John Doe is absent.", hasReturnedMsg.get());
1651 }
1652
1653 bt2.SetLogCallBack12b(null);
1654 hasReturnedMsg.set(null);
1655 {
1656 final T2_Callback12LogMessage logMessage = T2_Callback12LogMessage.create();
1657 logMessage.setCategory("SANITY");
1658 logMessage.setMessage("Callback is now unset");
1659 logMessage.setLevel(Bindingtest2.LOG_Fatal);
1660 expMessage.set(logMessage);
1661
1662 bt2.LogCallBack12bInject(logMessage, 3);
1663 Assert.assertEquals(null, hasReturnedMsg.get());
1664 }
1665 }
1666 private static void assertEquals(final T2_Callback12LogMessage exp, final T2_Callback12LogMessage has) {
1667 if( null == exp ) {
1668 Assert.assertNull(has);
1669 } else {
1670 Assert.assertNotNull(has);
1671 }
1672 Assert.assertEquals(exp.getCategory(), has.getCategory());
1673 Assert.assertEquals(exp.getMessage(), has.getMessage());
1674 Assert.assertEquals(exp.getLevel(), has.getLevel());
1675 }
1676
1677 /**
1678 * Test Bindingtest2 with T2_CallbackFunc13 JavaCallback via MessageCallback13()
1679 */
1680 public void chapter13(final Bindingtest2 bt2) throws Exception {
1681 //
1682 // Key 1
1683 //
1684 final AtomicReference<String> hasReturnedMsgKey1 = new AtomicReference<>(null);
1685 final T2_CallbackFunc13 callbackKey1 = new T2_CallbackFunc13() {
1686 int localCallCount = 1;
1687
1688 @Override
1689 public void callback(final String msg1, final T2_Callback13UserType info, final String msg2, final T2_Callback13UserKey1 usrParamKey1, final long usrKey2) {
1690 Assert.assertEquals(localCallCount, info.getANumber());
1691 final String strKey1 = String.valueOf( usrParamKey1.getKeyValue1() );
1692 final String strKey2 = String.valueOf( usrKey2 );
1693 Assert.assertEquals(strKey1, msg1);
1694 Assert.assertEquals(strKey2, msg2);
1695 hasReturnedMsgKey1.set("Result1-"+localCallCount+"-"+strKey1+"."+strKey2);
1696 System.err.println("Callback: "+hasReturnedMsgKey1.get());
1697 localCallCount++;
1698 }
1699 };
1700
1701 // key 1 + 1 = ibdex 2
1702 final T2_Callback13UserKey1 key1a = T2_Callback13UserKey1.create();
1703 key1a.setKeyValue1(1);
1704 final long key1b = 1;
1705 final MessageCallback13Key expKey1 = new MessageCallback13Key(key1a, key1b);
1706 bt2.MessageCallback13("a debug message - key2", callbackKey1, key1a, key1b);
1707
1708 //
1709 // Key 2
1710 //
1711 final AtomicReference<String> hasReturnedMsgKey2 = new AtomicReference<>(null);
1712 final T2_CallbackFunc13 callbackKey2 = new T2_CallbackFunc13() {
1713 int localCallCount = 1;
1714
1715 @Override
1716 public void callback(final String msg1, final T2_Callback13UserType info, final String msg2, final T2_Callback13UserKey1 usrParamKey2, final long usrKey2) {
1717 Assert.assertEquals(localCallCount, info.getANumber());
1718 final String strKey1 = String.valueOf( usrParamKey2.getKeyValue1() );
1719 final String strKey2 = String.valueOf( usrKey2 );
1720 Assert.assertEquals(strKey1, msg1);
1721 Assert.assertEquals(strKey2, msg2);
1722 hasReturnedMsgKey2.set("Result2-"+localCallCount+"-"+strKey1+"."+strKey2);
1723 System.err.println("Callback: "+hasReturnedMsgKey2.get());
1724 localCallCount++;
1725 }
1726 };
1727
1728 // key 2 + 2 = ibdex 4
1729 final T2_Callback13UserKey1 key2a = T2_Callback13UserKey1.create();
1730 key2a.setKeyValue1(2);
1731 final long key2b = 2;
1732 final MessageCallback13Key expKey2 = new MessageCallback13Key(key2a, key2b);
1733 bt2.MessageCallback13("a debug message - key2", callbackKey2, key2a, key2b);
1734
1735 // Check keys
1736 final Set<MessageCallback13Key> keys = bt2.getMessageCallback13Keys();
1737 Assert.assertNotNull(keys);
1738 Assert.assertEquals(2, keys.size());
1739 {
1740 System.err.println("XXX expKey1[key1a 0x"+Long.toHexString(key1a.getDirectBufferAddress())+", hash 0x"+Integer.toHexString(System.identityHashCode(key1a))+"]");
1741 System.err.println("XXX expKey1 hash 0x"+Integer.toHexString(expKey1.hashCode()));
1742
1743 System.err.println("XXX expKey2[key1a 0x"+Long.toHexString(key2a.getDirectBufferAddress())+", hash 0x"+Integer.toHexString(System.identityHashCode(key2a))+"]");
1744 System.err.println("XXX expKey2 hash 0x"+Integer.toHexString(expKey2.hashCode()));
1745
1746 final MessageCallback13Key[] keys0 = keys.toArray(new MessageCallback13Key[2]);
1747 Assert.assertEquals(2, keys0.length);
1748 final MessageCallback13Key hasKey1, hasKey2;
1749 if( 1 == keys0[0].usrKey2 ) {
1750 // keys0[0] -> hasKey1, keys0[1] -> hasKey2
1751 hasKey1 = keys0[0];
1752 hasKey2 = keys0[1];
1753 } else {
1754 // keys0[0] -> hasKey2, keys0[1] -> hasKey1
1755 hasKey1 = keys0[1];
1756 hasKey2 = keys0[0];
1757 }
1758 System.err.println("XXX hasKey1 hash 0x"+Integer.toHexString(hasKey1.hashCode()));
1759 System.err.println("XXX hasKey2 hash 0x"+Integer.toHexString(hasKey2.hashCode()));
1760
1761 Assert.assertEquals(key1a.getDirectBufferAddress(), hasKey1.usrParamKey1.getDirectBufferAddress());
1762 Assert.assertEquals(key1b, hasKey1.usrKey2);
1763 Assert.assertEquals(expKey1, hasKey1);
1764 Assert.assertEquals(expKey1.hashCode(), hasKey1.hashCode());
1765 final T2_CallbackFunc13 cb1 = bt2.getMessageCallback13(hasKey1);
1766 Assert.assertNotNull(cb1);
1767 final T2_Callback13UserKey1 up1 = bt2.getMessageCallback13UserParam(hasKey1);
1768 Assert.assertNotNull(up1);
1769
1770 Assert.assertEquals(key2a.getDirectBufferAddress(), hasKey2.usrParamKey1.getDirectBufferAddress());
1771 Assert.assertEquals(key2b, hasKey2.usrKey2);
1772 Assert.assertEquals(expKey2, hasKey2);
1773 Assert.assertEquals(expKey2.hashCode(), hasKey2.hashCode());
1774 final T2_CallbackFunc13 cb2 = bt2.getMessageCallback13(hasKey2);
1775 Assert.assertNotNull(cb2);
1776 final T2_Callback13UserKey1 up2 = bt2.getMessageCallback13UserParam(hasKey2);
1777 Assert.assertNotNull(up2);
1778 }
1779
1780 // Send -> Key1
1781 int key1CallCount = 1;
1782 final T2_Callback13UserType info1 = T2_Callback13UserType.create();
1783 hasReturnedMsgKey1.set(null);
1784 {
1785 final String expReturnedMsg = "Result1-"+key1CallCount+"-"+String.valueOf(key1a.getKeyValue1())+"."+String.valueOf(key1b);
1786 info1.setANumber(key1CallCount);
1787 bt2.InjectMessageCallback13(String.valueOf(key1a.getKeyValue1()), info1, String.valueOf(key1b), key1a, key1b);
1788 Assert.assertEquals(expReturnedMsg, hasReturnedMsgKey1.get());
1789 key1CallCount++;
1790 }
1791 // Send -> Key2
1792 int key2CallCount = 1;
1793 final T2_Callback13UserType info2 = T2_Callback13UserType.create();
1794 hasReturnedMsgKey2.set(null);
1795 {
1796 final String expReturnedMsg = "Result2-"+key2CallCount+"-"+String.valueOf(key2a.getKeyValue1())+"."+String.valueOf(key2b);
1797 info2.setANumber(key2CallCount);
1798 bt2.InjectMessageCallback13(String.valueOf(key2a.getKeyValue1()), info2, String.valueOf(key2b), key2a, key2b);
1799 Assert.assertEquals(expReturnedMsg, hasReturnedMsgKey2.get());
1800 key2CallCount++;
1801 }
1802
1803 // Send -> Key1
1804 hasReturnedMsgKey1.set(null);
1805 {
1806 final String expReturnedMsg = "Result1-"+key1CallCount+"-"+String.valueOf(key1a.getKeyValue1())+"."+String.valueOf(key1b);
1807 info1.setANumber(key1CallCount);
1808 bt2.InjectMessageCallback13(String.valueOf(key1a.getKeyValue1()), info1, String.valueOf(key1b), key1a, key1b);
1809 Assert.assertEquals(expReturnedMsg, hasReturnedMsgKey1.get());
1810 key1CallCount++;
1811 }
1812 // Send -> Key2
1813 hasReturnedMsgKey2.set(null);
1814 {
1815 final String expReturnedMsg = "Result2-"+key2CallCount+"-"+String.valueOf(key2a.getKeyValue1())+"."+String.valueOf(key2b);
1816 info2.setANumber(key2CallCount);
1817 bt2.InjectMessageCallback13(String.valueOf(key2a.getKeyValue1()), info2, String.valueOf(key2b), key2a, key2b);
1818 Assert.assertEquals(expReturnedMsg, hasReturnedMsgKey2.get());
1819 key2CallCount++;
1820 }
1821
1822 // Send -> Key1 -> nil
1823 bt2.MessageCallback13("turned off - key1", null, key1a, key1b);
1824 hasReturnedMsgKey1.set(null);
1825 {
1826 final String expReturnedMsg = null;
1827 info1.setANumber(key1CallCount);
1828 bt2.InjectMessageCallback13(String.valueOf(key1a.getKeyValue1()), info1, String.valueOf(key1b), key1a, key1b);
1829 Assert.assertEquals(expReturnedMsg, hasReturnedMsgKey1.get());
1830 }
1831 // Send -> Key2 -> nil
1832 bt2.MessageCallback13("turned off - key1", null, key2a, key2b);
1833 hasReturnedMsgKey2.set(null);
1834 {
1835 final String expReturnedMsg = null;
1836 info2.setANumber(key2CallCount);
1837 bt2.InjectMessageCallback13(String.valueOf(key2a.getKeyValue1()), info2, String.valueOf(key2b), key2a, key2b);
1838 Assert.assertEquals(expReturnedMsg, hasReturnedMsgKey2.get());
1839 }
1840 }
1841
1842 static private String toHexString(final int v) { return "0x"+Integer.toHexString(v); }
1843
1844}
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.ALCcontext
Definition: BaseClass4JavaCallback.java:163
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.ALCcontext.ALCcontext
ALCcontext(final long i)
Definition: BaseClass4JavaCallback.java:168
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.ALCcontext.hashCode
int hashCode()
Definition: BaseClass4JavaCallback.java:182
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.ALCcontext.ALCcontext
ALCcontext()
Definition: BaseClass4JavaCallback.java:169
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.ALCcontext.equals
boolean equals(final Object o)
Definition: BaseClass4JavaCallback.java:172
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.CustomAlBufferCallback1Key
Definition: BaseClass4JavaCallback.java:866
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.CustomAlBufferCallback1Key.equals
boolean equals(final Object o)
Definition: BaseClass4JavaCallback.java:872
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.CustomAlBufferCallback1Key.toString
String toString()
Definition: BaseClass4JavaCallback.java:887
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.CustomAlBufferCallback1Key.hashCode
int hashCode()
Definition: BaseClass4JavaCallback.java:883
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.CustomAlBufferCallback1Key.CustomAlBufferCallback1Key
CustomAlBufferCallback1Key(final int buffer)
Definition: BaseClass4JavaCallback.java:868
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.CustomMessageCallback11Key
Definition: BaseClass4JavaCallback.java:1536
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.CustomMessageCallback11Key.equals
boolean equals(final Object o)
Definition: BaseClass4JavaCallback.java:1540
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.CustomMessageCallback11Key.toString
String toString()
Definition: BaseClass4JavaCallback.java:1555
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.CustomMessageCallback11Key.CustomMessageCallback11Key
CustomMessageCallback11Key()
Definition: BaseClass4JavaCallback.java:1537
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.CustomMessageCallback11Key.hashCode
int hashCode()
Definition: BaseClass4JavaCallback.java:1551
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback
Test Bindingtest2 with T2_PointerStorage instance and pointer pointer.
Definition: BaseClass4JavaCallback.java:53
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.chapter04
void chapter04(final Bindingtest2 bt2)
Test in depth lifecycle of Bindingtest2 with ALBUFFERCALLBACKTYPESOFT JavaCallback via alBufferCallba...
Definition: BaseClass4JavaCallback.java:643
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.chapter03
void chapter03(final Bindingtest2 bt2)
Test Bindingtest2 with ALBUFFERCALLBACKTYPESOFT JavaCallback via alBufferCallback1() using our custom...
Definition: BaseClass4JavaCallback.java:441
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.chapter05a
void chapter05a(final Bindingtest2 bt2)
Test Bindingtest2 with ALEVENTPROCSOFT JavaCallback on alEventCallback0(..) having the 'Object userPa...
Definition: BaseClass4JavaCallback.java:896
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.chapter11b
void chapter11b(final Bindingtest2 bt2)
Test Bindingtest2 with T2_CallbackFunc11 JavaCallback via MessageCallback11b() using the default Mess...
Definition: BaseClass4JavaCallback.java:1369
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.chapter13
void chapter13(final Bindingtest2 bt2)
Test Bindingtest2 with T2_CallbackFunc13 JavaCallback via MessageCallback13()
Definition: BaseClass4JavaCallback.java:1680
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.chapter05b
void chapter05b(final Bindingtest2 bt2)
Test Bindingtest2 with ALEVENTPROCSOFT JavaCallback on alEventCallback0(..) having the 'Object userPa...
Definition: BaseClass4JavaCallback.java:1016
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.chapter01
void chapter01(final Bindingtest2 bt2)
Test Bindingtest2 with T2_CallbackFunc JavaCallback.
Definition: BaseClass4JavaCallback.java:79
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.chapter11a
void chapter11a(final Bindingtest2 bt2)
Test Bindingtest2 with T2_CallbackFunc11 JavaCallback via MessageCallback11a() using the default Mess...
Definition: BaseClass4JavaCallback.java:1148
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.chapter02
void chapter02(final Bindingtest2 bt2)
Test Bindingtest2 with ALBUFFERCALLBACKTYPESOFT JavaCallback via alBufferCallback1() using the defaul...
Definition: BaseClass4JavaCallback.java:192
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.chapter12a
void chapter12a(final Bindingtest2 bt2)
Test Bindingtest2 with T2_CallbackFunc12a JavaCallback via SetLogCallBack12a()
Definition: BaseClass4JavaCallback.java:1563
com.jogamp.gluegen.test.junit.generation.BaseClass4JavaCallback.chapter12b
void chapter12b(final Bindingtest2 bt2)
Test Bindingtest2 with T2_CallbackFunc12a JavaCallback via SetLogCallBack12a()
Definition: BaseClass4JavaCallback.java:1615
com.jogamp.gluegen.test.junit.generation.BaseClass
Definition: BaseClass.java:51
com.jogamp.gluegen.test.junit.generation.BaseClass.assertAPTR
static void assertAPTR(final long expected, final long actual)
Definition: BaseClass.java:1091