From d394002b07fdddb739c80ccbd6089241f2a27b04 Mon Sep 17 00:00:00 2001 From: Andrii Date: Mon, 1 Jul 2024 13:39:18 +0200 Subject: [PATCH] ci: added Partition Table Editor tests ci: added methods to prevent potential memory leak ci: increase memory for GUI tests ci: improved Regex method to cover special symbols cases ci: removed viewClose method --- ...sifIDFProjectPartitionTableEditorTest.java | 243 ++++++++++++++++++ .../project/NewEspressifIDFProjectTest.java | 12 +- .../test/operations/EnvSetupOperations.java | 13 +- .../operations/ProjectTestOperations.java | 73 +++++- tests/pom.xml | 2 +- 5 files changed, 311 insertions(+), 32 deletions(-) create mode 100644 tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java diff --git a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java new file mode 100644 index 000000000..d07aec10b --- /dev/null +++ b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java @@ -0,0 +1,243 @@ +/******************************************************************************* + * Copyright 2021 Espressif Systems (Shanghai) PTE LTD. All rights reserved. + * Use is subject to license terms. + *******************************************************************************/ +package com.espressif.idf.ui.test.executable.cases.project; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +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.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 test the SBOM feature + * + * @author Andrii Filippov + * + */ +@SuppressWarnings("restriction") +@RunWith(SWTBotJunit4ClassRunner.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class NewEspressifIDFProjectPartitionTableEditorTest +{ + @BeforeClass + public static void beforeTestClass() throws Exception + { + Fixture.loadEnv(); + } + + @After + public void afterEachTest() + { + try + { + Fixture.cleanTestEnv(); // Make sure test environment is always cleaned up + } + catch (Exception e) + { + System.err.println("Error during cleanup: " + e.getMessage()); + } + } + + @Test + public void givenNewProjectCreatedNotBuiltWhenOpenEmptyPartitionTableEditorThenInformationPopUpMessage() + throws Exception + { + Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); + Fixture.givenProjectNameIs("NewProjectPartitionTableEditor1Test"); + Fixture.whenNewProjectIsSelected(); + Fixture.whenOpenEmptyPartitionTableEditor(); + Fixture.ThenInformationMessagePopUp(); + } + + @Test + public void givenNewProjectCreatedBuiltWhenOpenPartitionTableEditorThenBuiltInPartitionTableDisplayed() + throws Exception + { + Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); + Fixture.givenProjectNameIs("NewProjectPartitionTableEditor2Test"); + Fixture.whenNewProjectIsSelected(); + Fixture.whenProjectIsBuiltUsingContextMenu(); + Fixture.whenOpenPartitionTableEditor(); + Fixture.ThenBuiltInPartitionTableDisplayed(); + } + + @Test + public void givenNewProjectCreatedBuiltWhenOpenPartitionTableEditorWhenAddRowThenCheckRowAdded() throws Exception + { + Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); + Fixture.givenProjectNameIs("NewProjectPartitionTableEditor3Test"); + Fixture.whenNewProjectIsSelected(); + Fixture.whenProjectIsBuiltUsingContextMenu(); + Fixture.whenOpenPartitionTableEditor(); + Fixture.whenAddRowToPartitionTable(); + Fixture.ThenCheckRowAdded(); + } + + @Test + public void givenNewProjectCreatedBuiltWhenOpenPartitionTableEditorWhenDeleteSelectedRowThenCheckRowDeleted() + throws Exception + { + Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); + Fixture.givenProjectNameIs("NewProjectPartitionTableEditor4Test"); + Fixture.whenNewProjectIsSelected(); + Fixture.whenProjectIsBuiltUsingContextMenu(); + Fixture.whenOpenPartitionTableEditor(); + Fixture.whenDeleteRowFromPartitionTable(); + Fixture.ThenCheckRowDeleted(); + } + + @Test + public void givenNewProjectCreatedBuiltWhenOpenPartitionTableEditorWhenDeleteSelectedRowWhenSaveAndQuitwhenReopenPartitionTableThenCheckChangesSaved() + throws Exception + { + Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); + Fixture.givenProjectNameIs("NewProjectPartitionTableEditor5Test"); + Fixture.whenNewProjectIsSelected(); + Fixture.whenProjectIsBuiltUsingContextMenu(); + Fixture.whenOpenPartitionTableEditor(); + Fixture.whenDeleteRowFromPartitionTable(); + Fixture.whenSaveAndQuit(); + Fixture.whenOpenPartitionTableEditor(); + Fixture.thenCheckChangesSaved(); + } + + @Test + public void givenNewProjectCreatedBuiltWhenOpenPartitionTableEditorWhenDeleteSelectedRowWhenSaveAndCancelwhenReopenPartitionTableThenCheckChangesSaved() + throws Exception + { + Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); + Fixture.givenProjectNameIs("NewProjectPartitionTableEditor6Test"); + Fixture.whenNewProjectIsSelected(); + Fixture.whenProjectIsBuiltUsingContextMenu(); + Fixture.whenOpenPartitionTableEditor(); + Fixture.whenDeleteRowFromPartitionTable(); + Fixture.whenSavePartitionTable(); + Fixture.whenCancel(); + Fixture.whenOpenPartitionTableEditor(); + Fixture.thenCheckChangesSaved(); + } + + private static class Fixture + { + private static SWTWorkbenchBot bot; + private static String category; + private static String subCategory; + private static String projectName; + + private static void loadEnv() throws Exception + { + bot = WorkBenchSWTBot.getBot(); + EnvSetupOperations.setupEspressifEnv(bot); + bot.sleep(1000); + } + + private static void givenNewEspressifIDFProjectIsSelected(String category, String subCategory) + { + Fixture.category = category; + Fixture.subCategory = subCategory; + } + + private static void givenProjectNameIs(String projectName) + { + Fixture.projectName = projectName; + } + + private static void whenNewProjectIsSelected() throws Exception + { + ProjectTestOperations.setupProject(projectName, category, subCategory, bot); + } + + private static void whenProjectIsBuiltUsingContextMenu() throws IOException + { + ProjectTestOperations.buildProjectUsingContextMenu(projectName, bot); + ProjectTestOperations.waitForProjectBuild(bot); + TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot); + } + + private static void whenOpenPartitionTableEditor() throws IOException + { + ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Partition Table Editor"); + TestWidgetWaitUtility.waitUntilDialogIsNotVisible(bot, "Partition Table Editor", 10000); + } + + private static void whenOpenEmptyPartitionTableEditor() throws IOException + { + ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Partition Table Editor"); + TestWidgetWaitUtility.waitUntilDialogIsNotVisible(bot, "Information", 10000); + } + + private static void ThenInformationMessagePopUp() throws IOException + { + assertTrue(ProjectTestOperations.checkShellContent(bot, "Information", + "Failed to get partition CSV file name from sdkconfig. Make sure your project is compiled and has sdkconfig.")); + } + + private static void ThenBuiltInPartitionTableDisplayed() throws IOException + { + assertTrue(ProjectTestOperations.checkPartitionTableContent(bot)); + } + + private static void whenAddRowToPartitionTable() throws IOException + { + bot.toolbarButton("Add Row").click(); + } + + private static void ThenCheckRowAdded() throws IOException + { + assertTrue(ProjectTestOperations.comparePartitionTableRows(bot, 1)); + } + + private static void whenDeleteRowFromPartitionTable() throws IOException + { + ProjectTestOperations.deletePartitionTableRow(bot); + } + + private static void ThenCheckRowDeleted() throws IOException + { + assertTrue(ProjectTestOperations.comparePartitionTableRows(bot, -1)); + } + + private static void whenSaveAndQuit() throws IOException + { + bot.button("Save and Quit").click(); + bot.button("OK").click(); + } + + private static void whenSavePartitionTable() throws IOException + { + bot.toolbarButton("Save").click(); + bot.button("OK").click(); + } + + private static void whenCancel() throws IOException + { + bot.button("Cancel").click(); + } + + private static void thenCheckChangesSaved() throws IOException + { + assertTrue(ProjectTestOperations.comparePartitionTableRows(bot, -1)); + } + + private static void cleanTestEnv() + { + TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot); + ProjectTestOperations.closeAllProjects(bot); + ProjectTestOperations.deleteAllProjects(bot); + } + } +} diff --git a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectTest.java b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectTest.java index e839225ea..e23c76aaa 100644 --- a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectTest.java +++ b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectTest.java @@ -71,7 +71,6 @@ public void givenNewIDFProjectIsSelectedThenProjectIsCreatedAndAddedToProjectExp Fixture.givenProjectNameIs("NewProjectTest"); Fixture.whenNewProjectIsSelected(); Fixture.thenProjectIsAddedToProjectExplorer(); - } @Test @@ -270,7 +269,7 @@ private static void whenProjectIsBuiltUsingContextMenu() throws IOException private static void whenInstallNewComponentUsingContextMenu() throws IOException { - ProjectTestOperations.openProjectNewComponentUsingContextMenu(projectName, bot); + ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Install New Component"); bot.editorByTitle(projectName).show(); bot.button("Install").click(); ProjectTestOperations.waitForProjectNewComponentInstalled(bot); @@ -335,13 +334,10 @@ private static void thenFileContentsMatchDefaultFile(String path, String fileNam } } - private static void thenConsoleShowsBuildSuccessful() + private static void thenConsoleShowsBuildSuccessful() throws IOException { - SWTBotView consoleView = ProjectTestOperations.viewConsole("CDT Build Console", bot); - consoleView.show(); - consoleView.setFocus(); - String consoleTextString = consoleView.bot().styledText().getText(); - assertTrue(consoleTextString.contains("Build complete (0 errors")); + ProjectTestOperations.findInConsole(bot, "CDT Build Console [" + Fixture.projectName + "]", + "Build complete (0 errors"); } private static void cleanTestEnv() diff --git a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/EnvSetupOperations.java b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/EnvSetupOperations.java index acccb6d56..27b673659 100644 --- a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/EnvSetupOperations.java +++ b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/EnvSetupOperations.java @@ -4,10 +4,8 @@ import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; -import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; -import com.espressif.idf.core.util.IDFUtil; import com.espressif.idf.ui.test.common.configs.DefaultPropertyFetcher; import com.espressif.idf.ui.test.common.utility.TestWidgetWaitUtility; @@ -47,15 +45,6 @@ public static void setupEspressifEnv(SWTWorkbenchBot bot) throws Exception { prefrencesShell.bot().checkBox("Refresh using native hooks or polling").click(); } - - prefrencesShell.bot().tree().getTreeItem("C/C++").select(); - prefrencesShell.bot().tree().getTreeItem("C/C++").expand(); - prefrencesShell.bot().tree().getTreeItem("C/C++").getNode("Indexer").select(); - if (prefrencesShell.bot().checkBox("Enable indexer").isChecked()) - { - prefrencesShell.bot().checkBox("Enable indexer").click(); - } - prefrencesShell.bot().button("Apply and Close").click(); bot.toolbarButtonWithTooltip("Select and deselect filters to apply to the content in the tree").click(); @@ -88,6 +77,8 @@ public static void setupEspressifEnv(SWTWorkbenchBot bot) throws Exception consoleView.show(); consoleView.setFocus(); TestWidgetWaitUtility.waitUntilViewContains(bot, "Tools Activated", consoleView, 99000000); + bot.cTabItem("ESP-IDF Manager").activate(); + bot.cTabItem("ESP-IDF Manager").close(); SETUP = true; } diff --git a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java index aeaa28934..5a9356335 100644 --- a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java +++ b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java @@ -9,6 +9,7 @@ import java.text.MessageFormat; import java.util.Arrays; import java.util.Optional; +import java.util.regex.Pattern; import java.util.stream.Stream; import org.eclipse.core.resources.IResource; @@ -24,8 +25,10 @@ import org.eclipse.swtbot.swt.finder.waits.DefaultCondition; import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton; import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotLabel; import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarDropDownButton; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; @@ -83,7 +86,9 @@ public static void waitForProjectBuild(SWTWorkbenchBot bot) throws IOException consoleView.show(); consoleView.setFocus(); TestWidgetWaitUtility.waitUntilViewContains(bot, "Build complete", consoleView, - DefaultPropertyFetcher.getLongPropertyValue(DEFAULT_PROJECT_BUILD_WAIT_PROPERTY, 600000)); + DefaultPropertyFetcher.getLongPropertyValue(DEFAULT_PROJECT_BUILD_WAIT_PROPERTY, 300000)); + bot.cTabItem("README.md").activate(); + bot.cTabItem("README.md").close(); } public static void waitForProjectNewComponentInstalled(SWTWorkbenchBot bot) throws IOException @@ -100,7 +105,8 @@ public static SWTBotView viewConsole(String consoleType, SWTWorkbenchBot bot) SWTBotView view = bot.viewByPartName("Console"); view.setFocus(); SWTBotToolbarDropDownButton b = view.toolbarDropDownButton("Display Selected Console"); - org.hamcrest.Matcher withRegex = WidgetMatcherFactory.withRegex(".*" + consoleType + ".*"); + String regex = ".*" + Pattern.quote(consoleType) + "( \\[.*\\])?.*"; + org.hamcrest.Matcher withRegex = WidgetMatcherFactory.withRegex(regex); b.menuItem(withRegex).click(); view.setFocus(); return view; @@ -247,16 +253,6 @@ public static boolean checkTextEditorContentForPhrase(String phrase, SWTWorkbenc return editorText.contains(phrase); } - public static void openProjectNewComponentUsingContextMenu(String projectName, SWTWorkbenchBot bot) - { - SWTBotTreeItem projectItem = fetchProjectFromProjectExplorer(projectName, bot); - if (projectItem != null) - { - projectItem.select(); - projectItem.contextMenu("Install New Component").click(); - } - } - /** * Creates an espressif idf project from the template * @@ -586,6 +582,59 @@ public static void findInConsole(SWTWorkbenchBot bot, String consoleName, String TestWidgetWaitUtility.waitUntilViewContains(bot, findText, consoleView, 3000); } + public static boolean checkShellContent(SWTWorkbenchBot bot, String shellName, String expectedText) + { + SWTBotShell shell = bot.shell(shellName); + shell.activate(); + SWTBotLabel label = bot.label(expectedText); + String actualText = label.getText(); + return expectedText.equals(actualText); + } + + public static boolean checkPartitionTableContent(SWTWorkbenchBot bot) + { + String[] builtInPartitionArray = { "nvs", "phy_init", "factory", "data", "data", "app", "nvs", "phy", "factory", + "0x9000", "0xf000", "0x10000", "0x6000", "0x1000", "1M", "", "", "" }; + int builtInIndex = 0; + SWTBotTable table = bot.table(); + int columns = table.columnCount(); + int rows = table.rowCount(); + if (columns != 6 && rows != 3) + { + return false; + } + for (int col = 0; col < columns; col++) + { + for (int row = 0; row < rows; row++) + { + String tableContent = table.cell(row, col); + + if (!builtInPartitionArray[builtInIndex].equals(tableContent)) + { + return false; + } + builtInIndex++; + } + } + return true; + } + + public static boolean comparePartitionTableRows(SWTWorkbenchBot bot, int expectedDifference) throws IOException + { + SWTBotTable table = bot.table(); + int defaultRows = 3; + int actualRows = table.rowCount(); + return (actualRows - defaultRows) == expectedDifference; + } + + public static void deletePartitionTableRow(SWTWorkbenchBot bot) throws IOException + { + SWTBotTable table = bot.table(); + table.select(1); + bot.toolbarButton("Delete Selected").click(); + bot.button("OK").click(); + } + public static void joinJobByName(String jobName) { Job[] jobs = Job.getJobManager().find(null); diff --git a/tests/pom.xml b/tests/pom.xml index c2c3caba5..965e0deaa 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -30,7 +30,7 @@ false org.eclipse.ui.ide.workbench - -Xms2048m -Xmx4096m + -Xms4096m -Xmx8192m ${skipTests} true ${testWorkspace}