summaryrefslogtreecommitdiff
path: root/src/main/java/testing/TestNoGuiErrors.java
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-21 20:10:38 +0300
committerPaul Buetow <paul@buetow.org>2025-06-21 20:10:38 +0300
commit695adc1f6bfb0a0eeef4dd6c035475ea2826871f (patch)
tree945fc0552d4f7f1ef1f468f6030e9925970fa72b /src/main/java/testing/TestNoGuiErrors.java
parentd3b697218773eaa5a3dd368705184726dbc0fa38 (diff)
Complete GUI decoupling implementation for headless testing
- Implement MessageHandler pattern to decouple message sending from visualization - Add HeadlessLoader to load simulations without GUI components - Create HeadlessProtocolRunner for clean protocol test execution - Update VSInternalProcess to use MessageHandler for message routing - Add null checks in VSSimulator for headless mode compatibility - Update VSSimulatorVisualization paint() to check for headless mode - Remove obsolete test scripts and documentation - Update test-protocols.sh to remove GUI error suppression options - Consolidate testing documentation in docs/testing-guide.md All protocol tests now run cleanly in headless mode without GUI errors, enabling proper CI/CD integration and automated testing. šŸ¤– Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'src/main/java/testing/TestNoGuiErrors.java')
-rw-r--r--src/main/java/testing/TestNoGuiErrors.java125
1 files changed, 125 insertions, 0 deletions
diff --git a/src/main/java/testing/TestNoGuiErrors.java b/src/main/java/testing/TestNoGuiErrors.java
new file mode 100644
index 0000000..d8cdaa3
--- /dev/null
+++ b/src/main/java/testing/TestNoGuiErrors.java
@@ -0,0 +1,125 @@
+package testing;
+
+import java.io.*;
+
+/**
+ * Test that verifies the GUI decoupling is working correctly.
+ * This should run without any GUI errors in headless mode.
+ */
+public class TestNoGuiErrors {
+
+ public static void main(String[] args) {
+ System.out.println("=== Testing GUI Decoupling ===");
+ System.out.println("This test should produce NO GUI errors.\n");
+
+ // Set headless mode
+ System.setProperty("java.awt.headless", "true");
+ System.setProperty("ds.sim.headless", "true");
+
+ // Capture stderr to check for errors
+ ByteArrayOutputStream errStream = new ByteArrayOutputStream();
+ PrintStream originalErr = System.err;
+ System.setErr(new PrintStream(errStream));
+
+ boolean success = true;
+
+ try {
+ // Test 1: Basic simulation loading and running
+ System.out.println("Test 1: Loading and running ping-pong simulation...");
+ HeadlessSimulationRunner runner = new HeadlessSimulationRunner();
+ runner.setPrintLogs(false); // Quiet mode
+
+ SimulationResult result = runner.runSimulation("saved-simulations/ping-pong.dat", 1000);
+
+ if (result != null && result.getAllLogs().size() > 0) {
+ System.out.println("āœ“ Simulation ran successfully");
+ System.out.println(" Captured " + result.getAllLogs().size() + " log entries");
+ } else {
+ System.out.println("āœ— Simulation failed to produce logs");
+ success = false;
+ }
+
+ runner.shutdown();
+
+ // Test 2: Check for GUI errors
+ System.out.println("\nTest 2: Checking for GUI errors...");
+ String errors = errStream.toString();
+
+ if (errors.contains("Component must have a valid peer")) {
+ System.out.println("āœ— FAILED: Found 'Component must have a valid peer' error");
+ success = false;
+ } else {
+ System.out.println("āœ“ No 'valid peer' errors");
+ }
+
+ if (errors.contains("IllegalStateException") && errors.contains("paint")) {
+ System.out.println("āœ— FAILED: Found paint-related IllegalStateException");
+ success = false;
+ } else {
+ System.out.println("āœ“ No paint-related exceptions");
+ }
+
+ if (errors.contains("createBufferStrategy")) {
+ System.out.println("āœ— FAILED: Found buffer strategy errors");
+ success = false;
+ } else {
+ System.out.println("āœ“ No buffer strategy errors");
+ }
+
+ // Test 3: Run multiple simulations
+ System.out.println("\nTest 3: Running multiple simulations...");
+ String[] simulations = {
+ "broadcast.dat",
+ "berkeley.dat",
+ "basic-multicast.dat"
+ };
+
+ for (String sim : simulations) {
+ try {
+ runner = new HeadlessSimulationRunner();
+ runner.setPrintLogs(false);
+
+ result = runner.runSimulation("saved-simulations/" + sim, 500);
+ if (result != null && result.getAllLogs().size() > 0) {
+ System.out.println("āœ“ " + sim + " - OK (" + result.getAllLogs().size() + " logs)");
+ } else {
+ System.out.println("āœ— " + sim + " - Failed");
+ success = false;
+ }
+
+ runner.shutdown();
+ } catch (Exception e) {
+ System.out.println("āœ— " + sim + " - Exception: " + e.getMessage());
+ success = false;
+ }
+ }
+
+ } catch (Exception e) {
+ System.out.println("\nāœ— Test failed with exception:");
+ e.printStackTrace(System.out);
+ success = false;
+ } finally {
+ System.setErr(originalErr);
+ }
+
+ // Print captured errors if any
+ String capturedErrors = errStream.toString();
+ if (!capturedErrors.isEmpty()) {
+ System.out.println("\n=== Captured Error Output ===");
+ System.out.println(capturedErrors);
+ System.out.println("=== End Error Output ===");
+ }
+
+ // Final result
+ System.out.println("\n=== Test Result ===");
+ if (success) {
+ System.out.println("āœ… SUCCESS: GUI decoupling is working correctly!");
+ System.out.println("No GUI errors were produced in headless mode.");
+ } else {
+ System.out.println("āŒ FAILED: GUI errors still present.");
+ System.out.println("The decoupling is not complete.");
+ }
+
+ System.exit(success ? 0 : 1);
+ }
+} \ No newline at end of file