GT-3333, #1255 fix string rendering issue when with dataOrg char sizes >

1 byte.

If the language's dataOrg specifies a character size larger than 1 byte,
strings with a charSet that uses just 1 byte (ie. UTF-8 strings inside a
java .dex file) will incorrectly treat some of the string bytes as
padding between array elements.

Fixes issue #1255.
This commit is contained in:
dev747368 2019-11-18 12:54:19 -05:00
parent 7cd82462e9
commit 26750e23f2
2 changed files with 38 additions and 8 deletions

View file

@ -45,6 +45,19 @@ public class StringDataTypeTest extends AbstractGTest {
private PascalStringDataType pascalString = new PascalStringDataType();
private PascalUnicodeDataType pascalUtf16String = new PascalUnicodeDataType();
private static class DataOrgDTM extends TestDummyDataTypeManager {
private DataOrganization dataOrg;
public DataOrgDTM(DataOrganization dataOrg) {
this.dataOrg = dataOrg;
}
@Override
public DataOrganization getDataOrganization() {
return dataOrg;
}
}
private ByteMemBufferImpl mb(boolean isBE, int... values) {
byte[] bytes = new byte[values.length];
for (int i = 0; i < values.length; i++) {
@ -216,6 +229,21 @@ public class StringDataTypeTest extends AbstractGTest {
assertEquals("ab\ucc01\u1202", actual);
}
@Test
public void testGetStringValue_utf8_2bytechar_dataorg() {
// test UTF-8 when the dataorg specifies a 2byte character (ie. JVM)
ByteMemBufferImpl buf = mb(false, 'a', 'b', 'c');
DataOrganizationImpl dataOrg = DataOrganizationImpl.getDefaultOrganization(null);
dataOrg.setCharSize(2);
DataOrgDTM dtm = new DataOrgDTM(dataOrg);
StringUTF8DataType wideCharUTF8DT = new StringUTF8DataType(dtm);
String actual = (String) wideCharUTF8DT.getValue(buf, newset(), buf.getLength());
assertEquals("abc", actual);
}
@Test
public void testGetStringValue_utf16_le() {
ByteMemBufferImpl buf = mb(false, //