Skip to content

Commit 19d6c00

Browse files
committed
move unit tests
1 parent 317c714 commit 19d6c00

File tree

4 files changed

+139
-0
lines changed

4 files changed

+139
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.reandroid.arsc.array;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
public class SparseOffsetsArrayTest {
7+
@Test
8+
public void testSetOffset() {
9+
//offsets are encoded is 16-bit, real_offset = offset * 4
10+
final SparseOffsetsArray sparseArr = new SparseOffsetsArray();
11+
12+
final int offset = 0x10;
13+
final int index = 0x0000;
14+
15+
//put data
16+
final int data = ((offset / 4) << 16) | index;
17+
sparseArr.set(new int[]{ data });
18+
Assert.assertEquals(offset, sparseArr.getOffset(0));
19+
20+
//test setOffset
21+
sparseArr.clear();
22+
sparseArr.setSize(1);
23+
sparseArr.setOffset(0, offset);
24+
Assert.assertEquals(offset, sparseArr.getOffset(0));
25+
}
26+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.reandroid.arsc.chunk;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
public class PackageBlockTest {
7+
8+
@Test
9+
public void testIsResourceId() {
10+
Assert.assertFalse(PackageBlock.isResourceId(0x7f00ffff));
11+
Assert.assertFalse(PackageBlock.isResourceId(0x00ff0000));
12+
Assert.assertFalse(PackageBlock.isResourceId(0x00ffffff));
13+
Assert.assertFalse(PackageBlock.isResourceId(0x0000ffff));
14+
Assert.assertFalse(PackageBlock.isResourceId(0xff000000));
15+
Assert.assertFalse(PackageBlock.isResourceId(0x0));
16+
Assert.assertTrue(PackageBlock.isResourceId(0x0101ffff));
17+
Assert.assertTrue(PackageBlock.isResourceId(0x01010000));
18+
}
19+
20+
@Test
21+
public void testIsPackageId() {
22+
Assert.assertFalse(PackageBlock.isPackageId(0x00));
23+
Assert.assertFalse(PackageBlock.isPackageId(0xfff));
24+
Assert.assertFalse(PackageBlock.isPackageId(0xffff));
25+
Assert.assertFalse(PackageBlock.isPackageId(0xfffff));
26+
Assert.assertFalse(PackageBlock.isPackageId(0xffffff));
27+
Assert.assertFalse(PackageBlock.isPackageId(0xffffffff));
28+
Assert.assertTrue(PackageBlock.isPackageId(0x01));
29+
Assert.assertTrue(PackageBlock.isPackageId(0x11));
30+
Assert.assertTrue(PackageBlock.isPackageId(0xff));
31+
}
32+
33+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.reandroid.arsc.value;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
public class AttributeTypeTest {
7+
private final static AttributeType[] PLURALS = new AttributeType[]{
8+
AttributeType.OTHER,
9+
AttributeType.ZERO,
10+
AttributeType.ONE,
11+
AttributeType.TWO,
12+
AttributeType.FEW,
13+
AttributeType.MANY
14+
};
15+
private final static AttributeType[] NON_PLURALS = new AttributeType[]{
16+
AttributeType.FORMATS,
17+
AttributeType.MIN,
18+
AttributeType.MAX,
19+
AttributeType.L10N
20+
};
21+
22+
@Test
23+
public void testIsPlural() {
24+
for(AttributeType type : PLURALS) {
25+
Assert.assertTrue(type.isPlural());
26+
}
27+
28+
for(AttributeType type : NON_PLURALS) {
29+
Assert.assertFalse(type.isPlural());
30+
}
31+
}
32+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.reandroid.arsc.value;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
public class ValueTypeTest {
7+
private static final ValueType[] ALL = ValueType.values();
8+
9+
@Test
10+
public void testIsColor() {
11+
for(ValueType type : ALL) {
12+
Assert.assertEquals(isColor(type), type.isColor());
13+
}
14+
}
15+
16+
@Test
17+
public void testIsInteger() {
18+
for(ValueType type : ALL) {
19+
Assert.assertEquals(isInteger(type), type.isInteger());
20+
}
21+
}
22+
23+
@Test
24+
public void testIsReference() {
25+
for(ValueType type : ALL) {
26+
Assert.assertEquals(isReference(type), type.isReference());
27+
}
28+
}
29+
30+
private static boolean isColor(ValueType valueType) {
31+
return valueType == ValueType.COLOR_ARGB8
32+
|| valueType == ValueType.COLOR_RGB8
33+
|| valueType == ValueType.COLOR_ARGB4
34+
|| valueType == ValueType.COLOR_RGB4;
35+
}
36+
37+
private static boolean isInteger(ValueType valueType) {
38+
return valueType == ValueType.DEC
39+
|| valueType == ValueType.HEX;
40+
}
41+
42+
private static boolean isReference(ValueType valueType) {
43+
return valueType == ValueType.REFERENCE
44+
|| valueType == ValueType.ATTRIBUTE
45+
|| valueType == ValueType.DYNAMIC_REFERENCE
46+
|| valueType == ValueType.DYNAMIC_ATTRIBUTE;
47+
}
48+
}

0 commit comments

Comments
 (0)