Skip to content

Commit

Permalink
Add test for non-varargs with type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Jan 5, 2022
1 parent e48075b commit bde8cb8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/test/java/jnr/ffi/VarargsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

public class VarargsTest {
public static interface C {
@Variadic(fixedCount = 3)
public int snprintf(Pointer buffer, @size_t long bufferSize, String format, @size_t int value);
@Variadic(fixedCount = 3)
public int snprintf(Pointer buffer, @size_t long bufferSize, String format, long value);
public int snprintf(Pointer buffer, @size_t long bufferSize, String format, Object... varargs);
Expand Down Expand Up @@ -52,10 +54,16 @@ public static void tearDownClass() throws Exception {

@Test public void testSizeTNoVarargs() {
Pointer ptr = Runtime.getRuntime(c).getMemoryManager().allocate(5000);
int size = c.snprintf(ptr, 5000, "%zu", 12345);
int size = c.snprintf(ptr, 5000, "%zu", 12345L);
assertEquals(5, size);
String result = ptr.getString(0, size, Charset.defaultCharset());
assertEquals("12345", result);

// int form with size_t annotation
size = c.snprintf(ptr, 5000, "%zu", 12345);
assertEquals(5, size);
result = ptr.getString(0, size, Charset.defaultCharset());
assertEquals("12345", result);
}

@Test public void testMetaAscii() throws UnsupportedEncodingException {
Expand Down

0 comments on commit bde8cb8

Please sign in to comment.