FileDocCategorySizeDatePackage
ConfigMatchTest.javaAPI DocAndroid 1.5 API10610Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.editors.resources.manager

ConfigMatchTest

public class ConfigMatchTest extends TestCase

Fields Summary
private static final String
SEARCHED_FILENAME
private static final String
MISC1_FILENAME
private static final String
MISC2_FILENAME
private ProjectResources
mResources
private com.android.ide.eclipse.editors.resources.configurations.ResourceQualifier[]
mQualifierList
private com.android.ide.eclipse.editors.resources.configurations.FolderConfiguration
config4
private com.android.ide.eclipse.editors.resources.configurations.FolderConfiguration
config3
private com.android.ide.eclipse.editors.resources.configurations.FolderConfiguration
config2
private com.android.ide.eclipse.editors.resources.configurations.FolderConfiguration
config1
Constructors Summary
Methods Summary
private ResourceFolder_addProjectResourceFolder(ProjectResources resources, com.android.ide.eclipse.editors.resources.configurations.FolderConfiguration config, com.android.ide.eclipse.mock.FolderMock folder)
Calls ProjectResource.add method via reflection to circumvent access restrictions that are enforced when running in the plug-in environment ie cannot access package or protected members in a different plug-in, even if they are in the same declared package as the accessor


        Method addMethod = ProjectResources.class.getDeclaredMethod("add", 
                ResourceFolderType.class, FolderConfiguration.class,
                IAbstractFolder.class);
        addMethod.setAccessible(true);
        ResourceFolder resFolder = (ResourceFolder)addMethod.invoke(resources,
                ResourceFolderType.LAYOUT, config, new IFolderWrapper(folder));
        return resFolder;
    
private voidaddFolder(ProjectResources resources, com.android.ide.eclipse.editors.resources.configurations.FolderConfiguration config, com.android.ide.eclipse.mock.FileMock[] memberList)
Adds a folder to the given {@link ProjectResources} with the given {@link FolderConfiguration}. The folder is filled with files from the provided list.

param
resources the {@link ProjectResources} in which to add the folder.
param
config the {@link FolderConfiguration} for the created folder.
param
memberList the list of files for the folder.

        
        // figure out the folder name based on the configuration
        String folderName = "layout";
        if (config.isDefault() == false) {
            folderName += "-" + config.toString();
        }
        
        // create the folder mock
        FolderMock folder = new FolderMock(folderName, memberList);

        // add it to the resource, and get back a ResourceFolder object.
        ResourceFolder resFolder = _addProjectResourceFolder(resources, config, folder);

        // and fill it with files from the list.
        for (FileMock file : memberList) {
            resFolder.addFile(new SingleResourceFile(new IFileWrapper(file), resFolder));
        }
    
private com.android.ide.eclipse.editors.resources.configurations.FolderConfigurationgetConfiguration(java.lang.String qualifierValues)
Creates a {@link FolderConfiguration}.

param
qualifierValues The list of qualifier values. The length must equals the total number of Qualifiers. null is permitted and will make the FolderConfiguration not use this particular qualifier.

        FolderConfiguration config = new FolderConfiguration();
        
        // those must be of the same length
        assertEquals(qualifierValues.length, mQualifierList.length);
        
        int index = 0;

        for (ResourceQualifier qualifier : mQualifierList) {
            String value = qualifierValues[index++];
            if (value != null) {
                assertTrue(qualifier.checkAndSet(value, config));
            }
        }

        return config;
    
protected voidsetUp()


    
         
        super.setUp();
        
        // create a Resource Manager to get a list of qualifier as instantiated by the real code.
        // Thanks for QualifierListTest we know this contains all the qualifiers. 
        ResourceManager manager = ResourceManager.getInstance();
        Field qualifierListField = ResourceManager.class.getDeclaredField("mQualifiers");
        assertNotNull(qualifierListField);
        qualifierListField.setAccessible(true);
        
        // get the actual list.
        mQualifierList = (ResourceQualifier[])qualifierListField.get(manager);
        
        // create the project resources.
        mResources = new ProjectResources(false /* isFrameworkRepository */);
        
        // create 2 arrays of IResource. one with the filename being looked up, and one without.
        // Since the required API uses IResource, we can use MockFolder for them.
        FileMock[] validMemberList = new FileMock[] {
                new FileMock(MISC1_FILENAME),
                new FileMock(SEARCHED_FILENAME),
                new FileMock(MISC2_FILENAME),
        };
        FileMock[] invalidMemberList = new FileMock[] {
                new FileMock(MISC1_FILENAME),
                new FileMock(MISC2_FILENAME),
        };
        
        // add multiple ResourceFolder to the project resource.
        FolderConfiguration defaultConfig = getConfiguration(
                null, // country code
                null, // network code
                null, // language
                null, // region
                null, // screen orientation
                null, // dpi
                null, // touch mode
                null, // keyboard state
                null, // text input
                null, // navigation
                null); // screen size
        
        addFolder(mResources, defaultConfig, validMemberList);
        
        config1 = getConfiguration(
                null, // country code
                null, // network code
                "en", // language
                null, // region
                null, // screen orientation
                null, // dpi
                null, // touch mode
                KeyboardState.EXPOSED.getValue(), // keyboard state
                null, // text input
                null, // navigation
                null); // screen size
        
        addFolder(mResources, config1, validMemberList);

        config2 = getConfiguration(
                null, // country code
                null, // network code
                "en", // language
                null, // region
                null, // screen orientation
                null, // dpi
                null, // touch mode
                KeyboardState.HIDDEN.getValue(), // keyboard state
                null, // text input
                null, // navigation
                null); // screen size
        
        addFolder(mResources, config2, validMemberList);

        config3 = getConfiguration(
                null, // country code
                null, // network code
                "en", // language
                null, // region
                ScreenOrientation.LANDSCAPE.getValue(), // screen orientation
                null, // dpi
                null, // touch mode
                null, // keyboard state
                null, // text input
                null, // navigation
                null); // screen size
        
        addFolder(mResources, config3, validMemberList);

        config4 = getConfiguration(
                "mcc310", // country code
                "mnc435", // network code
                "en", // language
                "rUS", // region
                ScreenOrientation.LANDSCAPE.getValue(), // screen orientation
                "160dpi", // dpi
                TouchScreenType.FINGER.getValue(), // touch mode
                KeyboardState.EXPOSED.getValue(), // keyboard state
                TextInputMethod.QWERTY.getValue(), // text input
                NavigationMethod.DPAD.getValue(), // navigation
                "480x320"); // screen size
        
        addFolder(mResources, config4, invalidMemberList);
    
protected voidtearDown()

        super.tearDown();
        mResources = null;
    
public voidtest1()

        FolderConfiguration testConfig = getConfiguration(
                "mcc310", // country code
                "mnc435", // network code
                "en", // language
                "rUS", // region
                ScreenOrientation.LANDSCAPE.getValue(), // screen orientation
                "160dpi", // dpi
                TouchScreenType.FINGER.getValue(), // touch mode
                KeyboardState.EXPOSED.getValue(), // keyboard state
                TextInputMethod.QWERTY.getValue(), // text input
                NavigationMethod.DPAD.getValue(), // navigation
                "480x320"); // screen size
        
        ResourceFile result = mResources.getMatchingFile(SEARCHED_FILENAME,
                ResourceFolderType.LAYOUT, testConfig);
        
        boolean bresult = result.getFolder().getConfiguration().equals(config3);
        assertEquals(bresult, true);