KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > retrotranslator > runtime > format > NondecimalIntegralConversionTestCase


1 /***
2  * Retrotranslator: a Java bytecode transformer that translates Java classes
3  * compiled with JDK 5.0 into classes that can be run on JVM 1.4.
4  *
5  * Copyright (c) 2005 - 2007 Taras Puchko
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the copyright holders nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30  * THE POSSIBILITY OF SUCH DAMAGE.
31  */

32 package net.sf.retrotranslator.runtime.format;
33
34 import java.math.BigInteger JavaDoc;
35 import java.util.*;
36 import net.sf.retrotranslator.tests.BaseTestCase;
37
38 /**
39  * @author Taras Puchko
40  */

41 public class NondecimalIntegralConversionTestCase extends BaseTestCase {
42
43     public void testFormat_Hex() throws Exception JavaDoc {
44         assertFormat("64", "%x", 100);
45         assertFormat("ffffff9c", "%x", -100);
46         assertFormat("64", "%x", (byte) 100);
47         assertFormat("9c", "%x", (byte) -100);
48         assertFormat("64", "%x", (short) 100);
49         assertFormat("ff9c", "%x", (short) -100);
50         assertFormat("64", "%x", 100L);
51         assertFormat("ffffffffffffff9c", "%x", -100L);
52         assertFormat("f4240", "%x", BigInteger.valueOf(1000000));
53         assertFormat("-f4240", "%x", BigInteger.valueOf(-1000000));
54
55         assertFormat("00064", "%05x", 100);
56         assertFormat("0x064", "%#05x", 100);
57         assertFormat("0xffffff9c", "%#x", -100);
58         assertFormat("0xffffffffffffff9c", "%#x", -100L);
59         assertFormat("0x00ffffffffffffff9c", "%0#20x", -100L);
60         assertFormat("ffffffffffffff9c ", "%-20x", -100L);
61         assertFormat("-0xf4240", "%#x", BigInteger.valueOf(-1000000));
62         assertFormat("-0x00f4240", "%#010x", BigInteger.valueOf(-1000000));
63         assertFormat("+0x00f4240", "%#+010x", BigInteger.valueOf(1000000));
64         assertFormat(" 0x00f4240", "%# 010x", BigInteger.valueOf(1000000));
65         assertFormat(" -0xf4240", "%#10x", BigInteger.valueOf(-1000000));
66         assertFormat("-0xf4240 ", "%-#10x", BigInteger.valueOf(-1000000));
67         assertFormat("(0xf4240) ", "%-(#15x", BigInteger.valueOf(-1000000));
68         assertFormat(" +0xf4240", "%+#15x", BigInteger.valueOf(1000000));
69         assertFormat(" f4240", "% x", BigInteger.valueOf(1000000));
70         assertFormat("-0XF4240", "%#X", BigInteger.valueOf(-1000000));
71
72         assertFormatException(IllegalFormatPrecisionException.class, "%,01.2x");
73         assertFormatException(MissingFormatWidthException.class, "%,-x");
74         assertFormatException(MissingFormatWidthException.class, "%,0x");
75         assertFormatException(FormatFlagsConversionMismatchException.class, "%,x");
76         assertFormatException(MissingFormatArgumentException.class, "%(x");
77         assertFormatException(IllegalFormatConversionException.class, "%(x", "z");
78         assertFormatException(FormatFlagsConversionMismatchException.class, "%(x", 5);
79         assertFormatException(FormatFlagsConversionMismatchException.class, "%+x", 5);
80         assertFormatException(FormatFlagsConversionMismatchException.class, "% x", 5);
81         assertFormatException(FormatFlagsConversionMismatchException.class, "%,x", 5);
82         assertFormatException(FormatFlagsConversionMismatchException.class, "%,x", BigInteger.valueOf(5));
83     }
84
85     public void testFormat_Octal() throws Exception JavaDoc {
86         assertFormat("144", "%o", 100);
87         assertFormat("37777777634", "%o", -100);
88         assertFormat("144", "%o", (byte) 100);
89         assertFormat("234", "%o", (byte) -100);
90         assertFormat("144", "%o", (short) 100);
91         assertFormat("177634", "%o", (short) -100);
92         assertFormat("144", "%o", 100L);
93         assertFormat("1777777777777777777634", "%o", -100L);
94         assertFormat("3641100", "%o", BigInteger.valueOf(1000000));
95         assertFormat("-3641100", "%o", BigInteger.valueOf(-1000000));
96
97         assertFormat("00144", "%05o", 100);
98         assertFormat("0144", "%#o", 100);
99         assertFormat("037777777634", "%#o", -100);
100         assertFormat("01777777777777777777634", "%#o", -100L);
101         assertFormat("0001777777777777777777634", "%0#25o", -100L);
102         assertFormat("1777777777777777777634 ", "%-25o", -100L);
103         assertFormat("-03641100", "%#o", BigInteger.valueOf(-1000000));
104         assertFormat("-003641100", "%#010o", BigInteger.valueOf(-1000000));
105         assertFormat("+003641100", "%#+010o", BigInteger.valueOf(1000000));
106         assertFormat(" 003641100", "%# 010o", BigInteger.valueOf(1000000));
107         assertFormat(" -03641100", "%#10o", BigInteger.valueOf(-1000000));
108         assertFormat("-03641100 ", "%-#10o", BigInteger.valueOf(-1000000));
109         assertFormat("(03641100) ", "%-(#15o", BigInteger.valueOf(-1000000));
110         assertFormat(" +03641100", "%+#15o", BigInteger.valueOf(1000000));
111         assertFormat(" 3641100", "% o", BigInteger.valueOf(1000000));
112
113         assertFormatException(UnknownFormatConversionException.class, "%#O");
114         assertFormatException(IllegalFormatPrecisionException.class, "%,01.2o");
115         assertFormatException(MissingFormatWidthException.class, "%,-o");
116         assertFormatException(MissingFormatWidthException.class, "%,0o");
117         assertFormatException(FormatFlagsConversionMismatchException.class, "%,o");
118         assertFormatException(MissingFormatArgumentException.class, "%(o");
119         assertFormatException(IllegalFormatConversionException.class, "%(o", "z");
120         assertFormatException(FormatFlagsConversionMismatchException.class, "%(o", 5);
121         assertFormatException(FormatFlagsConversionMismatchException.class, "%+o", 5);
122         assertFormatException(FormatFlagsConversionMismatchException.class, "% o", 5);
123         assertFormatException(FormatFlagsConversionMismatchException.class, "%,o", 5);
124         assertFormatException(FormatFlagsConversionMismatchException.class, "%,o", BigInteger.valueOf(5));
125     }
126
127 }
Popular Tags