Skip to content

Commit 7d4c3a3

Browse files
committed
close things properly in the test
1 parent 4b6c7cb commit 7d4c3a3

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

test/scripts/ghidra/util/FunctionSerializerTest.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
import org.junit.jupiter.api.*;
1313

14+
import com.google.gson.JsonObject;
15+
import com.google.gson.JsonParser;
16+
import com.google.gson.stream.JsonWriter;
17+
1418
import ghidra.test.AbstractGhidraHeadlessIntegrationTest;
1519
import ghidra.test.TestEnv;
1620

@@ -107,15 +111,40 @@ public void setUp() throws Exception {
107111
assertFalse(fns.isEmpty());
108112
}
109113

110-
@BeforeEach
111-
public void startTest() throws Exception {
114+
@AfterAll
115+
public void cleanUp() throws Exception {
116+
if (program != null) {
117+
program.release(this);
118+
}
119+
if (env != null) {
120+
env.dispose();
121+
}
122+
123+
if (!stringWriter.getBuffer().isEmpty()) {
124+
writer.close();
125+
stringWriter.close();
126+
}
127+
}
128+
129+
@Test
130+
public void testSerialize() throws Exception {
112131
stringWriter = new StringWriter();
113132
assertNotNull(stringWriter);
133+
114134
writer = new BufferedWriter(stringWriter);
115135
assertNotNull(writer);
116136

117137
functionSerializer = new FunctionSerializer(writer, program);
118138
assertNotNull(functionSerializer.currentProgram);
119139
assertFalse(functionSerializer.currentProgram.isClosed());
140+
141+
JsonWriter jsonWriter = functionSerializer.serialize(fns);
142+
assertNotNull(jsonWriter);
143+
144+
assertDoesNotThrow(() -> { stringWriter.toString(); });
145+
146+
JsonObject jsonOutput = JsonParser
147+
.parseString(stringWriter.toString())
148+
.getAsJsonObject();
120149
}
121150
}

0 commit comments

Comments
 (0)