Search in sources :

Example 1 with SparseRectFArrayBuilder

use of android.view.inputmethod.SparseRectFArray.SparseRectFArrayBuilder in project platform_frameworks_base by android.

the class SparseRectFArrayTest method testBuilder.

@SmallTest
public void testBuilder() throws Exception {
    final RectF TEMP_RECT = new RectF(10.0f, 20.0f, 30.0f, 40.0f);
    final int TEMP_FLAGS = 0x1234;
    final SparseRectFArrayBuilder builder = new SparseRectFArrayBuilder();
    builder.append(100, TEMP_RECT.left, TEMP_RECT.top, TEMP_RECT.right, TEMP_RECT.bottom, TEMP_FLAGS);
    assertNull(builder.build().get(-1));
    assertNull(builder.build().get(0));
    assertNull(builder.build().get(99));
    assertEquals(0, builder.build().getFlags(99, 0));
    assertEquals(1, builder.build().getFlags(99, 1));
    assertEquals(TEMP_RECT, builder.build().get(100));
    assertEquals(TEMP_FLAGS, builder.build().getFlags(100, 0));
    assertEquals(TEMP_FLAGS, builder.build().getFlags(100, 1));
    assertNull(builder.build().get(101));
    assertEquals(0, builder.build().getFlags(101, 0));
    assertEquals(1, builder.build().getFlags(101, 1));
    // Test if {@link SparseRectFArrayBuilder#reset} resets its internal state.
    builder.reset();
    assertNull(builder.build().get(100));
    builder.reset();
    for (int i = 0; i < MANY_RECTS.length; i++) {
        final RectF rect = MANY_RECTS[i];
        if (rect != null) {
            builder.append(i, rect.left, rect.top, rect.right, rect.bottom, i);
        }
    }
    final SparseRectFArray array = builder.build();
    for (int i = 0; i < MANY_RECTS.length; i++) {
        final RectF expectedRect = MANY_RECTS[i];
        assertEquals(expectedRect, array.get(i));
        if (expectedRect != null) {
            assertEquals(i, array.getFlags(i, 0x1234));
            assertEquals(i, array.getFlags(i, 0x4321));
        } else {
            assertEquals(0x1234, array.getFlags(i, 0x1234));
            assertEquals(0x4321, array.getFlags(i, 0x4321));
        }
    }
    // Make sure the builder reproduces an equivalent object.
    final SparseRectFArray array2 = builder.build();
    for (int i = 0; i < MANY_RECTS.length; i++) {
        final RectF expectedRect = MANY_RECTS[i];
        assertEquals(expectedRect, array2.get(i));
        if (expectedRect != null) {
            assertEquals(i, array2.getFlags(i, 0x1234));
            assertEquals(i, array2.getFlags(i, 0x4321));
        } else {
            assertEquals(0x1234, array2.getFlags(i, 0x1234));
            assertEquals(0x4321, array2.getFlags(i, 0x4321));
        }
    }
    assertEqualRects(array, array2);
    // Make sure the instance can be marshaled via {@link Parcel}.
    final SparseRectFArray array3 = cloneViaParcel(array);
    for (int i = 0; i < MANY_RECTS.length; i++) {
        final RectF expectedRect = MANY_RECTS[i];
        assertEquals(expectedRect, array3.get(i));
        if (expectedRect != null) {
            assertEquals(i, array3.getFlags(i, 0x1234));
            assertEquals(i, array3.getFlags(i, 0x4321));
        } else {
            assertEquals(0x1234, array3.getFlags(i, 0x1234));
            assertEquals(0x4321, array3.getFlags(i, 0x4321));
        }
    }
    assertEqualRects(array, array3);
    // Make sure the builder can be reset.
    builder.reset();
    assertNull(builder.build().get(0));
}
Also used : RectF(android.graphics.RectF) SparseRectFArrayBuilder(android.view.inputmethod.SparseRectFArray.SparseRectFArrayBuilder) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 2 with SparseRectFArrayBuilder

