2 * DictZip library test.
4 * Copyright (C) 2016 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.
21 package org.dict.zip.cli;
23 import static org.testng.Assert.assertTrue;
28 import org.dict.zip.DictZipHeader;
29 import org.dict.zip.DictZipFileUtils;
31 import org.testng.annotations.Test;
36 * @author Hiroshi Miura
38 public class DictDataTest {
40 * Test of printHeader method, of class DictData
41 * @throws java.lang.Exception if file operation failed.
44 public void testPrintHeader() throws Exception {
45 System.out.println("printHeader");
46 URL url = this.getClass().getResource("/test.dict.dz");
47 String testFile = url.getFile();
48 DictData instance = new DictData(testFile, null);
49 instance.printHeader();
53 * Test of doZip method, of class DictData.
54 * @throws java.lang.Exception if file operation failed.
57 public void testDoZip() throws Exception {
58 System.out.println("doZip");
59 String testFile = this.getClass().getResource("/test_dozip.dict").getFile();
60 String zippedFile = DictZipUtils.compressedFileName(testFile);
61 DictData instance = new DictData(testFile, zippedFile);
62 instance.doZip(DictZipHeader.CompressionLevel.DEFAULT_COMPRESSION);
63 File resultFile = new File(testFile + ".dz");
64 File expectFile = new File(this.getClass().getResource("/test_dozip.dict.dz.expected").getFile());
65 assertTrue(DictZipFileUtils.isFileBinaryEquals(resultFile, expectFile, 10, 512));
66 resultFile.deleteOnExit();
70 * Test of doUnzip method, of class DictData.
71 * @throws java.lang.Exception if file operation failed.
74 public void testDoZip_best() throws Exception {
75 System.out.println("doZip_best");
76 String testFile = this.getClass().getResource("/test_dozip.dict").getFile();
77 String zippedFile = testFile + "_best.dz";
78 DictData instance = new DictData(testFile, zippedFile);
79 instance.doZip(DictZipHeader.CompressionLevel.BEST_COMPRESSION);
80 File resultFile = new File(zippedFile);
81 File expectFile = new File(this.getClass().getResource("/test_dozip.dict.dz.expected.best")
83 assertTrue(DictZipFileUtils.isFileBinaryEquals(resultFile, expectFile, 10, 512));
84 resultFile.deleteOnExit();
88 * Test of doUnzip method, of class DictData.
89 * @throws java.lang.Exception if file operation failed.
92 public void testDoZip_fast() throws Exception {
93 System.out.println("doZip_fast");
94 String testFile = this.getClass().getResource("/test_dozip.dict").getFile();
95 String zippedFile = testFile + "_fast.dz";
96 DictData instance = new DictData(testFile, zippedFile);
97 instance.doZip(DictZipHeader.CompressionLevel.BEST_SPEED);
98 File resultFile = new File(zippedFile);
99 File expectFile = new File(this.getClass().getResource("/test_dozip.dict.dz.expected.fast")
101 assertTrue(DictZipFileUtils.isFileBinaryEquals(resultFile, expectFile, 10, 512));
102 resultFile.deleteOnExit();
106 * Test of doUnzip method, of class DictData.
107 * @throws java.lang.Exception if file operation failed.
110 public void testDoUnzip() throws Exception {
111 System.out.println("doUnzip");
112 URL url = this.getClass().getResource("/test.dict.dz");
113 String dzFile = url.getFile();
114 String file = DictZipUtils.uncompressedFileName(dzFile);
117 DictData instance = new DictData(file, dzFile);
118 instance.doUnzip(start, size);
119 URL resultUrl = this.getClass().getResource("/test.dict");
120 File resultFile = new File(resultUrl.getFile());
121 URL expectedUrl = this.getClass().getResource("/test.dict.expected");
122 assertTrue(DictZipFileUtils.isFileBinaryEquals(resultFile, new File(expectedUrl.getFile())));
123 resultFile.deleteOnExit();