1 17 18 19 20 package org.apache.fop.util; 21 22 import java.util.LinkedList ; 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 35 public class ElementListUtilsTestCase extends TestCase { 36 37 41 public void testRemoveElementPenalty1() throws Exception { 42 LinkedList lst = new LinkedList (); 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 67 public void testRemoveElementPenalty2() throws Exception { 68 LinkedList lst = new LinkedList (); 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 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 96 public void testRemoveElementFromEndPenalty1() throws Exception { 97 LinkedList lst = new LinkedList (); 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 122 public void testRemoveElementFromEndPenalty2() throws Exception { 123 LinkedList lst = new LinkedList (); 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 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 |