use of android.view.inputmethod.SparseRectFArray.SparseRectFArrayBuilder in project android_frameworks_base by ResurrectionRemix.

the class SparseRectFArrayTest method testBuilder.

@SmallTest
public void testBuilder() throws Exception {
    final RectF TEMP_RECT = new RectF(10.0f, 20.0f, 30.0f, 40.0f);
    final int TEMP_FLAGS = 0x1234;
    final SparseRectFArrayBuilder builder = new SparseRectFArrayBuilder();
    builder.append(100, TEMP_RECT.left, TEMP_RECT.top, TEMP_RECT.right, TEMP_RECT.bottom, TEMP_FLAGS);
    assertNull(builder.build().get(-1));
    assertNull(builder.build().get(0));
    assertNull(builder.build().get(99));
    assertEquals(0, builder.build().getFlags(99, 0));
    assertEquals(1, builder.build().getFlags(99, 1));
    assertEquals(TEMP_RECT, builder.build().get(100));
    assertEquals(TEMP_FLAGS, builder.build().getFlags(100, 0));
    assertEquals(TEMP_FLAGS, builder.build().getFlags(100, 1));
    assertNull(builder.build().get(101));
    assertEquals(0, builder.build().getFlags(101, 0));
    assertEquals(1, builder.build().getFlags(101, 1));
    // Test if {@link SparseRectFArrayBuilder#reset} resets its internal state.
    builder.reset();
    assertNull(builder.build().get(100));
    builder.reset();
    for (int i = 0; i < MANY_RECTS.length; i++) {
        final RectF rect = MANY_RECTS[i];
        if (rect != null) {
            builder.append(i, rect.left, rect.top, rect.right, rect.bottom, i);
        }
    }
    final SparseRectFArray array = builder.build();
    for (int i = 0; i < MANY_RECTS.length; i++) {
        final RectF expectedRect = MANY_RECTS[i];
        assertEquals(expectedRect, array.get(i));
        if (expectedRect != null) {
            assertEquals(i, array.getFlags(i, 0x1234));
            assertEquals(i, array.getFlags(i, 0x4321));
        } else {
            assertEquals(0x1234, array.getFlags(i, 0x1234));
            assertEquals(0x4321, array.getFlags(i, 0x4321));
        }
    }
    // Make sure the builder reproduces an equivalent object.
    final SparseRectFArray array2 = builder.build();
    for (int i = 0; i < MANY_RECTS.length; i++) {
        final RectF expectedRect = MANY_RECTS[i];
        assertEquals(expectedRect, array2.get(i));
        if (expectedRect != null) {
            assertEquals(i, array2.getFlags(i, 0x1234));
            assertEquals(i, array2.getFlags(i, 0x4321));
        } else {
            assertEquals(0x1234, array2.getFlags(i, 0x1234));
            assertEquals(0x4321, array2.getFlags(i, 0x4321));
        }
    }
    assertEqualRects(array, array2);
    // Make sure the instance can be marshaled via {@link Parcel}.
    final SparseRectFArray array3 = cloneViaParcel(array);
    for (int i = 0; i < MANY_RECTS.length; i++) {
        final RectF expectedRect = MANY_RECTS[i];
        assertEquals(expectedRect, array3.get(i));
        if (expectedRect != null) {
            assertEquals(i, array3.getFlags(i, 0x1234));
            assertEquals(i, array3.getFlags(i, 0x4321));
        } else {
            assertEquals(0x1234, array3.getFlags(i, 0x1234));
            assertEquals(0x4321, array3.getFlags(i, 0x4321));
        }
    }
    assertEqualRects(array, array3);
    // Make sure the builder can be reset.
    builder.reset();
    assertNull(builder.build().get(0));
}
Also used : RectF(android.graphics.RectF) SparseRectFArrayBuilder(android.view.inputmethod.SparseRectFArray.SparseRectFArrayBuilder) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 3 with SparseRectFArrayBuilder

