1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fixed a test order dependency.

This commit is contained in:
Sergey Prigogin 2013-03-30 13:32:50 -07:00
parent 54919b0124
commit c2306c20e5

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.ast2; package org.eclipse.cdt.core.parser.tests.ast2;
@ -27,166 +27,149 @@ import org.eclipse.core.runtime.jobs.Job;
* @author dsteffle * @author dsteffle
*/ */
public class CodeReaderCacheTest extends CDOMTestBase { public class CodeReaderCacheTest extends CDOMTestBase {
public CodeReaderCacheTest() {
}
public CodeReaderCacheTest(String name, Class className) { public CodeReaderCacheTest() {
super(name, className);
} }
public CodeReaderCacheTest(String name) { public CodeReaderCacheTest(String name) {
super(name, CodeReaderCacheTest.class); super(name, CodeReaderCacheTest.class);
} }
public static Test suite() { public static Test suite() {
TestSuite suite = new TestSuite( CodeReaderCacheTest.class ); TestSuite suite = new TestSuite(CodeReaderCacheTest.class);
suite.addTest( new CodeReaderCacheTest("cleanupProject") ); //$NON-NLS-1$ suite.addTest(new CodeReaderCacheTest("cleanupProject"));
return suite; return suite;
} }
private class UpdateFileJob extends Job { private class UpdateFileJob extends Job {
private IFile file = null; private IFile file;
private String fileName = null; private final String fileName;
private String code = null; private final String code;
public UpdateFileJob(String name, IFile file, String fileName, String code) { public UpdateFileJob(String name, IFile file, String fileName, String code) {
super(name); super(name);
this.file = file; this.file = file;
this.fileName = fileName; this.fileName = fileName;
this.code = code; this.code = code;
} }
@Override @Override
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
while(!monitor.isCanceled()) { while (!monitor.isCanceled()) {
try { try {
file = importFile(fileName, code); file = importFile(fileName, code);
} catch (Exception e) { } catch (Exception e) {
} }
} }
return Status.OK_STATUS; return Status.OK_STATUS;
} }
public IFile getFile() { public IFile getFile() {
return file; return file;
} }
} }
// THIS MUST BE RUN FIRST IN THIS TEST @Override
public void testSetCacheSize() { protected void setUp() throws Exception {
ICodeReaderCache cache = CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_SAVED_RESOURCES).getCodeReaderCache(); super.setUp();
// update the size of the cache... must be done for the first test since other test suites use 0MB cache size ICodeReaderCache cache = getCodeReaderCache();
assertTrue(cache instanceof CodeReaderCache); assertTrue(cache instanceof CodeReaderCache);
((CodeReaderCache)cache).setCacheSize(CodeReaderCache.DEFAULT_CACHE_SIZE_IN_MB); ((CodeReaderCache) cache).setCacheSize(CodeReaderCache.DEFAULT_CACHE_SIZE_IN_MB);
} }
public void testSimpleCacheFunctionality() { @Override
StringBuffer code = new StringBuffer(); public void tearDown() throws Exception {
code.append("int x;"); //$NON-NLS-1$ ICodeReaderCache cache = getCodeReaderCache();
assertTrue(cache instanceof CodeReaderCache);
IFile file = null; ((CodeReaderCache) cache).setCacheSize(0);
try { super.tearDown();
file = importFile("test.c", code.toString()); //$NON-NLS-1$ }
} catch (Exception e) {
e.printStackTrace(); private ICodeReaderCache getCodeReaderCache() {
} return CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_SAVED_RESOURCES).getCodeReaderCache();
}
public void testSimpleCacheFunctionality() throws Exception {
StringBuilder code = new StringBuilder();
code.append("int x;");
IFile file = importFile("test.c", code.toString());
parse(file); parse(file);
ICodeReaderCache cache = CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_SAVED_RESOURCES).getCodeReaderCache(); ICodeReaderCache cache = getCodeReaderCache();
cache.flush(); cache.flush();
assertEquals(0, cache.getCurrentSpace());
CodeReader reader = cache.get(file.getLocation().toOSString()); CodeReader reader = cache.get(file.getLocation().toOSString());
assertNotNull(reader); assertNotNull(reader);
assertEquals(cache.getCurrentSpace(), 1); assertEquals(1, cache.getCurrentSpace());
assertEquals(String.valueOf(reader.filename), file.getLocation().toOSString()); assertEquals(String.valueOf(reader.filename), file.getLocation().toOSString());
cache.remove(String.valueOf(reader.filename)); cache.remove(String.valueOf(reader.filename));
assertEquals(cache.getCurrentSpace(), 0); assertEquals(0, cache.getCurrentSpace());
} }
public void testResourceChangedUpdate() { public void testResourceChangedUpdate() throws Exception {
boolean hasPassed = false; boolean hasPassed = false;
StringBuffer code = new StringBuffer(); StringBuilder code = new StringBuilder();
code.append("int x;"); //$NON-NLS-1$ code.append("int x;");
ICodeReaderCache cache = CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_SAVED_RESOURCES).getCodeReaderCache(); ICodeReaderCache cache = getCodeReaderCache();
IFile file = null; IFile file = importFile("test.c", code.toString());
parse(file);
try {
file = importFile("test.c", code.toString()); //$NON-NLS-1$
} catch (Exception e) {
e.printStackTrace();
}
// start a new job that repeatedly updates the file... // start a new job that repeatedly updates the file...
UpdateFileJob job = new UpdateFileJob("updater", file, "test.c", code.toString()); //$NON-NLS-1$ //$NON-NLS-2$ UpdateFileJob job = new UpdateFileJob("updater", file, "test.c", code.toString()); //$NON-NLS-2$
job.schedule(); job.schedule();
while(!hasPassed) { while (!hasPassed) {
if (file != null) { if (file != null) {
parse(file); parse(file);
} }
try { try {
Thread.sleep(1000); // give the updater thread some time to update the resource Thread.sleep(1000); // give the updater thread some time to update the resource
file = job.getFile(); file = job.getFile();
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
if (cache.getCurrentSpace() == 0) // item was properly removed by the updater thread if (cache.getCurrentSpace() == 0) // item was properly removed by the updater thread
hasPassed = true; hasPassed = true;
} }
job.cancel(); job.cancel();
} }
// This is broken. // This is broken.
// I have a mind to delete any test that has a Thread.sleep() in it. // I have a mind to delete any test that has a Thread.sleep() in it.
public void testResourceChangedNestedPathUpdate(int off) { public void testResourceChangedNestedPathUpdate(int off) throws Exception {
boolean hasPassed = false; boolean hasPassed = false;
StringBuffer code = new StringBuffer(); StringBuilder code = new StringBuilder();
code.append("int x;"); //$NON-NLS-1$ code.append("int x;");
ICodeReaderCache cache = CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_SAVED_RESOURCES).getCodeReaderCache(); ICodeReaderCache cache = getCodeReaderCache();
IFile file = null; importFolder("test");
IFile file = importFile("test/test.c", code.toString());
try {
importFolder("test");
file = importFile("test/test.c", code.toString()); //$NON-NLS-1$
} catch (Exception e) {
e.printStackTrace();
}
// start a new job that repeatedly updates the file... // start a new job that repeatedly updates the file...
UpdateFileJob job = new UpdateFileJob("updater", file, "test/test.c", code.toString()); //$NON-NLS-1$ //$NON-NLS-2$ UpdateFileJob job = new UpdateFileJob("updater", file, "test/test.c", code.toString());
job.schedule(); job.schedule();
while(!hasPassed) { while (!hasPassed) {
if (file != null) { if (file != null) {
parse(file); parse(file);
} }
try { try {
Thread.sleep(1000); // give the updater thread some time to update the resource Thread.sleep(1000); // give the updater thread some time to update the resource
file = job.getFile(); file = job.getFile();
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
if (cache.getCurrentSpace() == 0) // item was properly removed by the updater thread if (cache.getCurrentSpace() == 0) // item was properly removed by the updater thread
hasPassed = true; hasPassed = true;
} }
job.cancel(); job.cancel();
} }
// THIS MUST BE RUN LAST IN THIS TEST
public void testClearCache() {
ICodeReaderCache cache = CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_SAVED_RESOURCES).getCodeReaderCache();
// now that the
assertTrue(cache instanceof CodeReaderCache);
((CodeReaderCache)cache).setCacheSize(0);
}
} }