Java
This commit is contained in:
42
src/java/tests/com/facebook/csslayout/CSSNodeTest.java
Normal file
42
src/java/tests/com/facebook/csslayout/CSSNodeTest.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package com.facebook.csslayout;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* Tests for {@link CSSNode}.
|
||||
*/
|
||||
public class CSSNodeTest {
|
||||
|
||||
@Test
|
||||
public void testAddChildGetParent() {
|
||||
CSSNode parent = new CSSNode();
|
||||
CSSNode child = new CSSNode();
|
||||
|
||||
assertNull(child.getParent());
|
||||
assertEquals(0, parent.getChildCount());
|
||||
|
||||
parent.addChildAt(child, 0);
|
||||
|
||||
assertEquals(1, parent.getChildCount());
|
||||
assertEquals(child, parent.getChildAt(0));
|
||||
assertEquals(parent, child.getParent());
|
||||
|
||||
parent.removeChildAt(0);
|
||||
|
||||
assertNull(child.getParent());
|
||||
assertEquals(0, parent.getChildCount());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testCannotAddChildToMultipleParents() {
|
||||
CSSNode parent1 = new CSSNode();
|
||||
CSSNode parent2 = new CSSNode();
|
||||
CSSNode child = new CSSNode();
|
||||
|
||||
parent1.addChildAt(child, 0);
|
||||
parent2.addChildAt(child, 0);
|
||||
}
|
||||
}
|
180
src/java/tests/com/facebook/csslayout/LayoutCachingTest.java
Normal file
180
src/java/tests/com/facebook/csslayout/LayoutCachingTest.java
Normal file
@@ -0,0 +1,180 @@
|
||||
package com.facebook.csslayout;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests for {@link LayoutEngine} and {@link CSSNode} to make sure layouts are only generated when
|
||||
* needed.
|
||||
*/
|
||||
public class LayoutCachingTest {
|
||||
|
||||
private void assertTreeHasNewLayout(boolean expectedHasNewLayout, CSSNode root) {
|
||||
assertEquals(expectedHasNewLayout, root.hasNewLayout());
|
||||
|
||||
for (int i = 0; i < root.getChildCount(); i++) {
|
||||
assertTreeHasNewLayout(expectedHasNewLayout, root.getChildAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
private void markLayoutAppliedForTree(CSSNode root) {
|
||||
root.markLayoutApplied();
|
||||
for (int i = 0; i < root.getChildCount(); i++) {
|
||||
markLayoutAppliedForTree(root.getChildAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCachesFullTree() {
|
||||
CSSNode root = new CSSNode();
|
||||
CSSNode c0 = new CSSNode();
|
||||
CSSNode c1 = new CSSNode();
|
||||
CSSNode c0c0 = new CSSNode();
|
||||
root.addChildAt(c0, 0);
|
||||
root.addChildAt(c1, 1);
|
||||
c0.addChildAt(c0c0, 0);
|
||||
|
||||
root.calculateLayout();
|
||||
assertTreeHasNewLayout(true, root);
|
||||
markLayoutAppliedForTree(root);
|
||||
|
||||
root.calculateLayout();
|
||||
assertTreeHasNewLayout(false, root);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidatesCacheWhenChildAdded() {
|
||||
CSSNode root = new CSSNode();
|
||||
CSSNode c0 = new CSSNode();
|
||||
CSSNode c1 = new CSSNode();
|
||||
CSSNode c0c0 = new CSSNode();
|
||||
CSSNode c0c1 = new CSSNode();
|
||||
c0c1.setStyleWidth(200);
|
||||
c0c1.setStyleHeight(200);
|
||||
root.addChildAt(c0, 0);
|
||||
root.addChildAt(c1, 1);
|
||||
c0.addChildAt(c0c0, 0);
|
||||
|
||||
root.calculateLayout();
|
||||
assertTreeHasNewLayout(true, root);
|
||||
markLayoutAppliedForTree(root);
|
||||
|
||||
root.calculateLayout();
|
||||
assertTreeHasNewLayout(false, root);
|
||||
|
||||
c0.addChildAt(c0c1, 1);
|
||||
|
||||
root.calculateLayout();
|
||||
assertTrue(root.hasNewLayout());
|
||||
assertTrue(c0.hasNewLayout());
|
||||
assertTrue(c0c1.hasNewLayout());
|
||||
|
||||
assertFalse(c0c0.hasNewLayout());
|
||||
assertFalse(c1.hasNewLayout());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidatesCacheWhenEnumPropertyChanges() {
|
||||
CSSNode root = new CSSNode();
|
||||
CSSNode c0 = new CSSNode();
|
||||
CSSNode c1 = new CSSNode();
|
||||
CSSNode c0c0 = new CSSNode();
|
||||
root.addChildAt(c0, 0);
|
||||
root.addChildAt(c1, 1);
|
||||
c0.addChildAt(c0c0, 0);
|
||||
|
||||
root.calculateLayout();
|
||||
assertTreeHasNewLayout(true, root);
|
||||
markLayoutAppliedForTree(root);
|
||||
|
||||
root.calculateLayout();
|
||||
assertTreeHasNewLayout(false, root);
|
||||
|
||||
c1.setAlignSelf(CSSAlign.CENTER);
|
||||
root.calculateLayout();
|
||||
|
||||
assertTrue(root.hasNewLayout());
|
||||
assertTrue(c1.hasNewLayout());
|
||||
|
||||
assertFalse(c0.hasNewLayout());
|
||||
assertFalse(c0c0.hasNewLayout());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidatesCacheWhenFloatPropertyChanges() {
|
||||
CSSNode root = new CSSNode();
|
||||
CSSNode c0 = new CSSNode();
|
||||
CSSNode c1 = new CSSNode();
|
||||
CSSNode c0c0 = new CSSNode();
|
||||
root.addChildAt(c0, 0);
|
||||
root.addChildAt(c1, 1);
|
||||
c0.addChildAt(c0c0, 0);
|
||||
|
||||
root.calculateLayout();
|
||||
assertTreeHasNewLayout(true, root);
|
||||
markLayoutAppliedForTree(root);
|
||||
|
||||
root.calculateLayout();
|
||||
assertTreeHasNewLayout(false, root);
|
||||
|
||||
c1.setMarginLeft(10);
|
||||
root.calculateLayout();
|
||||
|
||||
assertTrue(root.hasNewLayout());
|
||||
assertTrue(c1.hasNewLayout());
|
||||
|
||||
assertFalse(c0.hasNewLayout());
|
||||
assertFalse(c0c0.hasNewLayout());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidatesFullTreeWhenParentWidthChanges() {
|
||||
CSSNode root = new CSSNode();
|
||||
CSSNode c0 = new CSSNode();
|
||||
CSSNode c1 = new CSSNode();
|
||||
CSSNode c0c0 = new CSSNode();
|
||||
root.addChildAt(c0, 0);
|
||||
root.addChildAt(c1, 1);
|
||||
c0.addChildAt(c0c0, 0);
|
||||
|
||||
root.calculateLayout();
|
||||
assertTreeHasNewLayout(true, root);
|
||||
markLayoutAppliedForTree(root);
|
||||
|
||||
root.calculateLayout();
|
||||
assertTreeHasNewLayout(false, root);
|
||||
|
||||
c0.setStyleWidth(200);
|
||||
root.calculateLayout();
|
||||
|
||||
assertTrue(root.hasNewLayout());
|
||||
assertTrue(c0.hasNewLayout());
|
||||
assertTrue(c0c0.hasNewLayout());
|
||||
|
||||
assertFalse(c1.hasNewLayout());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoesNotInvalidateCacheWhenPropertyIsTheSame() {
|
||||
CSSNode root = new CSSNode();
|
||||
CSSNode c0 = new CSSNode();
|
||||
CSSNode c1 = new CSSNode();
|
||||
CSSNode c0c0 = new CSSNode();
|
||||
root.addChildAt(c0, 0);
|
||||
root.addChildAt(c1, 1);
|
||||
c0.addChildAt(c0c0, 0);
|
||||
root.setStyleWidth(200);
|
||||
|
||||
root.calculateLayout();
|
||||
assertTreeHasNewLayout(true, root);
|
||||
markLayoutAppliedForTree(root);
|
||||
|
||||
root.calculateLayout();
|
||||
assertTreeHasNewLayout(false, root);
|
||||
|
||||
root.setStyleWidth(200);
|
||||
root.calculateLayout();
|
||||
assertTreeHasNewLayout(false, root);
|
||||
}
|
||||
}
|
3722
src/java/tests/com/facebook/csslayout/LayoutEngineTest.java
Normal file
3722
src/java/tests/com/facebook/csslayout/LayoutEngineTest.java
Normal file
File diff suppressed because it is too large
Load Diff
17
src/java/tests/com/facebook/csslayout/TestConstants.java
Normal file
17
src/java/tests/com/facebook/csslayout/TestConstants.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.facebook.csslayout;
|
||||
|
||||
/**
|
||||
* Generated constants used in {@link LayoutEngineTest}.
|
||||
*/
|
||||
public class TestConstants {
|
||||
|
||||
/** START_GENERATED **/
|
||||
public static final float SMALL_WIDTH = 34.671875f;
|
||||
public static final float SMALL_HEIGHT = 18f;
|
||||
public static final float BIG_WIDTH = 172.421875f;
|
||||
public static final float BIG_HEIGHT = 36f;
|
||||
public static final float BIG_MIN_WIDTH = 100.453125f;
|
||||
public static final String SMALL_TEXT = "small";
|
||||
public static final String LONG_TEXT = "loooooooooong with space";
|
||||
/** END_GENERATED **/
|
||||
}
|
Reference in New Issue
Block a user