You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ASCII85OutputStreamTestCase.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.util;
  18. import java.io.OutputStream;
  19. import org.apache.commons.io.output.ByteArrayOutputStream;
  20. import junit.framework.TestCase;
  21. /**
  22. * Test case for ASCII85OutputStream
  23. *
  24. * @author <a href="mailto:jeremias@apache.org">Jeremias Maerki</a>
  25. */
  26. public class ASCII85OutputStreamTestCase extends TestCase {
  27. /** Test data */
  28. public static final byte[] DATA = new byte[100];
  29. static {
  30. //Fill in some data
  31. for (int i = 0; i < 100; i++) {
  32. DATA[i] = (byte)i;
  33. }
  34. }
  35. /**
  36. * @see junit.framework.TestCase#TestCase(String)
  37. */
  38. public ASCII85OutputStreamTestCase(String name) {
  39. super(name);
  40. }
  41. private String encode(int count) throws Exception {
  42. return encode(DATA, count);
  43. }
  44. private String encode(byte[] data, int len) throws Exception {
  45. ByteArrayOutputStream baout = new ByteArrayOutputStream();
  46. OutputStream out = new ASCII85OutputStream(baout);
  47. out.write(data, 0, len);
  48. out.close();
  49. return new String(baout.toByteArray(), "US-ASCII");
  50. }
  51. /**
  52. * Tests the output of ASCII85.
  53. * @throws Exception if an error occurs
  54. */
  55. public void testOutput() throws Exception {
  56. String sz = encode(new byte[] {0, 0, 0, 0, 0, 0, 0, 0}, 8);
  57. assertEquals("zz~>", sz);
  58. String s3 = encode(3);
  59. //System.out.println(">>>" + s3 + "<<<");
  60. assertEquals("!!*-~>", s3);
  61. String s10 = encode(10);
  62. //System.out.println(">>>" + s10 + "<<<");
  63. assertEquals("!!*-'\"9eu7#RL~>", s10);
  64. String s62 = encode(62);
  65. //System.out.println(">>>" + s62 + "<<<");
  66. assertEquals("!!*-'\"9eu7#RLhG$k3[W&.oNg'GVB\"(`=52*$$(B+<_pR,"
  67. + "UFcb-n-Vr/1iJ-0JP==1c70M3&s#]4?W~>", s62);
  68. String s63 = encode(63);
  69. //System.out.println(">>>" + s63 + "<<<");
  70. assertEquals("!!*-'\"9eu7#RLhG$k3[W&.oNg'GVB\"(`=52*$$(B+<_pR,"
  71. + "UFcb-n-Vr/1iJ-0JP==1c70M3&s#]4?Yk\n~>", s63);
  72. String s64 = encode(64);
  73. //System.out.println(">>>" + s64 + "<<<");
  74. assertEquals("!!*-'\"9eu7#RLhG$k3[W&.oNg'GVB\"(`=52*$$(B+<_pR,"
  75. + "UFcb-n-Vr/1iJ-0JP==1c70M3&s#]4?Ykm\n~>", s64);
  76. String s65 = encode(65);
  77. //System.out.println(">>>" + s65 + "<<<");
  78. assertEquals("!!*-'\"9eu7#RLhG$k3[W&.oNg'GVB\"(`=52*$$(B+<_pR,"
  79. + "UFcb-n-Vr/1iJ-0JP==1c70M3&s#]4?Ykm\n5Q~>", s65);
  80. }
  81. }