aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorGlenn Adams <gadams@apache.org>2014-10-13 20:57:22 +0000
committerGlenn Adams <gadams@apache.org>2014-10-13 20:57:22 +0000
commitc54cb7efe6d808e67882930e828e3bd89ee976b9 (patch)
tree16f1fda047591eb9ee9a367253e7a2cd188f7324 /test
parentcb807d07f176fd1f852c0a8fe6e99af43fa090bb (diff)
downloadxmlgraphics-fop-c54cb7efe6d808e67882930e828e3bd89ee976b9.tar.gz
xmlgraphics-fop-c54cb7efe6d808e67882930e828e3bd89ee976b9.zip
FOP-2416: add support for Arabic Joiners (ZWJ/ZWNJ) - preliminary
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1631546 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
-rw-r--r--test/java/org/apache/fop/complexscripts/scripts/ScriptsTestSuite.java8
-rw-r--r--test/java/org/apache/fop/complexscripts/scripts/arabic/ArabicJoinersTestCase.java138
-rw-r--r--test/java/org/apache/fop/complexscripts/scripts/arabic/ArabicWordFormsConstants.java (renamed from test/java/org/apache/fop/complexscripts/scripts/arabic/ArabicTestConstants.java)2
-rw-r--r--test/java/org/apache/fop/complexscripts/scripts/arabic/ArabicWordFormsTestCase.java (renamed from test/java/org/apache/fop/complexscripts/scripts/arabic/ArabicTestCase.java)2
-rw-r--r--test/java/org/apache/fop/complexscripts/scripts/arabic/GenerateArabicTestData.java2
5 files changed, 147 insertions, 5 deletions
diff --git a/test/java/org/apache/fop/complexscripts/scripts/ScriptsTestSuite.java b/test/java/org/apache/fop/complexscripts/scripts/ScriptsTestSuite.java
index c48be5220..27914450a 100644
--- a/test/java/org/apache/fop/complexscripts/scripts/ScriptsTestSuite.java
+++ b/test/java/org/apache/fop/complexscripts/scripts/ScriptsTestSuite.java
@@ -23,12 +23,16 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
-import org.apache.fop.complexscripts.scripts.arabic.ArabicTestCase;
+import org.apache.fop.complexscripts.scripts.arabic.ArabicJoinersTestCase;
+import org.apache.fop.complexscripts.scripts.arabic.ArabicWordFormsTestCase;
/**
* Test suite for script specific functionality related to complex scripts.
*/
@RunWith(Suite.class)
-@SuiteClasses(ArabicTestCase.class)
+@SuiteClasses({
+ ArabicJoinersTestCase.class,
+ ArabicWordFormsTestCase.class
+})
public class ScriptsTestSuite {
}
diff --git a/test/java/org/apache/fop/complexscripts/scripts/arabic/ArabicJoinersTestCase.java b/test/java/org/apache/fop/complexscripts/scripts/arabic/ArabicJoinersTestCase.java
new file mode 100644
index 000000000..092bebd41
--- /dev/null
+++ b/test/java/org/apache/fop/complexscripts/scripts/arabic/ArabicJoinersTestCase.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.complexscripts.scripts.arabic;
+
+import java.nio.IntBuffer;
+import java.util.BitSet;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+import org.apache.fop.complexscripts.scripts.ScriptProcessor;
+import org.apache.fop.complexscripts.util.CharScript;
+import org.apache.fop.complexscripts.util.GlyphContextTester;
+import org.apache.fop.complexscripts.util.GlyphSequence;
+import org.apache.fop.complexscripts.util.ScriptContextTester;
+import org.apache.fop.complexscripts.util.UTF32;
+
+// CSOFF: LineLength
+
+/**
+ * Tests for joiner (ZWJ, ZWNJ) functionality related to the arabic script.
+ */
+public class ArabicJoinersTestCase {
+
+ private static final String[][] ZWJ_TESTS_ISOL = new String[][] {
+ { "\u0643", "1", },
+ { "\u0643\u200D", "00", },
+ { "\u200D\u0643", "00", },
+ { "\u200D\u0643\u200D", "000", },
+ };
+
+ private static final String[][] ZWJ_TESTS_INIT = new String[][] {
+ { "\u0643", "0", },
+ { "\u0643\u200D", "10", },
+ { "\u200D\u0643", "00", },
+ { "\u200D\u0643\u200D", "000", },
+ };
+
+ private static final String[][] ZWJ_TESTS_MEDI = new String[][] {
+ { "\u0643", "0", },
+ { "\u0643\u200D", "00", },
+ { "\u200D\u0643", "00", },
+ { "\u200D\u0643\u200D", "010", },
+ };
+
+ private static final String[][] ZWJ_TESTS_FINA = new String[][] {
+ { "\u0643", "0", },
+ { "\u0643\u200D", "00", },
+ { "\u200D\u0643", "01", },
+ { "\u200D\u0643\u200D", "000", },
+ };
+
+ private static final String[][] ZWJ_TESTS_LIGA = new String[][] {
+ };
+
+ @Test
+ public void testArabicJoiners() {
+ String script = CharScript.scriptTagFromCode(CharScript.SCRIPT_ARABIC);
+ ScriptProcessor sp = ScriptProcessor.getInstance(script);
+ assertTrue(sp != null);
+ ScriptContextTester sct = sp.getSubstitutionContextTester();
+ assertTrue(sct != null);
+ String language = "dflt";
+ int flags = 0;
+ testZWJ(sct, script, language, "isol", flags, ZWJ_TESTS_ISOL);
+ testZWJ(sct, script, language, "init", flags, ZWJ_TESTS_INIT);
+ testZWJ(sct, script, language, "medi", flags, ZWJ_TESTS_MEDI);
+ testZWJ(sct, script, language, "fina", flags, ZWJ_TESTS_FINA);
+ testZWJ(sct, script, language, "liga", flags, ZWJ_TESTS_LIGA);
+ }
+
+ private void testZWJ(ScriptContextTester sct, String script, String language, String feature, int flags, String[][] tests) {
+ GlyphContextTester gct = sct.getTester(feature);
+ assertTrue(gct != null);
+ for (String[] t : tests) {
+ testZWJ(gct, script, language, feature, flags, t);
+ }
+ }
+
+ private void testZWJ(GlyphContextTester gct, String script, String language, String feature, int flags, String[] test) {
+ assert test.length == 2;
+ String str = test[0];
+ BitSet act = new BitSet();
+ GlyphSequence gs = makeGlyphSequence(str);
+ for (int i = 0, n = str.length(); i < n; ++i) {
+ if (gct.test(script, language, feature, gs, i, flags)) {
+ act.set(i);
+ }
+ }
+ BitSet exp = parseBitSet(test[1]);
+ assertTrue(act.equals(exp));
+ }
+
+ private GlyphSequence makeGlyphSequence(String s) {
+ Integer[] ca = UTF32.toUTF32(s, 0, true);
+ IntBuffer cb = IntBuffer.allocate(ca.length);
+ for (Integer c : ca) {
+ cb.put(c);
+ }
+ cb.rewind();
+ return new GlyphSequence(cb, null, null);
+ }
+
+ private BitSet parseBitSet(String s) {
+ BitSet bits = new BitSet();
+ for (int i = 0, n = s.length(); i < n; ++i) {
+ char c = s.charAt(i);
+ assert (c == '0') || (c == '1');
+ if (c == '1') {
+ bits.set(i);
+ }
+ }
+ return bits;
+ }
+
+ @Test
+ public void testArabicNonJoiners() {
+ }
+
+}
diff --git a/test/java/org/apache/fop/complexscripts/scripts/arabic/ArabicTestConstants.java b/test/java/org/apache/fop/complexscripts/scripts/arabic/ArabicWordFormsConstants.java
index cc9167553..41094b687 100644
--- a/test/java/org/apache/fop/complexscripts/scripts/arabic/ArabicTestConstants.java
+++ b/test/java/org/apache/fop/complexscripts/scripts/arabic/ArabicWordFormsConstants.java
@@ -22,7 +22,7 @@ package org.apache.fop.complexscripts.scripts.arabic;
/**
* Constants for test functionality related to the arabic script.
*/
-public interface ArabicTestConstants {
+public interface ArabicWordFormsConstants {
String WF_FILE_SCRIPT = "arab";
String WF_FILE_LANGUAGE = "dflt";
diff --git a/test/java/org/apache/fop/complexscripts/scripts/arabic/ArabicTestCase.java b/test/java/org/apache/fop/complexscripts/scripts/arabic/ArabicWordFormsTestCase.java
index 8542faae9..abe4f513a 100644
--- a/test/java/org/apache/fop/complexscripts/scripts/arabic/ArabicTestCase.java
+++ b/test/java/org/apache/fop/complexscripts/scripts/arabic/ArabicWordFormsTestCase.java
@@ -44,7 +44,7 @@ import org.apache.fop.complexscripts.util.GlyphSequence;
/**
* Tests for functionality related to the arabic script.
*/
-public class ArabicTestCase implements ArabicTestConstants {
+public class ArabicWordFormsTestCase implements ArabicWordFormsConstants {
@Test
public void testArabicWordForms() {
diff --git a/test/java/org/apache/fop/complexscripts/scripts/arabic/GenerateArabicTestData.java b/test/java/org/apache/fop/complexscripts/scripts/arabic/GenerateArabicTestData.java
index 9ca16a164..35bfb3128 100644
--- a/test/java/org/apache/fop/complexscripts/scripts/arabic/GenerateArabicTestData.java
+++ b/test/java/org/apache/fop/complexscripts/scripts/arabic/GenerateArabicTestData.java
@@ -40,7 +40,7 @@ import org.apache.fop.complexscripts.util.GlyphSequence;
/**
* Tests for functionality related to the arabic script.
*/
-public final class GenerateArabicTestData implements ArabicTestConstants {
+public final class GenerateArabicTestData implements ArabicWordFormsConstants {
private GenerateArabicTestData() {
}