TestLong.java revision 827:50a9a4db3500
1/* 2 * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20 * CA 95054 USA or visit www.sun.com if you need additional information or 21 * have any questions. 22 */ 23 24/* 25 * @test 26 * @summary Tests <long> element 27 * @author Sergey Malenkov 28 */ 29 30import java.beans.XMLDecoder; 31 32public final class TestLong extends AbstractTest { 33 public static final String XML 34 = "<java>\n" 35 + " <long>0</long>\n" 36 + " <long>127</long>\n" 37 + " <long>-128</long>\n" 38 + " <long>32767</long>\n" 39 + " <long>-32768</long>\n" 40 + " <long>2147483647</long>\n" 41 + " <long>-2147483648</long>\n" 42 + " <long>9223372036854775807</long>\n" 43 + " <long>-9223372036854775808</long>\n" 44 + "</java>"; 45 46 public static void main(String[] args) { 47 new TestLong().test(true); 48 } 49 50 @Override 51 protected void validate(XMLDecoder decoder) { 52 validate(0L, decoder.readObject()); 53 validate((long) Byte.MAX_VALUE, decoder.readObject()); 54 validate((long) Byte.MIN_VALUE, decoder.readObject()); 55 validate((long) Short.MAX_VALUE, decoder.readObject()); 56 validate((long) Short.MIN_VALUE, decoder.readObject()); 57 validate((long) Integer.MAX_VALUE, decoder.readObject()); 58 validate((long) Integer.MIN_VALUE, decoder.readObject()); 59 validate(Long.MAX_VALUE, decoder.readObject()); 60 validate(Long.MIN_VALUE, decoder.readObject()); 61 } 62 63 private static void validate(long value, Object object) { 64 if (!object.equals(Long.valueOf(value))) { 65 throw new Error("long " + value + " expected"); 66 } 67 } 68} 69