Skip to content

Commit

Permalink
feat: support GUI unit test
Browse files Browse the repository at this point in the history
- refacotr main gui classes to allow GUI test
    - MainWindowMenuHandler class inherited from BaseMenuHanlder
      abstract class
    - Tester should implement MenuHandler class for test inherited
      from BaseMenuHandler class
- Add testGui configuration on gradle
- Set gui test source under test/gui
- Introduce TestCoreGUI class
- Add BasicMenuItemTest
- test new project creation
- refactor: ProjectPropertiesDialog
	- Split looong-method into smaller one
	- Give component name
- refactor: extend IMainMenu interface
- refactor: MainWindowUI class
- refactor: MainWindow class
- refactor: MainWindowStatusBar class as 1st citizen class in o.o.gui.main package
- fix: do not assume MainWindow class as JFrame object but always use MainWindow#getApplicationFrame
- refactor: deprecate MainWindowUI class functions
- refactor: add IMainWindow#resetDesktopLayout interface
- chore: add task testAcceptance in gradle
- chore: testAcceptance task on java17
- chore: testAcceptance task with xvfb-run
- refactor: testAcceptance
	- Update core can be called from acceptance test class
	- Update TestCoreInitializer to call a part of core
	- Initialize main window docking style

feat: test with sample project

- refactor: Introduce IProjectFilesList
	- Move projWin object in Core
	- Initialize projWin in Core#initializeGUI
	- MainWindowMenuHandler handle projWin through IProjectFilesList
- feat: test glossary creation operation
	- fix: fix modules initialization
	- These modules initialize Swing GUI parts in static context. It can be error on non-GUI environment and test environment.
	- This fix changes these are initialized in application start event handler.
	- feat: load all plugins
	- test: check glossary search expectation
	- test: explain expected behavior in comment
- refactor: update TestMainWindowMenuHandler
	- Add more actions
	- Extend IMainWindow#addSearchWindow and IMainWindow#getSearchWindows
	- Move internal TestMainWindow class as regular class
	- refactor ProjectUICommands.doRecycleTrans and ProjectUICommands.doInsertTrans
- refactor: give ProjectPropertiesDialog UI names

Signed-off-by: Hiroshi Miura <miurahr@linux.com>
  • Loading branch information
miurahr committed May 24, 2024
1 parent 0a6a861 commit f5abb6a
Show file tree
Hide file tree
Showing 27 changed files with 1,093 additions and 570 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle-build-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
name: Setup Gradle
id: setup-gradle
- name: Run gradle build
run: xvfb-run -a --server-args='-screen 0, 1024x768x24' ./gradlew -PenvIsCi --scan build
run: xvfb-run -a --server-args='-screen 0, 1024x768x24' ./gradlew -PenvIsCi --scan build testAcceptance
id: gradle
- name: "Add Build Scan URL as PR comment"
uses: actions/github-script@v7
Expand Down
4 changes: 2 additions & 2 deletions src/org/omegat/convert/ConvertConfigs.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.io.File;

import org.omegat.convert.v20to21.Convert20to21;
import org.omegat.gui.main.MainWindowUI;
import org.omegat.gui.main.MainWindow;
import org.omegat.util.Log;
import org.omegat.util.StaticUtils;

Expand All @@ -53,7 +53,7 @@ public static void convert() {
}
}

