Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0fb4f79cdb218831d95107d93890b252e7747dbb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*******************************************************************************
 * Copyright (c) 2010, 2016 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.core.tests.model;

import java.util.Hashtable;

import junit.framework.Test;

import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.compiler.CharOperation;
/**
 * Tests JavaCore options
 */
@SuppressWarnings({"rawtypes", "unchecked"})
public class JavaCoreOptionsTests extends ModifyingResourceTests {

public static Test suite() {
	return buildModelTestSuite(JavaCoreOptionsTests.class);
}

// Use this static initializer to specify subset for tests
// All specified tests which do not belong to the class are skipped...
static {
//	TESTS_NUMBERS = new int[] { 4 };
}

public JavaCoreOptionsTests(String name) {
	super(name);
}
public void test1() {
	Hashtable options = JavaCore.getOptions();
	try {
		Hashtable currentOptions = new Hashtable(options);
		currentOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "HIGH,HIGH");
		currentOptions.put(JavaCore.COMPILER_TASK_TAGS, "TODO");
		JavaCore.setOptions(currentOptions);
		
		Hashtable options2 = JavaCore.getOptions();
		String taskTagsValue = (String) options2.get(JavaCore.COMPILER_TASK_TAGS);
		String taskPrioritiesValue = (String) options2.get(JavaCore.COMPILER_TASK_PRIORITIES);
		char[][] taskPriorities = CharOperation.splitAndTrimOn(',', taskPrioritiesValue.toCharArray());
		char[][] taskTags = CharOperation.splitAndTrimOn(',', taskTagsValue.toCharArray());
		assertEquals("wrong size", 1, taskPriorities.length);
		assertEquals("wrong size", 1, taskTags.length);
	} finally {
		JavaCore.setOptions(options);
	}
}
public void test2() {
	Hashtable options = JavaCore.getOptions();
	try {
		Hashtable currentOptions = new Hashtable(options);
		currentOptions.remove(JavaCore.COMPILER_TASK_PRIORITIES);
		currentOptions.remove(JavaCore.COMPILER_TASK_TAGS);
		JavaCore.setOptions(currentOptions);
		
		Hashtable options2 = JavaCore.getOptions();
		String taskTagsValue = (String) options2.get(JavaCore.COMPILER_TASK_TAGS);
		String taskPrioritiesValue = (String) options2.get(JavaCore.COMPILER_TASK_PRIORITIES);
		assertNull("wrong value", taskTagsValue);
		assertNull("wrong value", taskPrioritiesValue);
	} finally {
		JavaCore.setOptions(options);
	}
}
public void test3() {
	Hashtable options = JavaCore.getOptions();
	try {
		Hashtable currentOptions = new Hashtable(options);
		currentOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "HIGH,HIGH");
		currentOptions.remove(JavaCore.COMPILER_TASK_TAGS);
		JavaCore.setOptions(currentOptions);
		
		Hashtable options2 = JavaCore.getOptions();
		String taskTagsValue = (String) options2.get(JavaCore.COMPILER_TASK_TAGS);
		String taskPrioritiesValue = (String) options2.get(JavaCore.COMPILER_TASK_PRIORITIES);
		assertNull("wrong value", taskTagsValue);
		assertNull("wrong value", taskPrioritiesValue);
	} finally {
		JavaCore.setOptions(options);
	}
}
public void test4() {
	Hashtable options = JavaCore.getOptions();
	try {
		Hashtable currentOptions = new Hashtable(options);
		currentOptions.remove(JavaCore.COMPILER_TASK_PRIORITIES);
		currentOptions.put(JavaCore.COMPILER_TASK_TAGS, "TODO");
		JavaCore.setOptions(currentOptions);
		
		Hashtable options2 = JavaCore.getOptions();
		String taskTagsValue = (String) options2.get(JavaCore.COMPILER_TASK_TAGS);
		String taskPrioritiesValue = (String) options2.get(JavaCore.COMPILER_TASK_PRIORITIES);
		assertNull("wrong value", taskTagsValue);
		assertNull("wrong value", taskPrioritiesValue);
	} finally {
		JavaCore.setOptions(options);
	}
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=464845
public void test5() {
	assertTrue(JavaCore.compareJavaVersions("1.1", "1.3") < 0);
	assertTrue(JavaCore.compareJavaVersions("1.4", "1.1") > 0);
	assertTrue(JavaCore.compareJavaVersions("1.8", "cldc1.1") > 0);
	assertTrue(JavaCore.compareJavaVersions("cldc1.1", "1.1") > 0);
	assertTrue(JavaCore.compareJavaVersions("1.1", "cldc1.1") < 0);
	assertTrue(JavaCore.compareJavaVersions("1.8", "1.8") == 0);
	assertTrue(JavaCore.compareJavaVersions("1.8", "9") < 0);
	assertTrue(JavaCore.compareJavaVersions("9", "1.8") > 0);
	assertTrue(JavaCore.compareJavaVersions("9.0.1", "9.1.2") == 0);
	assertTrue(JavaCore.compareJavaVersions("9", "9.1.2") == 0);
	assertTrue(JavaCore.compareJavaVersions("12", "11") > 0);
	assertTrue(JavaCore.compareJavaVersions("12", "1.5") > 0);
	String latest = JavaCore.latestSupportedJavaVersion();
	String latestPlus = "" + (Integer.parseInt(latest) + 1);
	assertTrue(JavaCore.compareJavaVersions(latest, latestPlus) == 0);
}
}

Back to the top