blob: d8cdaa3dcfdfef03dcaaedc56f15d6d7e0c6dcaa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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);
}
}
|