Skip to content

Commit

Permalink
Fix \0 handling in the test parameters
Browse files Browse the repository at this point in the history
Previously if the variable contained a '\0' the rest of the string
was not displayed, with this fix, the rest of the string shows up too
  • Loading branch information
gzsombor committed Nov 11, 2024
1 parent b635fa4 commit c6b9e13
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ private TestElement addTreeEntry(String treeEntry) {
int index0= treeEntry.indexOf(',');
String id= treeEntry.substring(0, index0);

StringBuffer testNameBuffer= new StringBuffer(100);
StringBuilder testNameBuffer= new StringBuilder(100);
int index1= scanTestName(treeEntry, index0 + 1, testNameBuffer);
String testName= testNameBuffer.toString().trim();

Expand All @@ -493,11 +493,11 @@ private TestElement addTreeEntry(String treeEntry) {
boolean isDynamicTest;
String parentId;
String displayName;
StringBuffer displayNameBuffer= new StringBuffer(100);
StringBuilder displayNameBuffer= new StringBuilder(100);
String[] parameterTypes;
StringBuffer parameterTypesBuffer= new StringBuffer(200);
StringBuilder parameterTypesBuffer= new StringBuilder(200);
String uniqueId;
StringBuffer uniqueIdBuffer= new StringBuffer(200);
StringBuilder uniqueIdBuffer= new StringBuilder(200);
int index3= treeEntry.indexOf(',', index2 + 1);
if (index3 == -1) {
testCount= Integer.parseInt(treeEntry.substring(index2 + 1));
Expand All @@ -519,7 +519,7 @@ private TestElement addTreeEntry(String treeEntry) {
}

int index6= scanTestName(treeEntry, index5 + 1, displayNameBuffer);
displayName= displayNameBuffer.toString().trim();
displayName= displayNameBuffer.toString().replace('\0', ' ').trim();
if (displayName.equals(testName)) {
displayName= null;
}
Expand Down Expand Up @@ -592,7 +592,7 @@ public TestElement createTestElement(TestSuiteElement parent, String id, String
*
* @return the index of the next ','
*/
private int scanTestName(String s, int start, StringBuffer testName) {
private int scanTestName(String s, int start, StringBuilder testName) {
boolean inQuote= false;
int i= start;
for (; i < s.length(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,19 @@ public void setLoader(ITestLoader newInstance) {
fLoader = newInstance;
}

private void readPackageNames(String pkgNameFile) throws IOException {
try(BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(new File(pkgNameFile)), StandardCharsets.UTF_8))) {
private String[] readLines(String fileName) throws IOException {
try(BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(new File(fileName)), StandardCharsets.UTF_8))) {
String line;
Vector<String> list= new Vector<>();
while ((line= br.readLine()) != null) {
list.add(line);
}
fPackageNames= list.toArray(new String[list.size()]);
return list.toArray(new String[list.size()]);
}
}

private void readPackageNames(String pkgNameFile) throws IOException {
fPackageNames= readLines(pkgNameFile);
if (fDebugMode) {
System.out.println("Packages:"); //$NON-NLS-1$
for (String fPackageName : fPackageNames) {
Expand All @@ -404,14 +408,7 @@ private void readPackageNames(String pkgNameFile) throws IOException {
}

private void readTestNames(String testNameFile) throws IOException {
try(BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(new File(testNameFile)), StandardCharsets.UTF_8))) {
String line;
Vector<String> list= new Vector<>();
while ((line= br.readLine()) != null) {
list.add(line);
}
fTestClassNames= list.toArray(new String[list.size()]);
}
fTestClassNames= readLines(testNameFile);
if (fDebugMode) {
System.out.println("Tests:"); //$NON-NLS-1$
for (String fTestClassName : fTestClassNames) {
Expand All @@ -421,14 +418,7 @@ private void readTestNames(String testNameFile) throws IOException {
}

private void readFailureNames(String testFailureFile) throws IOException {
try(BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(new File(testFailureFile)), StandardCharsets.UTF_8))) {
String line;
Vector<String> list= new Vector<>();
while ((line= br.readLine()) != null) {
list.add(line);
}
fFailureNames= list.toArray(new String[list.size()]);
}
fFailureNames = readLines(testFailureFile);
if (fDebugMode) {
System.out.println("Failures:"); //$NON-NLS-1$
for (String fFailureName : fFailureNames) {
Expand Down Expand Up @@ -510,7 +500,7 @@ protected void notifyListenersOfTestEnd(TestExecution execution,
* @param testName individual method to be run
* @param execution executor
*/
public void runTests(String[] testClassNames, String testName, TestExecution execution) {
private void runTests(String[] testClassNames, String testName, TestExecution execution) {
ITestReference[] suites= fLoader.loadTests(loadClasses(testClassNames), testName, fFailureNames, fPackageNames, fIncludeExcludeTags, fUniqueId, this);

// count all testMethods and inform ITestRunListeners
Expand Down Expand Up @@ -754,7 +744,7 @@ public void flush() {
fWriter.flush();
}

public void runTests(TestExecution execution) {
private void runTests(TestExecution execution) {
runTests(fTestClassNames, fTestName, execution);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ private void notifyTestTreeEntry(final String treeEntry) {
}

int index6 = scanTestName(fixedTreeEntry, index5 + 1, displayNameBuffer);
displayName = displayNameBuffer.toString().trim();
displayName = displayNameBuffer.toString().replace('\0', ' ').trim();
if (displayName.equals(testName)) {
displayName = null;
}
Expand Down

0 comments on commit c6b9e13

Please sign in to comment.