Skip to content

Commit 6605103

Browse files
authored
Merge pull request #91 from Tahgolov/refactor/low-level-operations-unittests
Unit tests for #90
2 parents d672e7f + 693c098 commit 6605103

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-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: 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)