001: //--------------------------------------------------------------------------
002: // Copyright (c) 2004, Drew Davidson and Luke Blanshard
003: // All rights reserved.
004: //
005: // Redistribution and use in source and binary forms, with or without
006: // modification, are permitted provided that the following conditions are
007: // met:
008: //
009: // Redistributions of source code must retain the above copyright notice,
010: // this list of conditions and the following disclaimer.
011: // Redistributions in binary form must reproduce the above copyright
012: // notice, this list of conditions and the following disclaimer in the
013: // documentation and/or other materials provided with the distribution.
014: // Neither the name of the Drew Davidson nor the names of its contributors
015: // may be used to endorse or promote products derived from this software
016: // without specific prior written permission.
017: //
018: // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
019: // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
020: // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
021: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
022: // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
023: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
024: // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
025: // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
026: // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
027: // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
028: // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
029: // DAMAGE.
030: //--------------------------------------------------------------------------
031: package org.ognl.test;
032:
033: import java.util.*;
034: import junit.framework.TestSuite;
035: import ognl.ExpressionSyntaxException;
036:
037: public class ConstantTest extends OgnlTestCase {
038: private static Object[][] TESTS = {
039: { "12345", new Integer(12345) },
040: { "0x100", new Integer(256) },
041: { "0xfE", new Integer(254) },
042: { "01000", new Integer(512) },
043: { "1234L", new Long(1234) },
044: { "12.34", new Double(12.34) },
045: { ".1234", new Double(.12340000000000) },
046: { "12.34f", new Float(12.34f) },
047: { "12.", new Double(12) },
048: { "12e+1d", new Double(120) },
049: { "'x'", new Character('x') },
050: { "'\\n'", new Character('\n') },
051: { "'\\u048c'", new Character('\u048c') },
052: { "'\\47'", new Character('\47') },
053: { "'\\367'", new Character('\367') },
054: { "'\\367", ExpressionSyntaxException.class },
055: { "'\\x'", ExpressionSyntaxException.class },
056: { "\"hello world\"", "hello world" },
057: {
058: "\"\\u00a0\\u0068ell\\'o\\\\\\n\\r\\f\\t\\b\\\"\\167orld\\\"\"",
059: "\u00a0hell'o\\\n\r\f\t\b\"world\"" },
060: { "\"hello world", ExpressionSyntaxException.class },
061: { "\"hello\\x world\"", ExpressionSyntaxException.class },
062: { "null", null },
063: { "true", Boolean.TRUE },
064: { "false", Boolean.FALSE },
065: {
066: "{ false, true, null, 0, 1. }",
067: Arrays.asList(new Object[] { Boolean.FALSE,
068: Boolean.TRUE, null, new Integer(0),
069: new Double(1) }) },
070: {
071: "'HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"'",
072: "HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"" }, };
073:
074: /*===================================================================
075: Public static methods
076: ===================================================================*/
077: public static TestSuite suite() {
078: TestSuite result = new TestSuite();
079:
080: for (int i = 0; i < TESTS.length; i++) {
081: result.addTest(new ConstantTest((String) TESTS[i][0] + " ("
082: + TESTS[i][1] + ")", null, (String) TESTS[i][0],
083: TESTS[i][1]));
084: }
085: return result;
086: }
087:
088: /*===================================================================
089: Constructors
090: ===================================================================*/
091: public ConstantTest() {
092: super ();
093: }
094:
095: public ConstantTest(String name) {
096: super (name);
097: }
098:
099: public ConstantTest(String name, Object root,
100: String expressionString, Object expectedResult,
101: Object setValue, Object expectedAfterSetResult) {
102: super (name, root, expressionString, expectedResult, setValue,
103: expectedAfterSetResult);
104: }
105:
106: public ConstantTest(String name, Object root,
107: String expressionString, Object expectedResult,
108: Object setValue) {
109: super (name, root, expressionString, expectedResult, setValue);
110: }
111:
112: public ConstantTest(String name, Object root,
113: String expressionString, Object expectedResult) {
114: super(name, root, expressionString, expectedResult);
115: }
116: }
|