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.complexscripts.bidi;
21 
22 import org.junit.Test;
23 
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.fail;
26 
27 import org.apache.fop.util.CharUtilities;
28 
29 public class BidiClassTestCase {
30 
31     @Test
testBidiClasses()32     public void testBidiClasses() throws Exception {
33         String tdPfx = BidiTestData.TD_PFX;
34         int tdCount = BidiTestData.TD_CNT;
35         for (int i = 0; i < tdCount; i++) {
36             int[] da = BidiTestData.readTestData(tdPfx, i);
37             if (da != null) {
38                 testBidiClass(da);
39             } else {
40                 fail("unable to read bidi test data for resource at index " + i);
41             }
42         }
43     }
44 
testBidiClass(int[] da)45     private void testBidiClass(int[] da) throws Exception {
46         int bc = da[0];
47         for (int i = 1, n = da.length; i < n; i += 2) {
48             int s = da[i + 0];
49             int e = da[i + 1];
50             for (int c = s; c < e; c++) {
51                 int cbc = BidiClass.getBidiClass(c);
52                 assertEquals("bad bidi class for CH(" + CharUtilities.format(c) + ")", bc, cbc);
53             }
54         }
55     }
56 
57 }
58