Skip to content

Commit

Permalink
Reactivate tests in org.eclipse.debug.tests eclipse-platform#525
Browse files Browse the repository at this point in the history
In this commit the test testCheckReceiver() from the class CheckTests.java in org.eclipse.debug.tests is reactivated and fixed. It is about checking if a checkbox is properly toggled in the ui after changing its state. After fixing the issue the checked box can be clearly seen while debuging the code. Contributes to eclipse-platform#525.
  • Loading branch information
Michael5601 committed Aug 7, 2023
1 parent 3e3f88d commit bb4a1ba
Showing 1 changed file with 41 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
import org.eclipse.debug.internal.ui.viewers.model.provisional.ModelDelta;
import org.eclipse.debug.tests.viewer.model.TestModel.TestElement;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.swt.widgets.Display;
import org.junit.Assert;
import org.junit.Test;

/**
* Tests which verify the check box support. This test is very similar to the
* content test except that the extending class should create a viewer with
* the SWT.CHECK style enabled. <br>
* Most of the check box verification is performed in the test model.
* Tests which verify the check box support. This test is very similar to the
* content test except that the extending class should create a viewer with the
* SWT.CHECK style enabled. <br>
* Most of the check box verification is performed in the test model.
*
* @since 3.6
*/
Expand All @@ -44,9 +46,11 @@ public void testSimpleSingleLevel() throws Exception {
fViewer.setAutoExpandLevel(-1);

// Create the agent which forces the tree to populate
//TreeModelViewerAutopopulateAgent autopopulateAgent = new TreeModelViewerAutopopulateAgent(fViewer);
// TreeModelViewerAutopopulateAgent autopopulateAgent = new
// TreeModelViewerAutopopulateAgent(fViewer);

// Create the listener which determines when the view is finished updating.
// Create the listener which determines when the view is finished
// updating.
fListener.reset(TreePath.EMPTY, model.getRootElement(), -1, true, false);

// Set the viewer input (and trigger updates).
Expand All @@ -60,7 +64,8 @@ public void testSimpleSingleLevel() throws Exception {

@Test
public void testSimpleMultiLevel() throws Exception {
//TreeModelViewerAutopopulateAgent autopopulateAgent = new TreeModelViewerAutopopulateAgent(fViewer);
// TreeModelViewerAutopopulateAgent autopopulateAgent = new
// TreeModelViewerAutopopulateAgent(fViewer);

TestModel model = TestModel.simpleMultiLevel();
fViewer.setAutoExpandLevel(-1);
Expand All @@ -74,38 +79,37 @@ public void testSimpleMultiLevel() throws Exception {
model.validateData(fViewer, TreePath.EMPTY);
}

// TODO: no idea how to trigger a toggle event on an item
// public void testCheckReceiver() {
// // Initial setup
// TestModel model = TestModel.simpleSingleLevel();
// fViewer.setAutoExpandLevel(-1);
// //TreeModelViewerAutopopulateAgent autopopulateAgent = new TreeModelViewerAutopopulateAgent(fViewer);
// fListener.reset(TreePath.EMPTY, model.getRootElement(), -1, true, false);
// fViewer.setInput(model.getRootElement());
//
// // Wait for the updates to complete and validate.
// while (!fListener.isFinished()) if (!fDisplay.readAndDispatch ()) Thread.sleep(0);
// model.validateData(fViewer, TreePath.EMPTY);
//
// InternalTreeModelViewer treeViewer = ((InternalTreeModelViewer)fViewer);
// TreePath elementPath = model.findElement("1");
// TestElement element = model.getElement(elementPath);
// boolean initialCheckState = element.getChecked();
// Event event = new Event();
// event.item = treeViewer.findItem(elementPath);
// event.detail = SWT.CHECK;
// event.display = fDisplay;
// event.type = SWT.Selection;
// event.widget = treeViewer.getControl();
// fDisplay.post(event);
//
// while (fDisplay.readAndDispatch ());
//
// Assert.assertTrue(element.getChecked() != initialCheckState);
// }
@Test
public void testCheckReceiver() throws Exception {
// Initial setup
TestModel model = TestModel.simpleSingleLevel();
fViewer.setAutoExpandLevel(-1);
// TreeModelViewerAutopopulateAgent autopopulateAgent = new
// TreeModelViewerAutopopulateAgent(fViewer);
fListener.reset(TreePath.EMPTY, model.getRootElement(), -1, true, false);
fViewer.setInput(model.getRootElement());

waitWhile(t -> !fListener.isFinished(), createListenerErrorMessage());
model.validateData(fViewer, TreePath.EMPTY);

TestElement element = model.getRootElement().getChildren()[0];
boolean initialCheckState = element.getChecked();
TreePath elementPath = new TreePath(new Object[] { element });
ModelDelta delta = model.setElementChecked(elementPath, true, false);

fListener.reset(elementPath, element, -1, true, false);
model.postDelta(delta);

while (Display.getCurrent().readAndDispatch()) {
}

Assert.assertTrue(element.getChecked() != initialCheckState);
}

@Test
public void testUpdateCheck() throws Exception {
//TreeModelViewerAutopopulateAgent autopopulateAgent = new TreeModelViewerAutopopulateAgent(fViewer);
// TreeModelViewerAutopopulateAgent autopopulateAgent = new
// TreeModelViewerAutopopulateAgent(fViewer);

TestModel model = TestModel.simpleSingleLevel();
fViewer.setAutoExpandLevel(-1);
Expand Down

0 comments on commit bb4a1ba

Please sign in to comment.