KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > compiler > ViewSchema_Test


1 /* ****************************************************************************
2  * ViewSchema_Test.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.compiler;
11 import java.io.*;
12 import java.util.*;
13 // import org.apache.oro.text.regex.*;
14
import org.jdom.*;
15 import org.openlaszlo.compiler.ViewSchema;
16 import org.openlaszlo.utils.ChainedException;
17 import org.jdom.input.SAXBuilder;
18 import org.xml.sax.InputSource JavaDoc;
19
20 /*
21  * junit.awtui.TestRunner
22  * junit.swingui.TestRunner
23  * junit.textui.TestRunner
24  *
25  *
26  * java junit.textui.TestRunner org.openlaszlo.ic.ViewSchema_Test
27  */

28
29 import junit.framework.*;
30
31
32 public class ViewSchema_Test extends TestCase {
33     public ViewSchema_Test (String JavaDoc name) {
34         super(name);
35     }
36
37     public void setUp () {
38     }
39
40
41     public void testParseColors () {
42         ViewSchema schema = new ViewSchema();
43         assertEquals("parseColor #FFFFFF", 0XFFFFFF, schema.parseColor("#FFFFFF"));
44         assertEquals("parseColor #FF0000", 0xFF0000, schema.parseColor("#FF0000"));
45         assertEquals("parseColor #800080", 0x800080, schema.parseColor("#800080"));
46         assertEquals("parseColor #FF00FF", 0xFF00FF, schema.parseColor("#FF00FF"));
47         assertEquals("parseColor #123456", 0x123456, schema.parseColor("#123456"));
48         assertEquals("parseColor #DEADBE", 0xDEADBE, schema.parseColor("#DEADBE"));
49         assertEquals("parseColor #000000", 0x000000, schema.parseColor("#000000"));
50         assertEquals("parseColor black", 0x000000, schema.parseColor("black"));
51         assertEquals("parseColor green", 0x008000, schema.parseColor("green"));
52         assertEquals("parseColor silver", 0xC0C0C0, schema.parseColor("silver"));
53         assertEquals("parseColor lime", 0x00FF00, schema.parseColor("lime"));
54         assertEquals("parseColor gray", 0x808080, schema.parseColor("gray"));
55         assertEquals("parseColor olive", 0x808000, schema.parseColor("olive"));
56         assertEquals("parseColor white", 0xFFFFFF, schema.parseColor("white"));
57         assertEquals("parseColor yellow", 0xFFFF00, schema.parseColor("yellow"));
58         assertEquals("parseColor maroon", 0x800000, schema.parseColor("maroon"));
59         assertEquals("parseColor navy", 0x000080, schema.parseColor("navy"));
60         assertEquals("parseColor red", 0xFF0000, schema.parseColor("red"));
61         assertEquals("parseColor blue", 0x0000FF, schema.parseColor("blue"));
62         assertEquals("parseColor purple", 0x800080, schema.parseColor("purple"));
63         assertEquals("parseColor teal", 0x008080, schema.parseColor("teal"));
64         assertEquals("parseColor fuchsia", 0xFF00FF, schema.parseColor("fuchsia"));
65         assertEquals("parseColor aqua", 0x00FFFF, schema.parseColor("aqua"));
66
67     }
68
69
70     public void testHTMLContent () {
71         ViewSchema schema = new ViewSchema();
72
73         assertTrue("hasHTMLContent text", schema.hasHTMLContent(new Element("text")));
74         assertTrue("hasHTMLContent class", !schema.hasHTMLContent(new Element("class")));
75         assertTrue("hasHTMLContent method", !schema.hasHTMLContent(new Element("method")));
76         assertTrue("hasHTMLContent property", !schema.hasHTMLContent(new Element("property")));
77         assertTrue("hasHTMLContent script", !schema.hasHTMLContent(new Element("script")));
78     }
79
80     public void testSetAttributes () {
81
82         ViewSchema schema = new ViewSchema();
83         try {
84             schema.loadSchema();
85         } catch (JDOMException e) {
86             throw new RuntimeException JavaDoc(e.getMessage());
87         }
88
89         String JavaDoc class1 = "mynewclass";
90         String JavaDoc subclass = "mynewsubclass";
91
92         Element elt1 = new Element("classdef1");
93         Element elt2 = new Element("classdef2");
94
95         schema.addElement(elt1, "mynewclass", "view", new ArrayList());
96         schema.addElement(elt2, "mynewsubclass", "mynewclass", new ArrayList());
97
98         assertEquals("undefined class superclass",
99                      null,
100                      schema.getBaseClassname("view"));
101
102         assertEquals(" superclass",
103                      "view",
104                      schema.getSuperclassName("mynewclass"));
105
106         assertEquals(" superclass",
107                      "mynewclass",
108                      schema.getSuperclassName("mynewsubclass"));
109
110         assertEquals("mynewclass superclass",
111                      "view",
112                      schema.getBaseClassname("mynewclass"));
113
114         assertEquals("mynewsubclass superclass",
115                      "view",
116                      schema.getBaseClassname("mynewsubclass"));
117
118
119         schema.setAttributeType(elt1, "mynewclass", "foo-width", new AttributeSpec("foo-width", schema.SIZE_EXPRESSION_TYPE, null, null));
120         schema.setAttributeType(elt1, "mynewclass", "barbaz", new AttributeSpec("barbaz", schema.STRING_TYPE, null, null));
121
122         schema.setAttributeType(elt1, "mynewsubclass", "baz-width", new AttributeSpec("baz-width", schema.SIZE_EXPRESSION_TYPE, null, null));
123         schema.setAttributeType(elt1, "mynewsubclass", "barbaz", new AttributeSpec("barbaz", schema.EVENT_TYPE, null, null));
124
125         assertEquals("mynewclass foo-width type",
126                      schema.SIZE_EXPRESSION_TYPE,
127                      schema.getAttributeType(class1, "foo-width"));
128
129         assertEquals("mynewclass barbaz type",
130                      schema.STRING_TYPE,
131                      schema.getAttributeType(class1, "barbaz"));
132
133         // Check subclass attribute types
134
assertEquals("mynewsubclass foo-width type",
135                      schema.SIZE_EXPRESSION_TYPE,
136                      schema.getAttributeType(subclass, "foo-width"));
137
138         assertEquals("mynewsubclass baz-width type",
139                      schema.SIZE_EXPRESSION_TYPE,
140                      schema.getAttributeType(subclass, "baz-width"));
141
142         // Attribute type of subclass should override superclass type
143
assertEquals("mynewsubclass barbaz type",
144                      schema.EVENT_TYPE,
145                      schema.getAttributeType(subclass, "barbaz"));
146
147         // test for duplicate attributes, undefined superclass, redefined class, attr inheritance
148

149
150     }
151
152 }
153
154
Popular Tags