GlueGen v2.6.0-rc-20250712
GlueGen, Native Binding Generator for Java™ (public API).
BaseClass2FuncPtr.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 org.junit.Assert;
32
33/**
34 * Test {@link Bindingtest2} with {@link T2_InitializeOptions} instance and function pointer...
35 */
36public class BaseClass2FuncPtr extends BaseClass {
37
38 /**
39 * Test Bindingtest2 with T2_InitializeOptions instance and function pointer
40 */
41 public void chapter01(final Bindingtest2 bt2) throws Exception {
42 final T2_InitializeOptions options = T2_InitializeOptions.create();
43 Assert.assertEquals(true, options.isOverrideThreadAffinityNull());
44 Assert.assertEquals(true, options.isProductNameNull());
45 Assert.assertEquals(true, options.isProductVersionNull());
46 Assert.assertEquals(0, options.getCustomFuncA1());
47 Assert.assertEquals(0, options.getCustomFuncA2());
48 Assert.assertEquals(0, options.getCustomFuncB1());
49 Assert.assertEquals(0, options.getCustomFuncB2());
50
51 bt2.Initialize(options);
52 Assert.assertEquals(true, options.isOverrideThreadAffinityNull());
53 Assert.assertEquals(false, options.isProductNameNull());
54 Assert.assertEquals(false, options.isProductVersionNull());
55 Assert.assertNotEquals(0, options.getCustomFuncA1());
56 Assert.assertNotEquals(0, options.getCustomFuncA2());
57 Assert.assertNotEquals(0, options.getCustomFuncB1());
58 Assert.assertNotEquals(0, options.getCustomFuncB2());
59 Assert.assertEquals(1, options.getApiVersion());
60 // dropped: Assert.assertEquals(1, T2_InitializeOptions.getReserved1ElemCount());
61 BaseClass.assertAPTR(0x0000CAFFEEBEEFL, options.getReserved1());
62 {
63 options.setReserved1(0xBEEFCAFFEE0DADL);
64 BaseClass.assertAPTR(0xBEEFCAFFEE0DADL, options.getReserved1());
65 }
66 Assert.assertEquals("Product Name", options.getProductName());
67 Assert.assertEquals("Product Version", options.getProductVersion());
68 Assert.assertEquals(0xa001, options.CustomFuncA1(0));
69 Assert.assertEquals(0xa002, options.CustomFuncA2(0));
70 final T2_UserData ud1 = T2_UserData.create();
71 {
72 ud1.setBalance(101);
73 ud1.setName("John Doe");
74 Assert.assertEquals(101, ud1.getBalance());
75 Assert.assertEquals("John Doe", ud1.getName());
76 }
77 final T2_UserData ud2 = T2_UserData.create();
78 {
79 ud2.setBalance(404);
80 ud2.setName("Jane Doe");
81 Assert.assertEquals(404, ud2.getBalance());
82 Assert.assertEquals("Jane Doe", ud2.getName());
83 }
84 // Check func-ptr are original
85 {
86 final long[] funcBOrigs = options.getCustomFuncBVariants(0, new long[2], 0, 2);
87 final long funcB1 = options.getCustomFuncB1();
88 final long funcB2 = options.getCustomFuncB2();
89 Assert.assertEquals(funcBOrigs[0], funcB1);
90 Assert.assertEquals(funcBOrigs[1], funcB2);
91 }
92 Assert.assertEquals(101, options.CustomFuncB1(ud1));
93 Assert.assertEquals(404, options.CustomFuncB1(ud2));
94 Assert.assertEquals(-101, options.CustomFuncB2(ud1));
95 Assert.assertEquals(-404, options.CustomFuncB2(ud2));
96 // switch functions
97 {
98 final long funcB1 = options.getCustomFuncB1();
99 final long funcB2 = options.getCustomFuncB2();
100 options.setCustomFuncB1(funcB2);
101 options.setCustomFuncB2(funcB1);
102 }
103 // Check func-ptr are switched
104 {
105 final long[] funcBOrigs = options.getCustomFuncBVariants(0, new long[2], 0, 2);
106 final long funcB1 = options.getCustomFuncB1();
107 final long funcB2 = options.getCustomFuncB2();
108 Assert.assertEquals(funcBOrigs[1], funcB1);
109 Assert.assertEquals(funcBOrigs[0], funcB2);
110 }
111 Assert.assertEquals(-101, options.CustomFuncB1(ud1));
112 Assert.assertEquals(-404, options.CustomFuncB1(ud2));
113 Assert.assertEquals(101, options.CustomFuncB2(ud1));
114 Assert.assertEquals(404, options.CustomFuncB2(ud2));
115
116 bt2.Release(options);
117 Assert.assertEquals(true, options.isOverrideThreadAffinityNull());
118 Assert.assertEquals(true, options.isProductNameNull());
119 Assert.assertEquals(true, options.isProductVersionNull());
120 Assert.assertEquals(0, options.getCustomFuncA1());
121 // const Assert.assertEquals(0, options.getCustomFuncA2());
122 Assert.assertEquals(0, options.getCustomFuncB1());
123 Assert.assertEquals(0, options.getCustomFuncB2());
124 }
125
126}
Test Bindingtest2 with T2_InitializeOptions instance and function pointer...
void chapter01(final Bindingtest2 bt2)
Test Bindingtest2 with T2_InitializeOptions instance and function pointer.
static void assertAPTR(final long expected, final long actual)