summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-08-04 18:44:57 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-11-09 19:19:04 +0100
commit7c9f46acd202121e67557bb634961ef17a9f6c1f (patch)
treef21b6ff42a930cc97c31db9f20c03f1613e70291 /tests
parentcd4f66014f7b5269dff9e088c9d7d38241c03156 (diff)
downloadsubsurface-7c9f46acd202121e67557bb634961ef17a9f6c1f.tar.gz
Core: remove MAX_CYLINDERS restriction
Instead of using fixed size arrays, use a new cylinder_table structure. The code copies the weightsystem code, but is significantly more complex because cylinders are such an integral part of the core. Two functions to access the cylinders were added: get_cylinder() and get_or_create_cylinder() The former does a simple array access and supposes that the cylinder exists. The latter is used by the parser(s) and if a cylinder with the given id does not exist, cylinders up to that id are generated. One point will make C programmers cringe: the cylinder structure is passed by value. This is due to the way the table-macros work. A refactoring of the table macros is planned. It has to be noted that the size of a cylinder_t is 64 bytes, i.e. 8 long words on a 64-bit architecture, so passing on the stack is probably not even significantly slower than passing as reference. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'tests')
-rw-r--r--tests/testplan.cpp132
1 files changed, 80 insertions, 52 deletions
diff --git a/tests/testplan.cpp b/tests/testplan.cpp
index 2e78ec3c9..b567fe5d7 100644
--- a/tests/testplan.cpp
+++ b/tests/testplan.cpp
@@ -51,11 +51,14 @@ void setupPlan(struct diveplan *dp)
struct gasmix ean36 = {{360}, {0}};
struct gasmix oxygen = {{1000}, {0}};
pressure_t po2 = {1600};
- displayed_dive.cylinder[0].gasmix = bottomgas;
- displayed_dive.cylinder[0].type.size.mliter = 36000;
- displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
- displayed_dive.cylinder[1].gasmix = ean36;
- displayed_dive.cylinder[2].gasmix = oxygen;
+ cylinder_t *cyl0 = get_or_create_cylinder(&displayed_dive, 0);
+ cylinder_t *cyl1 = get_or_create_cylinder(&displayed_dive, 1);
+ cylinder_t *cyl2 = get_or_create_cylinder(&displayed_dive, 2);
+ cyl0->gasmix = bottomgas;
+ cyl0->type.size.mliter = 36000;
+ cyl0->type.workingpressure.mbar = 232000;
+ cyl1->gasmix = ean36;
+ cyl2->gasmix = oxygen;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
@@ -79,11 +82,14 @@ void setupPlanVpmb45m30mTx(struct diveplan *dp)
struct gasmix ean50 = {{500}, {0}};
struct gasmix oxygen = {{1000}, {0}};
pressure_t po2 = {1600};
- displayed_dive.cylinder[0].gasmix = bottomgas;
- displayed_dive.cylinder[0].type.size.mliter = 24000;
- displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
- displayed_dive.cylinder[1].gasmix = ean50;
- displayed_dive.cylinder[2].gasmix = oxygen;
+ cylinder_t *cyl0 = get_or_create_cylinder(&displayed_dive, 0);
+ cylinder_t *cyl1 = get_or_create_cylinder(&displayed_dive, 1);
+ cylinder_t *cyl2 = get_or_create_cylinder(&displayed_dive, 2);
+ cyl0->gasmix = bottomgas;
+ cyl0->type.size.mliter = 24000;
+ cyl0->type.workingpressure.mbar = 232000;
+ cyl1->gasmix = ean50;
+ cyl2->gasmix = oxygen;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
@@ -107,11 +113,14 @@ void setupPlanVpmb60m10mTx(struct diveplan *dp)
struct gasmix tx50_15 = {{500}, {150}};
struct gasmix oxygen = {{1000}, {0}};
pressure_t po2 = {1600};
- displayed_dive.cylinder[0].gasmix = bottomgas;
- displayed_dive.cylinder[0].type.size.mliter = 24000;
- displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
- displayed_dive.cylinder[1].gasmix = tx50_15;
- displayed_dive.cylinder[2].gasmix = oxygen;
+ cylinder_t *cyl0 = get_or_create_cylinder(&displayed_dive, 0);
+ cylinder_t *cyl1 = get_or_create_cylinder(&displayed_dive, 1);
+ cylinder_t *cyl2 = get_or_create_cylinder(&displayed_dive, 2);
+ cyl0->gasmix = bottomgas;
+ cyl0->type.size.mliter = 24000;
+ cyl0->type.workingpressure.mbar = 232000;
+ cyl1->gasmix = tx50_15;
+ cyl2->gasmix = oxygen;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
@@ -130,9 +139,10 @@ void setupPlanVpmb60m30minAir(struct diveplan *dp)
dp->decosac = prefs.decosac;
struct gasmix bottomgas = {{210}, {0}};
- displayed_dive.cylinder[0].gasmix = bottomgas;
- displayed_dive.cylinder[0].type.size.mliter = 100000;
- displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
+ cylinder_t *cyl0 = get_or_create_cylinder(&displayed_dive, 0);
+ cyl0->gasmix = bottomgas;
+ cyl0->type.size.mliter = 100000;
+ cyl0->type.workingpressure.mbar = 232000;
displayed_dive.surface_pressure.mbar = 1013;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
@@ -152,10 +162,12 @@ void setupPlanVpmb60m30minEan50(struct diveplan *dp)
struct gasmix bottomgas = {{210}, {0}};
struct gasmix ean50 = {{500}, {0}};
pressure_t po2 = {1600};
- displayed_dive.cylinder[0].gasmix = bottomgas;
- displayed_dive.cylinder[0].type.size.mliter = 36000;
- displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
- displayed_dive.cylinder[1].gasmix = ean50;
+ cylinder_t *cyl0 = get_or_create_cylinder(&displayed_dive, 0);
+ cylinder_t *cyl1 = get_or_create_cylinder(&displayed_dive, 1);
+ cyl0->gasmix = bottomgas;
+ cyl0->type.size.mliter = 36000;
+ cyl0->type.workingpressure.mbar = 232000;
+ cyl1->gasmix = ean50;
displayed_dive.surface_pressure.mbar = 1013;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
@@ -176,10 +188,12 @@ void setupPlanVpmb60m30minTx(struct diveplan *dp)
struct gasmix bottomgas = {{180}, {450}};
struct gasmix ean50 = {{500}, {0}};
pressure_t po2 = {1600};
- displayed_dive.cylinder[0].gasmix = bottomgas;
- displayed_dive.cylinder[0].type.size.mliter = 36000;
- displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
- displayed_dive.cylinder[1].gasmix = ean50;
+ cylinder_t *cyl0 = get_or_create_cylinder(&displayed_dive, 0);
+ cylinder_t *cyl1 = get_or_create_cylinder(&displayed_dive, 1);
+ cyl0->gasmix = bottomgas;
+ cyl0->type.size.mliter = 36000;
+ cyl0->type.workingpressure.mbar = 232000;
+ cyl1->gasmix = ean50;
displayed_dive.surface_pressure.mbar = 1013;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
@@ -198,9 +212,10 @@ void setupPlanVpmbMultiLevelAir(struct diveplan *dp)
dp->decosac = prefs.decosac;
struct gasmix bottomgas = {{210}, {0}};
- displayed_dive.cylinder[0].gasmix = bottomgas;
- displayed_dive.cylinder[0].type.size.mliter = 200000;
- displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
+ cylinder_t *cyl0 = get_or_create_cylinder(&displayed_dive, 0);
+ cyl0->gasmix = bottomgas;
+ cyl0->type.size.mliter = 200000;
+ cyl0->type.workingpressure.mbar = 232000;
displayed_dive.surface_pressure.mbar = 1013;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
@@ -223,11 +238,14 @@ void setupPlanVpmb100m60min(struct diveplan *dp)
struct gasmix ean50 = {{500}, {0}};
struct gasmix oxygen = {{1000}, {0}};
pressure_t po2 = {1600};
- displayed_dive.cylinder[0].gasmix = bottomgas;
- displayed_dive.cylinder[0].type.size.mliter = 200000;
- displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
- displayed_dive.cylinder[1].gasmix = ean50;
- displayed_dive.cylinder[2].gasmix = oxygen;
+ cylinder_t *cyl0 = get_or_create_cylinder(&displayed_dive, 0);
+ cylinder_t *cyl1 = get_or_create_cylinder(&displayed_dive, 1);
+ cylinder_t *cyl2 = get_or_create_cylinder(&displayed_dive, 2);
+ cyl0->gasmix = bottomgas;
+ cyl0->type.size.mliter = 200000;
+ cyl0->type.workingpressure.mbar = 232000;
+ cyl1->gasmix = ean50;
+ cyl2->gasmix = oxygen;
displayed_dive.surface_pressure.mbar = 1013;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
@@ -250,11 +268,14 @@ void setupPlanVpmb100m10min(struct diveplan *dp)
struct gasmix ean50 = {{500}, {0}};
struct gasmix oxygen = {{1000}, {0}};
pressure_t po2 = {1600};
- displayed_dive.cylinder[0].gasmix = bottomgas;
- displayed_dive.cylinder[0].type.size.mliter = 60000;
- displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
- displayed_dive.cylinder[1].gasmix = ean50;
- displayed_dive.cylinder[2].gasmix = oxygen;
+ cylinder_t *cyl0 = get_or_create_cylinder(&displayed_dive, 0);
+ cylinder_t *cyl1 = get_or_create_cylinder(&displayed_dive, 1);
+ cylinder_t *cyl2 = get_or_create_cylinder(&displayed_dive, 2);
+ cyl0->gasmix = bottomgas;
+ cyl0->type.size.mliter = 60000;
+ cyl0->type.workingpressure.mbar = 232000;
+ cyl1->gasmix = ean50;
+ cyl2->gasmix = oxygen;
displayed_dive.surface_pressure.mbar = 1013;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
@@ -274,9 +295,10 @@ void setupPlanVpmb30m20min(struct diveplan *dp)
dp->decosac = prefs.decosac;
struct gasmix bottomgas = {{210}, {0}};
- displayed_dive.cylinder[0].gasmix = bottomgas;
- displayed_dive.cylinder[0].type.size.mliter = 36000;
- displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
+ cylinder_t *cyl0 = get_or_create_cylinder(&displayed_dive, 0);
+ cyl0->gasmix = bottomgas;
+ cyl0->type.size.mliter = 36000;
+ cyl0->type.workingpressure.mbar = 232000;
displayed_dive.surface_pressure.mbar = 1013;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
@@ -298,12 +320,16 @@ void setupPlanVpmb100mTo70m30min(struct diveplan *dp)
struct gasmix ean50 = {{500}, {0}};
struct gasmix oxygen = {{1000}, {0}};
pressure_t po2 = {1600};
- displayed_dive.cylinder[0].gasmix = bottomgas;
- displayed_dive.cylinder[0].type.size.mliter = 36000;
- displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
- displayed_dive.cylinder[1].gasmix = tx21_35;
- displayed_dive.cylinder[2].gasmix = ean50;
- displayed_dive.cylinder[3].gasmix = oxygen;
+ cylinder_t *cyl0 = get_or_create_cylinder(&displayed_dive, 0);
+ cylinder_t *cyl1 = get_or_create_cylinder(&displayed_dive, 1);
+ cylinder_t *cyl2 = get_or_create_cylinder(&displayed_dive, 2);
+ cylinder_t *cyl3 = get_or_create_cylinder(&displayed_dive, 3);
+ cyl0->gasmix = bottomgas;
+ cyl0->type.size.mliter = 36000;
+ cyl0->type.workingpressure.mbar = 232000;
+ cyl1->gasmix = tx21_35;
+ cyl2->gasmix = ean50;
+ cyl3->gasmix = oxygen;
displayed_dive.surface_pressure.mbar = 1013;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
@@ -330,10 +356,12 @@ void setupPlanSeveralGases(struct diveplan *dp)
struct gasmix ean36 = {{360}, {0}};
struct gasmix tx11_50 = {{110}, {500}};
- displayed_dive.cylinder[0].gasmix = ean36;
- displayed_dive.cylinder[0].type.size.mliter = 36000;
- displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
- displayed_dive.cylinder[1].gasmix = tx11_50;
+ cylinder_t *cyl0 = get_or_create_cylinder(&displayed_dive, 0);
+ cylinder_t *cyl1 = get_or_create_cylinder(&displayed_dive, 1);
+ cyl0->gasmix = ean36;
+ cyl0->type.size.mliter = 36000;
+ cyl0->type.workingpressure.mbar = 232000;
+ cyl1->gasmix = tx11_50;
displayed_dive.surface_pressure.mbar = 1013;
reset_cylinders(&displayed_dive, true);
free_dps(dp);