001    /*
002     * Copyright 2002 - 2010 JEuclid, http://jeuclid.sf.net
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    /* $Id: CharacterMappingTest.java,v 92b6a7c39d7f 2010/08/11 20:23:17 max $ */
018    
019    package net.sourceforge.jeuclid.test;
020    
021    import java.awt.Font;
022    import java.util.List;
023    
024    import net.sourceforge.jeuclid.elements.support.attributes.FontFamily;
025    import net.sourceforge.jeuclid.elements.support.attributes.MathVariant;
026    import net.sourceforge.jeuclid.elements.support.text.CharacterMapping;
027    import net.sourceforge.jeuclid.elements.support.text.CodePointAndVariant;
028    
029    import org.junit.Assert;
030    import org.junit.Test;
031    
032    /**
033     * @version $Revision: 92b6a7c39d7f $
034     */
035    public class CharacterMappingTest {
036        /**
037         * Default Constructor.
038         */
039        public CharacterMappingTest() {
040            // Empty on purpose
041        }
042    
043        /**
044         * Tests some standard code mappings.
045         * @throws Exception if the test fails.
046         */
047        @Test
048        public void testMappings() throws Exception {
049            final CharacterMapping cMap = CharacterMapping.getInstance();
050            final CodePointAndVariant test = new CodePointAndVariant(0x1D555,
051                    MathVariant.ITALIC);
052            Assert.assertEquals(test, new CodePointAndVariant(0x1d555,
053                    MathVariant.ITALIC));
054            final CodePointAndVariant split = cMap.extractUnicodeAttr(test);
055            Assert.assertEquals(split, new CodePointAndVariant(0x64,
056                    new MathVariant(Font.ITALIC, FontFamily.DOUBLE_STRUCK)));
057            final CodePointAndVariant fin = cMap.composeUnicodeChar(split, false);
058            Assert.assertEquals(fin, new CodePointAndVariant(0x2146,
059                    MathVariant.NORMAL));
060            final CodePointAndVariant fina = cMap.composeUnicodeChar(split, true);
061            Assert.assertEquals(fina, new CodePointAndVariant(0x2146,
062                    MathVariant.NORMAL));
063    
064            final CodePointAndVariant test2 = new CodePointAndVariant(0x1D555,
065                    MathVariant.BOLD);
066            Assert.assertEquals(test2, new CodePointAndVariant(0x1d555,
067                    MathVariant.BOLD));
068            final CodePointAndVariant split2 = cMap.extractUnicodeAttr(test2);
069            Assert.assertEquals(split2, new CodePointAndVariant(0x64,
070                    new MathVariant(Font.BOLD, FontFamily.DOUBLE_STRUCK)));
071            final CodePointAndVariant fin2 = cMap.composeUnicodeChar(split2,
072                    false);
073            Assert.assertEquals(fin2, new CodePointAndVariant(0x1d555,
074                    MathVariant.BOLD));
075            final CodePointAndVariant fin2a = cMap.composeUnicodeChar(split2,
076                    true);
077            Assert.assertEquals(fin2a, new CodePointAndVariant(0x64,
078                    new MathVariant(Font.BOLD, FontFamily.DOUBLE_STRUCK)));
079        }
080    
081        /**
082         * Tests code mapping alternatives.
083         * @throws Exception if the test fails.
084         */
085        @Test
086        public void testAlternatives() throws Exception {
087            final CharacterMapping cMap = CharacterMapping.getInstance();
088            final CodePointAndVariant space = new CodePointAndVariant(0x20,
089                    MathVariant.NORMAL);
090            final List<CodePointAndVariant> spacelist = cMap
091                    .getAllAlternatives(space);
092            Assert.assertEquals(spacelist.get(0), space);
093            Assert.assertEquals(spacelist.get(1), new CodePointAndVariant(160,
094                    MathVariant.NORMAL));
095            Assert.assertEquals(spacelist.size(), 2);
096    
097            final CodePointAndVariant a = new CodePointAndVariant(65,
098                    MathVariant.NORMAL);
099            Assert.assertEquals(cMap.getAllAlternatives(a).size(), 1);
100    
101            final CodePointAndVariant test = new CodePointAndVariant(0x1D555,
102                    MathVariant.ITALIC);
103            Assert.assertEquals(cMap.getAllAlternatives(test).size(), 3);
104    
105        }
106    }