File newUI = new File(StaticUtils.getConfigDir(), MainWindowUI.UI_LAYOUT_FILE);
File newUI = new File(StaticUtils.getConfigDir(), MainWindow.UI_LAYOUT_FILE);
if (!newUI.exists()) {
try {
ConvertTo213.convertUIConfig(newUI);
Expand Down
46 changes: 30 additions & 16 deletions src/org/omegat/core/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,12 @@ public static void setSegmenter(Segmenter newSegmenter) {
* <p>
* An interface that was introduced in v5.6.0 when supporting theme plugin.
*
* @param cl class loader.
* @param params CLI parameters.
* @throws Exception when error occurred.
* @param cl
* class loader.
* @param params
* CLI parameters.
* @throws Exception
* when error occurred.
*/
@Deprecated(since = "6.1.0")
@SuppressWarnings("unused")
Expand All @@ -252,14 +255,29 @@ public static void initializeGUI(final Map<String, String> params) throws Except
// 3. Initialize application frame
MainWindow me = new MainWindow();
mainWindow = me;
initializeGUIimpl(me);

SaveThread th = new SaveThread();
saveThread = th;
th.start();

new VersionCheckThread(10).start();
}

/**
* initialize GUI for test.
*
* @throws Exception
*/
static void initializeGUIimpl(IMainWindow me) throws Exception {
MarkerController.init();
LanguageToolWrapper.init();

segmenter = new Segmenter(Preferences.getSRX());
filterMaster = new FilterMaster(Preferences.getFilters());

// 4. Initialize other components. They add themselves to the main window.
// 4. Initialize other components.
// They add themselves to the main window.
editor = new EditorController(me);
tagValidation = new TagValidationTool();
issuesWindow = new IssuesPanelController(me.getApplicationFrame());
Expand All @@ -274,12 +292,6 @@ public static void initializeGUI(final Map<String, String> params) throws Except
multiple = new MultipleTransPane(me);
new SegmentPropertiesArea(me);
projWin = new ProjectFilesListController();

SaveThread th = new SaveThread();
saveThread = th;
th.start();

new VersionCheckThread(10).start();
}

/**
Expand Down Expand Up @@ -346,7 +358,9 @@ public static void registerTokenizerClass(Class<? extends ITokenizer> clazz) {

/**
* Register spellchecker plugin.
* @param clazz spellchecker class.
*
* @param clazz
* spellchecker class.
*/
public static void registerSpellCheckClass(Class<? extends ISpellChecker> clazz) {
PluginUtils.getSpellCheckClasses().add(clazz);
Expand All @@ -369,18 +383,18 @@ public static void pluginLoadingError(String errorText) {
/**
* Use this to perform operations that must not be run concurrently.
* <p>
* For instance project load/save/compile/autosave operations must not be executed in parallel because it will break
* project files, especially during team synchronization. For guaranteed non-parallel execution, all such operations
* must be executed via this method.
* For instance project load/save/compile/autosave operations must not be
* executed in parallel because it will break project files, especially
* during team synchronization. For guaranteed non-parallel execution, all
* such operations must be executed via this method.
*
* @param waitForUnlock
* should execution wait for unlock 3 minutes
* @param run
* code for execute
* @throws Exception
*/
public static void executeExclusively(boolean waitForUnlock, RunnableWithException run)
throws Exception {
public static void executeExclusively(boolean waitForUnlock, RunnableWithException run) throws Exception {
if (!EXCLUSIVE_RUN_LOCK.tryLock(waitForUnlock ? 180000 : 1, TimeUnit.MILLISECONDS)) {
Exception ex = new TimeoutException("Timeout waiting for previous exclusive execution");
Exception cause = new Exception("Previous exclusive execution");
Expand Down
2 changes: 1 addition & 1 deletion src/org/omegat/core/data/RealProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ private void loadSourceFiles() throws IOException {

findNonUniqueSegments();

if (errorSrcList.size() > 0) {
if (!errorSrcList.isEmpty()) {
Core.getMainWindow().showStatusMessageRB("CT_LOAD_SRC_SKIP_FILES");
} else {
Core.getMainWindow().showStatusMessageRB("CT_LOAD_SRC_COMPLETE");
Expand Down
1 change: 1 addition & 0 deletions src/org/omegat/gui/dialogs/AboutDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import javax.swing.JDialog;

import org.apache.commons.io.IOUtils;

import org.omegat.help.Help;
import org.omegat.util.MemoryUtils;
import org.omegat.util.OConsts;
Expand Down
3 changes: 2 additions & 1 deletion src/org/omegat/gui/dialogs/LicenseDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
import java.nio.charset.StandardCharsets;

import org.apache.commons.io.IOUtils;
import org.openide.awt.Mnemonics;

import org.omegat.help.Help;
import org.omegat.util.OConsts;
import org.omegat.util.OStrings;
import org.omegat.util.gui.StaticUIUtils;
import org.openide.awt.Mnemonics;

/**
* Dialog showing GNU Public License.
Expand Down
Loading

0 comments on commit f5abb6a

Please sign in to comment.