Bubble up gzip/bzip errors, fix map dumper test, add datafile xtea testcase

This commit is contained in:
Adam
2016-06-18 18:11:20 -04:00
parent aeffd8aa67
commit 7682370c4e
8 changed files with 103 additions and 86 deletions

View File

@@ -1,3 +1,33 @@
/*
* Copyright (c) 2016, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Adam <Adam@sigterm.info>
* 4. Neither the name of the Adam <Adam@sigterm.info> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Adam <Adam@sigterm.info> ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Adam <Adam@sigterm.info> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.cache;
import com.google.common.io.Files;
@@ -26,7 +56,7 @@ public class MapDumperTest
public void dump() throws IOException
{
File base = StoreLocation.LOCATION,
outDir = new java.io.File("d:/rs/07/cache/maps");//folder.newFolder();
outDir = folder.newFolder();
try (Store store = new Store(base))
{
@@ -63,13 +93,18 @@ public class MapDumperTest
if (keys != null)
{
land.decompressAndLoad(keys);
try
{
land.decompressAndLoad(keys);
}
catch (IOException ex)
{
logger.warn("Unable to decompress and load land " + x + "/" + y + " (bad keys?)", ex);
continue;
}
data = land.getFiles().get(0).getContents();
if (data == null)
continue; // key is probably wrong
Files.write(data, new File(outDir, "l" + x + "_" + y + ".dat"));
}
}

View File

@@ -150,4 +150,28 @@ public class DataFileTest
Assert.assertEquals(42, res2.revision);
}
}
@Test
public void testKeys() throws IOException
{
File file = folder.newFile();
int[] keys = new int[] { 4, 8, 15, 16 };
try (Store store = new Store(folder.getRoot()))
{
DataFile df = new DataFile(store, file);
byte[] compressedData = DataFile.compress("testtesttesttest1".getBytes(), CompressionType.NONE, 42, keys);
DataFileWriteResult res = df.write(42, 3, compressedData, 0);
compressedData = df.read(42, 3, res.sector, res.compressedLength);
DataFileReadResult res2 = DataFile.decompress(compressedData, keys);
byte[] buf = res2.data;
String str = new String(buf);
Assert.assertEquals("testtesttesttest1", str);
Assert.assertEquals(res.crc, res2.crc);
Assert.assertEquals(42, res2.revision);
}
}
}