Expose methods of persistent yoga for Java

Summary: This diff extends the JNI version of yoga in order to allow Java instances of the YogaConfig class to receive a callback when a Yoga node is cloned.

Reviewed By: priteshrnandgaonkar

Differential Revision: D6918605

fbshipit-source-id: e424c78680c04e21154ebe21405671c4e90f6529
This commit is contained in:
David Vacca
2018-02-14 09:31:10 -08:00
committed by Facebook Github Bot
parent 3ec41b656f
commit b1222bf83e
4 changed files with 153 additions and 13 deletions

View File

@@ -9,10 +9,11 @@
package com.facebook.yoga;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
public class YogaNodeTest {
@@ -218,4 +219,32 @@ public class YogaNodeTest {
assertTrue(YogaConstants.isUndefined(node.getBorder(edge)));
}
}
@Test
public void testNodeClonedLeak() throws Exception {
YogaConfig config = new YogaConfig();
config.setOnNodeCloned(
new YogaNodeClonedFunction() {
@Override
public void onNodeCloned(
YogaNode oldNode, YogaNode newNode, YogaNode parent, int childIndex) {
// Do nothing
}
});
config.setOnNodeCloned(null);
java.lang.ref.WeakReference<Object> ref = new java.lang.ref.WeakReference<Object>(config);
// noinspection UnusedAssignment
config = null;
// try and free for the next 5 seconds, usually it works after the
// first GC attempt.
for (int i = 0; i < 50; i++) {
System.gc();
if (ref.get() == null) {
// free successfully
return;
}
Thread.sleep(100);
}
fail("YogaConfig leaked");
}
}