aboutsummaryrefslogtreecommitdiffstats
path: root/test/java
diff options
context:
space:
mode:
authorVincent Hennebert <vhennebert@apache.org>2013-08-29 16:26:12 +0000
committerVincent Hennebert <vhennebert@apache.org>2013-08-29 16:26:12 +0000
commit6a3a80f32459658c5edf5eb1a48f9a59edf5fe1b (patch)
tree0b37aff548c329fb9491f8ccc5cd35aa3c3530e5 /test/java
parentf4b08c8e1f5f6a8901695fe970d66b4ba95496c2 (diff)
downloadxmlgraphics-fop-6a3a80f32459658c5edf5eb1a48f9a59edf5fe1b.tar.gz
xmlgraphics-fop-6a3a80f32459658c5edf5eb1a48f9a59edf5fe1b.zip
FOP-2292: First bits of a whitespace management extension
Patch by Seifeddine Dridi, applied with some modifications (mainly, Java compliance and Checkstyle) git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_WhitespaceManagement@1518691 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java')
-rw-r--r--test/java/org/apache/fop/KnuthAlgorithmTestCase.java53
1 files changed, 47 insertions, 6 deletions
diff --git a/test/java/org/apache/fop/KnuthAlgorithmTestCase.java b/test/java/org/apache/fop/KnuthAlgorithmTestCase.java
index 18176117c..204cfade7 100644
--- a/test/java/org/apache/fop/KnuthAlgorithmTestCase.java
+++ b/test/java/org/apache/fop/KnuthAlgorithmTestCase.java
@@ -19,10 +19,16 @@
package org.apache.fop;
-import static org.junit.Assert.assertEquals;
-
import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.fop.layoutmgr.AlternativeManager.Alternative;
+import org.apache.fop.layoutmgr.AlternativeManager.FittingStrategy;
+import org.apache.fop.layoutmgr.BestFitPenalty;
import org.apache.fop.layoutmgr.BlockKnuthSequence;
import org.apache.fop.layoutmgr.BreakingAlgorithm;
import org.apache.fop.layoutmgr.ElementListObserver;
@@ -30,8 +36,6 @@ import org.apache.fop.layoutmgr.KnuthBox;
import org.apache.fop.layoutmgr.KnuthGlue;
import org.apache.fop.layoutmgr.KnuthPenalty;
import org.apache.fop.layoutmgr.KnuthSequence;
-import org.junit.Before;
-import org.junit.Test;
/**
* Tests the Knuth algorithm implementation.
@@ -63,6 +67,27 @@ public class KnuthAlgorithmTestCase {
return seq;
}
+ private static class BestFitPenaltyTestCase {
+
+ private static KnuthSequence getKnuthSequence() {
+ KnuthSequence seq = new BlockKnuthSequence();
+ FittingStrategy strategies[] = {FittingStrategy.FIRST_FIT,
+ FittingStrategy.SMALLEST_FIT,
+ FittingStrategy.BIGGEST_FIT};
+ for (int i = 0; i < 3; ++i) {
+ BestFitPenalty bestFitPenalty = new BestFitPenalty(strategies[i], null);
+ bestFitPenalty.addAlternative(new Alternative(null, 25000));
+ bestFitPenalty.addAlternative(new Alternative(null, 5000));
+ bestFitPenalty.addAlternative(new Alternative(null, 29000));
+ seq.add(new KnuthBox(0, null, false));
+ seq.add(bestFitPenalty);
+ seq.add(new KnuthPenalty(0, -KnuthPenalty.INFINITE, false, null, false));
+ }
+ return seq;
+ }
+
+ }
+
/**
* Tests a special condition where a negative-length glue occurs directly after a break
* possibility.
@@ -79,6 +104,22 @@ public class KnuthAlgorithmTestCase {
assertEquals(5000, parts[0].difference);
assertEquals(5000, parts[1].difference);
}
+ /**
+ * Testcase for BestFitPenalty
+ * @throws Exception if an error occurs
+ */
+ @Test
+ public void test2() throws Exception {
+ MyBreakingAlgorithm algo = new MyBreakingAlgorithm(0, 0, true, true, 0);
+ algo.setConstantLineWidth(30000);
+ KnuthSequence seq = BestFitPenaltyTestCase.getKnuthSequence();
+ algo.findBreakingPoints(seq, 1, true, BreakingAlgorithm.ALL_BREAKS);
+ Part[] parts = algo.getParts();
+ assertEquals("Sequence must produce 3 parts", 3, parts.length);
+ assertEquals(5000, parts[0].difference);
+ assertEquals(25000, parts[1].difference);
+ assertEquals(1000, parts[2].difference);
+ }
private class Part {
private int difference;
@@ -88,7 +129,7 @@ public class KnuthAlgorithmTestCase {
private class MyBreakingAlgorithm extends BreakingAlgorithm {
- private List parts = new java.util.ArrayList();
+ private List<Part> parts = new java.util.ArrayList<Part>();
public MyBreakingAlgorithm(int align, int alignLast, boolean first,
boolean partOverflowRecovery, int maxFlagCount) {
@@ -96,7 +137,7 @@ public class KnuthAlgorithmTestCase {
}
public Part[] getParts() {
- return (Part[])parts.toArray(new Part[parts.size()]);
+ return parts.toArray(new Part[parts.size()]);
}
public void updateData1(int total, double demerits) {