1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

Remove usage of Java 1.4 reserved keyword assert.

This commit is contained in:
Peter Graves 2003-07-17 15:23:56 +00:00
parent 176c8d7bf9
commit a7fedb9060
5 changed files with 88 additions and 534 deletions

View file

@ -1,4 +1,8 @@
2003-07-15
2003-07-17 Peter Graves
Remove the usage of the assert, as it's a reserved keyword in
Java 1.4 (Bugzilla 40377)
2003-07-15 Peter Graves
Clean up some left over stuff that was moved into org.eclipse.cdt.core.tests,
and fixed the test.xml to point to the correct test suite.

View file

@ -137,12 +137,12 @@ public class TextBufferTest extends TestCase {
fEditor.add(e2);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assert(e1.getTextRange(), 2, 2);
assert(e2.getTextRange(), 4, 4);
tb_assert(e1.getTextRange(), 2, 2);
tb_assert(e2.getTextRange(), 4, 4);
assertEquals("Buffer content", "01yy345656789", fBuffer.getContent());
doUndo(undo);
assert(e1.getTextRange(), 2, 0);
assert(e2.getTextRange(), 2, 3);
tb_assert(e1.getTextRange(), 2, 0);
tb_assert(e2.getTextRange(), 2, 3);
}
public void testInsert2() throws Exception {
@ -153,12 +153,12 @@ public class TextBufferTest extends TestCase {
fEditor.add(e2);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assert(e1.getTextRange(), 2, 2);
assert(e2.getTextRange(), 4, 2);
tb_assert(e1.getTextRange(), 2, 2);
tb_assert(e2.getTextRange(), 4, 2);
assertEquals("Buffer content", "01yyxx23456789", fBuffer.getContent());
doUndo(undo);
assert(e1.getTextRange(), 2, 0);
assert(e2.getTextRange(), 2, 0);
tb_assert(e1.getTextRange(), 2, 0);
tb_assert(e2.getTextRange(), 2, 0);
}
public void testInsert3() throws Exception {
@ -171,14 +171,14 @@ public class TextBufferTest extends TestCase {
fEditor.add(e3);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assert(e1.getTextRange(), 0, 3);
assert(e2.getTextRange(), 3, 2);
assert(e3.getTextRange(), 5, 1);
tb_assert(e1.getTextRange(), 0, 3);
tb_assert(e2.getTextRange(), 3, 2);
tb_assert(e3.getTextRange(), 5, 1);
assertEquals("Buffer content", "011xx2456789", fBuffer.getContent());
doUndo(undo);
assert(e1.getTextRange(), 0, 2);
assert(e2.getTextRange(), 2, 0);
assert(e3.getTextRange(), 2, 2);
tb_assert(e1.getTextRange(), 0, 2);
tb_assert(e2.getTextRange(), 2, 0);
tb_assert(e3.getTextRange(), 2, 2);
}
public void testInsert4() throws Exception {
@ -187,10 +187,10 @@ public class TextBufferTest extends TestCase {
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer length", 12, fBuffer.getLength());
assert(e1.getTextRange(), 0, 2);
tb_assert(e1.getTextRange(), 0, 2);
assertEquals("Buffer content", "xx0123456789", fBuffer.getContent());
doUndo(undo);
assert(e1.getTextRange(), 0, 0);
tb_assert(e1.getTextRange(), 0, 0);
}
public void testInsert5() throws Exception {
@ -199,10 +199,10 @@ public class TextBufferTest extends TestCase {
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer length", 12, fBuffer.getLength());
assert(e1.getTextRange(), 10, 2);
tb_assert(e1.getTextRange(), 10, 2);
assertEquals("Buffer content", "0123456789xx", fBuffer.getContent());
doUndo(undo);
assert(e1.getTextRange(), 10, 0);
tb_assert(e1.getTextRange(), 10, 0);
}
public void testDelete1() throws Exception {
@ -210,10 +210,10 @@ public class TextBufferTest extends TestCase {
fEditor.add(e1);
assertTrue("Can perform edits", fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assert(e1.getTextRange(), 3, 0);
tb_assert(e1.getTextRange(), 3, 0);
assertEquals("Buffer content", "012456789", fBuffer.getContent());
doUndo(undo);
assert(e1.getTextRange(), 3, 1);
tb_assert(e1.getTextRange(), 3, 1);
}
public void testDelete2() throws Exception {
@ -225,14 +225,14 @@ public class TextBufferTest extends TestCase {
fEditor.add(e3);
assertTrue("Can perform edits", fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assert(e1.getTextRange(), 3, 0);
assert(e2.getTextRange(), 3, 0);
assert(e3.getTextRange(), 3, 0);
tb_assert(e1.getTextRange(), 3, 0);
tb_assert(e2.getTextRange(), 3, 0);
tb_assert(e3.getTextRange(), 3, 0);
assertEquals("Buffer content", "0126789", fBuffer.getContent());
doUndo(undo);
assert(e1.getTextRange(), 4, 1);
assert(e2.getTextRange(), 3, 1);
assert(e3.getTextRange(), 5, 1);
tb_assert(e1.getTextRange(), 4, 1);
tb_assert(e2.getTextRange(), 3, 1);
tb_assert(e3.getTextRange(), 5, 1);
}
public void testDelete3() throws Exception {
@ -242,12 +242,12 @@ public class TextBufferTest extends TestCase {
fEditor.add(e2);
assertTrue("Can perform edits", fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assert(e1.getTextRange(), 3, 1);
assert(e2.getTextRange(), 4, 0);
tb_assert(e1.getTextRange(), 3, 1);
tb_assert(e2.getTextRange(), 4, 0);
assertEquals("Buffer content", "012x456789", fBuffer.getContent());
doUndo(undo);
assert(e1.getTextRange(), 3, 0);
assert(e2.getTextRange(), 3, 1);
tb_assert(e1.getTextRange(), 3, 0);
tb_assert(e2.getTextRange(), 3, 1);
}
public void testMove1() throws Exception {
@ -256,11 +256,11 @@ public class TextBufferTest extends TestCase {
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "0142356789", fBuffer.getContent());
assert(e1.getTargetRange(), 3, 2);
assert(e1.getSourceRange(), 2, 0);
tb_assert(e1.getTargetRange(), 3, 2);
tb_assert(e1.getSourceRange(), 2, 0);
doUndo(undo);
assert(e1.getSourceRange(), 2, 2);
assert(e1.getTargetRange(), 5, 0);
tb_assert(e1.getSourceRange(), 2, 2);
tb_assert(e1.getTargetRange(), 5, 0);
}
public void testMove2() throws Exception {
@ -269,11 +269,11 @@ public class TextBufferTest extends TestCase {
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "0156234789", fBuffer.getContent());
assert(e1.getTargetRange(), 2, 2);
assert(e1.getSourceRange(), 7, 0);
tb_assert(e1.getTargetRange(), 2, 2);
tb_assert(e1.getSourceRange(), 7, 0);
doUndo(undo);
assert(e1.getSourceRange(), 5, 2);
assert(e1.getTargetRange(), 2, 0);
tb_assert(e1.getSourceRange(), 5, 2);
tb_assert(e1.getTargetRange(), 2, 0);
}
public void testMove3() throws Exception {
@ -284,13 +284,13 @@ public class TextBufferTest extends TestCase {
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "01x5623789", fBuffer.getContent());
assert(e1.getTargetRange(), 5, 2);
assert(e1.getSourceRange(), 2, 0);
assert(e2.getTextRange(), 2, 1);
tb_assert(e1.getTargetRange(), 5, 2);
tb_assert(e1.getSourceRange(), 2, 0);
tb_assert(e2.getTextRange(), 2, 1);
doUndo(undo);
assert(e1.getSourceRange(), 2, 2);
assert(e1.getTargetRange(), 7, 0);
assert(e2.getTextRange(), 4, 1);
tb_assert(e1.getSourceRange(), 2, 2);
tb_assert(e1.getTargetRange(), 7, 0);
tb_assert(e2.getTextRange(), 4, 1);
}
public void testMove4() throws Exception {
@ -301,13 +301,13 @@ public class TextBufferTest extends TestCase {
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "0178234x69", fBuffer.getContent());
assert(e1.getTargetRange(), 2, 2);
assert(e1.getSourceRange(), 9, 0);
assert(e2.getTextRange(), 7, 1);
tb_assert(e1.getTargetRange(), 2, 2);
tb_assert(e1.getSourceRange(), 9, 0);
tb_assert(e2.getTextRange(), 7, 1);
doUndo(undo);
assert(e1.getSourceRange(), 7, 2);
assert(e1.getTargetRange(), 2, 0);
assert(e2.getTextRange(), 5, 1);
tb_assert(e1.getSourceRange(), 7, 2);
tb_assert(e1.getTargetRange(), 2, 0);
tb_assert(e2.getTextRange(), 5, 1);
}
public void testMove5() throws Exception {
@ -318,14 +318,14 @@ public class TextBufferTest extends TestCase {
fEditor.add(e2);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assert(e1.getTargetRange(), 2, 1);
assert(e1.getSourceRange(), 3, 0);
assert(e2.getTextRange(), 2, 1);
tb_assert(e1.getTargetRange(), 2, 1);
tb_assert(e1.getSourceRange(), 3, 0);
tb_assert(e2.getTextRange(), 2, 1);
assertEquals("Buffer content", "01x3456789", fBuffer.getContent());
doUndo(undo);
assert(e1.getSourceRange(), 2, 1);
assert(e1.getTargetRange(), 3, 0);
assert(e2.getTextRange(), 2, 1);
tb_assert(e1.getSourceRange(), 2, 1);
tb_assert(e1.getTargetRange(), 3, 0);
tb_assert(e2.getTextRange(), 2, 1);
}
public void testMove6() throws Exception {
@ -336,14 +336,14 @@ public class TextBufferTest extends TestCase {
fEditor.add(e2);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assert(e1.getTargetRange(), 2, 1);
assert(e1.getSourceRange(), 3, 0); // This gets normalized since a move from [2,1] -> 2 == [2,1] -> 3
assert(e2.getTextRange(), 2, 1);
tb_assert(e1.getTargetRange(), 2, 1);
tb_assert(e1.getSourceRange(), 3, 0); // This gets normalized since a move from [2,1] -> 2 == [2,1] -> 3
tb_assert(e2.getTextRange(), 2, 1);
assertEquals("Buffer content", "01x3456789", fBuffer.getContent());
doUndo(undo);
assert(e1.getSourceRange(), 2, 1);
assert(e1.getTargetRange(), 3, 0);
assert(e2.getTextRange(), 2, 1);
tb_assert(e1.getSourceRange(), 2, 1);
tb_assert(e1.getTargetRange(), 3, 0);
tb_assert(e2.getTextRange(), 2, 1);
}
public void testMove7() throws Exception {
@ -354,13 +354,13 @@ public class TextBufferTest extends TestCase {
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "01562x4789", fBuffer.getContent());
assert(e1.getTargetRange(), 4, 3);
assert(e1.getSourceRange(), 2, 0);
assert(e2.getTextRange(), 5, 1);
tb_assert(e1.getTargetRange(), 4, 3);
tb_assert(e1.getSourceRange(), 2, 0);
tb_assert(e2.getTextRange(), 5, 1);
doUndo(undo);
assert(e1.getSourceRange(), 2, 3);
assert(e1.getTargetRange(), 7, 0);
assert(e2.getTextRange(), 3, 1);
tb_assert(e1.getSourceRange(), 2, 3);
tb_assert(e1.getTargetRange(), 7, 0);
tb_assert(e2.getTextRange(), 3, 1);
}
public void testMove8() throws Exception {
@ -371,13 +371,13 @@ public class TextBufferTest extends TestCase {
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "05x7123489", fBuffer.getContent());
assert(e1.getTargetRange(), 1, 3);
assert(e1.getSourceRange(), 8, 0);
assert(e2.getTextRange(), 2, 1);
tb_assert(e1.getTargetRange(), 1, 3);
tb_assert(e1.getSourceRange(), 8, 0);
tb_assert(e2.getTextRange(), 2, 1);
doUndo(undo);
assert(e1.getSourceRange(), 5, 3);
assert(e1.getTargetRange(), 1, 0);
assert(e2.getTextRange(), 6, 1);
tb_assert(e1.getSourceRange(), 5, 3);
tb_assert(e1.getTargetRange(), 1, 0);
tb_assert(e2.getTextRange(), 6, 1);
}
public void testMove9() throws Exception {
@ -387,16 +387,16 @@ public class TextBufferTest extends TestCase {
fEditor.add(e2);
assertTrue("Can perform edits", fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assert(e1.getTargetRange(), 3, 1);
assert(e1.getSourceRange(), 2, 0);
assert(e2.getTargetRange(), 2, 3);
assert(e2.getSourceRange(), 1, 0);
tb_assert(e1.getTargetRange(), 3, 1);
tb_assert(e1.getSourceRange(), 2, 0);
tb_assert(e2.getTargetRange(), 2, 3);
tb_assert(e2.getSourceRange(), 1, 0);
assertEquals("Buffer content", "0421356789", fBuffer.getContent());
doUndo(undo);
assert(e1.getSourceRange(), 1, 1);
assert(e1.getTargetRange(), 3, 0);
assert(e2.getSourceRange(), 1, 3);
assert(e2.getTargetRange(), 5, 0);
tb_assert(e1.getSourceRange(), 1, 1);
tb_assert(e1.getTargetRange(), 3, 0);
tb_assert(e2.getSourceRange(), 1, 3);
tb_assert(e2.getTargetRange(), 5, 0);
}
public void testMove10() throws Exception {
@ -460,7 +460,7 @@ public class TextBufferTest extends TestCase {
assertBufferContent();
}
private void assert(TextRange r, int offset, int length) {
private void tb_assert(TextRange r, int offset, int length) {
assertEquals("Offset", offset, r.getOffset());
assertEquals("Length", length, r.getLength());
}

View file

@ -1,225 +0,0 @@
package org.eclipse.cdt.testplugin.util;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import junit.framework.Assert;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.ui.internal.WorkbenchPlugin;
/**
* A <code>DialogCheck</code> is used test a dialog in
* various ways.
* <p>
* For interactive tests use <code>assertDialog</code>.
* For automated tests use <code>assert DialogTexts</code>.
* </p>
*/
public class DialogCheck {
private DialogCheck() {
}
private static VerifyDialog _verifyDialog;
/**
* Asserts that a given dialog is not null and that it passes
* certain visual tests. These tests will be verified manually
* by the tester using an input dialog. Use this assert method
* to verify a dialog's sizing, initial focus, or accessiblity.
* To ensure that both the input dialog and the test dialog are
* accessible by the tester, the getShell() method should be used
* when creating the test dialog.
*
* Example usage:
* <code>Dialog dialog = new AboutDialog( DialogCheck.getShell() );
* DialogCheck.assertDialog(dialog, this);</code>
*
* @param dialog the test dialog to be verified.
* @param assert this is the test case object, assertions will be
* executed on this object.
*/
public static void assertDialog(Dialog dialog, Assert assert) {
Assert.assertNotNull(dialog);
if (_verifyDialog.getShell() == null) {
//force the creation of the verify dialog
getShell();
}
if (_verifyDialog.open(dialog) == IDialogConstants.NO_ID) {
Assert.assertTrue(_verifyDialog.getFailureText(), false);
}
}
/**
* Automated test that checks all the labels and buttons of a dialog
* to make sure there is enough room to display all the text. Any
* text that wraps is only approximated and is currently not accurate.
*
* @param dialog the test dialog to be verified.
* @param assert this is the test case object, assertions will be
* executed on this object.
*/
public static void assertDialogTexts(Dialog dialog, Assert assert) {
Assert.assertNotNull(dialog);
dialog.setBlockOnOpen(false);
dialog.open();
Shell shell = dialog.getShell();
verifyCompositeText(shell, assert);
dialog.close();
}
/**
* This method should be called when creating dialogs to test. This
* ensures that the dialog's parent shell will be that of the
* verification dialog.
*
* @return Shell The shell of the verification dialog to be used as
* the parent shell of the test dialog.
*/
public static Shell getShell() {
Shell shell =
WorkbenchPlugin
.getDefault()
.getWorkbench()
.getActiveWorkbenchWindow()
.getShell();
_verifyDialog = new VerifyDialog(shell);
_verifyDialog.create();
return _verifyDialog.getShell();
}
/*
* Looks at all the child widgets of a given composite and
* verifies the text on all labels and widgets.
* @param composite The composite to look through
* @param assert The object to invoke assertions on.
*/
private static void verifyCompositeText(Composite composite, Assert assert) {
Control children[] = composite.getChildren();
for (int i = 0; i < children.length; i++) {
try {
//verify the text if the child is a button
verifyButtonText((Button) children[i], assert);
} catch (ClassCastException exNotButton) {
try {
//child is not a button, maybe a label
verifyLabelText((Label) children[i], assert);
} catch (ClassCastException exNotLabel) {
try {
//child is not a label, make a recursive call if it is a composite
verifyCompositeText((Composite) children[i], assert);
} catch (ClassCastException exNotComposite) {
//the child is not a button, label, or composite - ignore it.
}
}
}
}
}
/*
* Verifies that a given button is large enough to display its text.
* @param button The button to verify,
* @param assert The object to invoke assertions on.
*/
private static void verifyButtonText(Button button, Assert assert) {
String widget = button.toString();
Point size = button.getSize();
//compute the size with no line wrapping
Point preferred = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
//if (size.y/preferred.y) == X, then label spans X lines, so divide
//the calculated value of preferred.x by X
if (preferred.y * size.y > 0) {
preferred.y /= countLines(button.getText()); //check for '\n\'
if (size.y / preferred.y > 1) {
preferred.x /= (size.y / preferred.y);
}
}
String message =
new StringBuffer("Warning: ")
.append(widget)
.append("\n\tActual Width -> ")
.append(size.x)
.append("\n\tRecommended Width -> ")
.append(preferred.x)
.toString();
if (preferred.x > size.x) {
//close the dialog
button.getShell().dispose();
Assert.assertTrue(message.toString(), false);
}
}
/*
* Verifies that a given label is large enough to display its text.
* @param label The label to verify,
* @param assert The object to invoke assertions on.
*/
private static void verifyLabelText(Label label, Assert assert) {
String widget = label.toString();
Point size = label.getSize();
//compute the size with no line wrapping
Point preferred = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
//if (size.y/preferred.y) == X, then label spans X lines, so divide
//the calculated value of preferred.x by X
if (preferred.y * size.y > 0) {
preferred.y /= countLines(label.getText());
if (size.y / preferred.y > 1) {
preferred.x /= (size.y / preferred.y);
}
}
String message =
new StringBuffer("Warning: ")
.append(widget)
.append("\n\tActual Width -> ")
.append(size.x)
.append("\n\tRecommended Width -> ")
.append(preferred.x)
.toString();
if (preferred.x > size.x) {
//close the dialog
label.getShell().dispose();
Assert.assertTrue(message.toString(), false);
}
}
/*
* Counts the number of lines in a given String.
* For example, if a string contains one (1) newline character,
* a value of two (2) would be returned.
* @param text The string to look through.
* @return int the number of lines in text.
*/
private static int countLines(String text) {
int newLines = 1;
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == '\n') {
newLines++;
}
}
return newLines;
}
}

View file

@ -1,35 +0,0 @@
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
package org.eclipse.cdt.ui.tests;
import org.eclipse.cdt.ui.tests.dialogs.PreferencesTest;
import junit.framework.Test;
import junit.framework.TestSuite;
/**
* Test all areas of the UI.
*/
public class UIInteractiveSuite extends TestSuite {
/**
* Returns the suite. This is required to
* use the JUnit Launcher.
*/
public static Test suite() {
return new UIInteractiveSuite();
}
/**
* Construct the test suite.
*/
public UIInteractiveSuite() {
addTest(PreferencesTest.suite());
//addTest(WizardsTest.suite());
//addTest(DialogsTest.suite());
}
}

View file

@ -1,190 +0,0 @@
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
package org.eclipse.cdt.ui.tests.dialogs;
import java.util.Iterator;
import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.testplugin.TestPluginLauncher;
import org.eclipse.cdt.testplugin.util.DialogCheck;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.preference.IPreferenceNode;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.preference.PreferenceManager;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.ui.internal.IHelpContextIds;
import org.eclipse.ui.internal.WorkbenchMessages;
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.internal.dialogs.PropertyDialog;
import org.eclipse.ui.internal.dialogs.PropertyPageContributorManager;
import org.eclipse.ui.internal.dialogs.PropertyPageManager;
import org.eclipse.ui.model.IWorkbenchAdapter;
public class PreferencesTest extends TestCase {
public static void main(String[] args) {
TestPluginLauncher.run(TestPluginLauncher.getLocationFromProperties(), PreferencesTest.class, args);
}
public static Test suite() {
TestSuite suite= new TestSuite(PreferencesTest.class.getName());
suite.addTest(new PreferencesTest("testCBasePrefPage"));
suite.addTest(new PreferencesTest("testTemplatePrefPage"));
suite.addTest(new PreferencesTest("testProjectPropertyPrefPage"));
suite.addTest(new PreferencesTest("testCEditorPrefPage"));
return suite;
}
private static class PreferenceDialogWrapper extends PreferenceDialog {
public PreferenceDialogWrapper(Shell parentShell, PreferenceManager manager) {
super(parentShell, manager);
}
protected boolean showPage(IPreferenceNode node) {
return super.showPage(node);
}
}
private class PropertyDialogWrapper extends PropertyDialog {
public PropertyDialogWrapper(Shell parentShell, PreferenceManager manager, ISelection selection) {
super(parentShell, manager, selection);
}
protected boolean showPage(IPreferenceNode node) {
return super.showPage(node);
}
}
private boolean fIsInteractive= true;
private static final String PROJECT_NAME = "DummyProject";
public PreferencesTest(String name) {
super(name);
}
private Shell getShell() {
return DialogCheck.getShell();
}
public void assertDialog(Dialog dialog, Assert assertTrue) {
if (fIsInteractive) {
DialogCheck.assertDialog(dialog, this);
} else {
DialogCheck.assertDialogTexts(dialog, this);
}
}
private PreferenceDialog getPreferenceDialog(String id) {
PreferenceDialogWrapper dialog = null;
PreferenceManager manager = WorkbenchPlugin.getDefault().getPreferenceManager();
if (manager != null) {
dialog = new PreferenceDialogWrapper(getShell(), manager);
dialog.create();
WorkbenchHelp.setHelp(dialog.getShell(), IHelpContextIds.PREFERENCE_DIALOG);
for (Iterator iterator = manager.getElements(PreferenceManager.PRE_ORDER).iterator();
iterator.hasNext();)
{
IPreferenceNode node = (IPreferenceNode)iterator.next();
if ( node.getId().equals(id) ) {
dialog.showPage(node);
break;
}
}
}
return dialog;
}
private PropertyDialog getPropertyDialog(String id, IAdaptable element) {
PropertyDialogWrapper dialog = null;
PropertyPageManager manager = new PropertyPageManager();
String title = "";
String name = "";
// load pages for the selection
// fill the manager with contributions from the matching contributors
PropertyPageContributorManager.getManager().contribute(manager, element);
IWorkbenchAdapter adapter = (IWorkbenchAdapter)element.getAdapter(IWorkbenchAdapter.class);
if (adapter != null) {
name = adapter.getLabel(element);
}
// testing if there are pages in the manager
Iterator pages = manager.getElements(PreferenceManager.PRE_ORDER).iterator();
if (!pages.hasNext()) {
return null;
} else {
title = WorkbenchMessages.format("PropertyDialog.propertyMessage", new Object[] {name});
dialog = new PropertyDialogWrapper(getShell(), manager, new StructuredSelection(element));
dialog.create();
dialog.getShell().setText(title);
WorkbenchHelp.setHelp(dialog.getShell(), IHelpContextIds.PROPERTY_DIALOG);
for (Iterator iterator = manager.getElements(PreferenceManager.PRE_ORDER).iterator();
iterator.hasNext();)
{
IPreferenceNode node = (IPreferenceNode)iterator.next();
if ( node.getId().equals(id) ) {
dialog.showPage(node);
break;
}
}
}
return dialog;
}
public void testCBasePrefPage() {
Dialog dialog = getPreferenceDialog("org.eclipse.cdt.ui.preferences.CPluginPreferencePage");
assertDialog(dialog, this);
}
public void testProjectPropertyPrefPage() {
Dialog dialog = getPreferenceDialog("org.eclipse.cdt.ui.preferences.CProjectPropertyPage");
assertDialog(dialog, this);
}
public void testTemplatePrefPage() {
Dialog dialog = getPreferenceDialog("org.eclipse.cdt.ui.preferences.TemplatePreferencePage");
assertDialog(dialog, this);
}
public void testCEditorPrefPage() {
Dialog dialog = getPreferenceDialog("org.eclipse.cdt.ui.preferences.CEditorPreferencePage");
assertDialog(dialog, this);
}
/* public void testInfoPropPage() throws Exception {
IJavaProject jproject= JavaProjectHelper.createJavaProject(PROJECT_NAME, "bin");
IPackageFragmentRoot root= JavaProjectHelper.addSourceContainer(jproject, "src");
IPackageFragment pack= root.createPackageFragment("org.eclipse.jdt.internal.ui.wizards.dummy", true, null);
ICompilationUnit cu= pack.getCompilationUnit("DummyCompilationUnitWizard.java");
IType type= cu.createType("public class DummyCompilationUnitWizard {\n\n}\n", null, true, null);
Dialog dialog = getPropertyDialog("org.eclipse.jdt.ui.propertyPages.InfoPage", cu);
assertDialog(dialog, this);
JavaProjectHelper.delete(jproject);
} */
}