Skip to content

Commit

Permalink
testCompleteActivationChar: single threaded #35
Browse files Browse the repository at this point in the history
  • Loading branch information
EcljpseB0T authored and jukzi committed Jun 2, 2023
1 parent 9e6b830 commit b37a605
Showing 1 changed file with 36 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.util.Arrays;
import java.util.Collection;
import java.util.concurrent.atomic.AtomicBoolean;

import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -50,6 +49,7 @@
public class AsyncContentAssistTest {

private ILogListener listener;

private IStatus errorStatus;

private Shell shell;
Expand All @@ -58,8 +58,8 @@ public class AsyncContentAssistTest {
public void setUp() {
shell= new Shell();
listener= (status, plugin) -> {
if(status.getSeverity() == IStatus.ERROR && "org.eclipse.jface.text".equals(status.getPlugin())) {
errorStatus = status;
if (status.getSeverity() == IStatus.ERROR && "org.eclipse.jface.text".equals(status.getPlugin())) {
errorStatus= status;
}
};
Platform.addLogListener(listener);
Expand All @@ -73,10 +73,10 @@ public void tearDown() {

@Test
public void testAsyncFailureStackOverflow() {
SourceViewer viewer = new SourceViewer(shell, null, SWT.NONE);
Document document = new Document("a");
SourceViewer viewer= new SourceViewer(shell, null, SWT.NONE);
Document document= new Document("a");
viewer.setDocument(document);
ContentAssistant contentAssistant = new ContentAssistant(true);
ContentAssistant contentAssistant= new ContentAssistant(true);
contentAssistant.addContentAssistProcessor(new DelayedErrorContentAssistProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
contentAssistant.addContentAssistProcessor(new ImmediateContentAssistProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
contentAssistant.install(viewer);
Expand All @@ -88,10 +88,10 @@ public void testAsyncFailureStackOverflow() {

@Test
public void testSyncFailureNPE() {
SourceViewer viewer = new SourceViewer(shell, null, SWT.NONE);
Document document = new Document("a");
SourceViewer viewer= new SourceViewer(shell, null, SWT.NONE);
Document document= new Document("a");
viewer.setDocument(document);
ContentAssistant contentAssistant = new ContentAssistant(true);
ContentAssistant contentAssistant= new ContentAssistant(true);
contentAssistant.addContentAssistProcessor(new ImmediateContentAssistProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
contentAssistant.addContentAssistProcessor(new ImmediateNullContentAssistProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
contentAssistant.install(viewer);
Expand All @@ -105,25 +105,25 @@ public void testSyncFailureNPE() {
public void testCompletePrefix() {
shell.setLayout(new FillLayout());
shell.setSize(500, 300);
SourceViewer viewer = new SourceViewer(shell, null, SWT.NONE);
Document document = new Document("b");
SourceViewer viewer= new SourceViewer(shell, null, SWT.NONE);
Document document= new Document("b");
viewer.setDocument(document);
viewer.setSelectedRange(1, 0);
ContentAssistant contentAssistant = new ContentAssistant(true);
ContentAssistant contentAssistant= new ContentAssistant(true);
contentAssistant.addContentAssistProcessor(new BarContentAssistProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
contentAssistant.enablePrefixCompletion(true);
contentAssistant.install(viewer);
shell.open();
DisplayHelper.driveEventQueue(shell.getDisplay());
Display display = shell.getDisplay();
Display display= shell.getDisplay();
final Collection<Shell> beforeShells= AbstractContentAssistTest.getCurrentShells();
contentAssistant.showPossibleCompletions();
Shell newShell= AbstractContentAssistTest.findNewShell(beforeShells);
assertTrue("Completion item not shown", new DisplayHelper() {
@Override
protected boolean condition() {
Table completionTable= findCompletionSelectionControl(newShell);
return Arrays.stream(completionTable.getItems()).map(TableItem::getText).anyMatch(item -> item.contains(BarContentAssistProcessor.PROPOSAL.substring(document.getLength())));
return Arrays.stream(completionTable.getItems()).map(TableItem::getText).anyMatch(item -> item.contains(BarContentAssistProcessor.PROPOSAL.substring(document.getLength())));
}
}.waitForCondition(display, 2000));
}
Expand All @@ -133,7 +133,7 @@ public void testCompleteActivationChar() {
shell.setLayout(new FillLayout());
shell.setSize(500, 300);
SourceViewer viewer= new SourceViewer(shell, null, SWT.NONE);
Document document= new Document("b");
Document document= new Document("something");
viewer.setDocument(document);
viewer.setSelectedRange(1, 0);
ContentAssistant contentAssistant= new ContentAssistant(true);
Expand All @@ -148,56 +148,32 @@ public void testCompleteActivationChar() {
Display display= shell.getDisplay();
Event keyEvent= new Event();
Control control= viewer.getTextWidget();
AtomicBoolean testEnded= new AtomicBoolean();
try {
display.timerExec(0, new Runnable() {
@Override
public void run() {
if (control.isDisposed() || testEnded.get()) {
// https://github.com/eclipse-platform/eclipse.platform.text/issues/75#issuecomment-1263429480
return; // do not fail other unit tests
}
control.getShell().forceActive();
if (!control.forceFocus()) {
display.timerExec(200, this);
System.out.println("no focus");
return;
}
keyEvent.widget= control;
keyEvent.type= SWT.KeyDown;
keyEvent.character= 'b';
keyEvent.keyCode= 'b';
control.getDisplay().post(keyEvent);
keyEvent.type= SWT.KeyUp;
control.getDisplay().post(keyEvent);
DisplayHelper.driveEventQueue(control.getDisplay());
if (!document.get().startsWith("bb")) {
System.out.println("character b not added to control");
display.timerExec(200, this);
}
}
});
final Collection<Shell> beforeShells= AbstractContentAssistTest.getCurrentShells();
AbstractContentAssistTest.processEvents();
Shell newShell= AbstractContentAssistTest.findNewShell(beforeShells);
assertTrue("Completion item not shown", new DisplayHelper() {
@Override
protected boolean condition() {
Table completionTable= findCompletionSelectionControl(newShell);
return Arrays.stream(completionTable.getItems()).map(TableItem::getText).anyMatch(item -> item.contains(BarContentAssistProcessor.PROPOSAL.substring(document.getLength())));
}
}.waitForCondition(display, 4000));
} finally {
testEnded.set(true);
}
keyEvent.widget= control;
keyEvent.type= SWT.KeyDown;
keyEvent.character= 'b';
keyEvent.keyCode= 'b';
control.getShell().forceActive();
control.getDisplay().post(keyEvent);
keyEvent.type= SWT.KeyUp;
control.getDisplay().post(keyEvent);
final Collection<Shell> beforeShells= AbstractContentAssistTest.getCurrentShells();
AbstractContentAssistTest.processEvents();
Shell newShell= AbstractContentAssistTest.findNewShell(beforeShells);
assertTrue("Completion item not shown", new DisplayHelper() {
@Override
protected boolean condition() {
Table completionTable= findCompletionSelectionControl(newShell);
return Arrays.stream(completionTable.getItems()).map(TableItem::getText).anyMatch(item -> item.contains(BarContentAssistProcessor.PROPOSAL.substring(document.getLength())));
}
}.waitForCondition(display, 4000));
}

private static Table findCompletionSelectionControl(Widget control) {
if (control instanceof Table) {
return (Table)control;
return (Table) control;
} else if (control instanceof Composite) {
for (Widget child : ((Composite)control).getChildren()) {
Table res = findCompletionSelectionControl(child);
for (Widget child : ((Composite) control).getChildren()) {
Table res= findCompletionSelectionControl(child);
if (res != null) {
return res;
}
Expand Down

0 comments on commit b37a605

Please sign in to comment.