[387973] Test that preference is actually set
diff --git a/plugins/org.eclipse.ocl.common/src/org/eclipse/ocl/common/OCLCommon.java b/plugins/org.eclipse.ocl.common/src/org/eclipse/ocl/common/OCLCommon.java
index f6c2c9a..3878686 100644
--- a/plugins/org.eclipse.ocl.common/src/org/eclipse/ocl/common/OCLCommon.java
+++ b/plugins/org.eclipse.ocl.common/src/org/eclipse/ocl/common/OCLCommon.java
@@ -96,8 +96,9 @@
public static <T> T getPreference(PreferenceableOption<T> option, IScopeContext[] contexts) {
if (eclipsePreferencesAvailable != Boolean.FALSE) { // null or TRUE
try {
- EclipseSupport.getPreference(option, contexts);
+ T preference = EclipseSupport.getPreference(option, contexts);
eclipsePreferencesAvailable = Boolean.TRUE;
+ return preference;
}
catch (Throwable e) {
eclipsePreferencesAvailable = Boolean.FALSE;
diff --git a/tests/org.eclipse.ocl.ecore.tests/src/org/eclipse/ocl/ecore/tests/ProblemOptionTest.java b/tests/org.eclipse.ocl.ecore.tests/src/org/eclipse/ocl/ecore/tests/ProblemOptionTest.java
index fe703bf..a9c3f2e 100644
--- a/tests/org.eclipse.ocl.ecore.tests/src/org/eclipse/ocl/ecore/tests/ProblemOptionTest.java
+++ b/tests/org.eclipse.ocl.ecore.tests/src/org/eclipse/ocl/ecore/tests/ProblemOptionTest.java
@@ -18,11 +18,17 @@
package org.eclipse.ocl.ecore.tests;
+import org.eclipse.core.runtime.preferences.ConfigurationScope;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.plugin.EcorePlugin;
import org.eclipse.ocl.ParserException;
+import org.eclipse.ocl.common.preferences.PreferenceableOption;
import org.eclipse.ocl.lpg.BasicEnvironment;
import org.eclipse.ocl.lpg.ProblemHandler;
+import org.eclipse.ocl.lpg.ProblemHandler.Severity;
import org.eclipse.ocl.options.ProblemOption;
import org.eclipse.ocl.util.OCLUtil;
@@ -34,6 +40,28 @@
@SuppressWarnings("nls")
public class ProblemOptionTest
extends AbstractTestSuite {
+ private static class EclipseSupport
+ {
+ public static void removePreference(PreferenceableOption<?> option, IScopeContext context) {
+ try {
+ IEclipsePreferences preferences = context.getNode(option.getPluginId());
+ preferences.remove(option.getKey());
+ preferences.flush();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static <T> void setPreference(PreferenceableOption<T> option, IScopeContext context, T value) {
+ try {
+ IEclipsePreferences preferences = context.getNode(option.getPluginId());
+ preferences.put(option.getKey(), value.toString());
+ preferences.flush();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
/**
* Tests the severity option for the <tt>toLower()</tt> and <tt>toUpper()</tt>
@@ -57,6 +85,19 @@
benv.setOption(ProblemOption.STRING_CASE_CONVERSION, ProblemHandler.Severity.ERROR);
assertError("self.toUpper()");
assertError("self.toLower()");
+
+ if (EcorePlugin.IS_ECLIPSE_RUNNING) {
+ benv.removeOption(ProblemOption.STRING_CASE_CONVERSION);
+ EclipseSupport.setPreference(ProblemOption.STRING_CASE_CONVERSION, ConfigurationScope.INSTANCE, Severity.WARNING);
+ assertWarning("self.toUpper()");
+ benv.removeOption(ProblemOption.STRING_CASE_CONVERSION);
+ EclipseSupport.setPreference(ProblemOption.STRING_CASE_CONVERSION, ConfigurationScope.INSTANCE, Severity.OK);
+ assertOK("self.toUpper()");
+ benv.removeOption(ProblemOption.STRING_CASE_CONVERSION);
+ EclipseSupport.setPreference(ProblemOption.STRING_CASE_CONVERSION, ConfigurationScope.INSTANCE, Severity.ERROR);
+ assertError("self.toUpper()");
+ EclipseSupport.removePreference(ProblemOption.STRING_CASE_CONVERSION, ConfigurationScope.INSTANCE);
+ }
}
/**