001: /***
002: * Retrotranslator: a Java bytecode transformer that translates Java classes
003: * compiled with JDK 5.0 into classes that can be run on JVM 1.4.
004: *
005: * Copyright (c) 2005 - 2008 Taras Puchko
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: * 3. Neither the name of the copyright holders nor the names of its
017: * contributors may be used to endorse or promote products derived from
018: * this software without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
021: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
022: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
023: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
024: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
025: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
026: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
027: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
028: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
029: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
030: * THE POSSIBILITY OF SUCH DAMAGE.
031: */package net.sf.retrotranslator.runtime.format;
032:
033: import java.math.BigInteger;
034: import java.util.*;
035: import net.sf.retrotranslator.tests.TestCaseBase;
036:
037: /**
038: * @author Taras Puchko
039: */
040: public class NondecimalIntegralConversionTestCase extends TestCaseBase {
041:
042: public void testFormat_Hex() throws Exception {
043: assertFormat("64", "%x", 100);
044: assertFormat("ffffff9c", "%x", -100);
045: assertFormat("64", "%x", (byte) 100);
046: assertFormat("9c", "%x", (byte) -100);
047: assertFormat("64", "%x", (short) 100);
048: assertFormat("ff9c", "%x", (short) -100);
049: assertFormat("64", "%x", 100L);
050: assertFormat("ffffffffffffff9c", "%x", -100L);
051: assertFormat("f4240", "%x", BigInteger.valueOf(1000000));
052: assertFormat("-f4240", "%x", BigInteger.valueOf(-1000000));
053:
054: assertFormat("00064", "%05x", 100);
055: assertFormat("0x064", "%#05x", 100);
056: assertFormat("0xffffff9c", "%#x", -100);
057: assertFormat("0xffffffffffffff9c", "%#x", -100L);
058: assertFormat("0x00ffffffffffffff9c", "%0#20x", -100L);
059: assertFormat("ffffffffffffff9c ", "%-20x", -100L);
060: assertFormat("-0xf4240", "%#x", BigInteger.valueOf(-1000000));
061: assertFormat("-0x00f4240", "%#010x", BigInteger
062: .valueOf(-1000000));
063: assertFormat("+0x00f4240", "%#+010x", BigInteger
064: .valueOf(1000000));
065: assertFormat(" 0x00f4240", "%# 010x", BigInteger
066: .valueOf(1000000));
067: assertFormat(" -0xf4240", "%#10x", BigInteger
068: .valueOf(-1000000));
069: assertFormat("-0xf4240 ", "%-#10x", BigInteger
070: .valueOf(-1000000));
071: assertFormat("(0xf4240) ", "%-(#15x", BigInteger
072: .valueOf(-1000000));
073: assertFormat(" +0xf4240", "%+#15x", BigInteger
074: .valueOf(1000000));
075: assertFormat(" f4240", "% x", BigInteger.valueOf(1000000));
076: assertFormat("-0XF4240", "%#X", BigInteger.valueOf(-1000000));
077:
078: assertFormatException(IllegalFormatPrecisionException.class,
079: "%,01.2x");
080: assertFormatException(MissingFormatWidthException.class, "%,-x");
081: assertFormatException(MissingFormatWidthException.class, "%,0x");
082: assertFormatException(
083: FormatFlagsConversionMismatchException.class, "%,x");
084: assertFormatException(MissingFormatArgumentException.class,
085: "%(x");
086: assertFormatException(IllegalFormatConversionException.class,
087: "%(x", "z");
088: assertFormatException(
089: FormatFlagsConversionMismatchException.class, "%(x", 5);
090: assertFormatException(
091: FormatFlagsConversionMismatchException.class, "%+x", 5);
092: assertFormatException(
093: FormatFlagsConversionMismatchException.class, "% x", 5);
094: assertFormatException(
095: FormatFlagsConversionMismatchException.class, "%,x", 5);
096: assertFormatException(
097: FormatFlagsConversionMismatchException.class, "%,x",
098: BigInteger.valueOf(5));
099: }
100:
101: public void testFormat_Octal() throws Exception {
102: assertFormat("144", "%o", 100);
103: assertFormat("37777777634", "%o", -100);
104: assertFormat("144", "%o", (byte) 100);
105: assertFormat("234", "%o", (byte) -100);
106: assertFormat("144", "%o", (short) 100);
107: assertFormat("177634", "%o", (short) -100);
108: assertFormat("144", "%o", 100L);
109: assertFormat("1777777777777777777634", "%o", -100L);
110: assertFormat("3641100", "%o", BigInteger.valueOf(1000000));
111: assertFormat("-3641100", "%o", BigInteger.valueOf(-1000000));
112:
113: assertFormat("00144", "%05o", 100);
114: assertFormat("0144", "%#o", 100);
115: assertFormat("037777777634", "%#o", -100);
116: assertFormat("01777777777777777777634", "%#o", -100L);
117: assertFormat("0001777777777777777777634", "%0#25o", -100L);
118: assertFormat("1777777777777777777634 ", "%-25o", -100L);
119: assertFormat("-03641100", "%#o", BigInteger.valueOf(-1000000));
120: assertFormat("-003641100", "%#010o", BigInteger
121: .valueOf(-1000000));
122: assertFormat("+003641100", "%#+010o", BigInteger
123: .valueOf(1000000));
124: assertFormat(" 003641100", "%# 010o", BigInteger
125: .valueOf(1000000));
126: assertFormat(" -03641100", "%#10o", BigInteger
127: .valueOf(-1000000));
128: assertFormat("-03641100 ", "%-#10o", BigInteger
129: .valueOf(-1000000));
130: assertFormat("(03641100) ", "%-(#15o", BigInteger
131: .valueOf(-1000000));
132: assertFormat(" +03641100", "%+#15o", BigInteger
133: .valueOf(1000000));
134: assertFormat(" 3641100", "% o", BigInteger.valueOf(1000000));
135:
136: assertFormatException(UnknownFormatConversionException.class,
137: "%#O");
138: assertFormatException(IllegalFormatPrecisionException.class,
139: "%,01.2o");
140: assertFormatException(MissingFormatWidthException.class, "%,-o");
141: assertFormatException(MissingFormatWidthException.class, "%,0o");
142: assertFormatException(
143: FormatFlagsConversionMismatchException.class, "%,o");
144: assertFormatException(MissingFormatArgumentException.class,
145: "%(o");
146: assertFormatException(IllegalFormatConversionException.class,
147: "%(o", "z");
148: assertFormatException(
149: FormatFlagsConversionMismatchException.class, "%(o", 5);
150: assertFormatException(
151: FormatFlagsConversionMismatchException.class, "%+o", 5);
152: assertFormatException(
153: FormatFlagsConversionMismatchException.class, "% o", 5);
154: assertFormatException(
155: FormatFlagsConversionMismatchException.class, "%,o", 5);
156: assertFormatException(
157: FormatFlagsConversionMismatchException.class, "%,o",
158: BigInteger.valueOf(5));
159: }
160:
161: }
|