Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Commit

Permalink
Move fbjni tests into fbjni directory (#2)
Browse files Browse the repository at this point in the history
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
dreiss authored and facebook-github-bot committed Sep 4, 2019
1 parent b4daa6b commit 12165e3
Show file tree
Hide file tree
Showing 25 changed files with 4,848 additions and 1 deletion.
2 changes: 1 addition & 1 deletion deps/fbjni/BUCK
Expand Up @@ -59,7 +59,7 @@ profilo_oss_xplat_cxx_library(
profilo_oss_android_library(
name = "fbjni-java",
srcs = glob([
"**/*.java",
"java/**/*.java",
]),
visibility = [
"PUBLIC",
Expand Down
4 changes: 4 additions & 0 deletions deps/fbjni/test/AndroidManifest.xml
@@ -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>
19 changes: 19 additions & 0 deletions deps/fbjni/test/BaseFBJniTests.java
@@ -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");
}
}
66 changes: 66 additions & 0 deletions deps/fbjni/test/ByteBufferTests.java
@@ -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);
}

0 comments on commit 12165e3

Please sign in to comment.