Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,14 @@ public static void waitForCTabToAppear(SWTWorkbenchBot workbenchBot, String tabN
@Override
public boolean test() throws Exception
{
return workbenchBot.cTabItem(tabName).isActive();
try
{
return workbenchBot.cTabItem(tabName) != null;
}
catch (WidgetNotFoundException e)
{
return false;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ public static void setupEnv() throws Exception
bot = WorkBenchSWTBot.getBot();
EnvSetupOperations.setupEspressifEnv(bot);
ProjectTestOperations.deleteAllProjects(bot);
ProjectTestOperations.setupProjectWithReconfigureCommand(PROJECT_NAME, "EspressIf", "Espressif IDF Project", //$NON-NLS-1$ //$NON-NLS-2$
bot);
TestWidgetWaitUtility.waitForOperationsInProgressToFinishSync(bot);
ProjectTestOperations.setupProject(PROJECT_NAME, "EspressIf", "Espressif IDF Project", bot);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix category label typo ("EspressIf" → "Espressif").

This will fail to locate the wizard node and break project setup.

-        ProjectTestOperations.setupProject(PROJECT_NAME, "EspressIf", "Espressif IDF Project", bot);
+        ProjectTestOperations.setupProject(PROJECT_NAME, "Espressif", "Espressif IDF Project", bot);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ProjectTestOperations.setupProject(PROJECT_NAME, "EspressIf", "Espressif IDF Project", bot);
ProjectTestOperations.setupProject(PROJECT_NAME, "Espressif", "Espressif IDF Project", bot);
🤖 Prompt for AI Agents
In
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectLspCdtFunctionalityTest.java
around line 51, the wizard category label is misspelled as "EspressIf" causing
the wizard node lookup to fail; update the string literal to "Espressif" in the
ProjectTestOperations.setupProject(...) call so the correct category name is
used.

ProjectTestOperations.buildProjectUsingContextMenu(PROJECT_NAME, bot);
ProjectTestOperations.waitForProjectBuild(bot);
TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot);
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
*******************************************************************************/
package com.espressif.idf.ui.test.executable.cases.project;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
Expand All @@ -28,13 +27,11 @@
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;

import com.espressif.idf.core.IDFConstants;
import com.espressif.idf.core.util.IDFUtil;
import com.espressif.idf.ui.test.common.WorkBenchSWTBot;
import com.espressif.idf.ui.test.common.utility.TestWidgetWaitUtility;
import com.espressif.idf.ui.test.operations.EnvSetupOperations;
import com.espressif.idf.ui.test.operations.ProjectTestOperations;
import com.espressif.idf.ui.test.operations.selectors.LaunchBarConfigSelector;
import com.espressif.idf.ui.test.operations.selectors.LaunchBarTargetSelector;

/**
Expand Down Expand Up @@ -116,7 +113,8 @@ public void givenNewProjectIsCreatedThenTestClangFormatFileSettingsAreBeingAppli
}

@Test
public void givenNewProjectsAreCreatedAndBuiltWhenPreferencesOpenedThenClangdArgumentMatchesExpected() throws Exception
public void givenNewProjectsAreCreatedAndBuiltWhenPreferencesOpenedThenClangdArgumentMatchesExpected()
throws Exception
{
Fixture.givenNewProjectIsCreated("NewProjectClangFilesTest4");
Fixture.whenProjectIsBuiltUsingContextMenu("NewProjectClangFilesTest4");
Expand All @@ -127,7 +125,8 @@ public void givenNewProjectsAreCreatedAndBuiltWhenPreferencesOpenedThenClangdArg
}

@Test
public void givenNewProjectIsCreatedWhenBuiltThenClangdDriversUpdateOnTargetWhenChangeTargetAndBuiltThenClangdDriversUpdateOnTargetChange() throws Exception
public void givenNewProjectIsCreatedWhenBuiltThenClangdDriversUpdateOnTargetWhenChangeTargetAndBuiltThenClangdDriversUpdateOnTargetChange()
throws Exception
{
Fixture.givenNewProjectIsCreated("NewProjectClangFilesTest6");
Fixture.whenProjectIsBuiltUsingContextMenu("NewProjectClangFilesTest6");
Expand Down Expand Up @@ -186,7 +185,7 @@ private static void thenCheckClangdArgumentAfterProjectBuilt(String projectName)
Fixture.closePreferencesDialog();
}

private static void whenNewProjectIsSelected( String projectName) throws Exception
private static void whenNewProjectIsSelected(String projectName) throws Exception
{
ProjectTestOperations.setupProject(projectName, category, subCategory, bot);
TestWidgetWaitUtility.waitForOperationsInProgressToFinishSync(bot);
Expand Down Expand Up @@ -255,14 +254,17 @@ private static void whenClangFormatFileOpenedUsingDoubleClick() throws IOExcepti

private static String getExpectedBuildFolderPATH(String projectName) throws IOException
{
try {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
String buildFolder = IDFUtil.getBuildDir(project);
Path buildFolderPath = Paths.get(buildFolder);
return buildFolderPath.toAbsolutePath().toString();
} catch (CoreException e) {
throw new IOException("Failed to get build directory for project: " + projectName, e);
}
try
{
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
String buildFolder = IDFUtil.getBuildDir(project);
Path buildFolderPath = Paths.get(buildFolder);
return buildFolderPath.toAbsolutePath().toString();
}
catch (CoreException e)
{
throw new IOException("Failed to get build directory for project: " + projectName, e);
}
}

private static void thenClangdFileContentChecked() throws Exception
Expand Down Expand Up @@ -290,31 +292,32 @@ private static void thenClangFormatContentChecked() throws Exception
bot.cTabItem(".clang-format").activate();
assertTrue(ProjectTestOperations.checkExactMatchInTextEditor(
"""
# We'll use defaults from the LLVM style, but with some modifications so that it's close to the CDT K&R style.
BasedOnStyle: LLVM
UseTab: Always
IndentWidth: 4
TabWidth: 4
BreakConstructorInitializers: AfterColon
IndentAccessModifiers: false
AccessModifierOffset: -4
""",
# We'll use defaults from the LLVM style, but with some modifications so that it's close to the CDT K&R style.
BasedOnStyle: LLVM
UseTab: Always
IndentWidth: 4
TabWidth: 4
BreakConstructorInitializers: AfterColon
IndentAccessModifiers: false
AccessModifierOffset: -4
""",
bot));
}

private static void thenClangFormatContentEdited() throws Exception
{
SWTBotEditor textEditor = bot.activeEditor();
textEditor.toTextEditor().setText("""
# We'll use defaults from the LLVM style, but with some modifications so that it's close to the CDT K&R style.
BasedOnStyle: LLVM
UseTab: Always
IndentWidth: 0
TabWidth: 0
BreakConstructorInitializers: AfterColon
IndentAccessModifiers: false
AccessModifierOffset: -4
""");
textEditor.toTextEditor().setText(
"""
# We'll use defaults from the LLVM style, but with some modifications so that it's close to the CDT K&R style.
BasedOnStyle: LLVM
UseTab: Always
IndentWidth: 0
TabWidth: 0
BreakConstructorInitializers: AfterColon
IndentAccessModifiers: false
AccessModifierOffset: -4
""");
}

private static void addSpaceToMainFile() throws Exception
Expand Down Expand Up @@ -391,39 +394,43 @@ private static void thenMainFileShellClosed() throws IOException
bot.shell("Save Resource").bot().button("Save").click();
}

private static String getExpectedBuildFolderPATHforClangdAdditionalArgument(String projectName) throws IOException
private static String getExpectedBuildFolderPATHforClangdAdditionalArgument(String projectName)
throws IOException
{
try {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
String buildFolder = IDFUtil.getBuildDir(project);
Path buildFolderPath = Paths.get(buildFolder);
return "--compile-commands-dir=" + buildFolderPath.toAbsolutePath().toString();
} catch (CoreException e) {
throw new IOException("Failed to get build directory for project: " + projectName, e);
}
try
{
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
String buildFolder = IDFUtil.getBuildDir(project);
Path buildFolderPath = Paths.get(buildFolder);
return "--compile-commands-dir=" + buildFolderPath.toAbsolutePath().toString();
}
catch (CoreException e)
{
throw new IOException("Failed to get build directory for project: " + projectName, e);
}
}

private static String getXtensaToolchainPathBasedOnTheTargetConfigured() throws IOException
{
String toolchain = IDFUtil.getToolchainExePathForActiveTarget();
String toolchain = IDFUtil.getToolchainExePathForActiveTarget();
Path toolchainPath = Paths.get(toolchain);
return toolchainPath.toAbsolutePath().toString();
}

private static void thenCompareActualClangdArgumentWithExpected(String projectName) throws IOException
{
SWTBotShell prefrencesShell = bot.shell("Preferences");
String actualClangdPath = prefrencesShell.bot().textWithLabel("Additional").getText();
String expectedClangdPath = getExpectedBuildFolderPATHforClangdAdditionalArgument(projectName);
assertTrue(expectedClangdPath.equals(actualClangdPath));
{
SWTBotShell prefrencesShell = bot.shell("Preferences");
String actualClangdPath = prefrencesShell.bot().textWithLabel("Additional").getText();
String expectedClangdPath = getExpectedBuildFolderPATHforClangdAdditionalArgument(projectName);
assertTrue(expectedClangdPath.equals(actualClangdPath));
}

private static void thenCompareActualClangdDriversWithExpected(String projectName) throws IOException
{
SWTBotShell prefrencesShell = bot.shell("Preferences");
String actualClangdPath = prefrencesShell.bot().textWithLabel("Drivers").getText();
String expectedClangdPath = getXtensaToolchainPathBasedOnTheTargetConfigured();
assertTrue(expectedClangdPath.equals(actualClangdPath));
{
SWTBotShell prefrencesShell = bot.shell("Preferences");
String actualDriversPath = prefrencesShell.bot().textWithLabel("Drivers").getText();
String expectedDriversPath = "**";
assertEquals(expectedDriversPath, actualDriversPath);
}

private static void whenProjectIsBuiltUsingContextMenu(String projectName) throws IOException
Expand All @@ -444,17 +451,19 @@ private static void whenOpenClangdPreferences() throws Exception
prefrencesShell.bot().tree().getTreeItem("C/C++").getNode("Editor (LSP)").getNode("clangd").select();
}

private static void closePreferencesDialog() {
SWTBotShell preferencesShell = bot.shell("Preferences");
preferencesShell.bot().button("Cancel").click(); // Or "Apply and Close"
TestWidgetWaitUtility.waitWhileDialogIsVisible(bot, "Preferences", 10000);
private static void closePreferencesDialog()
{
SWTBotShell preferencesShell = bot.shell("Preferences");
preferencesShell.bot().button("Cancel").click(); // Or "Apply and Close"
TestWidgetWaitUtility.waitWhileDialogIsVisible(bot, "Preferences", 10000);
}

private static void closeTargetDialog() {
private static void closeTargetDialog()
{
TestWidgetWaitUtility.waitForDialogToAppear(bot, "IDF Launch Target Changed", 10000);
SWTBotShell preferencesShell = bot.shell("IDF Launch Target Changed");
preferencesShell.bot().button("Yes").click(); // Or "Apply and Close"
TestWidgetWaitUtility.waitWhileDialogIsVisible(bot, "IDF Launch Target Changed", 10000);
SWTBotShell preferencesShell = bot.shell("IDF Launch Target Changed");
preferencesShell.bot().button("Yes").click(); // Or "Apply and Close"
TestWidgetWaitUtility.waitWhileDialogIsVisible(bot, "IDF Launch Target Changed", 10000);
}

private static void cleanTestEnv()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,26 +172,26 @@ private static void whenProjectIsBuiltUsingContextMenu() throws IOException

private static void thenSDKconfigFileIsPresent() throws IOException
{
assertTrue(bot.tree().getTreeItem(projectName).getNode("sdkconfig") != null);
assertTrue("SDKconfig file was not found", bot.tree().getTreeItem(projectName).getNode("sdkconfig") != null);
}

private static void thenSDKconfigFileIsAbsent() throws IOException
{
assertTrue(!bot.tree().getTreeItem(projectName).getNodes().contains("sdkconfig"));
assertTrue("SDKconfig file is still present",!bot.tree().getTreeItem(projectName).getNodes().contains("sdkconfig"));
}

private static void whenSDKconfigFileOpenedUsingDoubleClick() throws IOException
{
bot.tree().getTreeItem(projectName).getNode("sdkconfig").doubleClick();
TestWidgetWaitUtility.waitWhileDialogIsVisible(bot, "Progress Information", 40000);
TestWidgetWaitUtility.waitForCTabToAppear(bot, "SDK Configuration (sdkconfig)", 5000);
TestWidgetWaitUtility.waitForCTabToAppear(bot, "SDK Configuration (sdkconfig)", 10000);
}

private static void whenSDKconfigFileOpenedUsingContextMenu() throws IOException
{
ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Menu Config");
TestWidgetWaitUtility.waitWhileDialogIsVisible(bot, "Progress Information", 40000);
TestWidgetWaitUtility.waitForCTabToAppear(bot, "SDK Configuration (sdkconfig)", 5000);
TestWidgetWaitUtility.waitForCTabToAppear(bot, "SDK Configuration (sdkconfig)", 10000);
}

private static void thenSDKconfigFileContentChecked() throws Exception
Expand All @@ -200,7 +200,7 @@ private static void thenSDKconfigFileContentChecked() throws Exception
TestWidgetWaitUtility.waitForTreeItem("Partition Table", bot.tree(1), bot);
bot.tree(1).getTreeItem("Partition Table").click();
bot.sleep(1000);
assertTrue(bot.textWithLabel("Offset of partition table (hex)").getText().matches("0x8000"));
assertTrue("'Offset of partition table (hex)' does not match '0x8000'", bot.textWithLabel("Offset of partition table (hex)").getText().matches("0x8000"));
}

private static void thenSDKconfigFileContentEdited() throws Exception
Expand All @@ -210,9 +210,9 @@ private static void thenSDKconfigFileContentEdited() throws Exception
bot.tree(1).getTreeItem("Partition Table").click();
bot.sleep(1000);
bot.textWithLabel("Offset of partition table (hex)").setText("0x4000");
bot.sleep(2000);
bot.sleep(1000);
bot.comboBoxWithLabel("Partition Table").setSelection("Custom partition table CSV");
bot.sleep(2000);
bot.sleep(1000);
bot.checkBox("Generate an MD5 checksum for the partition table").click();
}

Expand All @@ -225,8 +225,7 @@ private static void whenSDKconfigFileIsSaved() throws IOException
{
bot.cTabItem("*SDK Configuration (sdkconfig)").activate();
bot.cTabItem("*SDK Configuration (sdkconfig)").close();
bot.sleep(5000);
TestWidgetWaitUtility.waitForDialogToAppear(bot, "Save Resource", 5000);
TestWidgetWaitUtility.waitForDialogToAppear(bot, "Save Resource", 10000);
bot.shell("Save Resource").bot().button("Save").click();
}

Expand All @@ -235,12 +234,12 @@ private static void thenCheckChangesAreSaved() throws Exception
bot.cTabItem("SDK Configuration (sdkconfig)").activate();
TestWidgetWaitUtility.waitForTreeItem("Partition Table", bot.tree(1), bot);
bot.tree(1).getTreeItem("Partition Table").click();
bot.sleep(2000);
assertTrue(bot.textWithLabel("Offset of partition table (hex)").getText().matches("0x4000"));
bot.sleep(2000);
assertTrue(bot.comboBoxWithLabel("Partition Table").selection().equals("Custom partition table CSV"));
bot.sleep(2000);
assertTrue(!bot.checkBox("Generate an MD5 checksum for the partition table").isChecked());
bot.sleep(1000);
assertTrue("'Offset of partition table (hex)' does not match '0x4000'", bot.textWithLabel("Offset of partition table (hex)").getText().matches("0x4000"));
bot.sleep(1000);
assertTrue("'Partition Table' does not match 'Custom partition table CSV'", bot.comboBoxWithLabel("Partition Table").selection().equals("Custom partition table CSV"));
bot.sleep(1000);
assertTrue("'Generate an MD5 checksum for the partition table' checkbox is still checked!", !bot.checkBox("Generate an MD5 checksum for the partition table").isChecked());
}

private static void cleanTestEnv()
Expand Down
Loading