KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > editor > highlighting > ZOrderTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.spi.editor.highlighting;
21
22 import org.netbeans.junit.NbTestCase;
23 import org.openide.util.TopologicalSortException;
24
25 /**
26  *
27  * @author vita
28  */

29 public class ZOrderTest extends NbTestCase {
30     
31     /** Creates a new instance of ZOrderTest */
32     public ZOrderTest(String JavaDoc name) {
33         super(name);
34     }
35     
36     public void testOrder() throws Exception JavaDoc {
37         ZOrder zOrderA = ZOrder.DEFAULT_RACK;
38         ZOrder zOrderB = ZOrder.above("layerA");
39         
40         HighlightsLayer [] layers = new HighlightsLayer [] {
41             simpleLayer("layerB", zOrderB),
42             simpleLayer("layerA", zOrderA),
43         };
44         
45         HighlightsLayer [] sortedLayers = ZOrder.sort(layers);
46         
47         assertNotNull("Sorted layers should not be null", sortedLayers);
48         assertEquals("Wrong size of sortedLayers array", layers.length, sortedLayers.length);
49         
50         assertSame("Wrong order", layers[0], sortedLayers[1]);
51         assertSame("Wrong order", layers[1], sortedLayers[0]);
52     }
53
54     public void testOrder2() throws Exception JavaDoc {
55         ZOrder zOrderA = ZOrder.DEFAULT_RACK.belowLayers("layerB");
56         ZOrder zOrderB = ZOrder.DEFAULT_RACK.aboveLayers("layerA").belowLayers("layerC");
57         ZOrder zOrderC = ZOrder.DEFAULT_RACK.aboveLayers("layerB").belowLayers("layerD");
58         ZOrder zOrderD = ZOrder.DEFAULT_RACK.aboveLayers("layerC").belowLayers("layerE");
59         ZOrder zOrderE = ZOrder.DEFAULT_RACK.aboveLayers("layerD");
60         
61         HighlightsLayer [] layers = new HighlightsLayer [] {
62             simpleLayer("layerD", zOrderD),
63             simpleLayer("layerC", zOrderC),
64             simpleLayer("layerA", zOrderA),
65             simpleLayer("layerE", zOrderE),
66             simpleLayer("layerB", zOrderB),
67         };
68         
69         HighlightsLayer [] sortedLayers = ZOrder.sort(layers);
70         
71         assertNotNull("Sorted layers should not be null", sortedLayers);
72         assertEquals("Wrong size of sortedLayers array", layers.length, sortedLayers.length);
73
74         char ch = 'A';
75         for (int i = 0; i < sortedLayers.length; i++) {
76             String JavaDoc expectedLayerName = "layer" + ch++;
77             assertEquals("Wrong order", expectedLayerName, sortedLayers[i].getLayerTypeId());
78         }
79     }
80
81     public void testCreation() {
82         ZOrder zOrder = ZOrder.DEFAULT_RACK;
83         assertNotNull("ZOrder.DEFAULT", zOrder);
84         assertEquals("DEFAULT.layersAbove", 1, zOrder.layersAbove.size());
85         assertEquals("DEFAULT.layersBelow", 1, zOrder.layersBelow.size());
86         
87         zOrder = ZOrder.BOTTOM_RACK;
88         assertNotNull("ZOrder.BOTTOM", zOrder);
89         assertEquals("BOTTOM.layersAbove", 1, zOrder.layersAbove.size());
90         assertEquals("BOTTOM.layersBelow", 0, zOrder.layersBelow.size());
91         
92         zOrder = ZOrder.TOP_RACK;
93         assertNotNull("ZOrder.TOP", zOrder);
94         assertEquals("TOP.layersAbove", 0, zOrder.layersAbove.size());
95         assertEquals("TOP.layersBelow", 1, zOrder.layersBelow.size());
96         
97         zOrder = ZOrder.above("layerA");
98         assertEquals("layersAbove should be empty", 0, zOrder.layersAbove.size());
99         assertEquals("Wrong number of layersBelow", 1, zOrder.layersBelow.size());
100         assertEquals("Wrong layersBelow", "layerA", zOrder.layersBelow.iterator().next());
101         
102         zOrder = ZOrder.below("layerA");
103         assertEquals("layersBelow should be empty", 0, zOrder.layersBelow.size());
104         assertEquals("Wrong number of layersAbove", 1, zOrder.layersAbove.size());
105         assertEquals("Wrong layersAbove", "layerA", zOrder.layersAbove.iterator().next());
106         
107         zOrder = ZOrder.DEFAULT_RACK.aboveLayers("layerA");
108         assertNotSame("ZOrder was not cloned", ZOrder.DEFAULT_RACK, zOrder);
109         assertEquals("layersAbove should be empty", 1, zOrder.layersAbove.size());
110         assertEquals("Wrong number of layersBelow", 2, zOrder.layersBelow.size());
111         assertTrue("Wrong layersBelow", zOrder.layersBelow.contains("layerA"));
112         
113         zOrder = ZOrder.DEFAULT_RACK.belowLayers("layerA");
114         assertNotSame("ZOrder was not cloned", ZOrder.DEFAULT_RACK, zOrder);
115         assertEquals("layersBelow should be empty", 1, zOrder.layersBelow.size());
116         assertEquals("Wrong number of layersAbove", 2, zOrder.layersAbove.size());
117         assertTrue("Wrong layersAbove", zOrder.layersAbove.contains("layerA"));
118         
119         zOrder = ZOrder.DEFAULT_RACK.aboveLayers("layerA").belowLayers("layerB");
120         assertEquals("Wrong number of layersAbove", 2, zOrder.layersAbove.size());
121         assertTrue("Wrong layersAbove", zOrder.layersAbove.contains("layerB"));
122         assertEquals("Wrong number of layersBelow", 2, zOrder.layersBelow.size());
123         assertTrue("Wrong layersBelow", zOrder.layersBelow.contains("layerA"));
124     }
125     
126     public void testTop() throws TopologicalSortException {
127         ZOrder zOrderA = ZOrder.TOP_RACK;
128         ZOrder zOrderB = ZOrder.above("layerA");
129         
130         HighlightsLayer [] layers = new HighlightsLayer [] {
131             simpleLayer("layerB", zOrderB),
132             simpleLayer("layerA", zOrderA),
133         };
134         
135         HighlightsLayer [] sortedLayers = ZOrder.sort(layers);
136         
137         assertNotNull("Sorted layers should not be null", sortedLayers);
138         assertEquals("Wrong size of sortedLayers array", layers.length, sortedLayers.length);
139         
140         assertSame("Wrong order", layers[0], sortedLayers[1]);
141         assertSame("Wrong order", layers[1], sortedLayers[0]);
142     }
143     
144     public void testBottom() throws TopologicalSortException {
145         ZOrder zOrderA = ZOrder.BOTTOM_RACK;
146         ZOrder zOrderB = ZOrder.below("layerA");
147         
148         HighlightsLayer [] layers = new HighlightsLayer [] {
149             simpleLayer("layerA", zOrderA),
150             simpleLayer("layerB", zOrderB),
151         };
152         
153         HighlightsLayer [] sortedLayers = ZOrder.sort(layers);
154         
155         assertNotNull("Sorted layers should not be null", sortedLayers);
156         assertEquals("Wrong size of sortedLayers array", layers.length, sortedLayers.length);
157         
158         assertSame("Wrong order", layers[0], sortedLayers[1]);
159         assertSame("Wrong order", layers[1], sortedLayers[0]);
160     }
161     
162     public void testRacks() throws TopologicalSortException {
163         HighlightsLayer [] layers = new HighlightsLayer [] {
164             simpleLayer("layerE", ZOrder.SHOW_OFF_RACK),
165             simpleLayer("layerC", ZOrder.CARET_RACK),
166             simpleLayer("layerF", ZOrder.TOP_RACK),
167             simpleLayer("layerA", ZOrder.BOTTOM_RACK),
168             simpleLayer("layerD", ZOrder.DEFAULT_RACK),
169             simpleLayer("layerB", ZOrder.SYNTAX_RACK),
170         };
171         
172         HighlightsLayer [] sortedLayers = ZOrder.sort(layers);
173         
174         assertNotNull("Sorted layers should not be null", sortedLayers);
175         assertEquals("Wrong size of sortedLayers array", layers.length, sortedLayers.length);
176         
177         char ch = 'A';
178         for(int i = 0; i < sortedLayers.length; i++) {
179             assertEquals("Wrong order", "layer" + ch, sortedLayers[i].getLayerTypeId());
180             ch++;
181         }
182     }
183     
184     public void testComplex() throws TopologicalSortException {
185         ZOrder zOrderA = ZOrder.BOTTOM_RACK;
186         ZOrder zOrderB = ZOrder.DEFAULT_RACK.aboveLayers("layerA").belowLayers("layerC");
187         ZOrder zOrderC = ZOrder.DEFAULT_RACK.aboveLayers("layerB").belowLayers("layerD");
188         ZOrder zOrderD = ZOrder.DEFAULT_RACK.aboveLayers("layerC").belowLayers("layerE");
189         ZOrder zOrderE = ZOrder.TOP_RACK;
190         
191         HighlightsLayer [] layers = new HighlightsLayer [] {
192             simpleLayer("layerD", zOrderD),
193             simpleLayer("layerC", zOrderC),
194             simpleLayer("layerA", zOrderA),
195             simpleLayer("layerE", zOrderE),
196             simpleLayer("layerB", zOrderB),
197         };
198         
199         HighlightsLayer [] sortedLayers = ZOrder.sort(layers);
200         
201         assertNotNull("Sorted layers should not be null", sortedLayers);
202         assertEquals("Wrong size of sortedLayers array", layers.length, sortedLayers.length);
203         
204         char ch = 'A';
205         for (int i = 0; i < sortedLayers.length; i++) {
206             String JavaDoc expectedLayerName = "layer" + ch++;
207             assertEquals("Wrong order", expectedLayerName, sortedLayers[i].getLayerTypeId());
208         }
209     }
210
211     private HighlightsLayer simpleLayer(String JavaDoc layerId, ZOrder zOrder) {
212         return HighlightsLayer.create(layerId, zOrder, true, null);
213     }
214 }
215
Popular Tags