public void testEnablement() {
    resetValueHandler();

    IProject project =
        ManagedBuildTestHelper.createProject("en", "cdt.managedbuild.target.enablement.exe");
    IFile aFile = ManagedBuildTestHelper.createFile(project, "a.c");
    IFile bFile = ManagedBuildTestHelper.createFile(project, "b.c");

    IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
    IConfiguration cfg = info.getManagedProject().getConfigurations()[0];
    assertFalse(fHandleValueCalled);

    doTestEnablement(cfg);

    doEnumAllValues(cfg);

    ManagedBuildTestHelper.removeProject("en");
  }
  public void testEnablement_Bug250686() throws Exception {
    final String testName = getName();
    IProject project = ManagedBuildTestHelper.createProject(testName, PROJECT_TYPE);
    assertNotNull(project);

    IFolder folder = ManagedBuildTestHelper.createFolder(project, "Folder");
    assertNotNull(folder);

    IFile file = ManagedBuildTestHelper.createFile(project, "Folder/file.c");
    assertNotNull(file);

    ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project);
    prjDescription.getConfigurationByName(CFG_NAME);

    IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
    IConfiguration cfg = info.getManagedProject().getConfigurations()[0];
    assertNotNull(cfg);
    assertEquals(CFG_NAME, cfg.getName());

    {
      // Round 1. Test root folder option
      IFolderInfo rootFolderInfo = cfg.getRootFolderInfo();
      assertNotNull(rootFolderInfo);

      IOption option = getOptionForFolder(rootFolderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ENABLEMENT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 1. Test subfolder option
      IResourceInfo folderInfo = cfg.getResourceInfo(folder.getFullPath(), false);
      assertNotNull(folderInfo);
      assertTrue(folderInfo instanceof IFolderInfo);

      IOption option = getOptionForFolder((IFolderInfo) folderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ENABLEMENT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 1. Test file option
      IResourceInfo fileInfo = cfg.getResourceInfo(file.getFullPath(), false);
      assertNotNull(fileInfo);
      assertTrue(fileInfo instanceof IFolderInfo);

      // Option is taken from root folder here
      IOption option = getOptionForFolder((IFolderInfo) fileInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ENABLEMENT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 2. Override the value of the option for the root folder
      IFolderInfo rootFolderInfo = cfg.getRootFolderInfo();
      ITool[] tools = rootFolderInfo.getToolsBySuperClassId(TOOL_ID);
      assertEquals(1, tools.length);
      IOption option = getOptionForFolder(rootFolderInfo, TOOL_ID, OPTION_ID);
      rootFolderInfo.setOption(tools[0], option, OPTION_VALUE_ROOT);
    }

    {
      // Round 2. Test root folder option
      IFolderInfo rootFolderInfo = cfg.getRootFolderInfo();
      assertNotNull(rootFolderInfo);

      IOption option = getOptionForFolder(rootFolderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ROOT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 2. Test subfolder option
      IResourceInfo folderInfo = cfg.getResourceInfo(folder.getFullPath(), false);
      assertNotNull(folderInfo);
      assertTrue(folderInfo instanceof IFolderInfo);

      IOption option = getOptionForFolder((IFolderInfo) folderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ROOT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 2. Test file option
      IResourceInfo fileInfo = cfg.getResourceInfo(file.getFullPath(), false);
      assertNotNull(fileInfo);
      assertTrue(fileInfo instanceof IFolderInfo);

      // Option is taken from root folder here
      IOption option = getOptionForFolder((IFolderInfo) fileInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ROOT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 3. Override the value of the option for the subfolder
      IFolderInfo folderInfo = cfg.createFolderInfo(folder.getFullPath());
      assertNotNull(folderInfo);

      ITool[] tools = folderInfo.getToolsBySuperClassId(TOOL_ID);
      assertEquals(1, tools.length);

      IOption option = getOptionForFolder(folderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ROOT, option.getValue());
      assertFalse(option.isExtensionElement());

      folderInfo.setOption(tools[0], option, OPTION_VALUE_FOLDER);
    }

    {
      // Round 3. Test root folder option
      IFolderInfo rootFolderInfo = cfg.getRootFolderInfo();
      assertNotNull(rootFolderInfo);

      IOption option = getOptionForFolder(rootFolderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ROOT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 3. Test subfolder option
      IResourceInfo folderInfo = cfg.getResourceInfo(folder.getFullPath(), false);
      assertNotNull(folderInfo);
      assertTrue(folderInfo instanceof IFolderInfo);

      IOption option = getOptionForFolder((IFolderInfo) folderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_FOLDER, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 3. Test file option
      IResourceInfo fileInfo = cfg.getResourceInfo(file.getFullPath(), false);
      assertNotNull(fileInfo);
      assertTrue(fileInfo instanceof IFolderInfo);

      // Option is taken from parent folder here
      IOption option = getOptionForFolder((IFolderInfo) fileInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_FOLDER, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 4. Override the value of the option for the file
      IFileInfo fileInfo = cfg.createFileInfo(file.getFullPath());
      assertNotNull(fileInfo);

      ITool[] tools = fileInfo.getTools();
      assertEquals(1, tools.length);
      ITool tool = tools[0];
      assertNotNull(tool);

      IOption option = getOptionForFile(fileInfo, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_FOLDER, option.getValue());
      assertFalse(option.isExtensionElement());

      fileInfo.setOption(tool, option, OPTION_VALUE_FILE);
    }

    {
      // Round 4. Test root folder option
      IFolderInfo rootFolderInfo = cfg.getRootFolderInfo();
      assertNotNull(rootFolderInfo);

      IOption option = getOptionForFolder(rootFolderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ROOT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 4. Test subfolder option
      IResourceInfo folderInfo = cfg.getResourceInfo(folder.getFullPath(), false);
      assertNotNull(folderInfo);
      assertTrue(folderInfo instanceof IFolderInfo);

      IOption option = getOptionForFolder((IFolderInfo) folderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_FOLDER, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 4. Test file option
      IResourceInfo fileInfo = cfg.getResourceInfo(file.getFullPath(), false);
      assertNotNull(fileInfo);
      assertTrue(fileInfo instanceof IFileInfo);

      IOption option = getOptionForFile((IFileInfo) fileInfo, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_FILE, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    ManagedBuildTestHelper.removeProject(testName);
  }