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:
parent
54919b0124
commit
c2306c20e5
1 changed files with 72 additions and 89 deletions
|
@ -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;
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
@ -59,13 +55,12 @@ public class CodeReaderCacheTest extends CDOMTestBase {
|
||||||
|
|
||||||
@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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,56 +69,58 @@ 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);
|
||||||
|
((CodeReaderCache) cache).setCacheSize(0);
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
IFile file = null;
|
private ICodeReaderCache getCodeReaderCache() {
|
||||||
try {
|
return CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_SAVED_RESOURCES).getCodeReaderCache();
|
||||||
file = importFile("test.c", code.toString()); //$NON-NLS-1$
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
@ -144,26 +141,20 @@ 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;
|
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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue