Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Fedorov2020-01-15 18:50:07 +0000
committerJonah Graham2020-01-18 21:09:36 +0000
commit8dae0221143c2f437657268952d4017ebafa1b16 (patch)
treeece62cb77dc5a230a658ea1b40fcde7bf0823031 /core/org.eclipse.cdt.core.tests
parent471a49f379f0508042d40a351e62fa74c7480943 (diff)
downloadorg.eclipse.cdt-8dae0221143c2f437657268952d4017ebafa1b16.tar.gz
org.eclipse.cdt-8dae0221143c2f437657268952d4017ebafa1b16.tar.xz
org.eclipse.cdt-8dae0221143c2f437657268952d4017ebafa1b16.zip
Bug 559193 - new API for preference management
Part 1 for "Rework DoxygenPreferences to encapsulate constants" (please refer to the Bug 559193 regarding the reasons to rework): - option metadata API - option storage API - Preference-based storage - tests for added types Change-Id: If6f2caa4c8e659497b0e95c00ec959a9888998d7 Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
Diffstat (limited to 'core/org.eclipse.cdt.core.tests')
-rw-r--r--core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/tests/BaseOptionTest.java58
-rw-r--r--core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/tests/OsgiPreferenceStorageTest.java195
-rw-r--r--core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java8
3 files changed, 260 insertions, 1 deletions
diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/tests/BaseOptionTest.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/tests/BaseOptionTest.java
new file mode 100644
index 00000000000..273f552caae
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/tests/BaseOptionTest.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2020 ArSysOp and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.internal.tests;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.cdt.core.options.BaseOption;
+import org.junit.Test;
+
+public class BaseOptionTest {
+
+ @Test
+ public void testBaseOption() {
+ BaseOption<String> option = new BaseOption<>(String.class, "identifier", "default", "name", "description");
+ assertEquals("identifier", option.identifer());
+ assertEquals("default", option.defaultValue());
+ assertEquals("name", option.name());
+ assertEquals("description", option.description());
+ assertEquals(String.class, option.valueClass());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testBaseOptionNullValueType() {
+ new BaseOption<>(null, "identifier", "default", "name", "description");
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testBaseOptionNullIdentifier() {
+ new BaseOption<>(Object.class, null, "default", "name", "description");
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testBaseOptionNullDefaultValue() {
+ new BaseOption<>(Object.class, "identifier", null, "name", "description");
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testBaseOptionNullName() {
+ new BaseOption<>(Object.class, "identifier", "default", null, "description");
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testBaseOptionNullDescription() {
+ new BaseOption<>(Object.class, "identifier", "default", "name", null);
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/tests/OsgiPreferenceStorageTest.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/tests/OsgiPreferenceStorageTest.java
new file mode 100644
index 00000000000..40c488ae898
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/tests/OsgiPreferenceStorageTest.java
@@ -0,0 +1,195 @@
+/*******************************************************************************
+ * Copyright (c) 2020 ArSysOp and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.internal.tests;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.cdt.core.options.BaseOption;
+import org.eclipse.cdt.core.options.OsgiPreferenceStorage;
+import org.junit.Test;
+import org.osgi.service.prefs.Preferences;
+
+public class OsgiPreferenceStorageTest {
+
+ private final BaseOption<Object> unknown = new BaseOption<>(Object.class, "unknown", "", "Unknown",
+ "An option with unclear semantic, i.e. typical one");
+ private final BaseOption<String> string2020 = new BaseOption<>(String.class, "string2020", "2020", "String 2020");
+ private final BaseOption<Boolean> negative = new BaseOption<>(Boolean.class, "negative", false, "Negative");
+ private final BaseOption<Boolean> positive = new BaseOption<>(Boolean.class, "positive", true, "Positive");
+ private final BaseOption<byte[]> bytes2020 = new BaseOption<>(byte[].class, "bytes2020", new byte[] { 20, 20 },
+ "Bytes 2020");
+ private final BaseOption<Double> double2020 = new BaseOption<>(Double.class, "double2020", 2020d, "Double 2020");
+ private final BaseOption<Float> float2020 = new BaseOption<>(Float.class, "float2020", 2020f, "Float 2020");
+ private final BaseOption<Integer> int2020 = new BaseOption<>(Integer.class, "int2020", 2020, "Int 2020");
+ private final BaseOption<Long> long2020 = new BaseOption<>(Long.class, "long2020", 2020l, "Long 2020");
+
+ @Test(expected = NullPointerException.class)
+ public void testNullPreferences() {
+ OsgiPreferenceStorage storage = new OsgiPreferenceStorage(null);
+ }
+
+ @Test
+ public void testConsumable() {
+ Preferences preferences = anyPreferences();
+ OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
+ assertFalse(storage.consumable(Object.class));
+ assertTrue(storage.consumable(String.class));
+ assertTrue(storage.consumable(Boolean.class));
+ assertTrue(storage.consumable(byte[].class));
+ assertFalse(storage.consumable(Byte[].class));
+ assertTrue(storage.consumable(Double.class));
+ assertTrue(storage.consumable(Float.class));
+ assertTrue(storage.consumable(Integer.class));
+ assertTrue(storage.consumable(Long.class));
+ }
+
+ @Test
+ public void testLoadString() {
+ Preferences preferences = anyPreferences();
+ OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
+ preferences.put(string2020.identifer(), "2002");
+ assertEquals("2002", storage.load(string2020));
+ }
+
+ @Test
+ public void testLoadBoolean() {
+ Preferences preferences = anyPreferences();
+ OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
+ preferences.putBoolean(negative.identifer(), true);
+ assertEquals(true, storage.load(negative));
+ preferences.putBoolean(positive.identifer(), false);
+ assertEquals(false, storage.load(positive));
+ }
+
+ @Test
+ public void testLoadByteArray() {
+ Preferences preferences = anyPreferences();
+ OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
+ preferences.putByteArray(bytes2020.identifer(), new byte[] { 20, 02 });
+ assertArrayEquals(new byte[] { 20, 02 }, storage.load(bytes2020));
+ }
+
+ @Test
+ public void testLoadDouble() {
+ Preferences preferences = anyPreferences();
+ OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
+ preferences.putDouble(double2020.identifer(), 2002d);
+ assertEquals(2002d, storage.load(double2020), 0);
+ }
+
+ @Test
+ public void testLoadFloat() {
+ Preferences preferences = anyPreferences();
+ OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
+ preferences.putFloat(float2020.identifer(), 2002f);
+ assertEquals(2002f, storage.load(float2020), 0);
+ }
+
+ @Test
+ public void testLoadInt() {
+ Preferences preferences = anyPreferences();
+ OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
+ preferences.putLong(int2020.identifer(), 2002l);
+ assertEquals(2002l, (long) storage.load(int2020));
+ }
+
+ @Test
+ public void testLoadLong() {
+ Preferences preferences = anyPreferences();
+ OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
+ preferences.putLong(long2020.identifer(), 2002l);
+ assertEquals(2002l, (long) storage.load(long2020));
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testLoadUnknown() {
+ Preferences preferences = anyPreferences();
+ OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
+ assertEquals(new Object(), storage.load(unknown));
+ }
+
+ @Test
+ public void testSaveString() {
+ Preferences anyPreferences = anyPreferences();
+ OsgiPreferenceStorage storage = new OsgiPreferenceStorage(anyPreferences);
+ storage.save("2002", string2020);
+ assertEquals("2002", anyPreferences.get(string2020.identifer(), string2020.defaultValue()));
+ }
+
+ @Test
+ public void testSaveBoolean() {
+ Preferences anyPreferences = anyPreferences();
+ OsgiPreferenceStorage storage = new OsgiPreferenceStorage(anyPreferences);
+ storage.save(true, negative);
+ assertEquals(true, anyPreferences.getBoolean(negative.identifer(), negative.defaultValue()));
+ storage.save(false, positive);
+ assertEquals(false, anyPreferences.getBoolean(positive.identifer(), positive.defaultValue()));
+ }
+
+ @Test
+ public void testSaveByteArray() {
+ Preferences anyPreferences = anyPreferences();
+ OsgiPreferenceStorage storage = new OsgiPreferenceStorage(anyPreferences);
+ storage.save(new byte[] { 20, 02 }, bytes2020);
+ assertArrayEquals(new byte[] { 20, 02 },
+ anyPreferences.getByteArray(bytes2020.identifer(), bytes2020.defaultValue()));
+ }
+
+ @Test
+ public void testSaveDouble() {
+ Preferences preferences = anyPreferences();
+ OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
+ storage.save(2002d, double2020);
+ assertEquals(2002d, preferences.getDouble(double2020.identifer(), double2020.defaultValue()), 0);
+ }
+
+ @Test
+ public void testSaveFloat() {
+ Preferences preferences = anyPreferences();
+ OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
+ storage.save(2002f, float2020);
+ assertEquals(2002f, preferences.getDouble(float2020.identifer(), float2020.defaultValue()), 0);
+ }
+
+ @Test
+ public void testSaveInt() {
+ Preferences preferences = anyPreferences();
+ OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
+ storage.save(2002, int2020);
+ assertEquals(2002, preferences.getInt(int2020.identifer(), int2020.defaultValue()));
+ }
+
+ @Test
+ public void testSaveLong() {
+ Preferences preferences = anyPreferences();
+ OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
+ storage.save(2002l, long2020);
+ assertEquals(2002l, preferences.getLong(long2020.identifer(), long2020.defaultValue()));
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testSaveUnknown() {
+ Preferences preferences = anyPreferences();
+ OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
+ storage.save(new Object(), unknown);
+ }
+
+ private Preferences anyPreferences() {
+ return new org.eclipse.core.internal.preferences.EclipsePreferences();
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
index 6babc089cbd..cfa0142ad91 100644
--- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
+++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2015 IBM Corporation and others.
+ * Copyright (c) 2005, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -12,6 +12,7 @@
* IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
* Norbert Ploett (Siemens AG)
+ * Alexander Fedorov <alexander.fedorov@arsysop.ru> Bug 559193
*******************************************************************************/
package org.eclipse.cdt.core.suite;
@@ -20,6 +21,8 @@ import org.eclipse.cdt.core.cdescriptor.tests.CDescriptorTests;
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManagerTests;
import org.eclipse.cdt.core.internal.efsextension.tests.EFSExtensionTests;
import org.eclipse.cdt.core.internal.errorparsers.tests.ErrorParserTests;
+import org.eclipse.cdt.core.internal.tests.BaseOptionTest;
+import org.eclipse.cdt.core.internal.tests.OsgiPreferenceStorageTest;
import org.eclipse.cdt.core.internal.tests.PositionTrackerTests;
import org.eclipse.cdt.core.internal.tests.ResourceLookupTests;
import org.eclipse.cdt.core.internal.tests.StringBuilderTest;
@@ -43,6 +46,7 @@ import org.eclipse.cdt.utils.UNCPathConverterTest;
import org.eclipse.cdt.utils.WeakHashSetTest;
import org.eclipse.cdt.utils.elf.ElfParserTest;
+import junit.framework.JUnit4TestAdapter;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -82,6 +86,8 @@ public class AutomatedIntegrationSuite extends TestSuite {
suite.addTest(AllCoreTests.suite());
suite.addTest(ElementDeltaTests.suite());
suite.addTest(WorkingCopyTests.suite());
+ suite.addTest(new JUnit4TestAdapter(BaseOptionTest.class));
+ suite.addTest(new JUnit4TestAdapter(OsgiPreferenceStorageTest.class));
suite.addTest(PositionTrackerTests.suite());
suite.addTest(ResourceLookupTests.suite());
suite.addTest(StringBuilderTest.suite());

Back to the top