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 jdk.incubator.foreign.ResourceScope; 25 import jdk.incubator.foreign.SegmentAllocator; 26 import org.testng.annotations.Test; 27 28 import jdk.incubator.foreign.MemorySegment; 29 30 import static org.testng.Assert.assertEquals; 31 import static test.jextract.printf.printf_h.*; 32 import static jdk.incubator.foreign.CLinker.*; 33 34 /* 35 * @test id=classes 36 * @bug 8244959 37 * @summary Jextract's VarargsInvoker fails to link functions when passing integer types other than long 38 * @library .. 39 * @modules jdk.incubator.jextract 40 * @run driver JtregJextract -t test.jextract.printf -l Printf -- printf.h 41 * @run testng/othervm --enable-native-access=jdk.incubator.jextract,ALL-UNNAMED Test8244959 42 */ 43 /* 44 * @test id=sources 45 * @bug 8244959 46 * @summary Jextract's VarargsInvoker fails to link functions when passing integer types other than long 47 * @library .. 48 * @modules jdk.incubator.jextract 49 * @run driver JtregJextractSources -t test.jextract.printf -l Printf -- printf.h 50 * @run testng/othervm --enable-native-access=jdk.incubator.jextract,ALL-UNNAMED Test8244959 51 */ 52 public class Test8244959 { 53 @Test 54 public void testsPrintf() { 55 try (ResourceScope scope = ResourceScope.newConfinedScope()) { 56 var allocator = SegmentAllocator.newNativeArena(scope); 57 MemorySegment s = allocator.allocate(1024); 58 my_sprintf(s, 59 allocator.allocateUtf8String("%hhd %c %.2f %.2f %lld %lld %d %hd %d %d %lld %c"), 12, 60 (byte) 1, 'b', -1.25f, 5.5d, -200L, Long.MAX_VALUE, (byte) -2, (short) 2, 3, (short) -4, 5L, 'a'); 61 String str = s.getUtf8String(0); 62 assertEquals(str, "1 b -1.25 5.50 -200 " + Long.MAX_VALUE + " -2 2 3 -4 5 a"); 63 } 64 } 65 }