Explorar el Código

Add tests for material editor animation functionality

Co-authored-by: neph1 <[email protected]>
copilot-swe-agent[bot] hace 3 días
padre
commit
320ad2a6a3

+ 53 - 0
jme3-materialeditor/test/manual/MaterialPreviewWidgetManualTest.java

@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2009-2024 jMonkeyEngine
+ * All rights reserved.
+ */
+package com.jme3.gde.materials.multiview.widgets;
+
+import javax.swing.JFrame;
+import javax.swing.SwingUtilities;
+
+/**
+ * Simple manual test to verify animation toggle functionality
+ * 
+ * @author copilot
+ */
+public class MaterialPreviewWidgetManualTest {
+    
+    public static void main(String[] args) {
+        SwingUtilities.invokeLater(() -> {
+            JFrame frame = new JFrame("Material Preview Widget Test");
+            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+            
+            MaterialPreviewWidget widget = new MaterialPreviewWidget();
+            frame.add(widget);
+            
+            frame.setSize(300, 250);
+            frame.setLocationRelativeTo(null);
+            frame.setVisible(true);
+            
+            // Test animation toggle after 2 seconds
+            new Thread(() -> {
+                try {
+                    Thread.sleep(2000);
+                    System.out.println("Animation enabled: " + widget.isAnimationEnabled());
+                    
+                    Thread.sleep(1000);
+                    SwingUtilities.invokeLater(() -> {
+                        widget.setAnimationEnabled(true);
+                        System.out.println("Animation enabled: " + widget.isAnimationEnabled());
+                    });
+                    
+                    Thread.sleep(3000);
+                    SwingUtilities.invokeLater(() -> {
+                        widget.setAnimationEnabled(false);
+                        System.out.println("Animation enabled: " + widget.isAnimationEnabled());
+                    });
+                    
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
+            }).start();
+        });
+    }
+}

+ 140 - 0
jme3-materialeditor/test/unit/src/com/jme3/gde/materialdefinition/editor/MatPanelTest.java

@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2009-2024 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.gde.materialdefinition.editor;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import org.junit.jupiter.api.Test;
+import java.awt.EventQueue;
+import java.lang.reflect.InvocationTargetException;
+import org.openide.util.Exceptions;
+
+/**
+ * Test class for MatPanel animation functionality
+ * 
+ * @author copilot
+ */
+public class MatPanelTest {
+    
+    public MatPanelTest() {
+    }
+    
+    @Test
+    public void testAnimationEnabled() {
+        MatPanel panel = new MatPanel();
+        
+        // Test initial state - animation should be disabled by default
+        assertFalse(panel.isAnimationEnabled());
+        
+        // Test enabling animation
+        try {
+            EventQueue.invokeAndWait(() -> {
+                panel.setAnimationEnabled(true);
+            });
+        } catch (InterruptedException | InvocationTargetException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+        
+        assertTrue(panel.isAnimationEnabled());
+        
+        // Test disabling animation
+        try {
+            EventQueue.invokeAndWait(() -> {
+                panel.setAnimationEnabled(false);
+            });
+        } catch (InterruptedException | InvocationTargetException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+        
+        assertFalse(panel.isAnimationEnabled());
+    }
+    
+    @Test
+    public void testAnimationToggle() {
+        MatPanel panel = new MatPanel();
+        
+        // Initially disabled
+        assertFalse(panel.isAnimationEnabled());
+        
+        // Enable and verify
+        try {
+            EventQueue.invokeAndWait(() -> {
+                panel.setAnimationEnabled(true);
+            });
+        } catch (InterruptedException | InvocationTargetException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+        
+        assertTrue(panel.isAnimationEnabled());
+        
+        // Toggle off and verify
+        try {
+            EventQueue.invokeAndWait(() -> {
+                panel.setAnimationEnabled(false);
+            });
+        } catch (InterruptedException | InvocationTargetException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+        
+        assertFalse(panel.isAnimationEnabled());
+    }
+    
+    @Test
+    public void testCleanupStopsAnimation() {
+        MatPanel panel = new MatPanel();
+        
+        // Enable animation
+        try {
+            EventQueue.invokeAndWait(() -> {
+                panel.setAnimationEnabled(true);
+            });
+        } catch (InterruptedException | InvocationTargetException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+        
+        assertTrue(panel.isAnimationEnabled());
+        
+        // Cleanup should stop animation
+        try {
+            EventQueue.invokeAndWait(() -> {
+                panel.cleanup();
+            });
+        } catch (InterruptedException | InvocationTargetException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+        
+        // Animation should still be logically enabled but timer stopped
+        // This tests that cleanup properly stops the timer
+        assertTrue(panel.isAnimationEnabled());
+    }
+}

+ 140 - 0
jme3-materialeditor/test/unit/src/com/jme3/gde/materials/multiview/widgets/MaterialPreviewWidgetTest.java

@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2009-2024 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.gde.materials.multiview.widgets;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import org.junit.jupiter.api.Test;
+import java.awt.EventQueue;
+import java.lang.reflect.InvocationTargetException;
+import org.openide.util.Exceptions;
+
+/**
+ * Test class for MaterialPreviewWidget animation functionality
+ * 
+ * @author copilot
+ */
+public class MaterialPreviewWidgetTest {
+    
+    public MaterialPreviewWidgetTest() {
+    }
+    
+    @Test
+    public void testAnimationEnabled() {
+        MaterialPreviewWidget widget = new MaterialPreviewWidget();
+        
+        // Test initial state - animation should be disabled by default
+        assertFalse(widget.isAnimationEnabled());
+        
+        // Test enabling animation
+        try {
+            EventQueue.invokeAndWait(() -> {
+                widget.setAnimationEnabled(true);
+            });
+        } catch (InterruptedException | InvocationTargetException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+        
+        assertTrue(widget.isAnimationEnabled());
+        
+        // Test disabling animation
+        try {
+            EventQueue.invokeAndWait(() -> {
+                widget.setAnimationEnabled(false);
+            });
+        } catch (InterruptedException | InvocationTargetException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+        
+        assertFalse(widget.isAnimationEnabled());
+    }
+    
+    @Test
+    public void testAnimationToggle() {
+        MaterialPreviewWidget widget = new MaterialPreviewWidget();
+        
+        // Initially disabled
+        assertFalse(widget.isAnimationEnabled());
+        
+        // Enable and verify
+        try {
+            EventQueue.invokeAndWait(() -> {
+                widget.setAnimationEnabled(true);
+            });
+        } catch (InterruptedException | InvocationTargetException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+        
+        assertTrue(widget.isAnimationEnabled());
+        
+        // Toggle off and verify
+        try {
+            EventQueue.invokeAndWait(() -> {
+                widget.setAnimationEnabled(false);
+            });
+        } catch (InterruptedException | InvocationTargetException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+        
+        assertFalse(widget.isAnimationEnabled());
+    }
+    
+    @Test
+    public void testCleanupStopsAnimation() {
+        MaterialPreviewWidget widget = new MaterialPreviewWidget();
+        
+        // Enable animation
+        try {
+            EventQueue.invokeAndWait(() -> {
+                widget.setAnimationEnabled(true);
+            });
+        } catch (InterruptedException | InvocationTargetException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+        
+        assertTrue(widget.isAnimationEnabled());
+        
+        // Cleanup should stop animation
+        try {
+            EventQueue.invokeAndWait(() -> {
+                widget.cleanUp();
+            });
+        } catch (InterruptedException | InvocationTargetException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+        
+        // Animation should still be logically enabled but timer stopped
+        // This tests that cleanup properly stops the timer
+        assertTrue(widget.isAnimationEnabled());
+    }
+}