cache: fix outputstream writeString to not write unicode strings
Add test for assembling a script with a nbsp in it
This commit is contained in:
@@ -26,6 +26,7 @@ package net.runelite.cache.io;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public final class OutputStream extends java.io.OutputStream
|
public final class OutputStream extends java.io.OutputStream
|
||||||
@@ -180,7 +181,15 @@ public final class OutputStream extends java.io.OutputStream
|
|||||||
|
|
||||||
public void writeString(String str)
|
public void writeString(String str)
|
||||||
{
|
{
|
||||||
byte[] b = str.getBytes();
|
byte[] b;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
b = str.getBytes("ISO-8859-1");
|
||||||
|
}
|
||||||
|
catch (UnsupportedEncodingException ex)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
writeBytes(b);
|
writeBytes(b);
|
||||||
writeByte(0);
|
writeByte(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import org.junit.Test;
|
|||||||
public class ScriptSaverTest
|
public class ScriptSaverTest
|
||||||
{
|
{
|
||||||
private static final String SCRIPT_RESOURCE = "/net/runelite/cache/script/assembler/91.rs2asm";
|
private static final String SCRIPT_RESOURCE = "/net/runelite/cache/script/assembler/91.rs2asm";
|
||||||
|
private static final String SCRIPT_RESOURCE_UNICODE = "/net/runelite/cache/script/assembler/Unicode.rs2asm";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSave() throws IOException
|
public void testSave() throws IOException
|
||||||
@@ -51,4 +52,15 @@ public class ScriptSaverTest
|
|||||||
assertEquals(script, loadedScripot);
|
assertEquals(script, loadedScripot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSaveUnicode() throws IOException
|
||||||
|
{
|
||||||
|
Instructions instructions = new Instructions();
|
||||||
|
instructions.init();
|
||||||
|
ScriptDefinition script = new Assembler(instructions).assemble(getClass().getResourceAsStream(SCRIPT_RESOURCE_UNICODE));
|
||||||
|
byte[] saved = new ScriptSaver().save(script);
|
||||||
|
ScriptDefinition loadedScripot = new ScriptLoader().load(42, saved);
|
||||||
|
assertEquals(script, loadedScripot);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.cache.io;
|
package net.runelite.cache.io;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class OutputStreamTest
|
public class OutputStreamTest
|
||||||
@@ -38,9 +38,22 @@ public class OutputStreamTest
|
|||||||
os.writeBigSmart(65535);
|
os.writeBigSmart(65535);
|
||||||
|
|
||||||
InputStream is = new InputStream(os.getArray());
|
InputStream is = new InputStream(os.getArray());
|
||||||
Assert.assertEquals(42, is.readBigSmart());
|
assertEquals(42, is.readBigSmart());
|
||||||
Assert.assertEquals(70000, is.readBigSmart());
|
assertEquals(70000, is.readBigSmart());
|
||||||
Assert.assertEquals(65535, is.readBigSmart());
|
assertEquals(65535, is.readBigSmart());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWriteString()
|
||||||
|
{
|
||||||
|
char[] c = new char[]{32, 160};
|
||||||
|
String str = new String(c, 0, c.length);
|
||||||
|
|
||||||
|
OutputStream os = new OutputStream();
|
||||||
|
os.writeString(str);
|
||||||
|
|
||||||
|
// 1 byte length + 32 + 160
|
||||||
|
assertEquals(3, os.getOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,8 @@ public class AssemblerTest
|
|||||||
return new String[]
|
return new String[]
|
||||||
{
|
{
|
||||||
"91.rs2asm",
|
"91.rs2asm",
|
||||||
"681.rs2asm"
|
"681.rs2asm",
|
||||||
|
"Unicode.rs2asm"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
6
cache/src/test/resources/net/runelite/cache/script/assembler/Unicode.rs2asm
vendored
Normal file
6
cache/src/test/resources/net/runelite/cache/script/assembler/Unicode.rs2asm
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
.int_stack_count 0
|
||||||
|
.string_stack_count 0
|
||||||
|
.int_var_count 0
|
||||||
|
.string_var_count 0
|
||||||
|
load_string ": "
|
||||||
|
return
|
||||||
Reference in New Issue
Block a user