diff options
author | Sergey Prigogin | 2011-10-04 01:10:03 +0000 |
---|---|---|
committer | Sergey Prigogin | 2011-10-04 01:10:03 +0000 |
commit | dacfc2d9b713c4a5105447fc9b6046dcf04975c8 (patch) | |
tree | 6ce9c77c3af2d09e01527d19f18943850666fd3e | |
parent | b87e568b78892d050212f74b99fd8ca34d06d301 (diff) | |
download | org.eclipse.cdt-dacfc2d9b713c4a5105447fc9b6046dcf04975c8.tar.gz org.eclipse.cdt-dacfc2d9b713c4a5105447fc9b6046dcf04975c8.tar.xz org.eclipse.cdt-dacfc2d9b713c4a5105447fc9b6046dcf04975c8.zip |
Added two more multi-variant header update tests. Currently all these
tests are failing.
-rw-r--r-- | core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java | 179 |
1 files changed, 175 insertions, 4 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java index e22b9001773..badaa6b685f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java @@ -450,18 +450,89 @@ public class IndexIncludeTest extends IndexTestBase { standardCheckUpdateIncludes(header, s1, "h20070427"); } - // #static const int X = 0; + // #ifdef A + // static const int a = 0; + // #endif + // #ifdef B + // static const int b = 0; + // #endif + // #ifdef C + // static const int c = 0; + // #endif - // #define X a + // #define A // #include "h1.h" - // #define X b + // #undef A + // #define B + // #include "h1.h" + // #undef B + + // #define C // #include "h1.h" // #include "h2.h" + public void testMultiVariantHeaderUpdate_1() throws Exception { + IndexerPreferences.set(fProject.getProject(), IndexerPreferences.KEY_INDEX_UNUSED_HEADERS_WITH_DEFAULT_LANG, "false"); + waitForIndexer(); + TestScannerProvider.sIncludes= new String[] { fProject.getProject().getLocation().toOSString() }; + StringBuilder[] contents= getContentsForTest(4); + final StringBuilder h1Contents = contents[0]; + final IFile h1= TestSourceReader.createFile(fProject.getProject(), "h1.h", h1Contents.toString()); + IFile h2= TestSourceReader.createFile(fProject.getProject(), "h2.h", contents[1].toString()); + IFile s1= TestSourceReader.createFile(fProject.getProject(), "s1.cpp", contents[2].toString()); + IFile s2= TestSourceReader.createFile(fProject.getProject(), "s2.cpp", contents[3].toString()); + TestSourceReader.waitUntilFileIsIndexed(fIndex, s1, INDEXER_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(fIndex, s2, INDEXER_WAIT_TIME); + + fIndex.acquireReadLock(); + try { + IIndexFile[] indexFiles = fIndex.getFiles(ILinkage.CPP_LINKAGE_ID, IndexLocationFactory.getWorkspaceIFL(h1)); + assertEquals(3, indexFiles.length); + } finally { + fIndex.releaseReadLock(); + } + + final long timestamp= System.currentTimeMillis(); + while (true) { + int pos = h1Contents.indexOf("int"); + if (pos < 0) + break; + h1Contents.replace(pos, pos + "int".length(), "float"); + } + ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { + public void run(IProgressMonitor monitor) throws CoreException { + h1.setContents(new ByteArrayInputStream(h1Contents.toString().getBytes()), false, false, npm()); + h1.setLocalTimeStamp(timestamp + 1000); + } + }, npm()); + waitForIndexer(); + + fIndex.acquireReadLock(); + try { + IIndexFile[] indexFiles = fIndex.getFiles(ILinkage.CPP_LINKAGE_ID, IndexLocationFactory.getWorkspaceIFL(h1)); + assertEquals(3, indexFiles.length); + for (IIndexFile indexFile : indexFiles) { + assertTrue("Timestamp not ok", indexFile.getTimestamp() >= timestamp); + } + } finally { + fIndex.releaseReadLock(); + } + } + + // static const int X = 0; + + // #define X a + // #include "h1.h" + // #undef X + // #define X b + // #include "h1.h" // #define X c // #include "h1.h" - public void _testMultiVariantHeaderUpdate() throws Exception { + + // #include "h2.h" + public void testMultiVariantHeaderUpdate_2() throws Exception { + IndexerPreferences.set(fProject.getProject(), IndexerPreferences.KEY_INDEX_UNUSED_HEADERS_WITH_DEFAULT_LANG, "false"); waitForIndexer(); TestScannerProvider.sIncludes= new String[] { fProject.getProject().getLocation().toOSString() }; StringBuilder[] contents= getContentsForTest(4); @@ -504,6 +575,106 @@ public class IndexIncludeTest extends IndexTestBase { } } + // #ifdef A + // static const int a = 0; + // #endif + // #ifdef B + // static const int b = 0; + // #endif + // #ifdef C + // static const int c = 0; + // #endif + + // #define A + // #include "h1.h" + // #undef A + // #define B + // #include "h1.h" + // #undef B + + // #define C + // #include "h1.h" + + // #include "h2.h" + + // #ifndef H1_H_ + // #define H1_H_ + // #ifdef A + // static const int a = 0; + // #endif + // #ifdef B + // static const int b = 0; + // #endif + // #ifdef C + // static const int c = 0; + // #endif + // #endif // H1_H_ + public void testPragmaOnceChange() throws Exception { + IndexerPreferences.set(fProject.getProject(), IndexerPreferences.KEY_INDEX_UNUSED_HEADERS_WITH_DEFAULT_LANG, "false"); + waitForIndexer(); + TestScannerProvider.sIncludes= new String[] { fProject.getProject().getLocation().toOSString() }; + CharSequence[] contents= getContentsForTest(4); + final CharSequence h1Contents = contents[0]; + final IFile h1= TestSourceReader.createFile(fProject.getProject(), "h1.h", h1Contents.toString()); + IFile h2= TestSourceReader.createFile(fProject.getProject(), "h2.h", contents[1].toString()); + IFile s1= TestSourceReader.createFile(fProject.getProject(), "s1.cpp", contents[2].toString()); + IFile s2= TestSourceReader.createFile(fProject.getProject(), "s2.cpp", contents[3].toString()); + TestSourceReader.waitUntilFileIsIndexed(fIndex, s1, INDEXER_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(fIndex, s2, INDEXER_WAIT_TIME); + + fIndex.acquireReadLock(); + try { + IIndexFile[] indexFiles = fIndex.getFiles(ILinkage.CPP_LINKAGE_ID, IndexLocationFactory.getWorkspaceIFL(h1)); + assertEquals(3, indexFiles.length); + } finally { + fIndex.releaseReadLock(); + } + + // Change h1.h so that it has the pragma-once semantics. + final long t1= System.currentTimeMillis(); + final String changedContents = contents[4].toString(); + ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { + public void run(IProgressMonitor monitor) throws CoreException { + h1.setContents(new ByteArrayInputStream(changedContents.getBytes()), false, false, npm()); + h1.setLocalTimeStamp(t1 + 1000); + } + }, npm()); + waitForIndexer(); + + fIndex.acquireReadLock(); + try { + IIndexFile[] indexFiles = fIndex.getFiles(ILinkage.CPP_LINKAGE_ID, IndexLocationFactory.getWorkspaceIFL(h1)); + assertEquals(1, indexFiles.length); + for (IIndexFile indexFile : indexFiles) { + assertTrue("Timestamp not ok", indexFile.getTimestamp() >= t1); + } + } finally { + fIndex.releaseReadLock(); + } + + + // Change h1.h back to the original state without the pragma-once semantics. + final long t2= System.currentTimeMillis(); + ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { + public void run(IProgressMonitor monitor) throws CoreException { + h1.setContents(new ByteArrayInputStream(h1Contents.toString().getBytes()), false, false, npm()); + h1.setLocalTimeStamp(t2 + 1000); + } + }, npm()); + waitForIndexer(); + + fIndex.acquireReadLock(); + try { + IIndexFile[] indexFiles = fIndex.getFiles(ILinkage.CPP_LINKAGE_ID, IndexLocationFactory.getWorkspaceIFL(h1)); + assertEquals(3, indexFiles.length); + for (IIndexFile indexFile : indexFiles) { + assertTrue("Timestamp not ok", indexFile.getTimestamp() >= t2); + } + } finally { + fIndex.releaseReadLock(); + } + } + private void standardCheckUpdateIncludes(IFile header, IFile s1, String tag) throws Exception { fIndex.acquireReadLock(); try { |