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 java.io.ByteArrayOutputStream;
27 import junit.framework.TestCase;
28 import org.junit.Test;
30 import org.apache.commons.io.FileUtils;
34 * @author Hiroshi Miura
36 public class DictDataTest extends TestCase {
38 public DictDataTest() {
41 public static void compareBinary(File f1, File f2) throws Exception {
42 ByteArrayOutputStream d1 = new ByteArrayOutputStream();
43 FileUtils.copyFile(f1, d1);
45 ByteArrayOutputStream d2 = new ByteArrayOutputStream();
46 FileUtils.copyFile(f2, d2);
48 assertEquals(d1.size(), d2.size());
49 byte[] a1 = d1.toByteArray();
50 byte[] a2 = d2.toByteArray();
51 for (int i = 0; i < d1.size(); i++) {
52 assertEquals(a1[i], a2[i]);
57 * Test of printHeader method, of class DictData
58 * @throws java.lang.Exception if file operation failed.
61 public void testPrintHeader() throws Exception {
62 System.out.println("printHeader");
63 URL url = this.getClass().getResource("/test.dict.dz");
64 String testFile = url.getFile();
65 DictData instance = new DictData(testFile, null);
66 instance.printHeader();
70 * Test of doZip method, of class DictData.
71 * @throws java.lang.Exception if file operation failed.
74 public void testDoZip() throws Exception {
75 System.out.println("doZip");
76 String testFile = this.getClass().getResource("/test2.dict").getFile();
77 String zippedFile = DictZipUtils.compressedFileName(testFile);
78 DictData instance = new DictData(testFile, zippedFile);
80 File resultFile = new File(testFile + ".dz");
81 //compareBinary(resultFile, new File("test/data/test2.dict.dz.expected"));
82 resultFile.deleteOnExit();
86 * Test of doUnzip method, of class DictData.
87 * @throws java.lang.Exception if file operation failed.
90 public void testDoUnzip() throws Exception {
91 System.out.println("doUnzip");
92 URL url = this.getClass().getResource("/test.dict.dz");
93 String dzFile = url.getFile();
94 String file = DictZipUtils.uncompressedFileName(dzFile);
97 DictData instance = new DictData(file, dzFile);
98 instance.doUnzip(start, size);
99 URL resultUrl = this.getClass().getResource("/test.dict");
100 File resultFile = new File(resultUrl.getFile());
101 URL expectedUrl = this.getClass().getResource("/test.dict.expected");
102 compareBinary(resultFile, new File(expectedUrl.getFile()));
103 resultFile.deleteOnExit();