Rename literalTools to LiteralTools

Just for evancharlton
This commit is contained in:
Ben Gruver 2011-07-20 20:13:38 -04:00
parent 3c4f8094a2
commit 4dbfae78e9
6 changed files with 200 additions and 200 deletions

View File

@ -361,14 +361,14 @@ literal returns[EncodedValue encodedValue]
//everything but string //everything but string
fixed_size_literal returns[byte[\] value] fixed_size_literal returns[byte[\] value]
: integer_literal { $value = literalTools.intToBytes($integer_literal.value); } : integer_literal { $value = LiteralTools.intToBytes($integer_literal.value); }
| long_literal { $value = literalTools.longToBytes($long_literal.value); } | long_literal { $value = LiteralTools.longToBytes($long_literal.value); }
| short_literal { $value = literalTools.shortToBytes($short_literal.value); } | short_literal { $value = LiteralTools.shortToBytes($short_literal.value); }
| byte_literal { $value = new byte[] { $byte_literal.value }; } | byte_literal { $value = new byte[] { $byte_literal.value }; }
| float_literal { $value = literalTools.floatToBytes($float_literal.value); } | float_literal { $value = LiteralTools.floatToBytes($float_literal.value); }
| double_literal { $value = literalTools.doubleToBytes($double_literal.value); } | double_literal { $value = LiteralTools.doubleToBytes($double_literal.value); }
| char_literal { $value = literalTools.charToBytes($char_literal.value); } | char_literal { $value = LiteralTools.charToBytes($char_literal.value); }
| bool_literal { $value = literalTools.boolToBytes($bool_literal.value); }; | bool_literal { $value = LiteralTools.boolToBytes($bool_literal.value); };
//everything but string //everything but string
fixed_64bit_literal returns[long value] fixed_64bit_literal returns[long value]
@ -385,7 +385,7 @@ fixed_64bit_literal returns[long value]
//long is allowed, but it must fit into an int //long is allowed, but it must fit into an int
fixed_32bit_literal returns[int value] fixed_32bit_literal returns[int value]
: integer_literal { $value = $integer_literal.value; } : integer_literal { $value = $integer_literal.value; }
| long_literal { literalTools.checkInt($long_literal.value); $value = (int)$long_literal.value; } | long_literal { LiteralTools.checkInt($long_literal.value); $value = (int)$long_literal.value; }
| short_literal { $value = $short_literal.value; } | short_literal { $value = $short_literal.value; }
| byte_literal { $value = $byte_literal.value; } | byte_literal { $value = $byte_literal.value; }
| float_literal { $value = Float.floatToRawIntBits($float_literal.value); } | float_literal { $value = Float.floatToRawIntBits($float_literal.value); }
@ -867,7 +867,7 @@ offset returns[int offsetValue]
if (offsetText.charAt(0) == '+') { if (offsetText.charAt(0) == '+') {
offsetText = offsetText.substring(1); offsetText = offsetText.substring(1);
} }
$offsetValue = literalTools.parseInt(offsetText); $offsetValue = LiteralTools.parseInt(offsetText);
}; };
offset_or_label_absolute[int baseAddress] returns[int address] offset_or_label_absolute[int baseAddress] returns[int address]
@ -938,7 +938,7 @@ instruction[int totalMethodRegisters, int methodParameterRegisters, List<Instruc
byte regA = parseRegister_nibble($REGISTER.text, $totalMethodRegisters, $methodParameterRegisters); byte regA = parseRegister_nibble($REGISTER.text, $totalMethodRegisters, $methodParameterRegisters);
short litB = $short_integral_literal.value; short litB = $short_integral_literal.value;
literalTools.checkNibble(litB); LiteralTools.checkNibble(litB);
$instructions.add(new Instruction11n(opcode, regA, (byte)litB)); $instructions.add(new Instruction11n(opcode, regA, (byte)litB));
} }
@ -1040,7 +1040,7 @@ instruction[int totalMethodRegisters, int methodParameterRegisters, List<Instruc
short regB = parseRegister_byte($registerB.text, $totalMethodRegisters, $methodParameterRegisters); short regB = parseRegister_byte($registerB.text, $totalMethodRegisters, $methodParameterRegisters);
short litC = $short_integral_literal.value; short litC = $short_integral_literal.value;
literalTools.checkByte(litC); LiteralTools.checkByte(litC);
$instructions.add(new Instruction22b(opcode, regA, regB, (byte)litC)); $instructions.add(new Instruction22b(opcode, regA, regB, (byte)litC));
} }
@ -1335,12 +1335,12 @@ type_descriptor returns [TypeIdItem type]
short_integral_literal returns[short value] short_integral_literal returns[short value]
: long_literal : long_literal
{ {
literalTools.checkShort($long_literal.value); LiteralTools.checkShort($long_literal.value);
$value = (short)$long_literal.value; $value = (short)$long_literal.value;
} }
| integer_literal | integer_literal
{ {
literalTools.checkShort($integer_literal.value); LiteralTools.checkShort($integer_literal.value);
$value = (short)$integer_literal.value; $value = (short)$integer_literal.value;
} }
| short_literal {$value = $short_literal.value;} | short_literal {$value = $short_literal.value;}
@ -1350,7 +1350,7 @@ short_integral_literal returns[short value]
integral_literal returns[int value] integral_literal returns[int value]
: long_literal : long_literal
{ {
literalTools.checkInt($long_literal.value); LiteralTools.checkInt($long_literal.value);
$value = (int)$long_literal.value; $value = (int)$long_literal.value;
} }
| integer_literal {$value = $integer_literal.value;} | integer_literal {$value = $integer_literal.value;}
@ -1359,16 +1359,16 @@ integral_literal returns[int value]
integer_literal returns[int value] integer_literal returns[int value]
: INTEGER_LITERAL { $value = literalTools.parseInt($INTEGER_LITERAL.text); }; : INTEGER_LITERAL { $value = LiteralTools.parseInt($INTEGER_LITERAL.text); };
long_literal returns[long value] long_literal returns[long value]
: LONG_LITERAL { $value = literalTools.parseLong($LONG_LITERAL.text); }; : LONG_LITERAL { $value = LiteralTools.parseLong($LONG_LITERAL.text); };
short_literal returns[short value] short_literal returns[short value]
: SHORT_LITERAL { $value = literalTools.parseShort($SHORT_LITERAL.text); }; : SHORT_LITERAL { $value = LiteralTools.parseShort($SHORT_LITERAL.text); };
byte_literal returns[byte value] byte_literal returns[byte value]
: BYTE_LITERAL { $value = literalTools.parseByte($BYTE_LITERAL.text); }; : BYTE_LITERAL { $value = LiteralTools.parseByte($BYTE_LITERAL.text); };
float_literal returns[float value] float_literal returns[float value]
: FLOAT_LITERAL { $value = parseFloat($FLOAT_LITERAL.text); }; : FLOAT_LITERAL { $value = parseFloat($FLOAT_LITERAL.text); };

