use of org.eclipse.core.internal.preferences.legacy.PreferenceForwarder in project eclipse.platform.runtime by eclipse.
the class PreferenceForwarderTest method testLong.
public void testLong() {
Preferences ps = new PreferenceForwarder(getUniqueString());
final String k1 = "key1";
final long[] values = { 0L, 1002L, -201788L, Long.MAX_VALUE, Long.MIN_VALUE };
assertEquals("1.0", 0L, Preferences.LONG_DEFAULT_DEFAULT);
assertEquals("1.1", Preferences.LONG_DEFAULT_DEFAULT, ps.getLong(k1));
for (long v1 : values) {
long v2 = v1 + 1;
ps.setValue(k1, v1);
assertEquals("1.2", v1, ps.getLong(k1));
ps.setDefault(k1, v2);
assertEquals("1.3", v2, ps.getDefaultLong(k1));
}
}
use of org.eclipse.core.internal.preferences.legacy.PreferenceForwarder in project eclipse.platform.runtime by eclipse.
the class PreferenceForwarderTest method testContains.
public void testContains() {
Preferences ps = new PreferenceForwarder(getUniqueString());
// there are no properties initially
assertEquals("1.0", false, ps.contains("a"));
// setting defaults adds name
ps.setDefault("a", "default");
assertEquals("1.1", true, ps.contains("a"));
// setting value adds name
assertEquals("1.2", false, ps.contains("b"));
ps.setValue("b", "any");
assertEquals("1.3", true, ps.contains("b"));
// setting value does not remove entry already there
ps.setValue("a", "any");
assertEquals("1.4", true, ps.contains("a"));
assertEquals("1.5", true, ps.contains("b"));
// setting to default removes name from set unless there is a default too
ps.setToDefault("b");
assertEquals("1.6", false, ps.contains("b"));
ps.setToDefault("a");
assertEquals("1.7", true, ps.contains("a"));
// fail gracefully in PreferenceForwarder.contains(null)
try {
assertTrue("2.0", !ps.contains(null));
} catch (NullPointerException e) {
fail("2.1", e);
}
}
use of org.eclipse.core.internal.preferences.legacy.PreferenceForwarder in project eclipse.platform.runtime by eclipse.
the class PreferenceForwarderTest method testDouble.
public void testDouble() {
Preferences ps = new PreferenceForwarder(getUniqueString());
final String k1 = "key1";
final double[] values = { 0.0, 1002.5, -201788.55, Double.MAX_VALUE, Double.MIN_VALUE };
final double tol = 1.0e-20;
assertEquals("1.0", 0.0, Preferences.DOUBLE_DEFAULT_DEFAULT, tol);
assertEquals("1.1", Preferences.DOUBLE_DEFAULT_DEFAULT, ps.getDouble(k1), tol);
for (double v1 : values) {
double v2 = v1 + 1.0;
ps.setValue(k1, v1);
assertEquals("1.2", v1, ps.getDouble(k1), tol);
ps.setDefault(k1, v2);
assertEquals("1.3", v2, ps.getDefaultDouble(k1), tol);
}
try {
ps.setValue(k1, Float.NaN);
assertTrue("1.4", false);
} catch (IllegalArgumentException e) {
// NaNs should be rejected
}
}
use of org.eclipse.core.internal.preferences.legacy.PreferenceForwarder in project eclipse.platform.runtime by eclipse.
the class PreferenceForwarderTest method testDefaultPropertyNames.
public void testDefaultPropertyNames() {
Preferences ps = new PreferenceForwarder(getUniqueString());
// there are no default properties initially
assertEquals("1.0", 0, ps.defaultPropertyNames().length);
String[] keys = { "a", "b", "c", "d" };
// setting actual values does not add name to set
for (String key : keys) {
ps.setValue(key, "actual");
}
assertEquals("1.1", 0, ps.defaultPropertyNames().length);
// setting defaults does add name to set
for (String key : keys) {
ps.setDefault(key, "default");
}
assertEquals("1.2", keys.length, ps.defaultPropertyNames().length);
Set<String> s1 = new HashSet<>(Arrays.asList(keys));
Set<String> s2 = new HashSet<>(Arrays.asList(ps.defaultPropertyNames()));
assertEquals("1.3", s1, s2);
// setting to default does not remove name from set
for (String key : keys) {
ps.setToDefault(key);
Set<String> s = new HashSet<>(Arrays.asList(ps.defaultPropertyNames()));
assertTrue("1.4", s.contains(key));
}
assertEquals("1.5", keys.length, ps.defaultPropertyNames().length);
// setting to default-default does not remove name from set either
for (String key : keys) {
ps.setDefault(key, Preferences.STRING_DEFAULT_DEFAULT);
Set<String> s = new HashSet<>(Arrays.asList(ps.defaultPropertyNames()));
assertTrue("1.6.1", s.contains(key));
ps.setDefault(key, Preferences.BOOLEAN_DEFAULT_DEFAULT);
s = new HashSet<>(Arrays.asList(ps.defaultPropertyNames()));
assertTrue("1.6.2", s.contains(key));
ps.setDefault(key, Preferences.INT_DEFAULT_DEFAULT);
s = new HashSet<>(Arrays.asList(ps.defaultPropertyNames()));
assertTrue("1.6.3", s.contains(key));
ps.setDefault(key, Preferences.LONG_DEFAULT_DEFAULT);
s = new HashSet<>(Arrays.asList(ps.defaultPropertyNames()));
assertTrue("1.6.4", s.contains(key));
ps.setDefault(key, Preferences.FLOAT_DEFAULT_DEFAULT);
s = new HashSet<>(Arrays.asList(ps.defaultPropertyNames()));
assertTrue("1.6.5", s.contains(key));
ps.setDefault(key, Preferences.DOUBLE_DEFAULT_DEFAULT);
s = new HashSet<>(Arrays.asList(ps.defaultPropertyNames()));
assertTrue("1.6.6", s.contains(key));
}
assertEquals("1.7", keys.length, ps.defaultPropertyNames().length);
}
use of org.eclipse.core.internal.preferences.legacy.PreferenceForwarder in project eclipse.platform.runtime by eclipse.
the class PreferenceForwarderTest method testInteger.
public void testInteger() {
Preferences ps = new PreferenceForwarder(getUniqueString());
final String k1 = "key1";
final int[] values = { 0, 1002, -201788, Integer.MAX_VALUE, Integer.MIN_VALUE };
assertEquals("1.0", 0, Preferences.INT_DEFAULT_DEFAULT);
assertEquals("1.1", Preferences.INT_DEFAULT_DEFAULT, ps.getInt(k1));
for (int v1 : values) {
int v2 = v1 + 1;
ps.setValue(k1, v1);
assertEquals("1.2", v1, ps.getInt(k1));
ps.setDefault(k1, v2);
assertEquals("1.3", v2, ps.getDefaultInt(k1));
}
}
Aggregations