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 static org.junit.Assert.*;
22  
23  import org.apache.commons.compress.compressors.gzip.GzipUtils;
24  import org.junit.Test;
25  
26  public class GzipUtilsTestCase {
27  
28      @Test
29      public void testIsCompressedFilename() {
30          assertFalse(GzipUtils.isCompressedFilename(""));
31          assertFalse(GzipUtils.isCompressedFilename(".gz"));
32  
33          assertTrue(GzipUtils.isCompressedFilename("x.tgz"));
34          assertTrue(GzipUtils.isCompressedFilename("x.taz"));
35          assertTrue(GzipUtils.isCompressedFilename("x.svgz"));
36          assertTrue(GzipUtils.isCompressedFilename("x.cpgz"));
37          assertTrue(GzipUtils.isCompressedFilename("x.wmz"));
38          assertTrue(GzipUtils.isCompressedFilename("x.emz"));
39          assertTrue(GzipUtils.isCompressedFilename("x.gz"));
40          assertTrue(GzipUtils.isCompressedFilename("x.z"));
41          assertTrue(GzipUtils.isCompressedFilename("x-gz"));
42          assertTrue(GzipUtils.isCompressedFilename("x-z"));
43          assertTrue(GzipUtils.isCompressedFilename("x_z"));
44  
45          assertFalse(GzipUtils.isCompressedFilename("xxgz"));
46          assertFalse(GzipUtils.isCompressedFilename("xzz"));
47          assertFalse(GzipUtils.isCompressedFilename("xaz"));
48  
49          assertTrue(GzipUtils.isCompressedFilename("x.SVGZ"));
50          assertTrue(GzipUtils.isCompressedFilename("x.Svgz"));
51          assertTrue(GzipUtils.isCompressedFilename("x.svGZ"));
52  
53          assertFalse(GzipUtils.isCompressedFilename("x.wmz "));
54          assertFalse(GzipUtils.isCompressedFilename("x.wmz\n"));
55          assertFalse(GzipUtils.isCompressedFilename("x.wmz.y"));
56      }
57  
58      @Test
59      public void testGetUncompressedFilename() {
60          assertEquals("", GzipUtils.getUncompressedFilename(""));
61          assertEquals(".gz", GzipUtils.getUncompressedFilename(".gz"));
62  
63          assertEquals("x.tar", GzipUtils.getUncompressedFilename("x.tgz"));
64          assertEquals("x.tar", GzipUtils.getUncompressedFilename("x.taz"));
65          assertEquals("x.svg", GzipUtils.getUncompressedFilename("x.svgz"));
66          assertEquals("x.cpio", GzipUtils.getUncompressedFilename("x.cpgz"));
67          assertEquals("x.wmf", GzipUtils.getUncompressedFilename("x.wmz"));
68          assertEquals("x.emf", GzipUtils.getUncompressedFilename("x.emz"));
69          assertEquals("x", GzipUtils.getUncompressedFilename("x.gz"));
70          assertEquals("x", GzipUtils.getUncompressedFilename("x.z"));
71          assertEquals("x", GzipUtils.getUncompressedFilename("x-gz"));
72          assertEquals("x", GzipUtils.getUncompressedFilename("x-z"));
73          assertEquals("x", GzipUtils.getUncompressedFilename("x_z"));
74  
75          assertEquals("x.svg", GzipUtils.getUncompressedFilename("x.SVGZ"));
76          assertEquals("X.svg", GzipUtils.getUncompressedFilename("X.SVGZ"));
77          assertEquals("X.svg", GzipUtils.getUncompressedFilename("X.svGZ"));
78  
79          assertEquals("x.wmz ", GzipUtils.getUncompressedFilename("x.wmz "));
80          assertEquals("x.wmz\n", GzipUtils.getUncompressedFilename("x.wmz\n"));
81          assertEquals("x.wmz.y", GzipUtils.getUncompressedFilename("x.wmz.y"));
82      }
83  
84      @Test
85      public void testGetCompressedFilename() {
86          assertEquals(".gz", GzipUtils.getCompressedFilename(""));
87          assertEquals("x.gz", GzipUtils.getCompressedFilename("x"));
88  
89          assertEquals("x.tgz", GzipUtils.getCompressedFilename("x.tar"));
90          assertEquals("x.svgz", GzipUtils.getCompressedFilename("x.svg"));
91          assertEquals("x.cpgz", GzipUtils.getCompressedFilename("x.cpio"));
92          assertEquals("x.wmz", GzipUtils.getCompressedFilename("x.wmf"));
93          assertEquals("x.emz", GzipUtils.getCompressedFilename("x.emf"));
94  
95          assertEquals("x.svgz", GzipUtils.getCompressedFilename("x.SVG"));
96          assertEquals("X.svgz", GzipUtils.getCompressedFilename("X.SVG"));
97          assertEquals("X.svgz", GzipUtils.getCompressedFilename("X.svG"));
98  
99          assertEquals("x.wmf .gz", GzipUtils.getCompressedFilename("x.wmf "));
100         assertEquals("x.wmf\n.gz", GzipUtils.getCompressedFilename("x.wmf\n"));
101         assertEquals("x.wmf.y.gz", GzipUtils.getCompressedFilename("x.wmf.y"));
102     }
103 
104 }