1 /*
 2  * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 5  * This code is free software; you can redistribute it and/or modify it
 6  * under the terms of the GNU General Public License version 2 only, as
 7  * published by the Free Software Foundation.
 8  *
 9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 import org.testng.annotations.Test;
25 import jdk.incubator.foreign.CLinker;
26 import jdk.incubator.foreign.MemoryAddress;
27 import jdk.incubator.foreign.MemorySegment;
28 import jdk.incubator.foreign.ResourceScope;
29 import static org.testng.Assert.assertEquals;
30 import static org.testng.Assert.assertTrue;
31 import static test.jextract.test8253102.test8253102_h.*;
32 import test.jextract.test8253102.*;
33 
34 /*
35  * @test id=classes
36  * @bug 8253102
37  * @summary jextract should emit address to segment utility method on struct classes
38  * @library ..
39  * @modules jdk.incubator.jextract
40  * @run driver JtregJextract -l Test8253102 -t test.jextract.test8253102 -- test8253102.h
41  * @run testng/othervm --enable-native-access=jdk.incubator.jextract,ALL-UNNAMED LibTest8253102Test
42  */
43 /*
44  * @test id=sources
45  * @bug 8253102
46  * @summary jextract should emit address to segment utility method on struct classes
47  * @library ..
48  * @modules jdk.incubator.jextract
49  * @run driver JtregJextractSources -l Test8253102 -t test.jextract.test8253102 -- test8253102.h
50  * @run testng/othervm --enable-native-access=jdk.incubator.jextract,ALL-UNNAMED LibTest8253102Test
51  */
52 public class LibTest8253102Test {
53     @Test
54     public void test() {
55         try (ResourceScope scope = ResourceScope.newConfinedScope()) {
56             MemoryAddress addr = make(14, 99);
57             MemorySegment seg = Point.ofAddress(addr, scope);
58             assertEquals(Point.x$get(seg), 14);
59             assertEquals(Point.y$get(seg), 99);
60             freePoint(addr);
61         }
62     }
63 }