This repository has been archived by the owner on May 1, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move fbjni tests into fbjni directory (#2)
Summary: Pull Request resolved: facebookincubator/fbjni#2 Want these to be included in Open Source fbjni. Reviewed By: passy Differential Revision: D17139151 fbshipit-source-id: 18d549fa4cbcc6860e9804abe2b8acdeb405d082
- Loading branch information
1 parent
b4daa6b
commit 12165e3
Showing
25 changed files
with
4,848 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.facebook"> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
|
||
package com.facebook.jni; | ||
|
||
import com.facebook.soloader.SoLoader; | ||
import org.junit.BeforeClass; | ||
import org.junit.Rule; | ||
import org.junit.rules.ExpectedException; | ||
|
||
public class BaseFBJniTests { | ||
@Rule public ExpectedException thrown = ExpectedException.none(); | ||
|
||
@BeforeClass | ||
public static void setup() { | ||
// Explicitly load fbjni to ensure that its JNI_OnLoad is run. | ||
SoLoader.loadLibrary("fbjni"); | ||
SoLoader.loadLibrary("fbjni-tests"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
|
||
package com.facebook.jni; | ||
|
||
import static org.fest.assertions.api.Assertions.assertThat; | ||
|
||
import java.nio.Buffer; | ||
import java.nio.ByteBuffer; | ||
import java.nio.ByteOrder; | ||
import java.nio.FloatBuffer; | ||
import org.junit.Test; | ||
|
||
public class ByteBufferTests extends BaseFBJniTests { | ||
@Test | ||
public void testDirectByteBuffer() { | ||
assertThat(nativeTestDirectByteBuffer()).isTrue(); | ||
} | ||
|
||
public static native boolean nativeTestDirectByteBuffer(); | ||
|
||
@Test | ||
public void testEmptyDirectByteBuffer() { | ||
assertThat(nativeTestEmptyDirectByteBuffer()).isTrue(); | ||
} | ||
|
||
public static native boolean nativeTestEmptyDirectByteBuffer(); | ||
|
||
@Test | ||
public void testRewindBuffer() { | ||
assertThat(nativeTestRewindBuffer()).isTrue(); | ||
} | ||
|
||
public native boolean nativeTestRewindBuffer(); | ||
|
||
@Test | ||
public void testAllocateDirect() { | ||
ByteBuffer buffer = nativeAllocateDirect(5); | ||
assertThat(buffer.isDirect()).isTrue(); | ||
assertThat(buffer.capacity()).isEqualTo(5); | ||
} | ||
|
||
public native ByteBuffer nativeAllocateDirect(int size); | ||
|
||
// called from native | ||
public static void writeBytes(ByteBuffer dest, byte a, byte b, byte c, byte d) { | ||
dest.put(a).put(b).put(c).put(d); | ||
} | ||
|
||
@Test | ||
public void testFloatBuffer() { | ||
final int BUFFER_COUNT = 5; | ||
final int FLOAT_SIZE = 4; | ||
FloatBuffer buffer = | ||
ByteBuffer.allocateDirect(BUFFER_COUNT * FLOAT_SIZE) | ||
.order(ByteOrder.nativeOrder()) | ||
.asFloatBuffer(); | ||
buffer.put(1f); | ||
buffer.put(2f); | ||
buffer.put(2.5f); | ||
buffer.put(2.75f); | ||
buffer.put(3f); | ||
assertThat(nativeTestFloatBuffer(buffer)).isTrue(); | ||
} | ||
|
||
public native boolean nativeTestFloatBuffer(Buffer buffer); | ||
} |
Oops, something went wrong.