View File

@ -28,7 +28,7 @@
package org.jf.smali; package org.jf.smali;
public class literalTools public class LiteralTools
{ {
public static byte parseByte(String byteLiteral) public static byte parseByte(String byteLiteral)
throws NumberFormatException { throws NumberFormatException {

View File

@ -26,7 +26,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
import org.jf.smali.literalTools; import org.jf.smali.LiteralTools;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -36,105 +36,105 @@ public class ByteLiteralTest
@Test @Test
public void SuccessHexTests() { public void SuccessHexTests() {
Assert.assertTrue(literalTools.parseByte("0x0T") == 0x0); Assert.assertTrue(LiteralTools.parseByte("0x0T") == 0x0);
Assert.assertTrue(literalTools.parseByte("0x00") == 0x0); Assert.assertTrue(LiteralTools.parseByte("0x00") == 0x0);
Assert.assertTrue(literalTools.parseByte("0x1T") == 0x1); Assert.assertTrue(LiteralTools.parseByte("0x1T") == 0x1);
Assert.assertTrue(literalTools.parseByte("0x12") == 0x12); Assert.assertTrue(LiteralTools.parseByte("0x12") == 0x12);
Assert.assertTrue(literalTools.parseByte("0x7fT") == 0x7f); Assert.assertTrue(LiteralTools.parseByte("0x7fT") == 0x7f);
Assert.assertTrue(literalTools.parseByte("0x80t") == Byte.MIN_VALUE); Assert.assertTrue(LiteralTools.parseByte("0x80t") == Byte.MIN_VALUE);
Assert.assertTrue(literalTools.parseByte("0xFFt") == -1); Assert.assertTrue(LiteralTools.parseByte("0xFFt") == -1);
Assert.assertTrue(literalTools.parseByte("-0x00") == 0); Assert.assertTrue(LiteralTools.parseByte("-0x00") == 0);
Assert.assertTrue(literalTools.parseByte("-0x01") == -1); Assert.assertTrue(LiteralTools.parseByte("-0x01") == -1);
Assert.assertTrue(literalTools.parseByte("-0x12") == -0x12); Assert.assertTrue(LiteralTools.parseByte("-0x12") == -0x12);
Assert.assertTrue(literalTools.parseByte("-0x80") == Byte.MIN_VALUE); Assert.assertTrue(LiteralTools.parseByte("-0x80") == Byte.MIN_VALUE);
Assert.assertTrue(literalTools.parseByte("-0x1f") == -0x1f); Assert.assertTrue(LiteralTools.parseByte("-0x1f") == -0x1f);
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FaileHexTest1() { public void FaileHexTest1() {
literalTools.parseByte("-0x81"); LiteralTools.parseByte("-0x81");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailHexTest2() { public void FailHexTest2() {
literalTools.parseByte("-0xFF"); LiteralTools.parseByte("-0xFF");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailHexTest3() { public void FailHexTest3() {
literalTools.parseByte("0x100"); LiteralTools.parseByte("0x100");
} }
@Test @Test
public void SuccessDecTests() { public void SuccessDecTests() {
Assert.assertTrue(literalTools.parseByte("0") == 0); Assert.assertTrue(LiteralTools.parseByte("0") == 0);
Assert.assertTrue(literalTools.parseByte("1t") == 1); Assert.assertTrue(LiteralTools.parseByte("1t") == 1);
Assert.assertTrue(literalTools.parseByte("123") == 123); Assert.assertTrue(LiteralTools.parseByte("123") == 123);
Assert.assertTrue(literalTools.parseByte("127T") == 127); Assert.assertTrue(LiteralTools.parseByte("127T") == 127);
Assert.assertTrue(literalTools.parseByte("128") == Byte.MIN_VALUE); Assert.assertTrue(LiteralTools.parseByte("128") == Byte.MIN_VALUE);
Assert.assertTrue(literalTools.parseByte("255") == -1); Assert.assertTrue(LiteralTools.parseByte("255") == -1);
Assert.assertTrue(literalTools.parseByte("-0") == 0); Assert.assertTrue(LiteralTools.parseByte("-0") == 0);
Assert.assertTrue(literalTools.parseByte("-1") == -1); Assert.assertTrue(LiteralTools.parseByte("-1") == -1);
Assert.assertTrue(literalTools.parseByte("-123") == -123); Assert.assertTrue(LiteralTools.parseByte("-123") == -123);
Assert.assertTrue(literalTools.parseByte("-127") == -127); Assert.assertTrue(LiteralTools.parseByte("-127") == -127);
Assert.assertTrue(literalTools.parseByte("-128") == Byte.MIN_VALUE); Assert.assertTrue(LiteralTools.parseByte("-128") == Byte.MIN_VALUE);
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FaileDecTest1() { public void FaileDecTest1() {
literalTools.parseByte("-129"); LiteralTools.parseByte("-129");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailDecTest2() { public void FailDecTest2() {
literalTools.parseByte("-255"); LiteralTools.parseByte("-255");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailDecTest3() { public void FailDecTest3() {
literalTools.parseByte("256"); LiteralTools.parseByte("256");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailDecTest4() { public void FailDecTest4() {
literalTools.parseByte("260"); LiteralTools.parseByte("260");
} }
@Test @Test
public void SuccessOctTests() { public void SuccessOctTests() {
Assert.assertTrue(literalTools.parseByte("00") == 00); Assert.assertTrue(LiteralTools.parseByte("00") == 00);
Assert.assertTrue(literalTools.parseByte("01") == 01); Assert.assertTrue(LiteralTools.parseByte("01") == 01);
Assert.assertTrue(literalTools.parseByte("0123t") == 0123); Assert.assertTrue(LiteralTools.parseByte("0123t") == 0123);
Assert.assertTrue(literalTools.parseByte("0177") == Byte.MAX_VALUE); Assert.assertTrue(LiteralTools.parseByte("0177") == Byte.MAX_VALUE);
Assert.assertTrue(literalTools.parseByte("0200T") == Byte.MIN_VALUE); Assert.assertTrue(LiteralTools.parseByte("0200T") == Byte.MIN_VALUE);
Assert.assertTrue(literalTools.parseByte("0377") == -1); Assert.assertTrue(LiteralTools.parseByte("0377") == -1);
Assert.assertTrue(literalTools.parseByte("-00") == 0); Assert.assertTrue(LiteralTools.parseByte("-00") == 0);
Assert.assertTrue(literalTools.parseByte("-01") == -1); Assert.assertTrue(LiteralTools.parseByte("-01") == -1);
Assert.assertTrue(literalTools.parseByte("-0123") == -0123); Assert.assertTrue(LiteralTools.parseByte("-0123") == -0123);
Assert.assertTrue(literalTools.parseByte("-0177") == -0177); Assert.assertTrue(LiteralTools.parseByte("-0177") == -0177);
Assert.assertTrue(literalTools.parseByte("-0200") == Byte.MIN_VALUE); Assert.assertTrue(LiteralTools.parseByte("-0200") == Byte.MIN_VALUE);
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FaileOctTest1() { public void FaileOctTest1() {
literalTools.parseByte("-0201"); LiteralTools.parseByte("-0201");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailOctTest2() { public void FailOctTest2() {
literalTools.parseByte("-0377"); LiteralTools.parseByte("-0377");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailOctTest3() { public void FailOctTest3() {
literalTools.parseByte("0400"); LiteralTools.parseByte("0400");
} }
} }

View File

@ -26,7 +26,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
import org.jf.smali.literalTools; import org.jf.smali.LiteralTools;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -35,110 +35,110 @@ public class IntLiteralTest
@Test @Test
public void SuccessHexTests() { public void SuccessHexTests() {
Assert.assertTrue(literalTools.parseInt("0x0") == 0x0); Assert.assertTrue(LiteralTools.parseInt("0x0") == 0x0);
Assert.assertTrue(literalTools.parseInt("0x00") == 0x0); Assert.assertTrue(LiteralTools.parseInt("0x00") == 0x0);
Assert.assertTrue(literalTools.parseInt("0x1") == 0x1); Assert.assertTrue(LiteralTools.parseInt("0x1") == 0x1);
Assert.assertTrue(literalTools.parseInt("0x12345678") == 0x12345678); Assert.assertTrue(LiteralTools.parseInt("0x12345678") == 0x12345678);
Assert.assertTrue(literalTools.parseInt("0x7fffffff") == 0x7fffffff); Assert.assertTrue(LiteralTools.parseInt("0x7fffffff") == 0x7fffffff);
Assert.assertTrue(literalTools.parseInt("0x80000000") == Integer.MIN_VALUE); Assert.assertTrue(LiteralTools.parseInt("0x80000000") == Integer.MIN_VALUE);
Assert.assertTrue(literalTools.parseInt("0xFFFFFFFF") == -1); Assert.assertTrue(LiteralTools.parseInt("0xFFFFFFFF") == -1);
Assert.assertTrue(literalTools.parseInt("-0x00") == 0); Assert.assertTrue(LiteralTools.parseInt("-0x00") == 0);
Assert.assertTrue(literalTools.parseInt("-0x01") == -1); Assert.assertTrue(LiteralTools.parseInt("-0x01") == -1);
Assert.assertTrue(literalTools.parseInt("-0x12345678") == -0x12345678); Assert.assertTrue(LiteralTools.parseInt("-0x12345678") == -0x12345678);
Assert.assertTrue(literalTools.parseInt("-0x80000000") == Integer.MIN_VALUE); Assert.assertTrue(LiteralTools.parseInt("-0x80000000") == Integer.MIN_VALUE);
Assert.assertTrue(literalTools.parseInt("-0x1FFFFFFF") == -0x1FFFFFFF); Assert.assertTrue(LiteralTools.parseInt("-0x1FFFFFFF") == -0x1FFFFFFF);
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FaileHexTest1() { public void FaileHexTest1() {
literalTools.parseInt("-0x80000001"); LiteralTools.parseInt("-0x80000001");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailHexTest2() { public void FailHexTest2() {
literalTools.parseInt("-0xFFFFFFFF"); LiteralTools.parseInt("-0xFFFFFFFF");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailHexTest3() { public void FailHexTest3() {
literalTools.parseInt("0x100000000"); LiteralTools.parseInt("0x100000000");
} }
@Test @Test
public void SuccessDecTests() { public void SuccessDecTests() {
Assert.assertTrue(literalTools.parseInt("0") == 0); Assert.assertTrue(LiteralTools.parseInt("0") == 0);
Assert.assertTrue(literalTools.parseInt("1") == 1); Assert.assertTrue(LiteralTools.parseInt("1") == 1);
Assert.assertTrue(literalTools.parseInt("1234567890") == 1234567890); Assert.assertTrue(LiteralTools.parseInt("1234567890") == 1234567890);
Assert.assertTrue(literalTools.parseInt("2147483647") == 2147483647); Assert.assertTrue(LiteralTools.parseInt("2147483647") == 2147483647);
Assert.assertTrue(literalTools.parseInt("2147483648") == Integer.MIN_VALUE); Assert.assertTrue(LiteralTools.parseInt("2147483648") == Integer.MIN_VALUE);
Assert.assertTrue(literalTools.parseInt("4294967295") == -1); Assert.assertTrue(LiteralTools.parseInt("4294967295") == -1);
Assert.assertTrue(literalTools.parseInt("-0") == 0); Assert.assertTrue(LiteralTools.parseInt("-0") == 0);
Assert.assertTrue(literalTools.parseInt("-1") == -1); Assert.assertTrue(LiteralTools.parseInt("-1") == -1);
Assert.assertTrue(literalTools.parseInt("-1234567890") == -1234567890); Assert.assertTrue(LiteralTools.parseInt("-1234567890") == -1234567890);
Assert.assertTrue(literalTools.parseInt("-2147483647") == -2147483647); Assert.assertTrue(LiteralTools.parseInt("-2147483647") == -2147483647);
Assert.assertTrue(literalTools.parseInt("-2147483648") == Integer.MIN_VALUE); Assert.assertTrue(LiteralTools.parseInt("-2147483648") == Integer.MIN_VALUE);
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FaileDecTest1() { public void FaileDecTest1() {
literalTools.parseInt("-2147483649"); LiteralTools.parseInt("-2147483649");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailDecTest2() { public void FailDecTest2() {
literalTools.parseInt("-4294967295"); LiteralTools.parseInt("-4294967295");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailDecTest3() { public void FailDecTest3() {
literalTools.parseInt("4294967296"); LiteralTools.parseInt("4294967296");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailDecTest4() { public void FailDecTest4() {
literalTools.parseInt("4294967300"); LiteralTools.parseInt("4294967300");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailDecTest5() { public void FailDecTest5() {
literalTools.parseInt("8589934592"); LiteralTools.parseInt("8589934592");
} }
@Test @Test
public void SuccessOctTests() { public void SuccessOctTests() {
Assert.assertTrue(literalTools.parseInt("00") == 00); Assert.assertTrue(LiteralTools.parseInt("00") == 00);
Assert.assertTrue(literalTools.parseInt("01") == 01); Assert.assertTrue(LiteralTools.parseInt("01") == 01);
Assert.assertTrue(literalTools.parseInt("012345670123") == 012345670123); Assert.assertTrue(LiteralTools.parseInt("012345670123") == 012345670123);
Assert.assertTrue(literalTools.parseInt("017777777777") == Integer.MAX_VALUE); Assert.assertTrue(LiteralTools.parseInt("017777777777") == Integer.MAX_VALUE);
Assert.assertTrue(literalTools.parseInt("020000000000") == Integer.MIN_VALUE); Assert.assertTrue(LiteralTools.parseInt("020000000000") == Integer.MIN_VALUE);
Assert.assertTrue(literalTools.parseInt("037777777777") == -1); Assert.assertTrue(LiteralTools.parseInt("037777777777") == -1);
Assert.assertTrue(literalTools.parseInt("-00") == 0); Assert.assertTrue(LiteralTools.parseInt("-00") == 0);
Assert.assertTrue(literalTools.parseInt("-01") == -1); Assert.assertTrue(LiteralTools.parseInt("-01") == -1);
Assert.assertTrue(literalTools.parseInt("-012345670123") == -012345670123); Assert.assertTrue(LiteralTools.parseInt("-012345670123") == -012345670123);
Assert.assertTrue(literalTools.parseInt("-017777777777") == -017777777777); Assert.assertTrue(LiteralTools.parseInt("-017777777777") == -017777777777);
Assert.assertTrue(literalTools.parseInt("-020000000000") == Integer.MIN_VALUE); Assert.assertTrue(LiteralTools.parseInt("-020000000000") == Integer.MIN_VALUE);
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FaileOctTest1() { public void FaileOctTest1() {
literalTools.parseInt("-020000000001"); LiteralTools.parseInt("-020000000001");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailOctTest2() { public void FailOctTest2() {
literalTools.parseInt("-037777777777"); LiteralTools.parseInt("-037777777777");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailOctTest3() { public void FailOctTest3() {
literalTools.parseInt("040000000000"); LiteralTools.parseInt("040000000000");
} }
} }

View File

@ -26,7 +26,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
import org.jf.smali.literalTools; import org.jf.smali.LiteralTools;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -34,100 +34,100 @@ public class LongLiteralTest
{ {
@Test @Test
public void SuccessHexTests() { public void SuccessHexTests() {
Assert.assertTrue(literalTools.parseLong("0x0L") == 0x0); Assert.assertTrue(LiteralTools.parseLong("0x0L") == 0x0);
Assert.assertTrue(literalTools.parseLong("0x00L") == 0x0); Assert.assertTrue(LiteralTools.parseLong("0x00L") == 0x0);
Assert.assertTrue(literalTools.parseLong("0x1L") == 0x1); Assert.assertTrue(LiteralTools.parseLong("0x1L") == 0x1);
Assert.assertTrue(literalTools.parseLong("0x1234567890123456L") == 0x1234567890123456L); Assert.assertTrue(LiteralTools.parseLong("0x1234567890123456L") == 0x1234567890123456L);
Assert.assertTrue(literalTools.parseLong("0x7fffffffffffffffL") == 0x7fffffffffffffffL); Assert.assertTrue(LiteralTools.parseLong("0x7fffffffffffffffL") == 0x7fffffffffffffffL);
Assert.assertTrue(literalTools.parseLong("0x8000000000000000L") == Long.MIN_VALUE); Assert.assertTrue(LiteralTools.parseLong("0x8000000000000000L") == Long.MIN_VALUE);
Assert.assertTrue(literalTools.parseLong("0xFFFFFFFFFFFFFFFFL") == -1); Assert.assertTrue(LiteralTools.parseLong("0xFFFFFFFFFFFFFFFFL") == -1);
Assert.assertTrue(literalTools.parseLong("-0x00L") == 0); Assert.assertTrue(LiteralTools.parseLong("-0x00L") == 0);
Assert.assertTrue(literalTools.parseLong("-0x01L") == -1); Assert.assertTrue(LiteralTools.parseLong("-0x01L") == -1);
Assert.assertTrue(literalTools.parseLong("-0x1234567890123456L") == -0x1234567890123456L); Assert.assertTrue(LiteralTools.parseLong("-0x1234567890123456L") == -0x1234567890123456L);
Assert.assertTrue(literalTools.parseLong("-0x8000000000000000L") == Long.MIN_VALUE); Assert.assertTrue(LiteralTools.parseLong("-0x8000000000000000L") == Long.MIN_VALUE);
Assert.assertTrue(literalTools.parseLong("-0x1fffffffffffffffL") == -0x1fffffffffffffffL); Assert.assertTrue(LiteralTools.parseLong("-0x1fffffffffffffffL") == -0x1fffffffffffffffL);
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FaileHexTest1() { public void FaileHexTest1() {
literalTools.parseLong("-0x8000000000000001"); LiteralTools.parseLong("-0x8000000000000001");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailHexTest2() { public void FailHexTest2() {
literalTools.parseLong("-0xFFFFFFFFFFFFFFFF"); LiteralTools.parseLong("-0xFFFFFFFFFFFFFFFF");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailHexTest3() { public void FailHexTest3() {
literalTools.parseLong("0x10000000000000000"); LiteralTools.parseLong("0x10000000000000000");
} }
@Test @Test
public void SuccessDecTests() { public void SuccessDecTests() {
Assert.assertTrue(literalTools.parseLong("0L") == 0); Assert.assertTrue(LiteralTools.parseLong("0L") == 0);
Assert.assertTrue(literalTools.parseLong("1") == 1); Assert.assertTrue(LiteralTools.parseLong("1") == 1);
Assert.assertTrue(literalTools.parseLong("1234567890123456789") == 1234567890123456789L); Assert.assertTrue(LiteralTools.parseLong("1234567890123456789") == 1234567890123456789L);
Assert.assertTrue(literalTools.parseLong("9223372036854775807") == 9223372036854775807L); Assert.assertTrue(LiteralTools.parseLong("9223372036854775807") == 9223372036854775807L);
Assert.assertTrue(literalTools.parseLong("9223372036854775808") == Long.MIN_VALUE); Assert.assertTrue(LiteralTools.parseLong("9223372036854775808") == Long.MIN_VALUE);
Assert.assertTrue(literalTools.parseLong("18446744073709551615L") == -1); Assert.assertTrue(LiteralTools.parseLong("18446744073709551615L") == -1);
Assert.assertTrue(literalTools.parseLong("-0") == 0); Assert.assertTrue(LiteralTools.parseLong("-0") == 0);
Assert.assertTrue(literalTools.parseLong("-1") == -1); Assert.assertTrue(LiteralTools.parseLong("-1") == -1);
Assert.assertTrue(literalTools.parseLong("-1234567890123456789") == -1234567890123456789L); Assert.assertTrue(LiteralTools.parseLong("-1234567890123456789") == -1234567890123456789L);
Assert.assertTrue(literalTools.parseLong("-9223372036854775807") == -9223372036854775807L); Assert.assertTrue(LiteralTools.parseLong("-9223372036854775807") == -9223372036854775807L);
Assert.assertTrue(literalTools.parseLong("-9223372036854775808") == Long.MIN_VALUE); Assert.assertTrue(LiteralTools.parseLong("-9223372036854775808") == Long.MIN_VALUE);
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FaileDecTest1() { public void FaileDecTest1() {
literalTools.parseLong("-9223372036854775809"); LiteralTools.parseLong("-9223372036854775809");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailDecTest2() { public void FailDecTest2() {
literalTools.parseLong("-18446744073709551616"); LiteralTools.parseLong("-18446744073709551616");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailDecTest3() { public void FailDecTest3() {
literalTools.parseLong("18446744073709551617"); LiteralTools.parseLong("18446744073709551617");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailDecTest4() { public void FailDecTest4() {
literalTools.parseLong("18446744073709551700"); LiteralTools.parseLong("18446744073709551700");
} }
@Test @Test
public void SuccessOctTests() { public void SuccessOctTests() {
Assert.assertTrue(literalTools.parseLong("00") == 00); Assert.assertTrue(LiteralTools.parseLong("00") == 00);
Assert.assertTrue(literalTools.parseLong("01") == 01); Assert.assertTrue(LiteralTools.parseLong("01") == 01);
Assert.assertTrue(literalTools.parseLong("0123456701234567012345") == 0123456701234567012345L); Assert.assertTrue(LiteralTools.parseLong("0123456701234567012345") == 0123456701234567012345L);
Assert.assertTrue(literalTools.parseLong("0777777777777777777777") == Long.MAX_VALUE); Assert.assertTrue(LiteralTools.parseLong("0777777777777777777777") == Long.MAX_VALUE);
Assert.assertTrue(literalTools.parseLong("01000000000000000000000") == Long.MIN_VALUE); Assert.assertTrue(LiteralTools.parseLong("01000000000000000000000") == Long.MIN_VALUE);
Assert.assertTrue(literalTools.parseLong("01777777777777777777777") == -1); Assert.assertTrue(LiteralTools.parseLong("01777777777777777777777") == -1);
Assert.assertTrue(literalTools.parseLong("-00") == 0); Assert.assertTrue(LiteralTools.parseLong("-00") == 0);
Assert.assertTrue(literalTools.parseLong("-01") == -1); Assert.assertTrue(LiteralTools.parseLong("-01") == -1);
Assert.assertTrue(literalTools.parseLong("-0123456701234567012345") == -0123456701234567012345L); Assert.assertTrue(LiteralTools.parseLong("-0123456701234567012345") == -0123456701234567012345L);
Assert.assertTrue(literalTools.parseLong("-0777777777777777777777") == -0777777777777777777777L); Assert.assertTrue(LiteralTools.parseLong("-0777777777777777777777") == -0777777777777777777777L);
Assert.assertTrue(literalTools.parseLong("-01000000000000000000000") == Long.MIN_VALUE); Assert.assertTrue(LiteralTools.parseLong("-01000000000000000000000") == Long.MIN_VALUE);
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FaileOctTest1() { public void FaileOctTest1() {
literalTools.parseLong("-01000000000000000000001"); LiteralTools.parseLong("-01000000000000000000001");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailOctTest2() { public void FailOctTest2() {
literalTools.parseLong("-01777777777777777777777"); LiteralTools.parseLong("-01777777777777777777777");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailOctTest3() { public void FailOctTest3() {
literalTools.parseLong("02000000000000000000000"); LiteralTools.parseLong("02000000000000000000000");
} }
} }

View File

@ -26,7 +26,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
import org.jf.smali.literalTools; import org.jf.smali.LiteralTools;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -36,105 +36,105 @@ public class ShortLiteralTest
@Test @Test
public void SuccessHexTests() { public void SuccessHexTests() {
Assert.assertTrue(literalTools.parseShort("0x0") == 0x0); Assert.assertTrue(LiteralTools.parseShort("0x0") == 0x0);
Assert.assertTrue(literalTools.parseShort("0x00") == 0x0); Assert.assertTrue(LiteralTools.parseShort("0x00") == 0x0);
Assert.assertTrue(literalTools.parseShort("0x1") == 0x1); Assert.assertTrue(LiteralTools.parseShort("0x1") == 0x1);
Assert.assertTrue(literalTools.parseShort("0x1234") == 0x1234); Assert.assertTrue(LiteralTools.parseShort("0x1234") == 0x1234);
Assert.assertTrue(literalTools.parseShort("0x7fff") == 0x7fff); Assert.assertTrue(LiteralTools.parseShort("0x7fff") == 0x7fff);
Assert.assertTrue(literalTools.parseShort("0x8000") == Short.MIN_VALUE); Assert.assertTrue(LiteralTools.parseShort("0x8000") == Short.MIN_VALUE);
Assert.assertTrue(literalTools.parseShort("0xFFFF") == -1); Assert.assertTrue(LiteralTools.parseShort("0xFFFF") == -1);
Assert.assertTrue(literalTools.parseShort("-0x00") == 0); Assert.assertTrue(LiteralTools.parseShort("-0x00") == 0);
Assert.assertTrue(literalTools.parseShort("-0x01") == -1); Assert.assertTrue(LiteralTools.parseShort("-0x01") == -1);
Assert.assertTrue(literalTools.parseShort("-0x1234") == -0x1234); Assert.assertTrue(LiteralTools.parseShort("-0x1234") == -0x1234);
Assert.assertTrue(literalTools.parseShort("-0x8000") == Short.MIN_VALUE); Assert.assertTrue(LiteralTools.parseShort("-0x8000") == Short.MIN_VALUE);
Assert.assertTrue(literalTools.parseShort("-0x1fff") == -0x1fff); Assert.assertTrue(LiteralTools.parseShort("-0x1fff") == -0x1fff);
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FaileHexTest1() { public void FaileHexTest1() {
literalTools.parseShort("-0x8001"); LiteralTools.parseShort("-0x8001");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailHexTest2() { public void FailHexTest2() {
literalTools.parseShort("-0xFFFF"); LiteralTools.parseShort("-0xFFFF");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailHexTest3() { public void FailHexTest3() {
literalTools.parseShort("0x100000"); LiteralTools.parseShort("0x100000");
} }
@Test @Test
public void SuccessDecTests() { public void SuccessDecTests() {
Assert.assertTrue(literalTools.parseShort("0") == 0); Assert.assertTrue(LiteralTools.parseShort("0") == 0);
Assert.assertTrue(literalTools.parseShort("1") == 1); Assert.assertTrue(LiteralTools.parseShort("1") == 1);
Assert.assertTrue(literalTools.parseShort("12345") == 12345); Assert.assertTrue(LiteralTools.parseShort("12345") == 12345);
Assert.assertTrue(literalTools.parseShort("32767") == 32767); Assert.assertTrue(LiteralTools.parseShort("32767") == 32767);
Assert.assertTrue(literalTools.parseShort("32768") == Short.MIN_VALUE); Assert.assertTrue(LiteralTools.parseShort("32768") == Short.MIN_VALUE);
Assert.assertTrue(literalTools.parseShort("65535") == -1); Assert.assertTrue(LiteralTools.parseShort("65535") == -1);
Assert.assertTrue(literalTools.parseShort("-0") == 0); Assert.assertTrue(LiteralTools.parseShort("-0") == 0);
Assert.assertTrue(literalTools.parseShort("-1") == -1); Assert.assertTrue(LiteralTools.parseShort("-1") == -1);
Assert.assertTrue(literalTools.parseShort("-12345") == -12345); Assert.assertTrue(LiteralTools.parseShort("-12345") == -12345);
Assert.assertTrue(literalTools.parseShort("-32767") == -32767); Assert.assertTrue(LiteralTools.parseShort("-32767") == -32767);
Assert.assertTrue(literalTools.parseShort("-32768") == Short.MIN_VALUE); Assert.assertTrue(LiteralTools.parseShort("-32768") == Short.MIN_VALUE);
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FaileDecTest1() { public void FaileDecTest1() {
literalTools.parseShort("-32769"); LiteralTools.parseShort("-32769");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailDecTest2() { public void FailDecTest2() {
literalTools.parseShort("-65535"); LiteralTools.parseShort("-65535");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailDecTest3() { public void FailDecTest3() {
literalTools.parseShort("65536"); LiteralTools.parseShort("65536");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailDecTest4() { public void FailDecTest4() {
literalTools.parseShort("65600"); LiteralTools.parseShort("65600");
} }
@Test @Test
public void SuccessOctTests() { public void SuccessOctTests() {
Assert.assertTrue(literalTools.parseShort("00") == 00); Assert.assertTrue(LiteralTools.parseShort("00") == 00);
Assert.assertTrue(literalTools.parseShort("01") == 01); Assert.assertTrue(LiteralTools.parseShort("01") == 01);
Assert.assertTrue(literalTools.parseShort("012345") == 012345); Assert.assertTrue(LiteralTools.parseShort("012345") == 012345);
Assert.assertTrue(literalTools.parseShort("077777") == Short.MAX_VALUE); Assert.assertTrue(LiteralTools.parseShort("077777") == Short.MAX_VALUE);
Assert.assertTrue(literalTools.parseShort("0100000") == Short.MIN_VALUE); Assert.assertTrue(LiteralTools.parseShort("0100000") == Short.MIN_VALUE);
Assert.assertTrue(literalTools.parseShort("0177777") == -1); Assert.assertTrue(LiteralTools.parseShort("0177777") == -1);
Assert.assertTrue(literalTools.parseShort("-00") == 0); Assert.assertTrue(LiteralTools.parseShort("-00") == 0);
Assert.assertTrue(literalTools.parseShort("-01") == -1); Assert.assertTrue(LiteralTools.parseShort("-01") == -1);
Assert.assertTrue(literalTools.parseShort("-012345") == -012345); Assert.assertTrue(LiteralTools.parseShort("-012345") == -012345);
Assert.assertTrue(literalTools.parseShort("-077777") == -077777); Assert.assertTrue(LiteralTools.parseShort("-077777") == -077777);
Assert.assertTrue(literalTools.parseShort("-0100000") == Short.MIN_VALUE); Assert.assertTrue(LiteralTools.parseShort("-0100000") == Short.MIN_VALUE);
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FaileOctTest1() { public void FaileOctTest1() {
literalTools.parseShort("-0100001"); LiteralTools.parseShort("-0100001");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailOctTest2() { public void FailOctTest2() {
literalTools.parseShort("-0177777"); LiteralTools.parseShort("-0177777");
} }
@Test(expected=NumberFormatException.class) @Test(expected=NumberFormatException.class)
public void FailOctTest3() { public void FailOctTest3() {
literalTools.parseShort("0200000"); LiteralTools.parseShort("0200000");
} }
} }