From b6c6a4781178d55aff908e1ac3be3f6a08700367 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Fri, 3 Mar 2023 18:23:40 -0700 Subject: [PATCH] Unit test to see if sim status is saved/loaded properly --- .../file/openrocket/OpenRocketSaverTest.java | 63 ++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/core/test/net/sf/openrocket/file/openrocket/OpenRocketSaverTest.java b/core/test/net/sf/openrocket/file/openrocket/OpenRocketSaverTest.java index 52014e4f1..6c613ee32 100644 --- a/core/test/net/sf/openrocket/file/openrocket/OpenRocketSaverTest.java +++ b/core/test/net/sf/openrocket/file/openrocket/OpenRocketSaverTest.java @@ -22,6 +22,7 @@ import net.sf.openrocket.database.motor.MotorDatabase; import net.sf.openrocket.database.motor.ThrustCurveMotorSetDatabase; import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.document.OpenRocketDocumentFactory; +import net.sf.openrocket.document.Simulation; import net.sf.openrocket.document.StorageOptions; import net.sf.openrocket.file.GeneralRocketLoader; import net.sf.openrocket.file.RocketLoadException; @@ -264,7 +265,64 @@ public class OpenRocketSaverTest { // TODO: fix estimateFileSize so that it's a lot more accurate } - + + /** + * Test sim status with/without sim data in file. + */ + @Test + public void TestSimStatus() { + Rocket rocket = TestRockets.makeEstesAlphaIII(); + OpenRocketDocument rocketDoc = OpenRocketDocumentFactory.createDocumentFromRocket(rocket); + + // Hook up some simulations. + // First sim will not have options set + Simulation sim1 = new Simulation(rocket); + rocketDoc.addSimulation(sim1); + + // Second sim has options, but hasn't been simulated + Simulation sim2 = new Simulation(rocket); + sim2.getOptions().setISAAtmosphere(true); + sim2.getOptions().setTimeStep(0.05); + sim2.setFlightConfigurationId(TestRockets.TEST_FCID_0); + rocketDoc.addSimulation(sim2); + + // Third sim has been executed + Simulation sim3 = new Simulation(rocket); + sim3.getOptions().setISAAtmosphere(true); + sim3.getOptions().setTimeStep(0.05); + sim3.setFlightConfigurationId(TestRockets.TEST_FCID_0); + try { + sim3.simulate(); + } catch (Exception e) { + fail(e.toString()); + } + rocketDoc.addSimulation(sim3); + + // Fourth sim has been executed, then configuration changed + Simulation sim4 = new Simulation(rocket); + sim4.getOptions().setISAAtmosphere(true); + sim4.getOptions().setTimeStep(0.05); + sim4.setFlightConfigurationId(TestRockets.TEST_FCID_0); + try { + sim4.simulate(); + } catch (Exception e) { + fail(e.toString()); + } + sim4.getOptions().setTimeStep(0.1); + rocketDoc.addSimulation(sim4); + + // save, then load document + StorageOptions options = new StorageOptions(); + options.setSaveSimulationData(true); + + File file = saveRocket(rocketDoc, options); + OpenRocketDocument rocketDocLoaded = loadRocket(file.getPath()); + + assertEquals(Simulation.Status.CANT_RUN, rocketDocLoaded.getSimulations().get(0).getStatus()); + assertEquals(Simulation.Status.NOT_SIMULATED, rocketDocLoaded.getSimulations().get(1).getStatus()); + assertEquals(Simulation.Status.LOADED, rocketDocLoaded.getSimulations().get(2).getStatus()); + assertEquals(Simulation.Status.OUTDATED, rocketDocLoaded.getSimulations().get(3).getStatus()); + } //////////////////////////////// // Tests for File Version 1.7 // @@ -276,7 +334,8 @@ public class OpenRocketSaverTest { assertEquals(108, getCalculatedFileVersion(rocketDoc)); } - + + //////////////////////////////// /* * Utility Functions */