コード例 #1
0
 @Test
 public void testParseHexPrefixEquals() throws Exception {
   long i = 123456;
   String s = Long.toHexString(i);
   String s1 = "0x" + s;
   String s2 = "0X" + s;
   //  Transitive property means we only have to test twice
   assertEquals(ParseLong.parseHex(s), ParseLong.parseHex(s1));
   assertEquals(ParseLong.parseHex(s1), ParseLong.parseHex(s2));
 }
コード例 #2
0
 @Test
 public void testParseHexOrDefaultOk() throws Exception {
   long i = 0x12;
   String s = "0x" + Long.toHexString(i);
   int def = 14;
   assertEquals(i, ParseLong.parseHexOrDefault(s, def));
 }
コード例 #3
0
 @Test
 public void testParseDecOrDefaultOk() throws Exception {
   long i = 12;
   String s = Long.toString(i);
   int def = 14;
   assertEquals(i, ParseLong.parseDecOrDefault(s, def));
 }
コード例 #4
0
 @Test
 public void testParseHexOptionalOk() throws Exception {
   long i = 0x14;
   String s = Long.toHexString(i);
   OptionalLong ret = ParseLong.parseHexOptional(s);
   assertTrue(ret.isPresent());
   assertEquals(i, ret.getAsLong());
 }
コード例 #5
0
 @Test
 public void testParseHexOrDefaultNull() throws Exception {
   int def = 14;
   assertEquals(def, ParseLong.parseHexOrDefault(null, def));
 }
コード例 #6
0
 @Test
 public void testParseHexOrDefaultFail() throws Exception {
   String s = "aq12.g";
   int def = 14;
   assertEquals(def, ParseLong.parseHexOrDefault(s, def));
 }
コード例 #7
0
 //  Test dec/hex picking
 @Test
 public void testParse_Hex() throws Exception {
   long i = 0x123ABC;
   String s = "0x" + Long.toHexString(i);
   assertEquals(i, ParseLong.parse(s));
 }
コード例 #8
0
 //  For values lower than the signed min, the method shouldn't thrown an exception but it will
 // return a
 //  garbage result
 @Test
 public void testParseDec_MinSignedUnderflow() throws Exception {
   String s = "-9223372036854775809";
   ParseLong.parseDec(s);
 }
コード例 #9
0
 //  Test empty
 @Test(expected = NumberFormatException.class)
 public void testParseDec_Empty() throws Exception {
   ParseLong.parseDec("");
 }
コード例 #10
0
 //  Test negative sign inside
 @Test(expected = NumberFormatException.class)
 public void testParseDec_NegativeBad() throws Exception {
   ParseLong.parseDec("-12-34");
 }
コード例 #11
0
 //  Test negative sign prefix
 @Test
 public void testParseDec_Negative() throws Exception {
   long i = -123456;
   String s = Long.toString(i);
   assertEquals(i, ParseLong.parseDec(s));
 }
コード例 #12
0
 @Test
 public void testParseHexOptionalFail() throws Exception {
   String s = "astg2148465klkast12hkls";
   OptionalLong ret = ParseLong.parseHexOptional(s);
   assertFalse(ret.isPresent());
 }
コード例 #13
0
 @Test
 public void testParseHexOptionalNull() throws Exception {
   OptionalLong ret = ParseLong.parseHexOptional(null);
   assertFalse(ret.isPresent());
 }
コード例 #14
0
 //  Test negative sign prefix reject (after prefix)
 @Test(expected = NumberFormatException.class)
 public void testParseHex_Negative2() throws Exception {
   String s = "0x-12AC";
   ParseLong.parseHex(s);
 }
コード例 #15
0
 //  Test bad
 @Test(expected = NumberFormatException.class)
 public void testParseHex_Bad() throws Exception {
   ParseLong.parseHex("12AB-**&1'");
 }
コード例 #16
0
 //  Technically this is the same as MaxUnsigned
 @Test
 public void testParseHexMinSigned() throws Exception {
   long i = Long.MIN_VALUE;
   String s = "0x" + Long.toHexString(i);
   assertEquals(i, ParseLong.parseHex(s));
 }
コード例 #17
0
 //  For values larger than the unsigned max, the method shouldn't thrown an exception but it will
 // return a
 //  garbage result
 @Test
 public void testParseHexMaxUnsignedOverflow() throws Exception {
   String s = "0x10000000000000000";
   ParseLong.parseHex(s);
 }
コード例 #18
0
 @Test
 public void testParseHexMaxUnsigned() throws Exception {
   long i = 0xFFFFFFFFFFFFFFFFL;
   String s = "0xFFFFFFFFFFFFFFFF";
   assertEquals(i, ParseLong.parseHex(s));
 }
コード例 #19
0
 @Test
 public void testParseOptionalHexFail() throws Exception {
   String s = "0x12akjhsdr?";
   OptionalLong ret = ParseLong.parseOptional(s);
   assertFalse(ret.isPresent());
 }
コード例 #20
0
 //  Test null reject
 @Test(expected = NumberFormatException.class)
 public void testParse_Null() throws Exception {
   ParseLong.parse(null);
 }
コード例 #21
0
 //  Test positive sign prefix reject (no prefix)
 @Test(expected = NumberFormatException.class)
 public void testParseHex_Positive3() throws Exception {
   String s = "+12AB";
   ParseLong.parseHex(s);
 }
コード例 #22
0
 //  Test positive sign inside
 @Test(expected = NumberFormatException.class)
 public void testParseDec_PositiveBad() throws Exception {
   ParseLong.parseDec("+12+34");
 }
コード例 #23
0
 //  Test dec/hex dec trimming
 @Test
 public void testParse_DecTrim() throws Exception {
   long i = 123456;
   String s = WHITESPACE + Long.toString(i) + WHITESPACE;
   assertEquals(i, ParseLong.parse(s));
 }
コード例 #24
0
 //  Test dec/hex picking
 @Test
 public void testParse_Dec() throws Exception {
   long i = 123456;
   String s = Long.toString(i);
   assertEquals(i, ParseLong.parse(s));
 }
コード例 #25
0
 //  Test dec/hex hex trimming
 @Test
 public void testParse_HexTrim() throws Exception {
   long i = 0x123ABC;
   String s = WHITESPACE + "0x" + Long.toHexString(i) + WHITESPACE;
   assertEquals(i, ParseLong.parse(s));
 }
コード例 #26
0
 //  Test prefix with no value reject
 @Test(expected = NumberFormatException.class)
 public void testParseHex_PrefixNoValue() throws Exception {
   String s = "0x";
   ParseLong.parseHex(s);
 }
コード例 #27
0
 //  Test missing hex digits reject
 @Test(expected = NumberFormatException.class)
 public void testParse_EmptyHex() throws Exception {
   String s = "0x";
   ParseLong.parse(s);
 }
コード例 #28
0
 @Test
 public void testParseOrDefaultDecDefault() throws Exception {
   String s = "abcd";
   int def = 14;
   assertEquals(def, ParseLong.parseOrDefault(s, def));
 }
コード例 #29
0
 @Test
 public void testParseDec_MaxSigned() throws Exception {
   long i = Long.MAX_VALUE;
   String s = Long.toString(i);
   assertEquals(i, ParseLong.parseDec(s));
 }
コード例 #30
0
 //  For values larger than the unsigned max, the method shouldn't thrown an exception but it will
 // return a
 //  garbage result
 @Test
 public void testParseDec_UnsignedOverflow() throws Exception {
   String s = "18446744073709551616";
   ParseLong.parseDec(s);
 }