diff options
author | Christof Marti | 2004-07-12 12:47:17 +0000 |
---|---|---|
committer | Christof Marti | 2004-07-12 12:47:17 +0000 |
commit | de70e2815255ac9aae5e2da6d9abed2afd4e0941 (patch) | |
tree | ac9ead6c33a7b4ca109b10842c50bd9782c3ca9e /org.eclipse.ui.editors.tests/src | |
parent | 2441994f12439bae8e06bdd822259b9cc6042ec3 (diff) | |
download | eclipse.platform.text-de70e2815255ac9aae5e2da6d9abed2afd4e0941.tar.gz eclipse.platform.text-de70e2815255ac9aae5e2da6d9abed2afd4e0941.tar.xz eclipse.platform.text-de70e2815255ac9aae5e2da6d9abed2afd4e0941.zip |
Fix Bug 69419: [implementation] ChainedPreferenceStore
- also remove assertions and thrown IAE and provide fallbacks in these cases
- tests
Diffstat (limited to 'org.eclipse.ui.editors.tests/src')
2 files changed, 136 insertions, 0 deletions
diff --git a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/ChainedPreferenceStoreTest.java b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/ChainedPreferenceStoreTest.java new file mode 100644 index 00000000000..8525e05cf27 --- /dev/null +++ b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/ChainedPreferenceStoreTest.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.ui.editors.tests; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceStore; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; + +import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; +import org.eclipse.ui.texteditor.ChainedPreferenceStore; + +public class ChainedPreferenceStoreTest extends TestCase { + + private class PropertyChangeListener implements IPropertyChangeListener { + + public void propertyChange(PropertyChangeEvent event) { + fEvents.add(event); + } + } + + private List fEvents= new ArrayList(); + private PropertyChangeListener fPropertyChangeListener= new PropertyChangeListener(); + + private static final String PROPERTY= AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH; + private static final String VALUE= "8"; + private static final String DEFAULT_VALUE= "4"; + private static final String DEFAULT_DEFAULT_VALUE= ""; + + public static Test suite() { + return new TestSuite(ChainedPreferenceStoreTest.class); + } + + /** + * [implementation] ChainedPreferenceStore + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=69419 + */ + public void testChainedStore0() { + IPreferenceStore store1= new PreferenceStore(); + IPreferenceStore store2= new PreferenceStore(); + IPreferenceStore chainedStore= new ChainedPreferenceStore(new IPreferenceStore[] { store1, store2 }); + store2.setDefault(PROPERTY, DEFAULT_VALUE); + + chainedStore.addPropertyChangeListener(fPropertyChangeListener); + store1.firePropertyChangeEvent(PROPERTY, VALUE, DEFAULT_DEFAULT_VALUE); // simulated removal with newValue != null + chainedStore.removePropertyChangeListener(fPropertyChangeListener); + + assertEquals(1, fEvents.size()); + PropertyChangeEvent event= (PropertyChangeEvent) fEvents.get(0); + assertEquals(chainedStore, event.getSource()); + assertEquals(PROPERTY, event.getProperty()); + assertEquals(VALUE, event.getOldValue()); + assertEquals(DEFAULT_VALUE, event.getNewValue()); + } + + /** + * Assertion failed in ChainedPreferenceStore.handlePropertyChangeEvent(..) + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=52827 + */ + public void testChainedStore1() { + IPreferenceStore store1= new PreferenceStore(); + IPreferenceStore store2= new PreferenceStore(); + IPreferenceStore chainedStore= new ChainedPreferenceStore(new IPreferenceStore[] { store1, store2 }); + + chainedStore.addPropertyChangeListener(fPropertyChangeListener); + store1.firePropertyChangeEvent(PROPERTY, VALUE, DEFAULT_DEFAULT_VALUE); // simulated removal with newValue != null + chainedStore.removePropertyChangeListener(fPropertyChangeListener); + + assertEquals(1, fEvents.size()); + PropertyChangeEvent event= (PropertyChangeEvent) fEvents.get(0); + assertEquals(store1, event.getSource()); + assertEquals(PROPERTY, event.getProperty()); + assertEquals(VALUE, event.getOldValue()); + assertEquals(DEFAULT_DEFAULT_VALUE, event.getNewValue()); + } + + /** + * Third case where the initial implementation used to have an assertion which would fail in this case + */ + public void testChainedStore2() { + IPreferenceStore store1= new PreferenceStore(); + IPreferenceStore store2= new PreferenceStore(); + IPreferenceStore chainedStore= new ChainedPreferenceStore(new IPreferenceStore[] { store1, store2 }); + store1.setValue(PROPERTY, VALUE); + + chainedStore.addPropertyChangeListener(fPropertyChangeListener); + store1.firePropertyChangeEvent(PROPERTY, DEFAULT_VALUE, null); // simulated change with newValue == null + chainedStore.removePropertyChangeListener(fPropertyChangeListener); + + assertEquals(1, fEvents.size()); + PropertyChangeEvent event= (PropertyChangeEvent) fEvents.get(0); + assertEquals(store1, event.getSource()); + assertEquals(PROPERTY, event.getProperty()); + assertEquals(DEFAULT_VALUE, event.getOldValue()); + assertEquals(null, event.getNewValue()); + } + + /** + * Case where the initial implementation used to throw an IAE + */ + public void testChainedStore3() { + IPreferenceStore store1= new PreferenceStore(); + IPreferenceStore store2= new PreferenceStore(); + IPreferenceStore chainedStore= new ChainedPreferenceStore(new IPreferenceStore[] { store1, store2 }); + store2.setDefault(PROPERTY, DEFAULT_VALUE); + + chainedStore.addPropertyChangeListener(fPropertyChangeListener); + store1.firePropertyChangeEvent(PROPERTY, null, null); // simulated removal with oldValue == null + chainedStore.removePropertyChangeListener(fPropertyChangeListener); + + assertEquals(1, fEvents.size()); + PropertyChangeEvent event= (PropertyChangeEvent) fEvents.get(0); + assertEquals(chainedStore, event.getSource()); + assertEquals(PROPERTY, event.getProperty()); + assertEquals(null, event.getOldValue()); + assertEquals(DEFAULT_VALUE, event.getNewValue()); + } +} diff --git a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java index 3106ac43aea..d4c54ff334c 100644 --- a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java +++ b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java @@ -23,6 +23,8 @@ public class EditorsTestSuite extends TestSuite { public static Test suite() { TestSuite suite = new TestSuite("Test Suite for org.eclipse.ui.editors"); //$NON-NLS-1$ + suite.addTest(ChainedPreferenceStoreTest.suite()); + return suite; } } |