001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: ASCII85OutputStreamTestCase.java 426584 2006-07-28 16:01:47Z jeremias $ */
019:
020: package org.apache.xmlgraphics.util.io;
021:
022: import java.io.OutputStream;
023:
024: import org.apache.commons.io.output.ByteArrayOutputStream;
025:
026: import junit.framework.TestCase;
027:
028: /**
029: * Test case for ASCII85OutputStream
030: */
031: public class ASCII85OutputStreamTestCase extends TestCase {
032:
033: /** Test data */
034: public static final byte[] DATA = new byte[100];
035:
036: static {
037: //Fill in some data
038: for (int i = 0; i < 100; i++) {
039: DATA[i] = (byte) i;
040: }
041: }
042:
043: /**
044: * @see junit.framework.TestCase#TestCase(String)
045: */
046: public ASCII85OutputStreamTestCase(String name) {
047: super (name);
048: }
049:
050: private String encode(int count) throws Exception {
051: return encode(DATA, count);
052: }
053:
054: private String encode(byte[] data, int len) throws Exception {
055: ByteArrayOutputStream baout = new ByteArrayOutputStream();
056: OutputStream out = new ASCII85OutputStream(baout);
057: out.write(data, 0, len);
058: out.close();
059: return new String(baout.toByteArray(), "US-ASCII");
060: }
061:
062: /**
063: * Tests the output of ASCII85.
064: * @throws Exception if an error occurs
065: */
066: public void testOutput() throws Exception {
067: String sz = encode(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }, 8);
068: assertEquals("zz~>", sz);
069:
070: String s3 = encode(3);
071: //System.out.println(">>>" + s3 + "<<<");
072: assertEquals("!!*-~>", s3);
073:
074: String s10 = encode(10);
075: //System.out.println(">>>" + s10 + "<<<");
076: assertEquals("!!*-'\"9eu7#RL~>", s10);
077:
078: String s62 = encode(62);
079: //System.out.println(">>>" + s62 + "<<<");
080: assertEquals("!!*-'\"9eu7#RLhG$k3[W&.oNg'GVB\"(`=52*$$(B+<_pR,"
081: + "UFcb-n-Vr/1iJ-0JP==1c70M3&s#]4?W~>", s62);
082:
083: String s63 = encode(63);
084: //System.out.println(">>>" + s63 + "<<<");
085: assertEquals("!!*-'\"9eu7#RLhG$k3[W&.oNg'GVB\"(`=52*$$(B+<_pR,"
086: + "UFcb-n-Vr/1iJ-0JP==1c70M3&s#]4?Yk\n~>", s63);
087:
088: String s64 = encode(64);
089: //System.out.println(">>>" + s64 + "<<<");
090: assertEquals("!!*-'\"9eu7#RLhG$k3[W&.oNg'GVB\"(`=52*$$(B+<_pR,"
091: + "UFcb-n-Vr/1iJ-0JP==1c70M3&s#]4?Ykm\n~>", s64);
092:
093: String s65 = encode(65);
094: //System.out.println(">>>" + s65 + "<<<");
095: assertEquals("!!*-'\"9eu7#RLhG$k3[W&.oNg'GVB\"(`=52*$$(B+<_pR,"
096: + "UFcb-n-Vr/1iJ-0JP==1c70M3&s#]4?Ykm\n5Q~>", s65);
097:
098: }
099:
100: }
|