use of android.view.inputmethod.SparseRectFArray.SparseRectFArrayBuilder in project android_frameworks_base by DirtyUnicorns.

the class SparseRectFArrayTest method testBuilder.

@SmallTest
public void testBuilder() throws Exception {
    final RectF TEMP_RECT = new RectF(10.0f, 20.0f, 30.0f, 40.0f);
    final int TEMP_FLAGS = 0x1234;
    final SparseRectFArrayBuilder builder = new SparseRectFArrayBuilder();
    builder.append(100, TEMP_RECT.left, TEMP_RECT.top, TEMP_RECT.right, TEMP_RECT.bottom, TEMP_FLAGS);
    assertNull(builder.build().get(-1));
    assertNull(builder.build().get(0));
    assertNull(builder.build().get(99));
    assertEquals(0, builder.build().getFlags(99, 0));
    assertEquals(1, builder.build().getFlags(99, 1));
    assertEquals(TEMP_RECT, builder.build().get(100));
    assertEquals(TEMP_FLAGS, builder.build().getFlags(100, 0));
    assertEquals(TEMP_FLAGS, builder.build().getFlags(100, 1));
    assertNull(builder.build().get(101));
    assertEquals(0, builder.build().getFlags(101, 0));
    assertEquals(1, builder.build().getFlags(101, 1));
    // Test if {@link SparseRectFArrayBuilder#reset} resets its internal state.
    builder.reset();
    assertNull(builder.build().get(100));
    builder.reset();
    for (int i = 0; i < MANY_RECTS.length; i++) {
        final RectF rect = MANY_RECTS[i];
        if (rect != null) {
            builder.append(i, rect.left, rect.top, rect.right, rect.bottom, i);
        }
    }
    final SparseRectFArray array = builder.build();
    for (int i = 0; i < MANY_RECTS.length; i++) {
        final RectF expectedRect = MANY_RECTS[i];
        assertEquals(expectedRect, array.get(i));
        if (expectedRect != null) {
            assertEquals(i, array.getFlags(i, 0x1234));
            assertEquals(i, array.getFlags(i, 0x4321));
        } else {
            assertEquals(0x1234, array.getFlags(i, 0x1234));
            assertEquals(0x4321, array.getFlags(i, 0x4321));
        }
    }
    // Make sure the builder reproduces an equivalent object.
    final SparseRectFArray array2 = builder.build();
    for (int i = 0; i < MANY_RECTS.length; i++) {
        final RectF expectedRect = MANY_RECTS[i];
        assertEquals(expectedRect, array2.get(i));
        if (expectedRect != null) {
            assertEquals(i, array2.getFlags(i, 0x1234));
            assertEquals(i, array2.getFlags(i, 0x4321));
        } else {
            assertEquals(0x1234, array2.getFlags(i, 0x1234));
            assertEquals(0x4321, array2.getFlags(i, 0x4321));
        }
    }
    assertEqualRects(array, array2);
    // Make sure the instance can be marshaled via {@link Parcel}.
    final SparseRectFArray array3 = cloneViaParcel(array);
    for (int i = 0; i < MANY_RECTS.length; i++) {
        final RectF expectedRect = MANY_RECTS[i];
        assertEquals(expectedRect, array3.get(i));
        if (expectedRect != null) {
            assertEquals(i, array3.getFlags(i, 0x1234));
            assertEquals(i, array3.getFlags(i, 0x4321));
        } else {
            assertEquals(0x1234, array3.getFlags(i, 0x1234));
            assertEquals(0x4321, array3.getFlags(i, 0x4321));
        }
    }
    assertEqualRects(array, array3);
    // Make sure the builder can be reset.
    builder.reset();
    assertNull(builder.build().get(0));
}
Also used : RectF(android.graphics.RectF) SparseRectFArrayBuilder(android.view.inputmethod.SparseRectFArray.SparseRectFArrayBuilder) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 4 with SparseRectFArrayBuilder

