1 /*******************************************************************************
2  * Copyright (c) 2009, 2018 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.pde.api.tools.builder.tests.usage;
15 
16 import org.eclipse.core.runtime.IPath;
17 import org.eclipse.jdt.core.JavaCore;
18 
19 import junit.framework.Test;
20 
21 /**
22  * Tests that usage from fragment -> host is not reported as a problem
23  *
24  * @since 1.0.1
25  */
26 public class FragmentUsageTests extends UsageTest {
27 
FragmentUsageTests(String name)28 	public FragmentUsageTests(String name) {
29 		super(name);
30 	}
31 
32 	@Override
getDefaultProblemId()33 	protected int getDefaultProblemId() {
34 		return 0;
35 	}
36 
37 	@Override
getTestCompliance()38 	protected String getTestCompliance() {
39 		return JavaCore.VERSION_1_5;
40 	}
41 
42 	/**
43 	 * @return the test suite for this class
44 	 */
suite()45 	public static Test suite() {
46 		return buildTestSuite(FragmentUsageTests.class);
47 	}
48 
49 	@Override
getTestSourcePath()50 	protected IPath getTestSourcePath() {
51 		return super.getTestSourcePath().append("fragments"); //$NON-NLS-1$
52 	}
53 
54 	@Override
getTestingProjectName()55 	protected String getTestingProjectName() {
56 		return "fragmenttests"; //$NON-NLS-1$
57 	}
58 
testClassExtendsI()59 	public void testClassExtendsI() {
60 		x1(true);
61 	}
62 
testClassExtendsF()63 	public void testClassExtendsF() {
64 		x1(false);
65 	}
66 
67 	/**
68 	 * Tests that extending an @noextend class from the host bundle is not a
69 	 * problem
70 	 *
71 	 * @param inc
72 	 */
x1(boolean inc)73 	private void x1(boolean inc) {
74 		expectingNoProblems();
75 		deployUsageTest("test1", inc); //$NON-NLS-1$
76 	}
77 
testImplementsI()78 	public void testImplementsI() {
79 		x2(true);
80 	}
81 
testImplementsF()82 	public void testImplementsF() {
83 		x2(false);
84 	}
85 
86 	/**
87 	 * Tests that implementing an @noimplement interface from the host bundle is
88 	 * not a problem
89 	 *
90 	 * @param inc
91 	 */
x2(boolean inc)92 	private void x2(boolean inc) {
93 		expectingNoProblems();
94 		deployUsageTest("test2", inc); //$NON-NLS-1$
95 	}
96 
testInstantiateI()97 	public void testInstantiateI() {
98 		x3(true);
99 	}
100 
testInstantiateF()101 	public void testInstantiateF() {
102 		x3(false);
103 	}
104 
105 	/**
106 	 * Tests that instantiating an @noinstantiate class from the host bundle is
107 	 * not a problem
108 	 *
109 	 * @param inc
110 	 */
x3(boolean inc)111 	private void x3(boolean inc) {
112 		expectingNoProblems();
113 		deployUsageTest("test3", inc); //$NON-NLS-1$
114 	}
115 
testConstNoRefI()116 	public void testConstNoRefI() {
117 		x4(true);
118 	}
119 
testConstNoRefF()120 	public void testConstNoRefF() {
121 		x4(false);
122 	}
123 
124 	/**
125 	 * Tests that referencing a constructor marked as @noreference is not a
126 	 * problem from the host bundle
127 	 *
128 	 * @param inc
129 	 */
x4(boolean inc)130 	private void x4(boolean inc) {
131 		expectingNoProblems();
132 		deployUsageTest("test4", inc); //$NON-NLS-1$
133 	}
134 
testFieldNoRefI()135 	public void testFieldNoRefI() {
136 		x5(true);
137 	}
138 
testFieldNoRefF()139 	public void testFieldNoRefF() {
140 		x5(false);
141 	}
142 
143 	/**
144 	 * Tests that referencing an @noreference field from the host if not a
145 	 * problem
146 	 *
147 	 * @param inc
148 	 */
x5(boolean inc)149 	private void x5(boolean inc) {
150 		expectingNoProblems();
151 		deployUsageTest("test5", inc); //$NON-NLS-1$
152 	}
153 
testOverrideI()154 	public void testOverrideI() {
155 		x6(true);
156 	}
157 
testOverrideF()158 	public void testOverrideF() {
159 		x6(false);
160 	}
161 
162 	/**
163 	 * Tests the overriding an @nooverride method form the host is not a problem
164 	 *
165 	 * @param inc
166 	 */
x6(boolean inc)167 	private void x6(boolean inc) {
168 		expectingNoProblems();
169 		deployUsageTest("test6", inc); //$NON-NLS-1$
170 	}
171 
testIExtendsI()172 	public void testIExtendsI() {
173 		x7(true);
174 	}
175 
testIExtendsF()176 	public void testIExtendsF() {
177 		x7(false);
178 	}
179 
180 	/**
181 	 * Tests that extending an @noextend interface from the host is not a
182 	 * problem
183 	 *
184 	 * @param inc
185 	 */
x7(boolean inc)186 	private void x7(boolean inc) {
187 		expectingNoProblems();
188 		deployUsageTest("test7", inc); //$NON-NLS-1$
189 	}
190 }
191