001/*
002 *  jDTAUS Banking Charset Providers
003 *  Copyright (C) 2005 Christian Schulte
004 *  <cs@schulte.it>
005 *
006 *  This library is free software; you can redistribute it and/or
007 *  modify it under the terms of the GNU Lesser General Public
008 *  License as published by the Free Software Foundation; either
009 *  version 2.1 of the License, or any later version.
010 *
011 *  This library is distributed in the hope that it will be useful,
012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 *  Lesser General Public License for more details.
015 *
016 *  You should have received a copy of the GNU Lesser General Public
017 *  License along with this library; if not, write to the Free Software
018 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
019 *
020 */
021package org.jdtaus.banking.charsets.spi.test;
022
023import junit.framework.Assert;
024import junit.framework.TestCase;
025import org.jdtaus.core.nio.util.Charsets;
026
027/**
028 * Tests the {@code Charsets} implementation.
029 *
030 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
031 * @version $JDTAUS: CharsetsTest.java 8661 2012-09-27 11:29:58Z schulte $
032 */
033public class CharsetsTest extends TestCase
034{
035    //--Tests-------------------------------------------------------------------
036
037    private static final String ASCII = "@[\\]{|}~";
038
039    private static final String ISO646DE = "§ÄÖÜäöüß";
040
041    public void testISO646DE() throws Exception
042    {
043        byte[] encoded = Charsets.encode( ISO646DE, "ISO646-DE" );
044        String decoded = Charsets.decode( encoded, "ISO646-DE" );
045        Assert.assertEquals( ISO646DE, decoded );
046
047        encoded = Charsets.encode( ASCII, "ISO646-DE" );
048        decoded = Charsets.decode( encoded, "ISO646-DE" );
049        Assert.assertEquals( "????????", decoded );
050
051        encoded = ISO646DE.getBytes( "ISO646-DE" );
052        decoded = new String( encoded, "ISO646-DE" );
053        Assert.assertEquals( ISO646DE, decoded );
054
055        encoded = ASCII.getBytes( "ISO646-DE" );
056        decoded = new String( encoded, "ISO646-DE" );
057        Assert.assertEquals( "????????", decoded );
058    }
059
060    public void testIBM273() throws Exception
061    {
062        byte[] encoded = Charsets.encode( ISO646DE, "IBM273" );
063        String decoded = Charsets.decode( encoded, "IBM273" );
064        Assert.assertEquals( ISO646DE, decoded );
065
066        encoded = Charsets.encode( ASCII, "IBM273" );
067        decoded = Charsets.decode( encoded, "IBM273" );
068        Assert.assertEquals( ASCII, decoded );
069
070        encoded = ISO646DE.getBytes( "IBM273" );
071        decoded = new String( encoded, "IBM273" );
072        Assert.assertEquals( ISO646DE, decoded );
073
074        encoded = ASCII.getBytes( "IBM273" );
075        decoded = new String( encoded, "IBM273" );
076        Assert.assertEquals( ASCII, decoded );
077    }
078
079    //-------------------------------------------------------------------Tests--
080}