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;
30 import org.testng.annotations.Test;
35 * @author Hiroshi Miura
37 public class DictDataTest {
39 * Test of printHeader method, of class DictData
40 * @throws java.lang.Exception if file operation failed.
43 public void testPrintHeader() throws Exception {
44 System.out.println("printHeader");
45 URL url = this.getClass().getResource("/test.dict.dz");
46 String testFile = url.getFile();
47 DictData instance = new DictData(testFile, null);
48 instance.printHeader();
52 * Test of doZip method, of class DictData.
53 * @throws java.lang.Exception if file operation failed.
56 public void testDoZip() throws Exception {
57 System.out.println("doZip");
58 String testFile = this.getClass().getResource("/test_dozip.dict").getFile();
59 String zippedFile = DictZipUtils.compressedFileName(testFile);
60 DictData instance = new DictData(testFile, zippedFile);
61 instance.doZip(DictZipHeader.CompressionLevel.DEFAULT_COMPRESSION);
62 File resultFile = new File(testFile + ".dz");
63 File expectFile = new File(this.getClass().getResource("/test_dozip.dict.dz.expected").getFile());
64 assertTrue(StaticUtils.isFileBinaryEquals(resultFile, expectFile, 10, 512));
65 resultFile.deleteOnExit();
69 * Test of doUnzip method, of class DictData.
70 * @throws java.lang.Exception if file operation failed.
73 public void testDoZip_best() throws Exception {
74 System.out.println("doZip_best");
75 String testFile = this.getClass().getResource("/test_dozip.dict").getFile();
76 String zippedFile = testFile + "_best.dz";
77 DictData instance = new DictData(testFile, zippedFile);
78 instance.doZip(DictZipHeader.CompressionLevel.BEST_COMPRESSION);
79 File resultFile = new File(zippedFile);
80 File expectFile = new File(this.getClass().getResource("/test_dozip.dict.dz.expected.best")
82 assertTrue(StaticUtils.isFileBinaryEquals(resultFile, expectFile, 10, 512));
83 resultFile.deleteOnExit();
87 * Test of doUnzip method, of class DictData.
88 * @throws java.lang.Exception if file operation failed.
91 public void testDoZip_fast() throws Exception {
92 System.out.println("doZip_fast");
93 String testFile = this.getClass().getResource("/test_dozip.dict").getFile();
94 String zippedFile = testFile + "_fast.dz";
95 DictData instance = new DictData(testFile, zippedFile);
96 instance.doZip(DictZipHeader.CompressionLevel.BEST_SPEED);
97 File resultFile = new File(zippedFile);
98 File expectFile = new File(this.getClass().getResource("/test_dozip.dict.dz.expected.fast")
100 assertTrue(StaticUtils.isFileBinaryEquals(resultFile, expectFile, 10, 512));
101 resultFile.deleteOnExit();
105 * Test of doUnzip method, of class DictData.
106 * @throws java.lang.Exception if file operation failed.
109 public void testDoUnzip() throws Exception {
110 System.out.println("doUnzip");
111 URL url = this.getClass().getResource("/test.dict.dz");
112 String dzFile = url.getFile();
113 String file = DictZipUtils.uncompressedFileName(dzFile);
116 DictData instance = new DictData(file, dzFile);
117 instance.doUnzip(start, size);
118 URL resultUrl = this.getClass().getResource("/test.dict");
119 File resultFile = new File(resultUrl.getFile());
120 URL expectedUrl = this.getClass().getResource("/test.dict.expected");
121 assertTrue(StaticUtils.isFileBinaryEquals(resultFile, new File(expectedUrl.getFile())));
122 resultFile.deleteOnExit();