001: /* ****************************************************************************
002: * ViewSchema_Test.java
003: * ****************************************************************************/
004:
005: /* J_LZ_COPYRIGHT_BEGIN *******************************************************
006: * Copyright 2001-2007 Laszlo Systems, Inc. All Rights Reserved. *
007: * Use is subject to license terms. *
008: * J_LZ_COPYRIGHT_END *********************************************************/
009:
010: package org.openlaszlo.compiler;
011:
012: import java.io.*;
013: import java.util.*; // import org.apache.oro.text.regex.*;
014: import org.jdom.*;
015: import org.openlaszlo.compiler.ViewSchema;
016: import org.openlaszlo.utils.ChainedException;
017: import org.jdom.input.SAXBuilder;
018: import org.xml.sax.InputSource;
019:
020: /*
021: * junit.awtui.TestRunner
022: * junit.swingui.TestRunner
023: * junit.textui.TestRunner
024: *
025: *
026: * java junit.textui.TestRunner org.openlaszlo.ic.ViewSchema_Test
027: */
028:
029: import junit.framework.*;
030:
031: public class ViewSchema_Test extends TestCase {
032: public ViewSchema_Test(String name) {
033: super (name);
034: }
035:
036: public void setUp() {
037: }
038:
039: public void testParseColors() {
040: ViewSchema schema = new ViewSchema();
041: assertEquals("parseColor #FFFFFF", 0XFFFFFF, schema
042: .parseColor("#FFFFFF"));
043: assertEquals("parseColor #FF0000", 0xFF0000, schema
044: .parseColor("#FF0000"));
045: assertEquals("parseColor #800080", 0x800080, schema
046: .parseColor("#800080"));
047: assertEquals("parseColor #FF00FF", 0xFF00FF, schema
048: .parseColor("#FF00FF"));
049: assertEquals("parseColor #123456", 0x123456, schema
050: .parseColor("#123456"));
051: assertEquals("parseColor #DEADBE", 0xDEADBE, schema
052: .parseColor("#DEADBE"));
053: assertEquals("parseColor #000000", 0x000000, schema
054: .parseColor("#000000"));
055: assertEquals("parseColor black", 0x000000, schema
056: .parseColor("black"));
057: assertEquals("parseColor green", 0x008000, schema
058: .parseColor("green"));
059: assertEquals("parseColor silver", 0xC0C0C0, schema
060: .parseColor("silver"));
061: assertEquals("parseColor lime", 0x00FF00, schema
062: .parseColor("lime"));
063: assertEquals("parseColor gray", 0x808080, schema
064: .parseColor("gray"));
065: assertEquals("parseColor olive", 0x808000, schema
066: .parseColor("olive"));
067: assertEquals("parseColor white", 0xFFFFFF, schema
068: .parseColor("white"));
069: assertEquals("parseColor yellow", 0xFFFF00, schema
070: .parseColor("yellow"));
071: assertEquals("parseColor maroon", 0x800000, schema
072: .parseColor("maroon"));
073: assertEquals("parseColor navy", 0x000080, schema
074: .parseColor("navy"));
075: assertEquals("parseColor red", 0xFF0000, schema
076: .parseColor("red"));
077: assertEquals("parseColor blue", 0x0000FF, schema
078: .parseColor("blue"));
079: assertEquals("parseColor purple", 0x800080, schema
080: .parseColor("purple"));
081: assertEquals("parseColor teal", 0x008080, schema
082: .parseColor("teal"));
083: assertEquals("parseColor fuchsia", 0xFF00FF, schema
084: .parseColor("fuchsia"));
085: assertEquals("parseColor aqua", 0x00FFFF, schema
086: .parseColor("aqua"));
087:
088: }
089:
090: public void testHTMLContent() {
091: ViewSchema schema = new ViewSchema();
092:
093: assertTrue("hasHTMLContent text", schema
094: .hasHTMLContent(new Element("text")));
095: assertTrue("hasHTMLContent class", !schema
096: .hasHTMLContent(new Element("class")));
097: assertTrue("hasHTMLContent method", !schema
098: .hasHTMLContent(new Element("method")));
099: assertTrue("hasHTMLContent property", !schema
100: .hasHTMLContent(new Element("property")));
101: assertTrue("hasHTMLContent script", !schema
102: .hasHTMLContent(new Element("script")));
103: }
104:
105: public void testSetAttributes() {
106:
107: ViewSchema schema = new ViewSchema();
108: CompilationEnvironment env = new CompilationEnvironment();
109: try {
110: schema.loadSchema(env);
111: } catch (JDOMException e) {
112: throw new RuntimeException(e.getMessage());
113: } catch (IOException e) {
114: throw new RuntimeException(e.getMessage());
115: }
116:
117: String class1 = "mynewclass";
118: String subclass = "mynewsubclass";
119:
120: Element elt1 = new Element("classdef1");
121: Element elt2 = new Element("classdef2");
122:
123: schema.addElement(elt1, "mynewclass", "view", new ArrayList(),
124: env);
125: schema.addElement(elt2, "mynewsubclass", "mynewclass",
126: new ArrayList(), env);
127:
128: assertEquals("undefined class superclass", "Object", schema
129: .getBaseClassname("view"));
130:
131: assertEquals(" superclass", "view", schema
132: .getSuperclassName("mynewclass"));
133:
134: assertEquals(" superclass", "mynewclass", schema
135: .getSuperclassName("mynewsubclass"));
136:
137: assertEquals("mynewclass superclass", "Object", schema
138: .getBaseClassname("mynewclass"));
139:
140: assertEquals("mynewsubclass superclass", "Object", schema
141: .getBaseClassname("mynewsubclass"));
142:
143: schema.setAttributeType(elt1, "mynewclass", "foo-width",
144: new AttributeSpec("foo-width",
145: schema.SIZE_EXPRESSION_TYPE, null, null));
146: schema.setAttributeType(elt1, "mynewclass", "barbaz",
147: new AttributeSpec("barbaz", schema.STRING_TYPE, null,
148: null));
149:
150: schema.setAttributeType(elt1, "mynewsubclass", "baz-width",
151: new AttributeSpec("baz-width",
152: schema.SIZE_EXPRESSION_TYPE, null, null));
153: schema.setAttributeType(elt1, "mynewsubclass", "barbaz",
154: new AttributeSpec("barbaz", schema.EVENT_HANDLER_TYPE,
155: null, null));
156:
157: assertEquals("mynewclass foo-width type",
158: schema.SIZE_EXPRESSION_TYPE, schema.getAttributeType(
159: class1, "foo-width"));
160:
161: assertEquals("mynewclass barbaz type", schema.STRING_TYPE,
162: schema.getAttributeType(class1, "barbaz"));
163:
164: // Check subclass attribute types
165: assertEquals("mynewsubclass foo-width type",
166: schema.SIZE_EXPRESSION_TYPE, schema.getAttributeType(
167: subclass, "foo-width"));
168:
169: assertEquals("mynewsubclass baz-width type",
170: schema.SIZE_EXPRESSION_TYPE, schema.getAttributeType(
171: subclass, "baz-width"));
172:
173: // Attribute type of subclass should override superclass type
174: assertEquals("mynewsubclass barbaz type",
175: schema.EVENT_HANDLER_TYPE, schema.getAttributeType(
176: subclass, "barbaz"));
177:
178: // test for duplicate attributes, undefined superclass, redefined class, attr inheritance
179:
180: }
181:
182: }
|