From dbd04beee47be2d86275cc53a52b5cf035ff3a50 Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Fri, 6 Oct 2023 16:17:09 -0500 Subject: [PATCH] Reimplemented the Trick View Test Suite --- .../test/java/trick/tv/TVApplicationTest.java | 92 +++++++++++++++++++ .../java/trick/tv/WaitForTVApplication.java | 50 ++++++++++ 2 files changed, 142 insertions(+) create mode 100644 trick_source/java/src/test/java/trick/tv/TVApplicationTest.java create mode 100644 trick_source/java/src/test/java/trick/tv/WaitForTVApplication.java diff --git a/trick_source/java/src/test/java/trick/tv/TVApplicationTest.java b/trick_source/java/src/test/java/trick/tv/TVApplicationTest.java new file mode 100644 index 00000000..d113078d --- /dev/null +++ b/trick_source/java/src/test/java/trick/tv/TVApplicationTest.java @@ -0,0 +1,92 @@ +package trick.tv; + +import static org.junit.Assert.assertTrue; + +import org.jdesktop.application.Application; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import trick.common.CheckApplicationProperties; + +/** + * + * Test TVApplication life cycle. + * + * @author hchen + * + */ +public class TVApplicationTest { + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + WaitForTVApplication.launchAndWait(WaitForTVApplication.class); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testReady() { + assertTrue("TVApplicationTest is not ready yet!", application().isReady()); + } + + /** + * Verify that all implemented actions exist as well as their text, shortDescription properties. + */ + /*@Test + public void testDefinedActions() { + String[] actionNames = {"newSession", "openSession", "openAndSet", "set", "saveSession", "startMonitoring", + "stopMonitoring", "stripchartSelection", "removeSelection", "addVariablesFromTree", + "addVariablesFromList", "purgeBadRefs", "commitVariableAddition"}; + String[] actionTexts = {"New", "Open", "Open & Set", "Set", "Save", "Start the Monitor", "Stop the Monitor", + "Stripchart Selection", "Remove Selection", "Add Selection", "Add Selection", + "Purge BAD_REFs", "Ok"}; + String[] actionShortDescriptions = {"Clear the variable table.", "Replace the variable table with a TV input file without setting the values.", + "Replace the variable table with a TV input file and set each value.", + "Set the variable values from a TV input file without changing the variable table.", + "Save the variable table to a TV input file.", + "Start updating variable values.", "Stop updating variable values.", + "Stripchart the selected variables.", "Delete the selected rows.", + "Begin watching the selected variables.", "Begin watching the selected variables.", + "Remove all variables that failed to resolve.", "Commit the variable additions."}; + for (int i = 0; i < actionNames.length; i++) { + CheckApplicationProperties.checkAction(application().actionMap, actionNames[i]); + CheckApplicationProperties.checkActionText(application().actionMap, actionNames[i], actionTexts[i]); + CheckApplicationProperties.checkActionShortDescription(application().actionMap, actionNames[i], actionShortDescriptions[i]); + } + }*/ + + @Test + public void testDefinedKeyText() { + CheckApplicationProperties.checkKeyText(application().resourceMap, "fileMenu.text", "&File"); + /*CheckApplicationProperties.checkKeyText(application().resourceMap, "actionsMenu.text", "&Actions"); + CheckApplicationProperties.checkKeyText(application().resourceMap, "preferencesMenu.text", "&Preferences"); + CheckApplicationProperties.checkKeyText(application().resourceMap, "notifyOnDisconnectCheckBoxMenuItem.text", "Not&ify on Disconnect"); + CheckApplicationProperties.checkKeyText(application().resourceMap, "caseInsensitiveCheckBox.text", "Case Insensitive"); + CheckApplicationProperties.checkKeyText(application().resourceMap, "containsRadioButton.text", "Contains"); + CheckApplicationProperties.checkKeyText(application().resourceMap, "regularExpressionRadioButton.text", "RegEx");*/ + } + + @Test + public void testExit() { + application().removeExitListener(application().exitListener); + application().exit(); + assertTrue(application().isEnded); + } + + private static WaitForTVApplication application() { + return Application.getInstance(WaitForTVApplication.class); + } +} \ No newline at end of file diff --git a/trick_source/java/src/test/java/trick/tv/WaitForTVApplication.java b/trick_source/java/src/test/java/trick/tv/WaitForTVApplication.java new file mode 100644 index 00000000..260d229e --- /dev/null +++ b/trick_source/java/src/test/java/trick/tv/WaitForTVApplication.java @@ -0,0 +1,50 @@ +package trick.tv; + + +import org.jdesktop.application.Application; + + +public class WaitForTVApplication extends TVApplication { + static Object lock = new Object(); + + boolean isEnded; + + @Override + protected void end() { + isEnded = true; + } + + @Override + protected void ready() { + super.ready(); + synchronized(lock) { + lock.notifyAll(); + } + } + + + /** + * Launch the specified subclsas of TVApplication and block + * (wait) until it's startup() method has run. + */ + public static void launchAndWait(Class applicationClass) { + synchronized(lock) { + Application.launch(applicationClass, new String[]{}); + while(true) { + try { + lock.wait(); + } + catch (InterruptedException e) { + System.err.println("launchAndWait interrupted!"); + break; + } + Application app = Application.getInstance(WaitForTVApplication.class); + if (app instanceof WaitForTVApplication) { + if (((WaitForTVApplication)app).isReady()) { + break; + } + } + } + } + } +} \ No newline at end of file