KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > util > ElementListUtilsTestCase


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id$ */
19
20 package org.apache.fop.util;
21
22 import java.util.LinkedList JavaDoc;
23
24 import org.apache.fop.layoutmgr.ElementListUtils;
25 import org.apache.fop.layoutmgr.KnuthBox;
26 import org.apache.fop.layoutmgr.KnuthElement;
27 import org.apache.fop.layoutmgr.KnuthGlue;
28 import org.apache.fop.layoutmgr.KnuthPenalty;
29
30 import junit.framework.TestCase;
31
32 /**
33  * Test class for ElementListUtils.
34  */

35 public class ElementListUtilsTestCase extends TestCase {
36
37     /**
38      * Tests ElementListUtils.removeLegalBreaks().
39      * @throws Exception if the test fails
40      */

41     public void testRemoveElementPenalty1() throws Exception JavaDoc {
42         LinkedList JavaDoc lst = new LinkedList JavaDoc();
43         lst.add(new KnuthBox(4000, null, false));
44         lst.add(new KnuthPenalty(0, 0, false, null, false));
45         lst.add(new KnuthBox(4000, null, false));
46         lst.add(new KnuthPenalty(0, 200, false, null, false));
47         lst.add(new KnuthBox(4000, null, false));
48         lst.add(new KnuthPenalty(0, 0, false, null, false));
49         lst.add(new KnuthBox(4000, null, false));
50         lst.add(new KnuthPenalty(0, KnuthElement.INFINITE, false, null, false));
51         lst.add(new KnuthGlue(0, Integer.MAX_VALUE, 0, null, false));
52         lst.add(new KnuthPenalty(0, -KnuthElement.INFINITE, false, null, false));
53         
54         boolean res = ElementListUtils.removeLegalBreaks(lst, 9000);
55         
56         assertFalse(res);
57
58         assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(1)).getP());
59         assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(3)).getP());
60         assertEquals(0, ((KnuthPenalty)lst.get(5)).getP());
61     }
62     
63     /**
64      * Tests ElementListUtils.removeLegalBreaks().
65      * @throws Exception if the test fails
66      */

67     public void testRemoveElementPenalty2() throws Exception JavaDoc {
68         LinkedList JavaDoc lst = new LinkedList JavaDoc();
69         lst.add(new KnuthBox(4000, null, false));
70         lst.add(new KnuthGlue(0, 0, 0, null, false));
71         lst.add(new KnuthBox(4000, null, false));
72         lst.add(new KnuthGlue(0, 0, 0, null, false));
73         lst.add(new KnuthBox(4000, null, false));
74         lst.add(new KnuthGlue(0, 0, 0, null, false));
75         lst.add(new KnuthBox(4000, null, false));
76         lst.add(new KnuthPenalty(0, KnuthElement.INFINITE, false, null, false));
77         lst.add(new KnuthGlue(0, Integer.MAX_VALUE, 0, null, false));
78         lst.add(new KnuthPenalty(0, -KnuthElement.INFINITE, false, null, false));
79         
80         boolean res = ElementListUtils.removeLegalBreaks(lst, 9000);
81         
82         assertFalse(res);
83         
84         //Must insert an INFINITE penalty
85
assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(1)).getP());
86         assertEquals(0, ((KnuthGlue)lst.get(2)).getW());
87         assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(4)).getP());
88         assertEquals(0, ((KnuthGlue)lst.get(5)).getW());
89         assertEquals(0, ((KnuthGlue)lst.get(7)).getW());
90     }
91     
92     /**
93      * Tests ElementListUtils.removeLegalBreaksFromEnd().
94      * @throws Exception if the test fails
95      */

96     public void testRemoveElementFromEndPenalty1() throws Exception JavaDoc {
97         LinkedList JavaDoc lst = new LinkedList JavaDoc();
98         lst.add(new KnuthBox(4000, null, false));
99         lst.add(new KnuthPenalty(0, 0, false, null, false));
100         lst.add(new KnuthBox(4000, null, false));
101         lst.add(new KnuthPenalty(0, 200, false, null, false));
102         lst.add(new KnuthBox(4000, null, false));
103         lst.add(new KnuthPenalty(0, 0, false, null, false));
104         lst.add(new KnuthBox(4000, null, false));
105         lst.add(new KnuthPenalty(0, KnuthElement.INFINITE, false, null, false));
106         lst.add(new KnuthGlue(0, Integer.MAX_VALUE, 0, null, false));
107         lst.add(new KnuthPenalty(0, -KnuthElement.INFINITE, false, null, false));
108         
109         boolean res = ElementListUtils.removeLegalBreaksFromEnd(lst, 9000);
110         
111         assertFalse(res);
112
113         assertEquals(0, ((KnuthPenalty)lst.get(1)).getP());
114         assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(3)).getP());
115         assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(5)).getP());
116     }
117     
118     /**
119      * Tests ElementListUtils.removeLegalBreaksFromEnd().
120      * @throws Exception if the test fails
121      */

122     public void testRemoveElementFromEndPenalty2() throws Exception JavaDoc {
123         LinkedList JavaDoc lst = new LinkedList JavaDoc();
124         lst.add(new KnuthBox(4000, null, false));
125         lst.add(new KnuthPenalty(0, 0, false, null, false));
126         lst.add(new KnuthBox(4000, null, false));
127         lst.add(new KnuthPenalty(0, 200, false, null, false));
128         lst.add(new KnuthBox(4000, null, false));
129         lst.add(new KnuthGlue(0, 0, 0, null, false));
130         lst.add(new KnuthBox(4000, null, false));
131         lst.add(new KnuthPenalty(0, KnuthElement.INFINITE, false, null, false));
132         lst.add(new KnuthGlue(0, Integer.MAX_VALUE, 0, null, false));
133         lst.add(new KnuthPenalty(0, -KnuthElement.INFINITE, false, null, false));
134         
135         boolean res = ElementListUtils.removeLegalBreaksFromEnd(lst, 9000);
136         
137         assertFalse(res);
138
139         //Must insert an INFINITE penalty
140
assertEquals(0, ((KnuthPenalty)lst.get(1)).getP());
141         assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(3)).getP());
142         assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(5)).getP());
143         assertEquals(0, ((KnuthGlue)lst.get(6)).getW());
144     }
145     
146     
147 }
Popular Tags