eclipse plugin: Add a couple of tests for the folder/file includes

This commit is contained in:
Timotei Dolean 2011-09-02 18:21:07 +00:00
parent ca1dd26301
commit 273e5267ff

View File

@ -47,6 +47,11 @@ public class ProjectDependencyListTests extends PDETest
ProjectUtils.getProjectCaches( ).clear( );
}
/**
* Tests the list for an empty project
*
* @throws CoreException
*/
public void testEmptyPDL( ) throws CoreException
{
IProject project = createProject( "test" );
@ -64,6 +69,11 @@ public class ProjectDependencyListTests extends PDETest
cleanup( project );
}
/**
* Tests the list for a project with a single file
*
* @throws Throwable
*/
public void testSingleFile( ) throws Throwable
{
IProject project = createProject( "test" );
@ -84,6 +94,12 @@ public class ProjectDependencyListTests extends PDETest
cleanup( project );
}
/**
* Tests the modification of the folder includes order
*
* @throws CoreException
* @throws IOException
*/
public void testFolderIncludes_OrderChanged( ) throws CoreException,
IOException
{
@ -123,7 +139,7 @@ public class ProjectDependencyListTests extends PDETest
project.build( IncrementalProjectBuilder.INCREMENTAL_BUILD,
new NullProgressMonitor( ) );
// check the re-ordering
// check the reordering
DependencyListNode node = list
.getNode( DependencyListBuilder.ROOT_NODE_KEY );
assertEquals( files[0], node.getFile( ) );
@ -146,6 +162,12 @@ public class ProjectDependencyListTests extends PDETest
cleanup( project );
}
/**
* Tests the file includes
*
* @throws CoreException
* @throws IOException
*/
public void testFilesIncludes( ) throws CoreException,
IOException
{
@ -179,6 +201,12 @@ public class ProjectDependencyListTests extends PDETest
cleanup( project );
}
/**
* Tests the modification of the file includes order
*
* @throws CoreException
* @throws IOException
*/
public void testFileIncludes_OrderChanged( ) throws CoreException,
IOException
{
@ -212,7 +240,7 @@ public class ProjectDependencyListTests extends PDETest
project.build( IncrementalProjectBuilder.INCREMENTAL_BUILD,
new NullProgressMonitor( ) );
// check the re-ordering
// check the reordering
DependencyListNode node = list
.getNode( DependencyListBuilder.ROOT_NODE_KEY );
assertEquals( files[0], node.getFile( ) );
@ -227,7 +255,7 @@ public class ProjectDependencyListTests extends PDETest
}
/**
* New include is added
* New file include is added
*
* @throws CoreException
* @throws IOException
@ -331,16 +359,473 @@ public class ProjectDependencyListTests extends PDETest
cleanup( project );
}
// TODO test combined folder + file directory add/removal
public void testIncludesCollapse( )
/**
* Tests includes that contain both folder and file includes
*
* @throws CoreException
* @throws IOException
*/
public void testFolderAndFileIncludes( ) throws CoreException, IOException
{
// add _main.cfg to an included folder
IProject project = createProject( "test" );
IFile files[] = new IFile[4];
ResourceUtils.createFolder( project, "f1" );
files[0] = ResourceUtils.createFile( project, "_main.cfg",
"{~add-ons/test/f1}\r\n{~add-ons/test/f2.cfg}\r\n" );
files[1] = ResourceUtils.createFile( project, "f1/f1_file1.cfg", "" );
files[2] = ResourceUtils.createFile( project, "f1/f1_file2.cfg", "" );
files[3] = ResourceUtils.createFile( project, "f2.cfg", "" );
project.build( IncrementalProjectBuilder.FULL_BUILD,
new NullProgressMonitor( ) );
DependencyListBuilder list = ProjectUtils.getCacheForProject( project )
.getDependencyList( );
assertEquals( true, list.isCreated( ) );
assertEquals( 4, list.getNodesCount( ) );
// check the includes
DependencyListNode node = list
.getNode( DependencyListBuilder.ROOT_NODE_KEY );
assertEquals( files[0], node.getFile( ) );
node = node.getNext( );
assertEquals( files[1], node.getFile( ) );
node = node.getNext( );
assertEquals( files[2], node.getFile( ) );
node = node.getNext( );
assertEquals( files[3], node.getFile( ) );
cleanup( project );
}
public void testIncludesExpand( )
/**
* Tests the modification of the file and folder includes order
*
* @throws CoreException
* @throws IOException
*/
public void testFolderAndFileIncludes_OrderChanged( ) throws CoreException,
IOException
{
// remove a _main.cfg from an included folder
IProject project = createProject( "test" );
IFile files[] = new IFile[4];
ResourceUtils.createFolder( project, "f1" );
files[0] = ResourceUtils.createFile( project, "_main.cfg",
"{~add-ons/test/f1}\r\n{~add-ons/test/f2.cfg}\r\n" );
files[1] = ResourceUtils.createFile( project, "f1/f1_file1.cfg", "" );
files[2] = ResourceUtils.createFile( project, "f1/f1_file2.cfg", "" );
files[3] = ResourceUtils.createFile( project, "f2.cfg", "" );
project.build( IncrementalProjectBuilder.FULL_BUILD,
new NullProgressMonitor( ) );
DependencyListBuilder list = ProjectUtils.getCacheForProject( project )
.getDependencyList( );
assertEquals( true, list.isCreated( ) );
assertEquals( 4, list.getNodesCount( ) );
// now reverse the include order
FileWriter writer = new FileWriter( files[0].getLocation( )
.toOSString( ) );
writer.write( "{~add-ons/test/f2.cfg}\r\n{~add-ons/test/f1}\r\n" );
writer.close( );
project.refreshLocal( IResource.DEPTH_INFINITE,
new NullProgressMonitor( ) );
// re-build now
project.build( IncrementalProjectBuilder.INCREMENTAL_BUILD,
new NullProgressMonitor( ) );
// check the reordering
DependencyListNode node = list
.getNode( DependencyListBuilder.ROOT_NODE_KEY );
assertEquals( files[0], node.getFile( ) );
node = node.getNext( );
assertEquals( files[3], node.getFile( ) );
node = node.getNext( );
assertEquals( files[1], node.getFile( ) );
node = node.getNext( );
assertEquals( files[2], node.getFile( ) );
cleanup( project );
}
/**
* New file included is added
*
* @throws CoreException
* @throws IOException
*/
public void testFolderAndFileIncludes_FileIncludeAdded( )
throws CoreException, IOException
{
IProject project = createProject( "test" );
IFile files[] = new IFile[5];
ResourceUtils.createFolder( project, "f1" );
files[0] = ResourceUtils.createFile( project, "_main.cfg",
"{~add-ons/test/f1}\r\n{~add-ons/test/f2.cfg}\r\n" );
files[1] = ResourceUtils.createFile( project, "f1/f1_file1.cfg", "" );
files[2] = ResourceUtils.createFile( project, "f1/f1_file2.cfg", "" );
files[3] = ResourceUtils.createFile( project, "f2.cfg", "" );
files[4] = ResourceUtils.createFile( project, "f3.cfg", "" );
project.build( IncrementalProjectBuilder.FULL_BUILD,
new NullProgressMonitor( ) );
DependencyListBuilder list = ProjectUtils.getCacheForProject( project )
.getDependencyList( );
assertEquals( true, list.isCreated( ) );
assertEquals( 4, list.getNodesCount( ) );
FileWriter writer = new FileWriter( files[0].getLocation( )
.toOSString( ) );
writer.write( "{~add-ons/test/f1}\r\n{~add-ons/test/f2.cfg}\r\n" +
"{~add-ons/test/f3.cfg}\r\n" );
writer.close( );
project.refreshLocal( IResource.DEPTH_INFINITE,
new NullProgressMonitor( ) );
// re-build now
project.build( IncrementalProjectBuilder.INCREMENTAL_BUILD,
new NullProgressMonitor( ) );
assertEquals( 5, list.getNodesCount( ) );
// check the list
DependencyListNode node = list
.getNode( DependencyListBuilder.ROOT_NODE_KEY );
assertEquals( files[0], node.getFile( ) );
node = node.getNext( );
assertEquals( files[1], node.getFile( ) );
node = node.getNext( );
assertEquals( files[2], node.getFile( ) );
node = node.getNext( );
assertEquals( files[3], node.getFile( ) );
node = node.getNext( );
assertEquals( files[4], node.getFile( ) );
cleanup( project );
}
/**
* File include removed
*
* @throws CoreException
* @throws IOException
*/
public void testFolderAndFileIncludes_FileIncludeRemoved( )
throws CoreException, IOException
{
IProject project = createProject( "test" );
IFile files[] = new IFile[5];
ResourceUtils.createFolder( project, "f1" );
files[0] = ResourceUtils.createFile( project, "_main.cfg",
"{~add-ons/test/f1}\r\n{~add-ons/test/f2.cfg}\r\n" +
"{~add-ons/test/f3.cfg}\r\n" );
files[1] = ResourceUtils.createFile( project, "f1/f1_file1.cfg", "" );
files[2] = ResourceUtils.createFile( project, "f1/f1_file2.cfg", "" );
files[3] = ResourceUtils.createFile( project, "f2.cfg", "" );
files[4] = ResourceUtils.createFile( project, "f3.cfg", "" );
project.build( IncrementalProjectBuilder.FULL_BUILD,
new NullProgressMonitor( ) );
DependencyListBuilder list = ProjectUtils.getCacheForProject( project )
.getDependencyList( );
assertEquals( true, list.isCreated( ) );
assertEquals( 5, list.getNodesCount( ) );
FileWriter writer = new FileWriter( files[0].getLocation( )
.toOSString( ) );
writer.write( "{~add-ons/test/f1}\r\n{~add-ons/test/f2.cfg}\r\n" );
writer.close( );
project.refreshLocal( IResource.DEPTH_INFINITE,
new NullProgressMonitor( ) );
// re-build now
project.build( IncrementalProjectBuilder.INCREMENTAL_BUILD,
new NullProgressMonitor( ) );
assertEquals( 4, list.getNodesCount( ) );
// check the list
DependencyListNode node = list
.getNode( DependencyListBuilder.ROOT_NODE_KEY );
assertEquals( files[0], node.getFile( ) );
node = node.getNext( );
assertEquals( files[1], node.getFile( ) );
node = node.getNext( );
assertEquals( files[2], node.getFile( ) );
node = node.getNext( );
assertEquals( files[3], node.getFile( ) );
cleanup( project );
}
/**
* New folder include added
*
* @throws CoreException
* @throws IOException
*/
public void testFolderAndFileIncludes_FolderIncludeAdded( )
throws CoreException, IOException
{
IProject project = createProject( "test" );
IFile files[] = new IFile[6];
ResourceUtils.createFolder( project, "f1" );
ResourceUtils.createFolder( project, "f3" );
files[0] = ResourceUtils.createFile( project, "_main.cfg",
"{~add-ons/test/f1}\r\n{~add-ons/test/f2.cfg}\r\n" );
files[1] = ResourceUtils.createFile( project, "f1/f1_file1.cfg", "" );
files[2] = ResourceUtils.createFile( project, "f1/f1_file2.cfg", "" );
files[3] = ResourceUtils.createFile( project, "f2.cfg", "" );
files[4] = ResourceUtils.createFile( project, "f3/f3_file1.cfg", "" );
files[5] = ResourceUtils.createFile( project, "f3/f3_file2.cfg", "" );
project.build( IncrementalProjectBuilder.FULL_BUILD,
new NullProgressMonitor( ) );
DependencyListBuilder list = ProjectUtils.getCacheForProject( project )
.getDependencyList( );
assertEquals( true, list.isCreated( ) );
assertEquals( 4, list.getNodesCount( ) );
FileWriter writer = new FileWriter( files[0].getLocation( )
.toOSString( ) );
writer.write( "{~add-ons/test/f1}\r\n{~add-ons/test/f2.cfg}\r\n" +
"{~add-ons/test/f3}\r\n" );
writer.close( );
project.refreshLocal( IResource.DEPTH_INFINITE,
new NullProgressMonitor( ) );
// re-build now
project.build( IncrementalProjectBuilder.INCREMENTAL_BUILD,
new NullProgressMonitor( ) );
assertEquals( 6, list.getNodesCount( ) );
// check the list
DependencyListNode node = list
.getNode( DependencyListBuilder.ROOT_NODE_KEY );
assertEquals( files[0], node.getFile( ) );
node = node.getNext( );
assertEquals( files[1], node.getFile( ) );
node = node.getNext( );
assertEquals( files[2], node.getFile( ) );
node = node.getNext( );
assertEquals( files[3], node.getFile( ) );
node = node.getNext( );
assertEquals( files[4], node.getFile( ) );
node = node.getNext( );
assertEquals( files[5], node.getFile( ) );
cleanup( project );
}
/**
* Folder include removed
*
* @throws CoreException
* @throws IOException
*/
public void testFolderAndFileIncludes_FolderIncludeRemoved( )
throws CoreException, IOException
{
IProject project = createProject( "test" );
IFile files[] = new IFile[6];
ResourceUtils.createFolder( project, "f1" );
ResourceUtils.createFolder( project, "f3" );
files[0] = ResourceUtils.createFile( project, "_main.cfg",
"{~add-ons/test/f1}\r\n{~add-ons/test/f2.cfg}\r\n" +
"{~add-ons/test/f3}\r\n" );
files[1] = ResourceUtils.createFile( project, "f1/f1_file1.cfg", "" );
files[2] = ResourceUtils.createFile( project, "f1/f1_file2.cfg", "" );
files[3] = ResourceUtils.createFile( project, "f2.cfg", "" );
files[4] = ResourceUtils.createFile( project, "f3/f3_file1.cfg", "" );
files[5] = ResourceUtils.createFile( project, "f3/f3_file2.cfg", "" );
project.build( IncrementalProjectBuilder.FULL_BUILD,
new NullProgressMonitor( ) );
DependencyListBuilder list = ProjectUtils.getCacheForProject( project )
.getDependencyList( );
assertEquals( true, list.isCreated( ) );
assertEquals( 6, list.getNodesCount( ) );
FileWriter writer = new FileWriter( files[0].getLocation( )
.toOSString( ) );
writer.write( "{~add-ons/test/f1}\r\n{~add-ons/test/f2.cfg}\r\n" );
writer.close( );
project.refreshLocal( IResource.DEPTH_INFINITE,
new NullProgressMonitor( ) );
// re-build now
project.build( IncrementalProjectBuilder.INCREMENTAL_BUILD,
new NullProgressMonitor( ) );
assertEquals( 4, list.getNodesCount( ) );
DependencyListNode node = list
.getNode( DependencyListBuilder.ROOT_NODE_KEY );
assertEquals( files[0], node.getFile( ) );
node = node.getNext( );
assertEquals( files[1], node.getFile( ) );
node = node.getNext( );
assertEquals( files[2], node.getFile( ) );
node = node.getNext( );
assertEquals( files[3], node.getFile( ) );
cleanup( project );
}
/**
* Tests the collapsing of the files in an included folder when
* _main.cfg is added to it. The files nodes in that folder get
* replaced with _main.cfg's node.
*
* @throws CoreException
*/
public void testIncludesCollapse( ) throws CoreException
{
IProject project = createProject( "test" );
IFile files[] = new IFile[4];
ResourceUtils.createFolder( project, "f1" );
files[0] = ResourceUtils.createFile( project, "_main.cfg",
"{~add-ons/test/f1}\r\n" );
files[2] = ResourceUtils.createFile( project, "f1/f1_file1.cfg", "" );
files[3] = ResourceUtils.createFile( project, "f1/f1_file2.cfg", "" );
project.build( IncrementalProjectBuilder.FULL_BUILD,
new NullProgressMonitor( ) );
DependencyListBuilder list = ProjectUtils.getCacheForProject( project )
.getDependencyList( );
assertEquals( true, list.isCreated( ) );
assertEquals( 3, list.getNodesCount( ) );
// create _main.cfg
files[1] = ResourceUtils.createFile( project, "f1/_main.cfg", "" );
project.refreshLocal( IResource.DEPTH_INFINITE,
new NullProgressMonitor( ) );
// re-build now
project.build( IncrementalProjectBuilder.INCREMENTAL_BUILD,
new NullProgressMonitor( ) );
// check the new list
assertEquals( 2, list.getNodesCount( ) );
DependencyListNode node = list
.getNode( DependencyListBuilder.ROOT_NODE_KEY );
assertEquals( files[0], node.getFile( ) );
node = node.getNext( );
assertEquals( files[1], node.getFile( ) );
cleanup( project );
}
/**
* Removing the _main.cfg from an included folder should expand that
* _main.cfg's into the existing files from that folder.
*
* @throws CoreException
*/
public void testIncludesExpand( ) throws CoreException
{
IProject project = createProject( "test" );
IFile files[] = new IFile[4];
ResourceUtils.createFolder( project, "f1" );
files[0] = ResourceUtils.createFile( project, "_main.cfg",
"{~add-ons/test/f1}\r\n" );
files[1] = ResourceUtils.createFile( project, "f1/_main.cfg", "" );
files[2] = ResourceUtils.createFile( project, "f1/f1_file1.cfg", "" );
files[3] = ResourceUtils.createFile( project, "f1/f1_file2.cfg", "" );
project.build( IncrementalProjectBuilder.FULL_BUILD,
new NullProgressMonitor( ) );
DependencyListBuilder list = ProjectUtils.getCacheForProject( project )
.getDependencyList( );
assertEquals( true, list.isCreated( ) );
assertEquals( 2, list.getNodesCount( ) );
// now remove the _main.cfg
files[1].delete( true, new NullProgressMonitor( ) );
project.refreshLocal( IResource.DEPTH_INFINITE,
new NullProgressMonitor( ) );
// re-build now
project.build( IncrementalProjectBuilder.INCREMENTAL_BUILD,
new NullProgressMonitor( ) );
// check the new list
assertEquals( 3, list.getNodesCount( ) );
DependencyListNode node = list
.getNode( DependencyListBuilder.ROOT_NODE_KEY );
assertEquals( files[0], node.getFile( ) );
node = node.getNext( );
assertEquals( files[2], node.getFile( ) );
node = node.getNext( );
assertEquals( files[3], node.getFile( ) );
cleanup( project );
}
/**