Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 51836253af7ffd5d8aff9f2b6a3619b7916e0a35 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*******************************************************************************
 * Copyright (c) 2017 Nathan Ridge and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;

import static org.eclipse.cdt.ui.tests.text.contentassist2.AbstractContentAssistTest.CompareType.CONTEXT;
import static org.eclipse.cdt.ui.tests.text.contentassist2.AbstractContentAssistTest.CompareType.REPLACEMENT;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.preference.IPreferenceStore;

import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;

public class CompletionTestBase extends AbstractContentAssistTest {
	private static final String HEADER_FILE_NAME = "CompletionTest.h";
	private static final String SOURCE_FILE_NAME = "CompletionTest.cpp";
	private static final String CURSOR_LOCATION_TAG = "/*cursor*/";
	
	protected int fCursorOffset;
	protected IProject fProject;
	
	public CompletionTestBase(String name) {
		super(name, true);
	}

	/*
	 * @see org.eclipse.cdt.ui.tests.text.contentassist2.AbstractCompletionTest#setUpProjectContent(org.eclipse.core.resources.IProject)
	 */
	@Override
	protected IFile setUpProjectContent(IProject project) throws Exception {
		fProject= project;
		String headerContent= readTaggedComment(CompletionTestBase.class, HEADER_FILE_NAME);
		StringBuilder sourceContent= getContentsForTest(1)[0];
		sourceContent.insert(0, "#include \"" + HEADER_FILE_NAME + "\"\n");
		fCursorOffset= sourceContent.indexOf(CURSOR_LOCATION_TAG);
		assertTrue("No cursor location specified", fCursorOffset >= 0);
		sourceContent.delete(fCursorOffset, fCursorOffset + CURSOR_LOCATION_TAG.length());
		assertNotNull(createFile(project, HEADER_FILE_NAME, headerContent));
		return createFile(project, SOURCE_FILE_NAME, sourceContent.toString());
	}
	
	protected static final int DEFAULT_FLAGS = AbstractContentAssistTest.DEFAULT_FLAGS | IS_COMPLETION;

	protected void assertCompletionResults(int offset, String[] expected, CompareType compareType) throws Exception {
		assertContentAssistResults(offset, expected, DEFAULT_FLAGS, compareType);
	}

	protected void assertMinimumCompletionResults(int offset, String[] expected, CompareType compareType) throws Exception {
		assertContentAssistResults(offset, expected, DEFAULT_FLAGS | ALLOW_EXTRA_RESULTS, compareType);
	}
	
	protected void assertOrderedCompletionResults(int offset, String[] expected, CompareType compareType) throws Exception {
		assertContentAssistResults(offset, expected, DEFAULT_FLAGS | CHECK_ORDER, compareType);
	}

	protected void assertCompletionResults(String[] expected) throws Exception {
		assertCompletionResults(fCursorOffset, expected, REPLACEMENT);
	}

	protected void assertOrderedCompletionResults(String[] expected) throws Exception {
		assertOrderedCompletionResults(fCursorOffset, expected, REPLACEMENT);
	}

	protected void assertParameterHint(String[] expected) throws Exception {
		assertContentAssistResults(fCursorOffset, expected, AbstractContentAssistTest.DEFAULT_FLAGS, CONTEXT);
	}
	
	protected void assertDotReplacedWithArrow() throws Exception {
		assertEquals("->", getDocument().get(fCursorOffset - 1, 2));
	}

	protected static void setDisplayDefaultArguments(boolean value) {
		IPreferenceStore preferenceStore = getPreferenceStore();
		preferenceStore.setValue(ContentAssistPreference.DEFAULT_ARGUMENT_DISPLAY_ARGUMENTS, value);
	}

	protected void setReplaceDotWithArrow(boolean value) {
		IPreferenceStore preferenceStore = getPreferenceStore();
		preferenceStore.setValue(ContentAssistPreference.AUTOACTIVATION_TRIGGERS_REPLACE_DOT_WITH_ARROW, value);
		fProcessorNeedsConfiguring = true;  // to pick up the modified auto-activation preference
	}
	
	protected static void setDisplayDefaultedParameters(boolean value) {
		IPreferenceStore preferenceStore = getPreferenceStore();
		preferenceStore.setValue(ContentAssistPreference.DEFAULT_ARGUMENT_DISPLAY_PARAMETERS_WITH_DEFAULT_ARGUMENT, value);
	}
	
	//	{CompletionTest.h}
	//	class C1;
	//	class C2;
	//	class C3;
	//
	//	extern C1* gC1;
	//	C2* gC2 = 0;
	//
	//	extern C1* gfC1();
	//	C2* gfC2();
	//
	//	enum E1 {e11, e12};
	//
	//	class C1 {
	//		public:
	//			enum E2 {e21, e22};
	//
	//			C1* fMySelf;
	//			void iam1();
	//
	//			C1* m123();
	//			C1* m12();
	//			C1* m13();
	//
	//			protected:
	//				void m1protected();
	//			private:
	//				void m1private();
	//	};
	//	typedef C1 T1;
	//	using A1 = C1;
	//
	//	class C2 : public T1 {
	//		public:
	//			C2* fMySelf;
	//	void iam2();
	//
	//	C2* m123();
	//	C2* m12();
	//	C2* m23();
	//	C1* operator()(int x);
	//
	//	protected:
	//		void m2protected();
	//	private:
	//		void m2private();
	//	friend void _friend_function(C3* x);
	//	friend class _friend_class;
	//	};
	//	typedef C2 T2;
	//
	//	class C3 : public C2 {
	//		public:
	//			C3* fMySelf;
	//	void iam3();
	//
	//	C3* m123();
	//	C3* m13();
	//
	//	template<typename T> T tConvert();
	//	protected:
	//		void m3protected();
	//	private:
	//		void m3private();
	//	};
	//	typedef C3 T3;
	//
	//	namespace ns {
	//		const int NSCONST= 1;
	//		class CNS {
	//			void mcns();
	//		};
	//	};
	//	template <class T> class TClass {
	//		T fTField;
	//		public:
	//			TClass(T tArg) : fTField(tArg) {
	//			}
	//			T add(T tOther) {
	//				return fTField + tOther;
	//			}
	//		class NestedClass{};
	//	};
	//	// bug 109480
	//	class Printer
	//	{
	//		public:
	//			static void InitPrinter(unsigned char port);
	//	private:
	//		//Storage for port printer is on
	//		static unsigned char port;
	//	protected:
	//	};
	//	struct Struct1;
	//	struct Struct2;
	//	union Union1;
	//	union Union2;
	//	struct s206450 {
	//		struct {int a1; int a2;};
	//		union {int u1; char u2;};
	//		struct {int a3;} a4;
	//		int b;
	//	};
	//	typedef enum {__nix} _e204758;
	//	void _f204758(_e204758 x);
	//
	// // Bug 331056
	//	namespace _A_331056 {
	//		class Reference {};
	//	}
	//	namespace _B_331056 {
	//		using ::_A_331056::Reference;
	//	}
	//
	//	template<typename T1, typename T2>
	//	struct Specialization {
	//	};
	//	template<typename T2>
	//	struct Specialization<int, T2> {
	//	};
	//	template<>
	//	struct Specialization<int, int> {
	//	};
	//
	//	template<typename T1, typename T2>
	//	using AliasForSpecialization = Specialization<T1, T2>;
	//
	//	template<typename T1, typename T2>
	//	using AliasForTemplateAlias = AliasForSpecialization<T1, T2>;
}

Back to the top