Skip to content

Commit

Permalink
Add test for int to boolean conversion working like C. See #123.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Jun 6, 2017
1 parent f39d290 commit 4697272
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/test/java/jnr/ffi/NumberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,16 @@ public static interface TestLib {
}
static TestLib testlib;

public static interface TestBoolean {

public boolean ret_int32_t(int l);
}
static TestBoolean testboolean;

@BeforeClass
public static void setUpClass() throws Exception {
testlib = TstUtil.loadTestLib(TestLib.class);
testboolean = TstUtil.loadTestLib(TestBoolean.class);
}

@AfterClass
Expand Down Expand Up @@ -343,4 +350,11 @@ public long n(long i1, long i2) {
@Test public void testZeroExtension() throws Exception {
assertEquals("upper 32 bits not set to zero", 0xdeadbeefL, testlib.ret_uint32_t(0xfee1deadbeefL));
}

@Test public void testBooleanFromInt() throws Exception {
assertEquals(false, testboolean.ret_int32_t(0));
assertEquals(true, testboolean.ret_int32_t(-1));
assertEquals(true, testboolean.ret_int32_t(1));
assertEquals(true, testboolean.ret_int32_t(2));
}
}

0 comments on commit 4697272

Please sign in to comment.