jaroslav@611: /** jaroslav@611: * Back 2 Browser Bytecode Translator jaroslav@611: * Copyright (C) 2012 Jaroslav Tulach jaroslav@611: * jaroslav@611: * This program is free software: you can redistribute it and/or modify jaroslav@611: * it under the terms of the GNU General Public License as published by jaroslav@611: * the Free Software Foundation, version 2 of the License. jaroslav@611: * jaroslav@611: * This program is distributed in the hope that it will be useful, jaroslav@611: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@611: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@611: * GNU General Public License for more details. jaroslav@611: * jaroslav@611: * You should have received a copy of the GNU General Public License jaroslav@611: * along with this program. Look for COPYING file in the top folder. jaroslav@611: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@611: */ jaroslav@611: package org.apidesign.bck2brwsr.vmtest.impl; jaroslav@611: jaroslav@611: import java.io.IOException; jaroslav@611: import java.io.InputStream; jaroslav@611: import java.util.zip.ZipEntry; jaroslav@611: import java.util.zip.ZipInputStream; jaroslav@611: import org.apidesign.bck2brwsr.vmtest.Compare; jaroslav@611: import org.apidesign.bck2brwsr.vmtest.VMTest; jaroslav@611: import org.testng.annotations.Factory; jaroslav@611: jaroslav@611: /** jaroslav@611: * jaroslav@611: * @author Jaroslav Tulach jaroslav@611: */ jaroslav@611: public class ZipFileTest { jaroslav@611: jaroslav@611: @GenerateZip(name = "readAnEntry.zip", contents = { "my/main/file.txt", "Hello World!" }) jaroslav@611: @Compare public String readAnEntry() throws IOException { jaroslav@611: InputStream is = ZipFileTest.class.getResourceAsStream("readAnEntry.zip"); jaroslav@611: ZipInputStream zip = new ZipInputStream(is); jaroslav@611: ZipEntry entry = zip.getNextEntry(); jaroslav@611: assertEquals(entry.getName(), "my/main/file.txt", "Correct entry"); jaroslav@611: jaroslav@611: byte[] arr = new byte[4096]; jaroslav@611: int len = zip.read(arr); jaroslav@611: jaroslav@611: return new String(arr, 0, len, "UTF-8"); jaroslav@611: } jaroslav@611: jaroslav@611: private static void assertEquals(String real, String exp, String msg) { jaroslav@611: assert exp.equals(real) : msg + " exp: " + exp + " real: " + real; jaroslav@611: } jaroslav@611: jaroslav@611: @Factory public static Object[] create() { jaroslav@611: return VMTest.create(ZipFileTest.class); jaroslav@611: } jaroslav@611: }