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

@ -31,24 +31,20 @@ public class CodeReaderCacheTest extends CDOMTestBase {
public CodeReaderCacheTest() { public CodeReaderCacheTest() {
} }
public CodeReaderCacheTest(String name, Class className) {
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);
@ -65,7 +61,6 @@ public class CodeReaderCacheTest extends CDOMTestBase {
} catch (Exception e) { } catch (Exception e) {
} }
} }
return Status.OK_STATUS; return Status.OK_STATUS;
} }
@ -74,53 +69,55 @@ public class CodeReaderCacheTest extends CDOMTestBase {
} }
} }
// 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) {
@ -144,23 +141,17 @@ public class CodeReaderCacheTest extends CDOMTestBase {
// 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;
try {
importFolder("test"); importFolder("test");
file = importFile("test/test.c", code.toString()); //$NON-NLS-1$ IFile file = importFile("test/test.c", code.toString());
} 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) {
@ -181,12 +172,4 @@ public class CodeReaderCacheTest extends CDOMTestBase {
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);
}
} }