use of android.view.inputmethod.SparseRectFArray.SparseRectFArrayBuilder in project android_frameworks_base by AOSPA.

the class SparseRectFArrayTest method testEquality.

@SmallTest
public void testEquality() throws Exception {
    // Empty array should be equal.
    assertEqualRects(new SparseRectFArrayBuilder().build(), new SparseRectFArrayBuilder().build());
    assertEqualRects(new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 1).build(), new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 1).build());
    assertEqualRects(new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0).build(), new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0).build());
    assertNotEqualRects(new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0).build(), new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 1).build());
    assertNotEqualRects(new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 1).build(), new SparseRectFArrayBuilder().append(100, 2.0f, 2.0f, 3.0f, 4.0f, 1).build());
    assertNotEqualRects(new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 1).build(), new SparseRectFArrayBuilder().append(101, 1.0f, 2.0f, 3.0f, 4.0f, 1).build());
    assertEqualRects(new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0).append(101, 0.0f, 0.0f, 0.0f, 0.0f, 0).build(), new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0).append(101, 0.0f, 0.0f, 0.0f, 0.0f, 0).build());
    assertNotEqualRects(new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0).build(), new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0).append(101, 0.0f, 0.0f, 0.0f, 0.0f, 0).build());
    assertNotEqualRects(new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0).append(101, 0.0f, 0.0f, 0.0f, 0.0f, 0).build(), new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0).build());
    assertNotEqualRects(new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0).append(101, 0.0f, 0.0f, 0.0f, 0.0f, 0).build(), new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0).append(101, 1.0f, 0.0f, 0.0f, 0.0f, 0).build());
    assertNotEqualRects(new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0).append(101, 1.0f, 0.0f, 0.0f, 0.0f, 0).build(), new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0).append(101, 0.0f, 0.0f, 0.0f, 0.0f, 0).build());
    assertNotEqualRects(new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0).append(101, 0.0f, 0.0f, 0.0f, 0.0f, 0).build(), new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0).append(102, 0.0f, 0.0f, 0.0f, 0.0f, 0).build());
    assertEqualRects(new SparseRectFArrayBuilder().append(1, 1.0f, 2.0f, 3.0f, 4.0f, 0).append(1000, 0.0f, 0.0f, 0.0f, 0.0f, 0).append(100000000, 0.0f, 0.0f, 0.0f, 0.0f, 0).build(), new SparseRectFArrayBuilder().append(1, 1.0f, 2.0f, 3.0f, 4.0f, 0).append(1000, 0.0f, 0.0f, 0.0f, 0.0f, 0).append(100000000, 0.0f, 0.0f, 0.0f, 0.0f, 0).build());
    assertNotEqualRects(new SparseRectFArrayBuilder().append(1, 1.0f, 2.0f, 3.0f, 4.0f, 0).append(1000, 0.0f, 0.0f, 0.0f, 0.0f, 0).append(100000000, 0.0f, 0.0f, 0.0f, 0.0f, 0).build(), new SparseRectFArrayBuilder().append(1, 1.0f, 2.0f, 3.0f, 4.0f, 0).build());
    assertNotEqualRects(new SparseRectFArrayBuilder().append(1, 1.0f, 2.0f, 3.0f, 4.0f, 0).append(1000, 0.0f, 0.0f, 0.0f, 0.0f, 0).append(100000000, 0.0f, 0.0f, 0.0f, 0.0f, 0).build(), new SparseRectFArrayBuilder().append(1, 1.0f, 2.0f, 3.0f, 4.0f, 0).append(1000, 1.0f, 0.0f, 0.0f, 0.0f, 0).append(100000000, 0.0f, 0.0f, 0.0f, 0.0f, 0).build());
}
Also used : SparseRectFArrayBuilder(android.view.inputmethod.SparseRectFArray.SparseRectFArrayBuilder) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 5 with SparseRectFArrayBuilder

use of android.view.inputmethod.SparseRectFArray.SparseRectFArrayBuilder in project android_frameworks_base by crdroidandroid.

