Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e6a7a6c479f823cbf66ec6acd8a062756ee6ccdf (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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/*******************************************************************************
 * Copyright (c) 2006, 2008 Wind River Systems, Inc. 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
 *
 * Contributors:
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
 *     Sergey Prigogin, Google
 *     Andrew Ferguson (Symbian)
 *******************************************************************************/

package org.eclipse.cdt.ui.tests.text.doctools.doxygen;

import java.util.HashMap;

import junit.framework.Test;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;

import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.tests.text.DefaultCCommentAutoEditStrategyTest;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy;
import org.eclipse.cdt.ui.text.doctools.doxygen.DoxygenMultilineAutoEditStrategy;

import org.eclipse.cdt.internal.core.model.TranslationUnit;

import org.eclipse.cdt.internal.ui.text.CAutoIndentStrategy;
import org.eclipse.cdt.internal.ui.text.CTextTools;


/**
 * Testing the auto indent strategies.
 */
public class DoxygenCCommentAutoEditStrategyTest extends DefaultCCommentAutoEditStrategyTest {
	private HashMap fOptions;
	protected ICProject fCProject;
	
	/**
	 * @param name
	 */
	public DoxygenCCommentAutoEditStrategyTest(String name) {
		super(name);
	}

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

	protected void setUp() throws Exception {
		super.setUp();
		fCProject= CProjectHelper.createCCProject("test"+System.currentTimeMillis(), null);
		fOptions= CCorePlugin.getOptions();
	}

	/*
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		CProjectHelper.delete(fCProject);
		CCorePlugin.setOptions(fOptions);
		super.tearDown();
	}

	private AutoEditTester createAutoEditTester() {
		CTextTools textTools = CUIPlugin.getDefault().getTextTools();
		IDocument doc = new Document();
		textTools.setupCDocument(doc);
		AutoEditTester tester = new AutoEditTester(doc, ICPartitions.C_PARTITIONING);


		tester.setAutoEditStrategy(IDocument.DEFAULT_CONTENT_TYPE, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null));
		tester.setAutoEditStrategy(ICPartitions.C_MULTI_LINE_COMMENT, new DefaultMultilineCommentAutoEditStrategy());
		tester.setAutoEditStrategy(ICPartitions.C_PREPROCESSOR, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null));
		return tester;
	}
	
	// /**X
	//  void foo() {}
	
	// /**
	//  * X
	//  */
	//  void foo() {}
	public void testAutoDocCommentContent1() throws CoreException {
		assertAutoEditBehaviour();
	}
	
	// /**   X
	//  void foo() {}
	
	// /**   
	//  * X
	//  */
	//  void foo() {}
	public void testAutoDocCommentContent2() throws CoreException {
		assertAutoEditBehaviour();
	}
	
	// /**X
	//  int foo_bar() {}
	
	// /**
	//  * X
	//  * @return
	//  */
	//  int foo_bar() {}
	public void testAutoDocCommentContent3() throws CoreException {
		assertAutoEditBehaviour();
	}
	
	// /**   X
	//  int foo_bar() {}
	
	// /**   
	//  * X
	//  * @return
	//  */
	//  int foo_bar() {}
	public void testAutoDocCommentContent4() throws CoreException {
		assertAutoEditBehaviour();
	}
	
	// /**X
	//  *
	//  */
	//  int foo_bar() {}
	
	// /**
	//  * X
	//  *
	//  */
	//  int foo_bar() {}
	public void testAutoDocCommentContent5() throws CoreException {
		assertAutoEditBehaviour();
	}
	
	// /**X
	//  void foo_bar(int x) {}
	
	// /**
	//  * X
	//  * @param x
	//  */
	//  void foo_bar(int x) {}
	public void testAutoDocCommentContent6() throws CoreException {
		assertAutoEditBehaviour();
	}
	
	// class A {}; class B {};
	// /**X
	//  C* bar_baz(A a, B b, int c) {}
	
	// class A {}; class B {};
	// /**
	//  * X
	//  * @param a
	//  * @param b
	//  * @param c
	//  * @return
	//  */
	//  C* bar_baz(A a, B b, int c) {}
	public void testAutoDocCommentContent7() throws CoreException {
		assertAutoEditBehaviour();
	}
	
	// /**
	//  * namespace
	//  */
	// namespace NS {
    // class A {
	//    private:
	//    /*
	//     * TODO
	//     */
	//    /*!
	//     * class
	//     */
	//    class B {
	//       public:
	//       /**
	//        *
	//        */
	//        void foo() {}
	//        /*!X
	//        A bar(A as[], B bs[]) {}
	//    };
	// };
	// }
	
	// /**
	//  * namespace
	//  */
	// namespace NS {
    // class A {
	//    private:
	//    /*
	//     * TODO
	//     */
	//    /*!
	//     * class
	//     */
	//    class B {
	//       public:
	//       /**
	//        *
	//        */
	//        void foo() {}
	//        /*!
	//         * X
	//         * @param as
	//         * @param bs
	//         * @return
	//         */
	//        A bar(A as[], B bs[]) {}
	//    };
	// };
	// }
	public void testAutoDocCommentContent8() throws CoreException {
		assertAutoEditBehaviour();
	}
	
	// void foo_bar(int x)
	// /**X
	// {}
	
	// void foo_bar(int x)
	// /**
	//  * X
	//  * @param x
	//  */
	// {}
	public void _testAutoDocCommentContent9() throws CoreException {
		assertAutoEditBehaviour();
		// TODO - desired behaviour when there is a comment preceding the declaration
		// needs defining
	}
	
	// void foo_bar(int x)
	// {
	// /**X
	// }
	
	// void foo_bar(int x)
	// {
	// /**
	//  * X
	//  * @param x
	//  */
	// }
	public void _testAutoDocCommentContent10() throws CoreException {
		assertAutoEditBehaviour();
		// TODO - desired behaviour when there is a comment preceding the declaration
		// or when there is a comment after the signature but before the brace, both need defining
	}
	
	// /*!X
	// enum A { B, C };
	
	// /*!
	//  * X
	//  */
	// enum A { B, C };
	public void testAutoDocCommentContent11() throws CoreException {
		assertAutoEditBehaviour();
	}
	
	// /**X
	// enum A { B,
	//     C };

	// /**
	//  * X
	//  */
	// enum A { B,//!< B
	//     C };   //!< C
	public void testAutoDocCommentContent13() throws CoreException {
		assertAutoEditBehaviour();
	}
	
	// /**X
	// enum A { B,
	//     C };//!< C

	// /**
	//  * X
	//  */
	// enum A { B,//!< B
	//     C };//!< C
	public void testAutoDocCommentContent14() throws CoreException {
		assertAutoEditBehaviour();
	}
	
	// /**X
	// enum A { B,//!< B
	//     C };

	// /**
	//  * X
	//  */
	// enum A { B,//!< B
	//     C };//!< C
	public void testAutoDocCommentContent15() throws CoreException {
		assertAutoEditBehaviour();
	}
	
	// /**X
	// enum A { B,
	// 		C };

	// /**
	//  * X
	//  */
	// enum A { B,//!< B
	// 		C };  //!< C
	public void _testAutoDocCommentContent16() throws CoreException {
		/*
		 * Indenting in the presence of tabs is not handled at the moment.
		 */
		assertAutoEditBehaviour();
	}
	
	protected void assertAutoEditBehaviour() throws CoreException {
		CTextTools textTools = CUIPlugin.getDefault().getTextTools();
		final IDocument doc = new Document();
		textTools.setupCDocument(doc);
		
		StringBuffer[] raw= getTestContents();
		String init= raw[0].toString(), expected= raw[1].toString();

		int caretInit= init.indexOf('X');
		init= init.replaceFirst("X", "");

		int caretExpected= expected.indexOf('X');
		expected= expected.replaceFirst("X", "");
				
		
		DoxygenMultilineAutoEditStrategy ds= new DoxygenMultilineAutoEditStrategy() {
			public IASTTranslationUnit getAST() {
				final IFile file= fCProject.getProject().getFile("testContent.cpp");
				try {
					TestSourceReader.createFile(fCProject.getProject(), "testContent.cpp", doc.get());
					String id = CoreModel.getRegistedContentTypeId(file.getProject(), file.getName());
					return new TranslationUnit(fCProject, file, id).getAST();
				} catch(CoreException ce) {
					assertTrue("Could not get test content AST", false);
					return null;
				}
			}
		};


		doc.set(init);
		int caretActual= -1;
		try {
			TestDocumentCommand dc= new TestDocumentCommand(caretInit, 0, "\n");
			ds.customizeDocumentCommand(doc, dc);
			caretActual= dc.exec(doc);
		} catch(BadLocationException ble) {
			fail(ble.getMessage());
		}
		String actual= doc.get();
		assertEquals(expected, actual);
		assertEquals(caretExpected, caretActual);
	}
}

Back to the top