FileDocCategorySizeDatePackage
SampleProjectTest.javaAPI DocAndroid 1.5 API5785Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.tests.functests.sampleProjects

SampleProjectTest

public class SampleProjectTest extends com.android.ide.eclipse.tests.FuncTestCase
Test case that verifies all SDK sample projects can be imported, built in Eclipse TODO: add support for deploying apps onto emulator and verifying successful execution there

Fields Summary
private static final Logger
sLogger
Constructors Summary
Methods Summary
protected voiddoTestSampleProject(java.lang.String name)
Tests the sample project with the given name

param
name - name of sample project to test


                           
        
        try {

            StubSampleProjectWizard newProjCreator = new StubSampleProjectWizard(
                    name, getOsSdkLocation());
            newProjCreator.init(null, null);
            newProjCreator.performFinish();

            IProject iproject = validateProjectExists(name);

            validateNoProblems(iproject);

        } 
        catch (CoreException e) {
            fail("Unexpected exception when creating sample project: " + e.toString());
        }
    
private org.eclipse.core.resources.IProjectgetIProject(java.lang.String name)

        IProject iproject = ResourcesPlugin.getWorkspace().getRoot()
                .getProject(name);
        return iproject;
    
public voidtestApiDemos()

        doTestSampleProject("ApiDemos");
    
public voidtestHelloActivity()

        doTestSampleProject("HelloActivity");
    
public voidtestLunarLander()

        doTestSampleProject("LunarLander");
    
public voidtestNotePad()

        doTestSampleProject("NotePad");
    
public voidtestSkeletonApp()

        doTestSampleProject("SkeletonApp");
    
public voidtestSnake()

        doTestSampleProject("Snake");
    
private voidvalidateNoProblems(org.eclipse.core.resources.IProject iproject)

        waitForBuild(iproject);
        assertFalse(ProjectHelper.hasError(iproject, true));
    
private org.eclipse.core.resources.IProjectvalidateProjectExists(java.lang.String name)

        IProject iproject = getIProject(name);
        assertTrue(iproject.exists());
        assertTrue(iproject.isOpen());
        return iproject;
    
private voidwaitForBuild(org.eclipse.core.resources.IProject iproject)
Waits for build to complete.

param
iproject

       
        final BuiltProjectDeltaVisitor deltaVisitor = new BuiltProjectDeltaVisitor(iproject);
        IResourceChangeListener newBuildListener = new IResourceChangeListener() {

            public void resourceChanged(IResourceChangeEvent event) {
                try {
                    event.getDelta().accept(deltaVisitor);
                }
                catch (CoreException e) {
                    fail();
                }
            }
            
        };
        iproject.getWorkspace().addResourceChangeListener(newBuildListener, 
          IResourceChangeEvent.POST_BUILD);

        // poll build listener to determine when build is done
        // loop max of 1200 times * 50 ms = 60 seconds
        final int maxWait = 1200;
        for (int i=0; i < maxWait; i++) {
            if (deltaVisitor.isProjectBuilt()) {
                return;
            }
            try {
                Thread.sleep(50);
            }
            catch (InterruptedException e) {
                
            }
           if (Display.getCurrent() != null) {
               Display.getCurrent().readAndDispatch();
           }
        }
        
        sLogger.log(Level.SEVERE, "expected build event never happened?");
        fail("expected build event never happened for " + iproject.getName());