the class SparseRectFArrayTest method testBuilder.

@SmallTest
public void testBuilder() throws Exception {
    final RectF TEMP_RECT = new RectF(10.0f, 20.0f, 30.0f, 40.0f);
    final int TEMP_FLAGS = 0x1234;
    final SparseRectFArrayBuilder builder = new SparseRectFArrayBuilder();
    builder.append(100, TEMP_RECT.left, TEMP_RECT.top, TEMP_RECT.right, TEMP_RECT.bottom, TEMP_FLAGS);
    assertNull(builder.build().get(-1));
    assertNull(builder.build().get(0));
    assertNull(builder.build().get(99));
    assertEquals(0, builder.build().getFlags(99, 0));
    assertEquals(1, builder.build().getFlags(99, 1));
    assertEquals(TEMP_RECT, builder.build().get(100));
    assertEquals(TEMP_FLAGS, builder.build().getFlags(100, 0));
    assertEquals(TEMP_FLAGS, builder.build().getFlags(100, 1));
    assertNull(builder.build().get(101));
    assertEquals(0, builder.build().getFlags(101, 0));
    assertEquals(1, builder.build().getFlags(101, 1));
    // Test if {@link SparseRectFArrayBuilder#reset} resets its internal state.
    builder.reset();
    assertNull(builder.build().get(100));
    builder.reset();
    for (int i = 0; i < MANY_RECTS.length; i++) {
        final RectF rect = MANY_RECTS[i];
        if (rect != null) {
            builder.append(i, rect.left, rect.top, rect.right, rect.bottom, i);
        }
    }
    final SparseRectFArray array = builder.build();
    for (int i = 0; i < MANY_RECTS.length; i++) {
        final RectF expectedRect = MANY_RECTS[i];
        assertEquals(expectedRect, array.get(i));
        if (expectedRect != null) {
            assertEquals(i, array.getFlags(i, 0x1234));
            assertEquals(i, array.getFlags(i, 0x4321));
        } else {
            assertEquals(0x1234, array.getFlags(i, 0x1234));
            assertEquals(0x4321, array.getFlags(i, 0x4321));
        }
    }
    // Make sure the builder reproduces an equivalent object.
    final SparseRectFArray array2 = builder.build();
    for (int i = 0; i < MANY_RECTS.length; i++) {
        final RectF expectedRect = MANY_RECTS[i];
        assertEquals(expectedRect, array2.get(i));
        if (expectedRect != null) {
            assertEquals(i, array2.getFlags(i, 0x1234));
            assertEquals(i, array2.getFlags(i, 0x4321));
        } else {
            assertEquals(0x1234, array2.getFlags(i, 0x1234));
            assertEquals(0x4321, array2.getFlags(i, 0x4321));
        }
    }
    assertEqualRects(array, array2);
    // Make sure the instance can be marshaled via {@link Parcel}.
    final SparseRectFArray array3 = cloneViaParcel(array);
    for (int i = 0; i < MANY_RECTS.length; i++) {
        final RectF expectedRect = MANY_RECTS[i];
        assertEquals(expectedRect, array3.get(i));
        if (expectedRect != null) {
            assertEquals(i, array3.getFlags(i, 0x1234));
            assertEquals(i, array3.getFlags(i, 0x4321));
        } else {
            assertEquals(0x1234, array3.getFlags(i, 0x1234));
            assertEquals(0x4321, array3.getFlags(i, 0x4321));
        }
    }
    assertEqualRects(array, array3);
    // Make sure the builder can be reset.
    builder.reset();
    assertNull(builder.build().get(0));
}
Also used : RectF(android.graphics.RectF) SparseRectFArrayBuilder(android.view.inputmethod.SparseRectFArray.SparseRectFArrayBuilder) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

SmallTest (android.test.suitebuilder.annotation.SmallTest)10 SparseRectFArrayBuilder (android.view.inputmethod.SparseRectFArray.SparseRectFArrayBuilder)10 RectF (android.graphics.RectF)5