2 * DictZip Library test.
4 * Copyright (C) 2016,2019 Hiroshi Miura
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * Linking this library statically or dynamically with other modules is
21 * making a combined work based on this library. Thus, the terms and
22 * conditions of the GNU General Public License cover the whole
25 * As a special exception, the copyright holders of this library give you
26 * permission to link this library with independent modules to produce an
27 * executable, regardless of the license terms of these independent
28 * modules, and to copy and distribute the resulting executable under
29 * terms of your choice, provided that you also meet, for each linked
30 * independent module, the terms and conditions of the license of that
31 * module. An independent module is a module which is not derived from
32 * or based on this library. If you modify this library, you may extend
33 * this exception to your version of the library, but you are not
34 * obligated to do so. If you do not wish to do so, delete this
35 * exception statement from your version.
40 import org.junit.jupiter.api.Test;
43 import java.io.IOException;
44 import java.nio.file.Path;
45 import java.nio.file.Paths;
46 import java.util.Objects;
48 import static org.junit.jupiter.api.Assertions.assertFalse;
49 import static org.junit.jupiter.api.Assertions.assertTrue;
50 import static tokyo.northside.io.FileUtils2.contentEquals;
53 * Created by Hiroshi Miura on 16/04/09.
55 public class FileUtils2Test {
58 * Check equals two file contentss.
59 * @throws Exception when fails to open.
62 public void testContentEquals() throws Exception {
63 Path firstFile = Paths.get(
64 Objects.requireNonNull(this.getClass().getResource("/test_util.txt")).toURI());
65 Path secondFile = Paths.get(
66 Objects.requireNonNull(this.getClass().getResource("/test_util1.txt")).toURI());
67 assertTrue(contentEquals(firstFile, secondFile));
71 * Check equals two file paths which is canonical path.
72 * @throws Exception when fails to open.
75 public void testContentEqualsSameCanonicalPath() throws Exception {
76 Path firstFile = Paths.get(
77 Objects.requireNonNull(this.getClass().getResource("/test_util.txt")).toURI());
78 Path secondFile = Paths.get(
79 Objects.requireNonNull(this.getClass().getResource("/test_util.txt")).toURI());
80 assertTrue(contentEquals(firstFile, secondFile));
84 * Check not equals two file contents.
85 * @throws Exception when fails to open.
88 public void testContentEqualsFalse() throws Exception {
89 File firstFile = new File(
90 Objects.requireNonNull(this.getClass().getResource("/test_util.txt")).getFile());
91 File secondFile = new File(
92 Objects.requireNonNull(this.getClass().getResource("/test_util2.txt")).getFile());
93 assertFalse(contentEquals(firstFile, secondFile));
97 * Check equals tow files content with range.
98 * @throws Exception when fails to open.
101 public void testContentEqualsRange() throws Exception {
102 File firstFile = new File(this.getClass().getResource("/test_util.txt").getFile());
103 File secondFile = new File(this.getClass().getResource("/test_util2.txt").getFile());
104 assertTrue(contentEquals(firstFile, secondFile, 10, 64));
108 * Check not equals two file contents with range.
109 * @throws Exception when fails to open.
112 public void testContentEqualsRangeFalse() throws Exception {
113 File firstFile = new File(this.getClass().getResource("/test_util.txt").getFile());
114 File secondFile = new File(this.getClass().getResource("/test_util2.txt").getFile());
115 assertFalse(contentEquals(firstFile, secondFile, 0, 64));
119 * Check dictzip inputstream.
120 * @throws Exception when fails.
123 public void testCheckDictZipInputStreamString() throws Exception {
124 String targetFile = this.getClass().getResource("/test.dict.dz").getFile();
125 assertTrue(DictZipFileUtils.checkDictZipInputStream(targetFile));
129 * Check dictzip input streasm which is not exist.
132 public void testCheckDictZipInputStreamStringNoExist() {
133 String targetFile = "false.dict.dz";
136 DictZipFileUtils.checkDictZipInputStream(targetFile);
138 } catch (IOException e) {
146 * Check dictzip input stream.
147 * @throws Exception when fails.
150 public void testCheckDictZipInputStream() throws Exception {
151 String targetFile = this.getClass().getResource("/test.dict.dz").getFile();
152 try (DictZipInputStream dzin = new DictZipInputStream(new
153 RandomAccessInputStream(targetFile, "r"))) {
154 assertTrue(DictZipFileUtils.checkDictZipInputStream(dzin));