Add tests for java jni bindings
Summary: Add tests for java jni integration Reviewed By: lucasr Differential Revision: D4008411 fbshipit-source-id: c896a3925ff3f7fa368176a3d03c84eb7188ef60
This commit is contained in:
committed by
Facebook Github Bot
parent
8939bcb96d
commit
df6b4d3682
@@ -9,6 +9,11 @@ GTEST_TARGET = '//lib/gtest:gtest'
|
|||||||
GTEST_DL_URL = 'https://github.com/google/googletest/archive/release-1.7.0.zip'
|
GTEST_DL_URL = 'https://github.com/google/googletest/archive/release-1.7.0.zip'
|
||||||
JNI_DEPS = ['//lib/fb:fbjni']
|
JNI_DEPS = ['//lib/fb:fbjni']
|
||||||
|
|
||||||
|
CXX_LIBRARY_WHITELIST = [
|
||||||
|
'//lib/fb:fbjni',
|
||||||
|
'//java:jni',
|
||||||
|
]
|
||||||
|
|
||||||
def csslayout_dep(dep):
|
def csslayout_dep(dep):
|
||||||
return '//' + dep
|
return '//' + dep
|
||||||
|
|
||||||
|
11
java/BUCK
11
java/BUCK
@@ -43,3 +43,14 @@ java_library(
|
|||||||
],
|
],
|
||||||
visibility = ['PUBLIC'],
|
visibility = ['PUBLIC'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
java_test(
|
||||||
|
name = 'tests',
|
||||||
|
srcs = glob(['tests/**/*.java']),
|
||||||
|
deps = [
|
||||||
|
':java',
|
||||||
|
JUNIT_TARGET,
|
||||||
|
],
|
||||||
|
use_cxx_libraries = True,
|
||||||
|
cxx_library_whitelist = CXX_LIBRARY_WHITELIST,
|
||||||
|
)
|
||||||
|
@@ -29,6 +29,11 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get native instance count. Useful for testing only.
|
||||||
|
*/
|
||||||
|
static native int jni_CSSNodeGetInstanceCount();
|
||||||
|
|
||||||
private CSSNode mParent;
|
private CSSNode mParent;
|
||||||
private List<CSSNode> mChildren;
|
private List<CSSNode> mChildren;
|
||||||
private MeasureFunction mMeasureFunction;
|
private MeasureFunction mMeasureFunction;
|
||||||
|
@@ -41,6 +41,10 @@ static inline CSSNodeRef _jlong2CSSNodeRef(jlong addr) {
|
|||||||
return reinterpret_cast<CSSNodeRef>(static_cast<intptr_t>(addr));
|
return reinterpret_cast<CSSNodeRef>(static_cast<intptr_t>(addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jint jni_CSSNodeGetInstanceCount(alias_ref<jclass> clazz) {
|
||||||
|
return CSSNodeGetInstanceCount();
|
||||||
|
}
|
||||||
|
|
||||||
jlong jni_CSSNodeNew(alias_ref<jobject> thiz) {
|
jlong jni_CSSNodeNew(alias_ref<jobject> thiz) {
|
||||||
const CSSNodeRef node = CSSNodeNew();
|
const CSSNodeRef node = CSSNodeNew();
|
||||||
auto globalThiz = make_global(thiz);
|
auto globalThiz = make_global(thiz);
|
||||||
@@ -234,6 +238,8 @@ jint JNI_OnLoad(JavaVM *vm, void *) {
|
|||||||
CSSMakeNativeMethod(jni_CSSNodeLayoutGetWidth),
|
CSSMakeNativeMethod(jni_CSSNodeLayoutGetWidth),
|
||||||
CSSMakeNativeMethod(jni_CSSNodeLayoutGetHeight),
|
CSSMakeNativeMethod(jni_CSSNodeLayoutGetHeight),
|
||||||
CSSMakeNativeMethod(jni_CSSNodeLayoutGetDirection),
|
CSSMakeNativeMethod(jni_CSSNodeLayoutGetDirection),
|
||||||
|
|
||||||
|
CSSMakeNativeMethod(jni_CSSNodeGetInstanceCount),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
61
java/tests/com/facebook/csslayout/CSSNodeTest.java
Normal file
61
java/tests/com/facebook/csslayout/CSSNodeTest.java
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.facebook.csslayout;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class CSSNodeTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInit() {
|
||||||
|
final int refCount = CSSNode.jni_CSSNodeGetInstanceCount();
|
||||||
|
final CSSNode node = new CSSNode();
|
||||||
|
assertEquals(refCount + 1, CSSNode.jni_CSSNodeGetInstanceCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFree() {
|
||||||
|
final int refCount = CSSNode.jni_CSSNodeGetInstanceCount();
|
||||||
|
final CSSNode node = new CSSNode();
|
||||||
|
node.free();
|
||||||
|
assertEquals(refCount, CSSNode.jni_CSSNodeGetInstanceCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReinit() {
|
||||||
|
final int refCount = CSSNode.jni_CSSNodeGetInstanceCount();
|
||||||
|
final CSSNode node = new CSSNode();
|
||||||
|
node.free();
|
||||||
|
node.reinit();
|
||||||
|
assertEquals(refCount + 1, CSSNode.jni_CSSNodeGetInstanceCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMeasure() {
|
||||||
|
final CSSNode node = new CSSNode();
|
||||||
|
node.setMeasureFunction(new CSSNodeAPI.MeasureFunction() {
|
||||||
|
public void measure(
|
||||||
|
CSSNodeAPI node,
|
||||||
|
float width,
|
||||||
|
CSSMeasureMode widthMode,
|
||||||
|
float height,
|
||||||
|
CSSMeasureMode heightMode,
|
||||||
|
MeasureOutput measureOutput) {
|
||||||
|
measureOutput.width = 100;
|
||||||
|
measureOutput.height = 100;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
node.calculateLayout(null);
|
||||||
|
assertEquals(100, (int) node.getLayoutWidth());
|
||||||
|
assertEquals(100, (int) node.getLayoutHeight());
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user