Skip to content
Open
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
@@ -0,0 +1,172 @@
package com.espressif.idf.ui.test.executable.cases.project;

import static org.junit.Assert.assertTrue;

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

import org.apache.commons.lang3.SystemUtils;
import org.eclipse.core.runtime.IPath;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
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;

/**
* Test class to verify tools installation
*
* @author Andrii Filippov
*
*/
@SuppressWarnings("restriction")
@RunWith(SWTBotJunit4ClassRunner.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class IDFProjectToolsInstallationTest {
@BeforeClass
public static void beforeTestClass() throws Exception {
Fixture.loadEnv();
}

@After
public void afterEachTest() {
Fixture.cleanTestEnv();
}

@Test
public void givenNewEnvironmentWhenOpenSbomThenSbomIsDisabled() throws Exception {
Fixture.openPreferencesBuildEnvVariables();
Fixture.verifyToolsPaths();
}

private static class Fixture {
private static SWTWorkbenchBot bot;

private static void loadEnv() throws Exception {
bot = WorkBenchSWTBot.getBot();
EnvSetupOperations.setupEspressifEnv(bot);
bot.sleep(1000);
}

private static void cleanTestEnv() {
TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot);
ProjectTestOperations.closeAllProjects(bot);
ProjectTestOperations.deleteAllProjects(bot);
}

private static void openPreferencesBuildEnvVariables() throws Exception {
bot.menu("Window").menu("Preferences...").click();
SWTBotShell preferencesShell = bot.shell("Preferences");
preferencesShell.bot().tree().getTreeItem("C/C++").select();
preferencesShell.bot().tree().getTreeItem("C/C++").expand();
preferencesShell.bot().tree().getTreeItem("C/C++").getNode("Build").select();
preferencesShell.bot().tree().getTreeItem("C/C++").getNode("Build").expand();
preferencesShell.bot().tree().getTreeItem("C/C++").getNode("Build").getNode("Environment").select();
}

private static void verifyToolsPaths() {
idfToolsPath();
closeDialog();
idfPath();
closeDialog();
openOCDScripts();
closeDialog();
idfPythonEnvPath();
closeDialog();
pythonExePath();
closeDialog();
cmakeAndNinjaPath();
closeDialog();
}

private static void idfToolsPath() {
bot.table().select("IDF_TOOLS_PATH");
bot.table().getTableItem("IDF_TOOLS_PATH").doubleClick();
TestWidgetWaitUtility.waitForDialogToAppear(bot, "Edit variable", 5000);

Path idfToolsPath = Paths.get(System.getProperty("user.home"), ".espressif", IDFConstants.TOOLS_FOLDER);
String actualPath = bot.textWithLabel("Value:").getText();
assertTrue("IDF_TOOLS_PATH mismatch", actualPath.equals(idfToolsPath.toString()));
}

private static void idfPath() {
bot.table().select("IDF_PATH");
bot.table().getTableItem("IDF_PATH").doubleClick();
TestWidgetWaitUtility.waitForDialogToAppear(bot, "Edit variable", 5000);

Path idfPath = Paths.get(IDFUtil.getIDFPath());
String actualPath = bot.textWithLabel("Value:").getText();
assertTrue("IDF_PATH mismatch", actualPath.equals(idfPath.toString()));
}

private static void openOCDScripts() {
bot.table().select("OPENOCD_SCRIPTS");
bot.table().getTableItem("OPENOCD_SCRIPTS").doubleClick();
TestWidgetWaitUtility.waitForDialogToAppear(bot, "Edit variable", 5000);

String actualPath = bot.textWithLabel("Value:").getText();
String home = System.getProperty("user.home").replace("\\", "/");
String pattern = "glob:" + home + "/.espressif/" + IDFConstants.TOOLS_FOLDER
+ "/openocd-esp32/*/openocd-esp32/share/openocd/scripts";

PathMatcher matcher = FileSystems.getDefault().getPathMatcher(pattern);
assertTrue("OPENOCD_SCRIPTS mismatch", matcher.matches(Paths.get(actualPath)));
}

private static void idfPythonEnvPath() {
bot.table().select("IDF_PYTHON_ENV_PATH");
bot.table().getTableItem("IDF_PYTHON_ENV_PATH").doubleClick();
TestWidgetWaitUtility.waitForDialogToAppear(bot, "Edit variable", 5000);

String actualPath = bot.textWithLabel("Value:").getText();
String home = System.getProperty("user.home").replace("\\", "/");
String pattern = "glob:" + home + "/.espressif/" + IDFConstants.TOOLS_FOLDER + "/python/*/venv";

PathMatcher matcher = FileSystems.getDefault().getPathMatcher(pattern);
assertTrue("IDF_PYTHON_ENV_PATH mismatch", matcher.matches(Paths.get(actualPath)));
}

private static void pythonExePath() {
bot.table().select("PYTHON_EXE_PATH");
bot.table().getTableItem("PYTHON_EXE_PATH").doubleClick();
TestWidgetWaitUtility.waitForDialogToAppear(bot, "Edit variable", 5000);

String actualPath = bot.textWithLabel("Value:").getText();
String home = System.getProperty("user.home").replace("\\", "/");
String pattern = "glob:" + home + "/.espressif/" + IDFConstants.TOOLS_FOLDER + "/python/*/venv/bin/python";

PathMatcher matcher = FileSystems.getDefault().getPathMatcher(pattern);
assertTrue("PYTHON_EXE_PATH mismatch", matcher.matches(Paths.get(actualPath)));
}

private static void cmakeAndNinjaPath() {
bot.table().select("PATH");
bot.table().getTableItem("PATH").doubleClick();
TestWidgetWaitUtility.waitForDialogToAppear(bot, "Edit variable", 5000);

String actualPath = bot.textWithLabel("Value:").getText();
assertTrue("cmake not found in the PATH", actualPath.contains("cmake"));
assertTrue("ninja not found in the PATH", actualPath.contains("ninja"));
}

private static void closeDialog() {
bot.button("OK").click();
}
}
}
6 changes: 4 additions & 2 deletions tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<useUIHarness>true</useUIHarness>
<useUIThread>false</useUIThread>
<application>org.eclipse.ui.ide.workbench</application>
<useUIHarness>true</useUIHarness>
<useUIThread>true</useUIThread>

<product>org.eclipse.platform.ide</product>
<!-- Debugging helper arguments -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=0.0.0.0:8989 -->
<argLine>-Xms4096m -Xmx8192m -DtestRun=true</argLine>
<skipTests>${skipTests}</skipTests>
Expand Down
Loading