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
|
/*******************************************************************************
* Copyright (c) 2006, 2007 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:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests;
import java.io.IOException;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.swt.widgets.Display;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
public class BaseUITestCase extends BaseTestCase {
public BaseUITestCase() {
super();
}
public BaseUITestCase(String name) {
super(name);
}
/**
* Reads a section in comments form the source of the given class. Fully
* equivalent to <code>readTaggedComment(getClass(), tag)</code>
* @since 4.0
*/
protected String readTaggedComment(final String tag) throws IOException {
return TestSourceReader.readTaggedComment(CTestPlugin.getDefault().getBundle(), "ui", getClass(), tag);
}
/**
* Reads multiple sections in comments from the source of the given class.
* @since 4.0
*/
public StringBuffer[] getContentsForTest(int sections) throws IOException {
return TestSourceReader.getContentsForTest(CTestPlugin.getDefault().getBundle(), "ui", getClass(), getName(), sections);
}
protected IFile createFile(IContainer container, String fileName, String contents) throws Exception {
return TestSourceReader.createFile(container, new Path(fileName), contents);
}
protected IASTTranslationUnit createIndexBasedAST(IIndex index, ICProject project, IFile file) throws CModelException, CoreException {
return TestSourceReader.createIndexBasedAST(index, project, file);
}
protected void waitForIndexer(IIndex index, IFile file, int maxmillis) throws Exception {
boolean firstTime= true;
long endTime= System.currentTimeMillis() + maxmillis;
while (firstTime || System.currentTimeMillis() < endTime) {
if (!firstTime)
Thread.sleep(50);
firstTime= false;
index.acquireReadLock();
try {
IIndexFile pfile= index.getFile(IndexLocationFactory.getWorkspaceIFL(file));
if (pfile != null && pfile.getTimestamp() >= file.getLocalTimeStamp()) {
return;
}
}
finally {
index.releaseReadLock();
}
}
throw new Exception("Indexer did not complete in time!");
}
protected void runEventQueue(int time) {
long endTime= System.currentTimeMillis()+time;
do {
while (Display.getCurrent().readAndDispatch());
}
while(System.currentTimeMillis() < endTime);
}
}
|