/* * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @test * @bug 5017980 6576055 8041972 8055251 * @summary Test parsing methods * @author Joseph D. Darcy
*/
/** * There are seven methods in java.lang.Long which transform strings * into a long or Long value: * * public Long(String s) * public static Long decode(String nm) * public static long parseLong(CharSequence s, int radix, int beginIndex, int endIndex) * public static long parseLong(String s, int radix) * public static long parseLong(String s) * public static Long valueOf(String s, int radix) * public static Long valueOf(String s) * * Besides decode, all the methods and constructor call down into * parseLong(CharSequence, int, int, int) to do the actual work. Therefore, the * behavior of parseLong(CharSequence, int, int, int) will be tested here.
*/
privatestaticvoid check(long expected, String val) { long n = Long.parseLong(val); if (n != expected) thrownew RuntimeException("Long.parseLong failed. String:" +
val + " Result:" + n);
}
privatestaticvoid checkFailure(String val) { long n = 0L; try {
n = Long.parseLong(val);
System.err.println("parseLong(" + val + ") incorrectly returned " + n); thrownew RuntimeException();
} catch (NumberFormatException nfe) {
; // Expected
}
}
privatestaticvoid checkNumberFormatException(String val, int start, int end, int radix) { long n = 0; try {
n = Long.parseLong(val, start, end, radix);
System.err.println("parseLong(" + val + ", " + start + ", " + end + ", " + radix + ") incorrectly returned " + n); thrownew RuntimeException();
} catch (NumberFormatException nfe) {
; // Expected
}
}
privatestaticvoid checkIndexOutOfBoundsException(String val, int start, int end, int radix) { long n = 0; try {
n = Long.parseLong(val, start, end, radix);
System.err.println("parseLong(" + val + ", " + start + ", " + end + ", " + radix + ") incorrectly returned " + n); thrownew RuntimeException();
} catch (IndexOutOfBoundsException ioob) {
; // Expected
}
}
privatestaticvoid checkNull(int start, int end, int radix) { long n = 0; try {
n = Long.parseLong(null, start, end, radix);
System.err.println("parseLong(null, " + start + ", " + end + ", " + radix + ") incorrectly returned " + n); thrownew RuntimeException();
} catch (NullPointerException npe) {
; // Expected
}
}
privatestaticvoid check(long expected, String val, int start, int end, int radix) { long n = Long.parseLong(val, start, end, radix); if (n != expected) thrownew RuntimeException("Long.parseLong failed. Expexted: " + expected + " String: \"" +
val + "\", start: " + start + ", end: " + end + " radix: " + radix + " Result: " + n);
}
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.21Bemerkung:
(vorverarbeitet am 2026-06-04)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.