View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.commons.compress.compressors;
20  
21  import junit.framework.TestCase;
22  
23  import org.apache.commons.compress.compressors.gzip.GzipUtils;
24  
25  public class GzipUtilsTestCase extends TestCase {
26  
27      public void testIsCompressedFilename() {
28          assertFalse(GzipUtils.isCompressedFilename(""));
29          assertFalse(GzipUtils.isCompressedFilename(".gz"));
30  
31          assertTrue(GzipUtils.isCompressedFilename("x.tgz"));
32          assertTrue(GzipUtils.isCompressedFilename("x.taz"));
33          assertTrue(GzipUtils.isCompressedFilename("x.svgz"));
34          assertTrue(GzipUtils.isCompressedFilename("x.cpgz"));
35          assertTrue(GzipUtils.isCompressedFilename("x.wmz"));
36          assertTrue(GzipUtils.isCompressedFilename("x.emz"));
37          assertTrue(GzipUtils.isCompressedFilename("x.gz"));
38          assertTrue(GzipUtils.isCompressedFilename("x.z"));
39          assertTrue(GzipUtils.isCompressedFilename("x-gz"));
40          assertTrue(GzipUtils.isCompressedFilename("x-z"));
41          assertTrue(GzipUtils.isCompressedFilename("x_z"));
42  
43          assertFalse(GzipUtils.isCompressedFilename("xxgz"));
44          assertFalse(GzipUtils.isCompressedFilename("xzz"));
45          assertFalse(GzipUtils.isCompressedFilename("xaz"));
46  
47          assertTrue(GzipUtils.isCompressedFilename("x.SVGZ"));
48          assertTrue(GzipUtils.isCompressedFilename("x.Svgz"));
49          assertTrue(GzipUtils.isCompressedFilename("x.svGZ"));
50  
51          assertFalse(GzipUtils.isCompressedFilename("x.wmz "));
52          assertFalse(GzipUtils.isCompressedFilename("x.wmz\n"));
53          assertFalse(GzipUtils.isCompressedFilename("x.wmz.y"));
54      }
55  
56      public void testGetUncompressedFilename() {
57          assertEquals("", GzipUtils.getUncompressedFilename(""));
58          assertEquals(".gz", GzipUtils.getUncompressedFilename(".gz"));
59  
60          assertEquals("x.tar", GzipUtils.getUncompressedFilename("x.tgz"));
61          assertEquals("x.tar", GzipUtils.getUncompressedFilename("x.taz"));
62          assertEquals("x.svg", GzipUtils.getUncompressedFilename("x.svgz"));
63          assertEquals("x.cpio", GzipUtils.getUncompressedFilename("x.cpgz"));
64          assertEquals("x.wmf", GzipUtils.getUncompressedFilename("x.wmz"));
65          assertEquals("x.emf", GzipUtils.getUncompressedFilename("x.emz"));
66          assertEquals("x", GzipUtils.getUncompressedFilename("x.gz"));
67          assertEquals("x", GzipUtils.getUncompressedFilename("x.z"));
68          assertEquals("x", GzipUtils.getUncompressedFilename("x-gz"));
69          assertEquals("x", GzipUtils.getUncompressedFilename("x-z"));
70          assertEquals("x", GzipUtils.getUncompressedFilename("x_z"));
71  
72          assertEquals("x.svg", GzipUtils.getUncompressedFilename("x.SVGZ"));
73          assertEquals("X.svg", GzipUtils.getUncompressedFilename("X.SVGZ"));
74          assertEquals("X.svg", GzipUtils.getUncompressedFilename("X.svGZ"));
75  
76          assertEquals("x.wmz ", GzipUtils.getUncompressedFilename("x.wmz "));
77          assertEquals("x.wmz\n", GzipUtils.getUncompressedFilename("x.wmz\n"));
78          assertEquals("x.wmz.y", GzipUtils.getUncompressedFilename("x.wmz.y"));
79      }
80  
81      public void testGetCompressedFilename() {
82          assertEquals(".gz", GzipUtils.getCompressedFilename(""));
83          assertEquals("x.gz", GzipUtils.getCompressedFilename("x"));
84  
85          assertEquals("x.tgz", GzipUtils.getCompressedFilename("x.tar"));
86          assertEquals("x.svgz", GzipUtils.getCompressedFilename("x.svg"));
87          assertEquals("x.cpgz", GzipUtils.getCompressedFilename("x.cpio"));
88          assertEquals("x.wmz", GzipUtils.getCompressedFilename("x.wmf"));
89          assertEquals("x.emz", GzipUtils.getCompressedFilename("x.emf"));
90  
91          assertEquals("x.svgz", GzipUtils.getCompressedFilename("x.SVG"));
92          assertEquals("X.svgz", GzipUtils.getCompressedFilename("X.SVG"));
93          assertEquals("X.svgz", GzipUtils.getCompressedFilename("X.svG"));
94  
95          assertEquals("x.wmf .gz", GzipUtils.getCompressedFilename("x.wmf "));
96          assertEquals("x.wmf\n.gz", GzipUtils.getCompressedFilename("x.wmf\n"));
97          assertEquals("x.wmf.y.gz", GzipUtils.getCompressedFilename("x.wmf.y"));
98      }
99  
100 }