Added tests for OR file versions. Added test rockets for each version number that is implemented.
This commit is contained in:
parent
f2874e0f00
commit
d57b132b51
@ -194,6 +194,17 @@ public class OpenRocketSaver extends RocketSaver {
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public test accessor method for calculateNecessaryFileVersion, used by unit tests.
|
||||
*
|
||||
* @param document the document to output.
|
||||
* @param opts the storage options.
|
||||
* @return the integer file version to use.
|
||||
*/
|
||||
public int testAccessor_calculateNecessaryFileVersion(OpenRocketDocument document, StorageOptions opts) {
|
||||
// TODO: should check for test context here and fail if not running junit
|
||||
return calculateNecessaryFileVersion(document, opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine which file version is required in order to store all the features of the
|
||||
@ -225,6 +236,10 @@ public class OpenRocketSaver extends RocketSaver {
|
||||
* Otherwise use version 1.0.
|
||||
*/
|
||||
|
||||
/////////////////
|
||||
// Version 1.6 //
|
||||
/////////////////
|
||||
|
||||
// Search the rocket for any Appearances or non-motor flight configurations (version 1.6)
|
||||
for (RocketComponent c : document.getRocket()) {
|
||||
if (c.getAppearance() != null) {
|
||||
@ -252,6 +267,10 @@ public class OpenRocketSaver extends RocketSaver {
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////
|
||||
// Version 1.5 //
|
||||
/////////////////
|
||||
|
||||
// Search the rocket for any ComponentPresets (version 1.5)
|
||||
for (RocketComponent c : document.getRocket()) {
|
||||
if (c.getPresetComponent() != null) {
|
||||
@ -268,11 +287,15 @@ public class OpenRocketSaver extends RocketSaver {
|
||||
}
|
||||
}
|
||||
|
||||
// Check for custom expressions
|
||||
// Check for custom expressions (version 1.5)
|
||||
if (!document.getCustomExpressions().isEmpty()) {
|
||||
return FILE_VERSION_DIVISOR + 5;
|
||||
}
|
||||
|
||||
/////////////////
|
||||
// Version 1.4 //
|
||||
/////////////////
|
||||
|
||||
// Check if design has simulations defined (version 1.4)
|
||||
if (document.getSimulationCount() > 0) {
|
||||
return FILE_VERSION_DIVISOR + 4;
|
||||
@ -291,7 +314,23 @@ public class OpenRocketSaver extends RocketSaver {
|
||||
}
|
||||
}
|
||||
|
||||
// Check for fin tabs (version 1.1)
|
||||
/////////////////
|
||||
// Version 1.3 //
|
||||
/////////////////
|
||||
|
||||
// no version 1.3 file type exists
|
||||
|
||||
/////////////////
|
||||
// Version 1.2 //
|
||||
/////////////////
|
||||
|
||||
// no version 1.2 file type exists
|
||||
|
||||
/////////////////
|
||||
// Version 1.1 //
|
||||
/////////////////
|
||||
|
||||
// Check for fin tabs or tube coupler children (version 1.1)
|
||||
for (RocketComponent c : document.getRocket()) {
|
||||
// Check for fin tabs
|
||||
if (c instanceof FinSet) {
|
||||
@ -310,6 +349,10 @@ public class OpenRocketSaver extends RocketSaver {
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////
|
||||
// Version 1.0 //
|
||||
/////////////////
|
||||
|
||||
// Default (version 1.0)
|
||||
return FILE_VERSION_DIVISOR + 0;
|
||||
}
|
||||
|
@ -2,28 +2,42 @@ package net.sf.openrocket.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.sf.openrocket.appearance.Appearance;
|
||||
import net.sf.openrocket.database.Databases;
|
||||
import net.sf.openrocket.material.Material;
|
||||
import net.sf.openrocket.material.Material.Type;
|
||||
import net.sf.openrocket.motor.Manufacturer;
|
||||
import net.sf.openrocket.motor.Motor;
|
||||
import net.sf.openrocket.motor.ThrustCurveMotor;
|
||||
import net.sf.openrocket.preset.ComponentPreset;
|
||||
import net.sf.openrocket.preset.ComponentPresetFactory;
|
||||
import net.sf.openrocket.preset.InvalidComponentPresetException;
|
||||
import net.sf.openrocket.preset.TypedPropertyMap;
|
||||
import net.sf.openrocket.rocketcomponent.BodyTube;
|
||||
import net.sf.openrocket.rocketcomponent.Bulkhead;
|
||||
import net.sf.openrocket.rocketcomponent.CenteringRing;
|
||||
import net.sf.openrocket.rocketcomponent.DeploymentConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.DeploymentConfiguration.DeployEvent;
|
||||
import net.sf.openrocket.rocketcomponent.ExternalComponent;
|
||||
import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish;
|
||||
import net.sf.openrocket.rocketcomponent.FinSet.CrossSection;
|
||||
import net.sf.openrocket.rocketcomponent.FreeformFinSet;
|
||||
import net.sf.openrocket.rocketcomponent.IgnitionConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.IllegalFinPointException;
|
||||
import net.sf.openrocket.rocketcomponent.InnerTube;
|
||||
import net.sf.openrocket.rocketcomponent.InternalComponent;
|
||||
import net.sf.openrocket.rocketcomponent.LaunchLug;
|
||||
import net.sf.openrocket.rocketcomponent.MassComponent;
|
||||
import net.sf.openrocket.rocketcomponent.MotorConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.NoseCone;
|
||||
import net.sf.openrocket.rocketcomponent.Parachute;
|
||||
import net.sf.openrocket.rocketcomponent.RecoveryDevice;
|
||||
import net.sf.openrocket.rocketcomponent.ReferenceType;
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent.Position;
|
||||
import net.sf.openrocket.rocketcomponent.Stage;
|
||||
import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.Transition;
|
||||
import net.sf.openrocket.rocketcomponent.Transition.Shape;
|
||||
import net.sf.openrocket.rocketcomponent.TrapezoidFinSet;
|
||||
@ -81,12 +95,10 @@ public class TestRockets {
|
||||
rocket.setRevision("Rocket revision " + key);
|
||||
rocket.setName(key);
|
||||
|
||||
|
||||
Stage stage = new Stage();
|
||||
setBasics(stage);
|
||||
rocket.addChild(stage);
|
||||
|
||||
|
||||
NoseCone nose = new NoseCone();
|
||||
setBasics(stage);
|
||||
nose.setAftRadius(rnd(0.03));
|
||||
@ -104,7 +116,6 @@ public class TestRockets {
|
||||
nose.setType((Shape) randomEnum(Shape.class));
|
||||
stage.addChild(nose);
|
||||
|
||||
|
||||
Transition shoulder = new Transition();
|
||||
setBasics(shoulder);
|
||||
shoulder.setAftRadius(rnd(0.06));
|
||||
@ -128,7 +139,6 @@ public class TestRockets {
|
||||
shoulder.setType((Shape) randomEnum(Shape.class));
|
||||
stage.addChild(shoulder);
|
||||
|
||||
|
||||
BodyTube body = new BodyTube();
|
||||
setBasics(body);
|
||||
body.setThickness(rnd(0.002));
|
||||
@ -140,7 +150,6 @@ public class TestRockets {
|
||||
body.setOuterRadiusAutomatic(rnd.nextBoolean());
|
||||
stage.addChild(body);
|
||||
|
||||
|
||||
Transition boattail = new Transition();
|
||||
setBasics(boattail);
|
||||
boattail.setAftRadius(rnd(0.03));
|
||||
@ -164,7 +173,6 @@ public class TestRockets {
|
||||
boattail.setType((Shape) randomEnum(Shape.class));
|
||||
stage.addChild(boattail);
|
||||
|
||||
|
||||
MassComponent mass = new MassComponent();
|
||||
setBasics(mass);
|
||||
mass.setComponentMass(rnd(0.05));
|
||||
@ -174,9 +182,6 @@ public class TestRockets {
|
||||
mass.setRadius(rnd(0.05));
|
||||
nose.addChild(mass);
|
||||
|
||||
|
||||
|
||||
|
||||
return rocket;
|
||||
}
|
||||
|
||||
@ -211,8 +216,6 @@ public class TestRockets {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private double rnd(double scale) {
|
||||
return (rnd.nextDouble() * 0.2 + 0.9) * scale;
|
||||
}
|
||||
@ -230,9 +233,6 @@ public class TestRockets {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public Rocket makeSmallFlyable() {
|
||||
double noseconeLength = 0.10, noseconeRadius = 0.01;
|
||||
double bodytubeLength = 0.20, bodytubeRadius = 0.01, bodytubeThickness = 0.001;
|
||||
@ -241,7 +241,6 @@ public class TestRockets {
|
||||
@SuppressWarnings("unused")
|
||||
double finRootChord = 0.04, finTipChord = 0.05, finSweep = 0.01, finThickness = 0.003, finHeight = 0.03;
|
||||
|
||||
|
||||
Rocket rocket;
|
||||
Stage stage;
|
||||
NoseCone nosecone;
|
||||
@ -257,11 +256,9 @@ public class TestRockets {
|
||||
|
||||
finset = new TrapezoidFinSet(finCount, finRootChord, finTipChord, finSweep, finHeight);
|
||||
|
||||
|
||||
// Stage construction
|
||||
rocket.addChild(stage);
|
||||
|
||||
|
||||
// Component construction
|
||||
stage.addChild(nosecone);
|
||||
stage.addChild(bodytube);
|
||||
@ -283,7 +280,6 @@ public class TestRockets {
|
||||
|
||||
rocket.getDefaultConfiguration().setAllStages();
|
||||
|
||||
|
||||
return rocket;
|
||||
}
|
||||
|
||||
@ -330,7 +326,6 @@ public class TestRockets {
|
||||
rocket.addChild(stage);
|
||||
rocket.setPerfectFinish(false);
|
||||
|
||||
|
||||
// Component construction
|
||||
stage.addChild(nosecone);
|
||||
stage.addChild(bodytube);
|
||||
@ -354,12 +349,10 @@ public class TestRockets {
|
||||
|
||||
rocket.getDefaultConfiguration().setAllStages();
|
||||
|
||||
|
||||
return rocket;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Rocket makeIsoHaisu() {
|
||||
Rocket rocket;
|
||||
Stage stage;
|
||||
@ -397,7 +390,6 @@ public class TestRockets {
|
||||
tube3.setOverrideMass(0.730);
|
||||
stage.addChild(tube3);
|
||||
|
||||
|
||||
LaunchLug lug = new LaunchLug();
|
||||
tube1.addChild(lug);
|
||||
|
||||
@ -411,7 +403,6 @@ public class TestRockets {
|
||||
coupler.setPositionValue(-0.14);
|
||||
tube1.addChild(coupler);
|
||||
|
||||
|
||||
// Parachute
|
||||
MassComponent mass = new MassComponent(0.05, 0.05, 0.280);
|
||||
mass.setRelativePosition(Position.TOP);
|
||||
@ -430,7 +421,6 @@ public class TestRockets {
|
||||
mass.setPositionValue(0.25);
|
||||
tube1.addChild(mass);
|
||||
|
||||
|
||||
auxfinset = new TrapezoidFinSet();
|
||||
auxfinset.setName("CONTROL");
|
||||
auxfinset.setFinCount(2);
|
||||
@ -445,9 +435,6 @@ public class TestRockets {
|
||||
auxfinset.setBaseRotation(Math.PI / 2);
|
||||
tube1.addChild(auxfinset);
|
||||
|
||||
|
||||
|
||||
|
||||
coupler = new TubeCoupler();
|
||||
coupler.setOuterRadiusAutomatic(true);
|
||||
coupler.setLength(0.28);
|
||||
@ -457,8 +444,6 @@ public class TestRockets {
|
||||
coupler.setOverrideMass(0.360);
|
||||
tube2.addChild(coupler);
|
||||
|
||||
|
||||
|
||||
// Parachute
|
||||
mass = new MassComponent(0.1, 0.05, 0.028);
|
||||
mass.setRelativePosition(Position.TOP);
|
||||
@ -479,8 +464,6 @@ public class TestRockets {
|
||||
mass.setPositionValue(0.19);
|
||||
tube2.addChild(mass);
|
||||
|
||||
|
||||
|
||||
InnerTube inner = new InnerTube();
|
||||
inner.setOuterRadius(0.08 / 2);
|
||||
inner.setInnerRadius(0.0762 / 2);
|
||||
@ -489,7 +472,6 @@ public class TestRockets {
|
||||
inner.setOverrideMass(0.388);
|
||||
tube3.addChild(inner);
|
||||
|
||||
|
||||
CenteringRing center = new CenteringRing();
|
||||
center.setInnerRadiusAutomatic(true);
|
||||
center.setOuterRadiusAutomatic(true);
|
||||
@ -500,7 +482,6 @@ public class TestRockets {
|
||||
center.setPositionValue(0);
|
||||
tube3.addChild(center);
|
||||
|
||||
|
||||
center = new CenteringRing();
|
||||
center.setInnerRadiusAutomatic(true);
|
||||
center.setOuterRadiusAutomatic(true);
|
||||
@ -511,7 +492,6 @@ public class TestRockets {
|
||||
center.setPositionValue(0.28);
|
||||
tube3.addChild(center);
|
||||
|
||||
|
||||
center = new CenteringRing();
|
||||
center.setInnerRadiusAutomatic(true);
|
||||
center.setOuterRadiusAutomatic(true);
|
||||
@ -522,10 +502,6 @@ public class TestRockets {
|
||||
center.setPositionValue(0.83);
|
||||
tube3.addChild(center);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
finset = new TrapezoidFinSet();
|
||||
finset.setRootChord(0.495);
|
||||
finset.setTipChord(0.1);
|
||||
@ -537,17 +513,13 @@ public class TestRockets {
|
||||
finset.setBaseRotation(Math.PI / 2);
|
||||
tube3.addChild(finset);
|
||||
|
||||
|
||||
finset.setCantAngle(0 * Math.PI / 180);
|
||||
//System.err.println("Fin cant angle: " + (finset.getCantAngle() * 180 / Math.PI));
|
||||
|
||||
|
||||
// Stage construction
|
||||
rocket.addChild(stage);
|
||||
rocket.setPerfectFinish(false);
|
||||
|
||||
|
||||
|
||||
String id = rocket.newFlightConfigurationID();
|
||||
tube3.setMotorMount(true);
|
||||
|
||||
@ -560,6 +532,306 @@ public class TestRockets {
|
||||
|
||||
rocket.getDefaultConfiguration().setAllStages();
|
||||
|
||||
return rocket;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Create a new file version 1.00 rocket
|
||||
*/
|
||||
public static Rocket makeTestRocket_v100() {
|
||||
Rocket rocket = new Rocket();
|
||||
rocket.setName("v100");
|
||||
|
||||
// make stage
|
||||
Stage stage = new Stage();
|
||||
stage.setName("Stage1");
|
||||
|
||||
// make body tube
|
||||
BodyTube bodyTube = new BodyTube(12, 1, 0.05);
|
||||
stage.addChild(bodyTube);
|
||||
|
||||
rocket.addChild(stage);
|
||||
|
||||
return rocket;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new file version 1.01 rocket with finTabs
|
||||
*/
|
||||
public static Rocket makeTestRocket_v101_withFinTabs() {
|
||||
|
||||
Rocket rocket = new Rocket();
|
||||
rocket.setName("v101_withFinTabs");
|
||||
|
||||
// make stage
|
||||
Stage stage = new Stage();
|
||||
stage.setName("Stage1");
|
||||
rocket.addChild(stage);
|
||||
|
||||
// make body tube
|
||||
BodyTube bodyTube = new BodyTube(12, 1, 0.05);
|
||||
stage.addChild(bodyTube);
|
||||
|
||||
// make fins with fin tabs and add to body tube
|
||||
TrapezoidFinSet fins = new TrapezoidFinSet();
|
||||
fins.setFinCount(3);
|
||||
fins.setFinShape(1.0, 1.0, 0.0, 1.0, .005);
|
||||
fins.setTabHeight(0.25);
|
||||
fins.setTabLength(0.25);
|
||||
bodyTube.addChild(fins);
|
||||
|
||||
return rocket;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new file version 1.01 rocket with tube coupler child
|
||||
*/
|
||||
public static Rocket makeTestRocket_v101_withTubeCouplerChild() {
|
||||
|
||||
Rocket rocket = new Rocket();
|
||||
rocket.setName("v101_withTubeCouplerChild");
|
||||
|
||||
// make stage
|
||||
Stage stage = new Stage();
|
||||
stage.setName("Stage1");
|
||||
rocket.addChild(stage);
|
||||
|
||||
// make body tube
|
||||
BodyTube bodyTube = new BodyTube(12, 1, 0.05);
|
||||
stage.addChild(bodyTube);
|
||||
|
||||
// make tube coupler with centering ring, add to stage
|
||||
TubeCoupler tubeCoupler = new TubeCoupler();
|
||||
CenteringRing centeringRing = new CenteringRing();
|
||||
tubeCoupler.addChild(centeringRing);
|
||||
bodyTube.addChild(tubeCoupler);
|
||||
|
||||
return rocket;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new file version 1.04 rocket with motor in flight config
|
||||
*/
|
||||
public static Rocket makeTestRocket_v104_withMotor() {
|
||||
|
||||
Rocket rocket = new Rocket();
|
||||
rocket.setName("v101_withTubeCouplerChild");
|
||||
|
||||
// make stage
|
||||
Stage stage = new Stage();
|
||||
stage.setName("Stage1");
|
||||
rocket.addChild(stage);
|
||||
|
||||
// make body tube
|
||||
BodyTube bodyTube = new BodyTube(12, 1, 0.05);
|
||||
stage.addChild(bodyTube);
|
||||
|
||||
// make inner tube with motor mount flag set
|
||||
InnerTube innerTube = new InnerTube();
|
||||
innerTube.setMotorMount(true);
|
||||
bodyTube.addChild(innerTube);
|
||||
|
||||
// create motor config and add a motor to it
|
||||
MotorConfiguration motorConfig = new MotorConfiguration();
|
||||
ThrustCurveMotor motor = new ThrustCurveMotor(
|
||||
Manufacturer.getManufacturer("A"),
|
||||
"F12X", "Desc", Motor.Type.UNKNOWN, new double[] {},
|
||||
0.024, 0.07, new double[] { 0, 1, 2 }, new double[] { 0, 1, 0 },
|
||||
new Coordinate[] { Coordinate.NUL, Coordinate.NUL, Coordinate.NUL }, "digestA");
|
||||
motorConfig.setMotor(motor);
|
||||
motorConfig.setEjectionDelay(5);
|
||||
|
||||
// add motor config to inner tube (motor mount)
|
||||
innerTube.getMotorConfiguration().set("F12X", motorConfig);
|
||||
|
||||
// add motor config to rocket's flight config
|
||||
rocket.newFlightConfigurationID();
|
||||
rocket.addMotorConfigurationID("F12X");
|
||||
|
||||
return rocket;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new file version 1.05 rocket with component preset
|
||||
*/
|
||||
public static Rocket makeTestRocket_v105_withComponentPreset() {
|
||||
Rocket rocket = new Rocket();
|
||||
rocket.setName("v105_withComponentPreset");
|
||||
|
||||
// make stage
|
||||
Stage stage = new Stage();
|
||||
stage.setName("Stage1");
|
||||
|
||||
// make body tube
|
||||
BodyTube bodyTube = new BodyTube();
|
||||
|
||||
TypedPropertyMap presetspec = new TypedPropertyMap();
|
||||
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BODY_TUBE);
|
||||
presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
|
||||
presetspec.put(ComponentPreset.PARTNO, "partno");
|
||||
presetspec.put(ComponentPreset.LENGTH, 2.0);
|
||||
presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0);
|
||||
presetspec.put(ComponentPreset.INNER_DIAMETER, 1.0);
|
||||
presetspec.put(ComponentPreset.MASS, 100.0);
|
||||
ComponentPreset preset;
|
||||
try {
|
||||
preset = ComponentPresetFactory.create(presetspec);
|
||||
bodyTube.loadPreset(preset);
|
||||
stage.addChild(bodyTube);
|
||||
} catch (InvalidComponentPresetException e) {
|
||||
// should never happen
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
rocket.addChild(stage);
|
||||
|
||||
return rocket;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new file version 1.05 rocket with lower stage recovery device
|
||||
*/
|
||||
public static Rocket makeTestRocket_v105_withLowerStageRecoveryDevice() {
|
||||
Rocket rocket = new Rocket();
|
||||
rocket.setName("v105_withLowerStageRecoveryDevice");
|
||||
|
||||
// make 1st stage
|
||||
Stage stage1 = new Stage();
|
||||
stage1.setName("Stage1");
|
||||
rocket.addChild(stage1);
|
||||
|
||||
// make 1st stage body tube
|
||||
BodyTube bodyTube1 = new BodyTube(5, 1, 0.05);
|
||||
stage1.addChild(bodyTube1);
|
||||
|
||||
//getDeploymentConfiguration().getDefault().getDeployEvent() == DeployEvent.LOWER_STAGE_SEPARATION)
|
||||
|
||||
// make 1st stage recovery device with deployment config in default
|
||||
RecoveryDevice parachute = new Parachute();
|
||||
DeploymentConfiguration deploymentConfig = new DeploymentConfiguration();
|
||||
deploymentConfig.setDeployEvent(DeployEvent.LOWER_STAGE_SEPARATION);
|
||||
parachute.getDeploymentConfiguration().setDefault(deploymentConfig);
|
||||
bodyTube1.addChild(parachute);
|
||||
|
||||
// make 2nd stage
|
||||
Stage stage2 = new Stage();
|
||||
stage2.setName("Stage2");
|
||||
rocket.addChild(stage2);
|
||||
|
||||
return rocket;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new file version 1.06 rocket with appearance
|
||||
*/
|
||||
public static Rocket makeTestRocket_v106_withAppearance() {
|
||||
Rocket rocket = new Rocket();
|
||||
rocket.setName("v106_withAppearance");
|
||||
|
||||
// make stage
|
||||
Stage stage = new Stage();
|
||||
stage.setName("Stage1");
|
||||
rocket.addChild(stage);
|
||||
|
||||
// make body tube with an appearance setting
|
||||
BodyTube bodyTube = new BodyTube(12, 1, 0.05);
|
||||
Appearance appearance = new Appearance(new Color(100, 25, 50), 1, null);
|
||||
bodyTube.setAppearance(appearance);
|
||||
stage.addChild(bodyTube);
|
||||
|
||||
return rocket;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new file version 1.06 rocket with flight configuration with motor mount ignition configuration
|
||||
*/
|
||||
public static Rocket makeTestRocket_v106_withMotorMountIgnitionConfig() {
|
||||
Rocket rocket = new Rocket();
|
||||
rocket.setName("v106_withwithMotorMountIgnitionConfig");
|
||||
|
||||
// make stage
|
||||
Stage stage = new Stage();
|
||||
stage.setName("Stage1");
|
||||
rocket.addChild(stage);
|
||||
|
||||
// make body tube
|
||||
BodyTube bodyTube = new BodyTube(12, 1, 0.05);
|
||||
stage.addChild(bodyTube);
|
||||
|
||||
// make inner tube with motor mount flag set
|
||||
InnerTube innerTube = new InnerTube();
|
||||
innerTube.setMotorMount(true);
|
||||
bodyTube.addChild(innerTube);
|
||||
|
||||
// set ignition configuration for motor mount
|
||||
IgnitionConfiguration ignitionConfig = new IgnitionConfiguration();
|
||||
ignitionConfig.setIgnitionDelay(2);
|
||||
innerTube.getIgnitionConfiguration().set("2SecondDelay", ignitionConfig);
|
||||
|
||||
return rocket;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new file version 1.06 rocket with flight configuration with recovery device deployment configuration non-default
|
||||
*/
|
||||
public static Rocket makeTestRocket_v106_withRecoveryDeviceDeploymentConfig() {
|
||||
Rocket rocket = new Rocket();
|
||||
rocket.setName("v106_withRecoveryDeviceDeploymentConfig");
|
||||
|
||||
// make stage
|
||||
Stage stage = new Stage();
|
||||
stage.setName("Stage1");
|
||||
rocket.addChild(stage);
|
||||
|
||||
// make body tube
|
||||
BodyTube bodyTube = new BodyTube(12, 1, 0.05);
|
||||
stage.addChild(bodyTube);
|
||||
|
||||
// make recovery device with deployment config
|
||||
RecoveryDevice parachute = new Parachute();
|
||||
DeploymentConfiguration deploymentConfig = new DeploymentConfiguration();
|
||||
deploymentConfig.setDeployAltitude(1000);
|
||||
parachute.getDeploymentConfiguration().set("testParachute", deploymentConfig);
|
||||
bodyTube.addChild(parachute);
|
||||
|
||||
return rocket;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new file version 1.06 rocket with flight configuration with stage separation configuration
|
||||
*/
|
||||
public static Rocket makeTestRocket_v106_withStageSeparationConfig() {
|
||||
Rocket rocket = new Rocket();
|
||||
rocket.setName("v106_withStageSeparationConfig");
|
||||
|
||||
// make 1st stage
|
||||
Stage stage1 = new Stage();
|
||||
stage1.setName("Stage1");
|
||||
rocket.addChild(stage1);
|
||||
|
||||
// make 1st stage body tube
|
||||
BodyTube bodyTube1 = new BodyTube(5, 1, 0.05);
|
||||
stage1.addChild(bodyTube1);
|
||||
|
||||
// make1st stage recovery device
|
||||
RecoveryDevice parachute = new Parachute();
|
||||
bodyTube1.addChild(parachute);
|
||||
|
||||
// set stage separation configuration
|
||||
StageSeparationConfiguration stageSepConfig = new StageSeparationConfiguration();
|
||||
stageSepConfig.setSeparationDelay(3);
|
||||
stage1.getStageSeparationConfiguration().set("3SecondDelay", stageSepConfig);
|
||||
|
||||
// make 2nd stage
|
||||
Stage stage2 = new Stage();
|
||||
stage2.setName("Stage2");
|
||||
rocket.addChild(stage2);
|
||||
|
||||
// make 2st stage body tube
|
||||
BodyTube bodyTube2 = new BodyTube(12, 1, 0.05);
|
||||
stage2.addChild(bodyTube2);
|
||||
|
||||
return rocket;
|
||||
}
|
||||
|
@ -0,0 +1,158 @@
|
||||
package net.sf.openrocket.file.openrocket;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.document.OpenRocketDocumentFactory;
|
||||
import net.sf.openrocket.document.Simulation;
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
import net.sf.openrocket.simulation.customexpression.CustomExpression;
|
||||
import net.sf.openrocket.simulation.exception.SimulationException;
|
||||
import net.sf.openrocket.simulation.listeners.AbstractSimulationListener;
|
||||
import net.sf.openrocket.simulation.listeners.SimulationListener;
|
||||
import net.sf.openrocket.util.TestRockets;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class OpenRocketSaverTest {
|
||||
|
||||
////////////////////////////////
|
||||
// Tests for File Version 1.0 //
|
||||
////////////////////////////////
|
||||
|
||||
@Test
|
||||
public void testFileVersion100() {
|
||||
Rocket rocket = TestRockets.makeTestRocket_v100();
|
||||
assertEquals(100, getCalculatedFileVersion(rocket));
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Tests for File Version 1.1 //
|
||||
////////////////////////////////
|
||||
|
||||
@Test
|
||||
public void testFileVersion101_withFinTabs() {
|
||||
Rocket rocket = TestRockets.makeTestRocket_v101_withFinTabs();
|
||||
assertEquals(101, getCalculatedFileVersion(rocket));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileVersion101_withTubeCouplerChild() {
|
||||
Rocket rocket = TestRockets.makeTestRocket_v101_withTubeCouplerChild();
|
||||
assertEquals(101, getCalculatedFileVersion(rocket));
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Tests for File Version 1.2 //
|
||||
////////////////////////////////
|
||||
|
||||
// no version 1.2 file type exists
|
||||
|
||||
////////////////////////////////
|
||||
// Tests for File Version 1.3 //
|
||||
////////////////////////////////
|
||||
|
||||
// no version 1.3 file type exists
|
||||
|
||||
////////////////////////////////
|
||||
// Tests for File Version 1.4 //
|
||||
////////////////////////////////
|
||||
|
||||
@Test
|
||||
public void testFileVersion104_withSimulationData() {
|
||||
Rocket rocket = TestRockets.makeTestRocket_v100();
|
||||
rocket.setName("v104_withSimulationData");
|
||||
|
||||
OpenRocketDocument rocketDoc = OpenRocketDocumentFactory.createDocumentFromRocket(rocket);
|
||||
Simulation simulation = new Simulation(rocket);
|
||||
rocketDoc.addSimulation(simulation);
|
||||
|
||||
SimulationListener simulationListener = new AbstractSimulationListener();
|
||||
try {
|
||||
simulation.simulate(simulationListener);
|
||||
} catch (SimulationException e) {
|
||||
// do nothing, we don't care
|
||||
}
|
||||
|
||||
assertEquals(104, getCalculatedFileVersion(rocketDoc));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileVersion104_withMotor() {
|
||||
Rocket rocket = TestRockets.makeTestRocket_v104_withMotor();
|
||||
assertEquals(104, getCalculatedFileVersion(rocket));
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Tests for File Version 1.5 //
|
||||
////////////////////////////////
|
||||
|
||||
@Test
|
||||
public void testFileVersion105_withComponentPresets() {
|
||||
Rocket rocket = TestRockets.makeTestRocket_v105_withComponentPreset();
|
||||
assertEquals(105, getCalculatedFileVersion(rocket));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileVersion105_withCustomExpressions() {
|
||||
Rocket rocket = TestRockets.makeTestRocket_v100();
|
||||
rocket.setName("v105_withCustomExpressions");
|
||||
|
||||
OpenRocketDocument rocketDoc = OpenRocketDocumentFactory.createDocumentFromRocket(rocket);
|
||||
CustomExpression expression = new CustomExpression(rocketDoc, "name", "symbol", "unit", "expression");
|
||||
rocketDoc.addCustomExpression(expression);
|
||||
|
||||
assertEquals(105, getCalculatedFileVersion(rocketDoc));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileVersion105_withLowerStageRecoveryDevice() {
|
||||
Rocket rocket = TestRockets.makeTestRocket_v105_withLowerStageRecoveryDevice();
|
||||
assertEquals(105, getCalculatedFileVersion(rocket));
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Tests for File Version 1.6 //
|
||||
///////////////////////////////////////////////
|
||||
|
||||
@Test
|
||||
public void testFileVersion106_withAppearance() {
|
||||
Rocket rocket = TestRockets.makeTestRocket_v106_withAppearance();
|
||||
assertEquals(106, getCalculatedFileVersion(rocket));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileVersion106_withMotorMountIgnitionConfig() {
|
||||
Rocket rocket = TestRockets.makeTestRocket_v106_withMotorMountIgnitionConfig();
|
||||
assertEquals(106, getCalculatedFileVersion(rocket));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileVersion106_withRecoveryDeviceDeploymentConfig() {
|
||||
Rocket rocket = TestRockets.makeTestRocket_v106_withRecoveryDeviceDeploymentConfig();
|
||||
assertEquals(106, getCalculatedFileVersion(rocket));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileVersion106_withStageDeploymentConfig() {
|
||||
Rocket rocket = TestRockets.makeTestRocket_v106_withStageSeparationConfig();
|
||||
assertEquals(106, getCalculatedFileVersion(rocket));
|
||||
}
|
||||
|
||||
/*
|
||||
* Utility Functions
|
||||
*/
|
||||
|
||||
static int getCalculatedFileVersion(Rocket rocket) {
|
||||
OpenRocketSaver saver = new OpenRocketSaver();
|
||||
OpenRocketDocument rocketDoc = OpenRocketDocumentFactory.createDocumentFromRocket(rocket);
|
||||
int fileVersion = saver.testAccessor_calculateNecessaryFileVersion(rocketDoc, null);
|
||||
return fileVersion;
|
||||
}
|
||||
|
||||
static int getCalculatedFileVersion(OpenRocketDocument rocketDoc) {
|
||||
OpenRocketSaver saver = new OpenRocketSaver();
|
||||
int fileVersion = saver.testAccessor_calculateNecessaryFileVersion(rocketDoc, null);
|
||||
return fileVersion;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package net.sf.openrocket.file.openrocket.importt;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.sf.openrocket.file.openrocket.OpenRocketSaver;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class DocumentConfigTest {
|
||||
|
||||
/**
|
||||
* Check that unit tests exist for all supported OR file versions.
|
||||
*
|
||||
* This test is here to remind future developers to update the unit tests after adding a file version.
|
||||
*
|
||||
* Whenever a new file version is created, this test needs to be updated after new unit tests
|
||||
* are created in OpenRocketSaver.java for the new file version.
|
||||
*/
|
||||
@Test
|
||||
public void testAllVersionsTested() {
|
||||
|
||||
// Update this after creating new unit tests in OpenRocketSaver for a new OR file version
|
||||
String[] testedVersionsStr = { "1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6" };
|
||||
|
||||
List<String> supportedVersions = Arrays.asList(DocumentConfig.SUPPORTED_VERSIONS);
|
||||
List<String> testedVersions = Arrays.asList(testedVersionsStr);
|
||||
|
||||
for (String supportedVersion : supportedVersions) {
|
||||
String msg = String.format("No unit tests exist for OpenRocket file version %s", supportedVersion);
|
||||
assertTrue(msg, testedVersions.contains(supportedVersion));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileVersionDivisor() {
|
||||
assertEquals(OpenRocketSaver.FILE_VERSION_DIVISOR, DocumentConfig.FILE_VERSION_DIVISOR);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user