Skip to content

Commit 5e0b6d6

Browse files
authored
HPCC4J-587 Character handling test failure (#701)
- Modified test to ignore non-defined unicode chars - Modified test to discard invalid surrogate pairs - Modified fixed strings to have enough capacity for multi-char codepoints Signed-off-by: James McMullan [email protected] Signed-off-by: James McMullan [email protected]
1 parent ac00f75 commit 5e0b6d6

File tree

1 file changed

+40
-11
lines changed

1 file changed

+40
-11
lines changed

dfsclient/src/test/java/org/hpccsystems/dfs/client/DFSReadWriteTest.java

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,43 @@ public void readWithForcedTimeoutTest() throws Exception
9292
public void nullCharTests() throws Exception
9393
{
9494
// Unicode
95+
boolean unicodePassed = true;
9596
{
9697
FieldDef recordDef = null;
9798
{
9899
FieldDef[] fieldDefs = new FieldDef[2];
99100
fieldDefs[0] = new FieldDef("uni", FieldType.STRING, "STRING", 100, false, false, HpccSrcType.UTF16LE, new FieldDef[0]);
100-
fieldDefs[1] = new FieldDef("fixedUni", FieldType.STRING, "STRING", 100, true, false, HpccSrcType.UTF16LE, new FieldDef[0]);
101+
fieldDefs[1] = new FieldDef("fixedUni", FieldType.STRING, "STRING", 200, true, false, HpccSrcType.UTF16LE, new FieldDef[0]);
101102

102103
recordDef = new FieldDef("RootRecord", FieldType.RECORD, "rec", 4, false, false, HpccSrcType.LITTLE_ENDIAN, fieldDefs);
103104
}
104105

105106
List<HPCCRecord> records = new ArrayList<HPCCRecord>();
106107
int maxUTF16BMPChar = Character.MAX_CODE_POINT;
107-
for (int i = 0; i < maxUTF16BMPChar; i++) {
108+
for (int i = 0; i < maxUTF16BMPChar; i++)
109+
{
110+
108111
String strMidEOS = "";
109-
for (int j = 0; j < 98; j++, i++) {
110-
if (j == 50) {
112+
for (int j = 0; j < 98; j++, i++)
113+
{
114+
if (!Character.isValidCodePoint(i) || !Character.isDefined(i))
115+
{
116+
continue;
117+
}
118+
119+
char[] chars = Character.toChars(i);
120+
if (Character.isSurrogate(chars[0]))
121+
{
122+
continue;
123+
}
124+
125+
if (j == 50 && strMidEOS.length() > 0)
126+
{
111127
strMidEOS += "\0";
112128
}
113-
strMidEOS += Character.toString((char) i);
129+
130+
String charStr = new String(chars);
131+
strMidEOS += charStr;
114132
}
115133

116134
Object[] fields = {strMidEOS, strMidEOS};
@@ -123,17 +141,20 @@ public void nullCharTests() throws Exception
123141
HPCCFile file = new HPCCFile(fileName, connString , hpccUser, hpccPass);
124142
List<HPCCRecord> readRecords = readFile(file, 10000, false, false, BinaryRecordReader.TRIM_STRINGS);
125143

126-
for (int i = 0; i < records.size(); i++) {
144+
for (int i = 0; i < records.size(); i++)
145+
{
127146
HPCCRecord record = records.get(i);
128147
HPCCRecord readRecord = readRecords.get(i);
129148
if (readRecord.equals(record) == false)
130149
{
131150
System.out.println("Record: " + i + " did not match\n" + record + "\n" + readRecord);
151+
unicodePassed = false;
132152
}
133153
}
134154
}
135155

136156
// SBC / ASCII
157+
boolean sbcPassed = true;
137158
{
138159
FieldDef recordDef = null;
139160
{
@@ -145,13 +166,16 @@ public void nullCharTests() throws Exception
145166
}
146167

147168
List<HPCCRecord> records = new ArrayList<HPCCRecord>();
148-
for (int i = 0; i < 255; i++) {
169+
for (int i = 0; i < 255; i++)
170+
{
149171
String strMidEOS = "";
150-
for (int j = 0; j < 9; j++, i++) {
151-
if (j == 5) {
172+
for (int j = 0; j < 9; j++, i++)
173+
{
174+
if (j == 5)
175+
{
152176
strMidEOS += "\0";
153177
}
154-
strMidEOS += Character.toString((char) i);
178+
strMidEOS += new String(Character.toChars(j));
155179
}
156180

157181
Object[] fields = {strMidEOS, strMidEOS};
@@ -164,15 +188,20 @@ public void nullCharTests() throws Exception
164188
HPCCFile file = new HPCCFile(fileName, connString , hpccUser, hpccPass);
165189
List<HPCCRecord> readRecords = readFile(file, 10000, false, false, BinaryRecordReader.TRIM_STRINGS);
166190

167-
for (int i = 0; i < records.size(); i++) {
191+
for (int i = 0; i < records.size(); i++)
192+
{
168193
HPCCRecord record = records.get(i);
169194
HPCCRecord readRecord = readRecords.get(i);
170195
if (readRecord.equals(record) == false)
171196
{
172197
System.out.println("Record: " + i + " did not match\n" + record + "\n" + readRecord);
198+
sbcPassed = false;
173199
}
174200
}
175201
}
202+
203+
assertTrue("Unicode EOS character test failed. See mismatches above.", unicodePassed);
204+
assertTrue("Single byte EOS character test failed. See mismatches above.", sbcPassed);
176205
}
177206

178207
@Test

0 commit comments

Comments
 (0)