diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testparse.cpp | 128 | ||||
-rw-r--r-- | tests/testplan.cpp | 327 | ||||
-rw-r--r-- | tests/testplan.h | 6 |
3 files changed, 436 insertions, 25 deletions
diff --git a/tests/testparse.cpp b/tests/testparse.cpp index fa1d6d223..76b3912da 100644 --- a/tests/testparse.cpp +++ b/tests/testparse.cpp @@ -4,19 +4,77 @@ #include "divelist.h" #include <QTextStream> +char *intdup(int index) +{ + char tmpbuf[21]; + + snprintf(tmpbuf, sizeof(tmpbuf) - 2, "%d", index); + tmpbuf[20] = 0; + return strdup(tmpbuf); +} + void TestParse::testParseCSV() { // some basic file parsing tests // // CSV import should work verbose = 1; - QCOMPARE(parse_manual_file(SUBSURFACE_SOURCE "/dives/test41.csv", - 0, // tab separator - 0, // metric units - 1, // mm/dd/yyyy - 2, // min:sec - 0, 1, 2, 3, -1, -1, 4, 5, // Dive #, date, time, duration, maxdepth, avgdepth - -1, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1), 0); // buddy, suit + char *params[55]; + int pnr = 0; + + params[pnr++] = strdup(strdup("numberField")); + params[pnr++] = intdup(0); + params[pnr++] = strdup("dateField"); + params[pnr++] = intdup(1); + params[pnr++] = strdup("timeField"); + params[pnr++] = intdup(2); + params[pnr++] = strdup("durationField"); + params[pnr++] = intdup(3); + params[pnr++] = strdup("locationField"); + params[pnr++] = intdup(-1); + params[pnr++] = strdup("gpsField"); + params[pnr++] = intdup(-1); + params[pnr++] = strdup("maxDepthField"); + params[pnr++] = intdup(4); + params[pnr++] = strdup("meanDepthField"); + params[pnr++] = intdup(5); + params[pnr++] = strdup("divemasterField"); + params[pnr++] = intdup(-1); + params[pnr++] = strdup("buddyField"); + params[pnr++] = intdup(6); + params[pnr++] = strdup("suitField"); + params[pnr++] = intdup(7); + params[pnr++] = strdup("notesField"); + params[pnr++] = intdup(-1); + params[pnr++] = strdup("weightField"); + params[pnr++] = intdup(-1); + params[pnr++] = strdup("tagsField"); + params[pnr++] = intdup(-1); + params[pnr++] = strdup("separatorIndex"); + params[pnr++] = intdup(0); + params[pnr++] = strdup("units"); + params[pnr++] = intdup(0); + params[pnr++] = strdup("datefmt"); + params[pnr++] = intdup(1); + params[pnr++] = strdup("durationfmt"); + params[pnr++] = intdup(2); + params[pnr++] = strdup("cylindersizeField"); + params[pnr++] = intdup(-1); + params[pnr++] = strdup("startpressureField"); + params[pnr++] = intdup(-1); + params[pnr++] = strdup("endpressureField"); + params[pnr++] = intdup(-1); + params[pnr++] = strdup("o2Field"); + params[pnr++] = intdup(-1); + params[pnr++] = strdup("heField"); + params[pnr++] = intdup(-1); + params[pnr++] = strdup("airtempField"); + params[pnr++] = intdup(-1); + params[pnr++] = strdup("watertempField"); + params[pnr++] = intdup(-1); + params[pnr++] = NULL; + + QCOMPARE(parse_manual_file(SUBSURFACE_SOURCE "/dives/test41.csv", params, pnr - 1), 0); fprintf(stderr, "number of dives %d \n", dive_table.nr); } @@ -210,25 +268,45 @@ void TestParse::testParseNewFormat() * Validate the parsing routine returns success. */ + char *params[40]; + int pnr = 0; + + params[pnr++] = strdup("timeField"); + params[pnr++] = intdup(headers.indexOf(tr("Sample time"))); + params[pnr++] = strdup("depthField"); + params[pnr++] = intdup(headers.indexOf(tr("Sample depth"))); + params[pnr++] = strdup("tempField"); + params[pnr++] = intdup(headers.indexOf(tr("Sample temperature"))); + params[pnr++] = strdup("po2Field"); + params[pnr++] = intdup(headers.indexOf(tr("Sample pO₂"))); + params[pnr++] = strdup("o2sensor1Field"); + params[pnr++] = intdup(headers.indexOf(tr("Sample sensor1 pO₂"))); + params[pnr++] = strdup("o2sensor2Field"); + params[pnr++] = intdup(headers.indexOf(tr("Sample sensor2 pO₂"))); + params[pnr++] = strdup("o2sensor3Field"); + params[pnr++] = intdup(headers.indexOf(tr("Sample sensor3 pO₂"))); + params[pnr++] = strdup("cnsField"); + params[pnr++] = intdup(headers.indexOf(tr("Sample CNS"))); + params[pnr++] = strdup("ndlField"); + params[pnr++] = intdup(headers.indexOf(tr("Sample NDL"))); + params[pnr++] = strdup("ttsField"); + params[pnr++] = intdup(headers.indexOf(tr("Sample TTS"))); + params[pnr++] = strdup("stopdepthField"); + params[pnr++] = intdup(headers.indexOf(tr("Sample stopdepth"))); + params[pnr++] = strdup("pressureField"); + params[pnr++] = intdup(headers.indexOf(tr("Sample pressure"))); + params[pnr++] = strdup("setpointFiend"); + params[pnr++] = intdup(-1); + params[pnr++] = strdup("separatorIndex"); + params[pnr++] = intdup(2); + params[pnr++] = strdup("units"); + params[pnr++] = intdup(0); + params[pnr++] = strdup("delta"); + params[pnr++] = strdup(delta.toUtf8().data()); + params[pnr++] = NULL; + QCOMPARE(parse_seabear_csv_file(file.toUtf8().data(), - headers.indexOf(tr("Sample time")), - headers.indexOf(tr("Sample depth")), - headers.indexOf(tr("Sample temperature")), - headers.indexOf(tr("Sample pO₂")), - headers.indexOf(tr("Sample sensor1 pO₂")), - headers.indexOf(tr("Sample sensor2 pO₂")), - headers.indexOf(tr("Sample sensor3 pO₂")), - headers.indexOf(tr("Sample CNS")), - headers.indexOf(tr("Sample NDL")), - headers.indexOf(tr("Sample TTS")), - headers.indexOf(tr("Sample stopdepth")), - headers.indexOf(tr("Sample pressure")), - 2, - "csv", - 0, - delta.toUtf8().data(), - "" - ), 0); + params, pnr - 1, "csv"), 0); /* * Set artificial but static dive times so the result diff --git a/tests/testplan.cpp b/tests/testplan.cpp index 88f136602..f09773524 100644 --- a/tests/testplan.cpp +++ b/tests/testplan.cpp @@ -2,6 +2,7 @@ #include "testplan.h" #include "planner.h" #include "units.h" +#include "qthelper.h" #include <QDebug> #define DEBUG 1 @@ -19,6 +20,18 @@ void setupPrefs() prefs.last_stop = true; } +void setupPrefsVpmb() +{ + prefs = default_prefs; + prefs.ascrate50 = 10000 / 60; + prefs.ascrate75 = prefs.ascrate50; + prefs.ascratestops = prefs.ascrate50; + prefs.ascratelast6m = prefs.ascrate50; + prefs.descrate = 99000 / 60; + prefs.last_stop = false; + prefs.deco_mode = VPMB; +} + void setupPlan(struct diveplan *dp) { dp->salinity = 10300; @@ -45,6 +58,140 @@ void setupPlan(struct diveplan *dp) plan_add_segment(dp, 0, gas_mod(&oxygen, po2, &displayed_dive, M_OR_FT(3,10)).mm, oxygen, 0, 1); } +void setupPlanVpmb60m30minAir(struct diveplan *dp) +{ + dp->salinity = 10300; + dp->surface_pressure = 1013; + dp->bottomsac = 0; + dp->decosac = 0; + + struct gasmix bottomgas = { {210}, {0} }; + pressure_t po2 = { 1600 }; + displayed_dive.cylinder[0].gasmix = bottomgas; + displayed_dive.surface_pressure.mbar = 1013; + reset_cylinders(&displayed_dive, true); + free_dps(dp); + + int droptime = M_OR_FT(60, 200) * 60 / M_OR_FT(99, 330); + plan_add_segment(dp, droptime, M_OR_FT(60, 200), bottomgas, 0, 1); + plan_add_segment(dp, 30*60 - droptime, M_OR_FT(60, 200), bottomgas, 0, 1); +} + +void setupPlanVpmb60m30minEan50(struct diveplan *dp) +{ + dp->salinity = 10300; + dp->surface_pressure = 1013; + dp->bottomsac = 0; + dp->decosac = 0; + + struct gasmix bottomgas = { {210}, {0} }; + struct gasmix ean50 = { {500}, {0} }; + pressure_t po2 = { 1600 }; + displayed_dive.cylinder[0].gasmix = bottomgas; + displayed_dive.cylinder[1].gasmix = ean50; + displayed_dive.surface_pressure.mbar = 1013; + reset_cylinders(&displayed_dive, true); + free_dps(dp); + + int droptime = M_OR_FT(60, 200) * 60 / M_OR_FT(99, 330); + plan_add_segment(dp, droptime, M_OR_FT(60, 200), bottomgas, 0, 1); + plan_add_segment(dp, 30*60 - droptime, M_OR_FT(60, 200), bottomgas, 0, 1); + plan_add_segment(dp, 0, gas_mod(&ean50, po2, &displayed_dive, M_OR_FT(3,10)).mm, ean50, 0, 1); +} + +void setupPlanVpmb60m30minTx(struct diveplan *dp) +{ + dp->salinity = 10300; + dp->surface_pressure = 1013; + dp->bottomsac = 0; + dp->decosac = 0; + + struct gasmix bottomgas = { {180}, {450} }; + struct gasmix ean50 = { {500}, {0} }; + pressure_t po2 = { 1600 }; + displayed_dive.cylinder[0].gasmix = bottomgas; + displayed_dive.cylinder[1].gasmix = ean50; + displayed_dive.surface_pressure.mbar = 1013; + reset_cylinders(&displayed_dive, true); + free_dps(dp); + + int droptime = M_OR_FT(60, 200) * 60 / M_OR_FT(99, 330); + plan_add_segment(dp, droptime, M_OR_FT(60, 200), bottomgas, 0, 1); + plan_add_segment(dp, 30*60 - droptime, M_OR_FT(60, 200), bottomgas, 0, 1); + plan_add_segment(dp, 0, gas_mod(&ean50, po2, &displayed_dive, M_OR_FT(3,10)).mm, ean50, 0, 1); +} + +void setupPlanVpmbMultiLevelAir(struct diveplan *dp) +{ + dp->salinity = 10300; + dp->surface_pressure = 1013; + dp->bottomsac = 0; + dp->decosac = 0; + + struct gasmix bottomgas = { {210}, {0} }; + pressure_t po2 = { 1600 }; + displayed_dive.cylinder[0].gasmix = bottomgas; + displayed_dive.surface_pressure.mbar = 1013; + reset_cylinders(&displayed_dive, true); + free_dps(dp); + + int droptime = M_OR_FT(20, 66) * 60 / M_OR_FT(99, 330); + plan_add_segment(dp, droptime, M_OR_FT(20, 66), bottomgas, 0, 1); + plan_add_segment(dp, 10*60 - droptime, M_OR_FT(20, 66), bottomgas, 0, 1); + plan_add_segment(dp, 1*60, M_OR_FT(60, 200), bottomgas, 0, 1); + plan_add_segment(dp, 29*60, M_OR_FT(60, 200), bottomgas, 0, 1); +} + +void setupPlanVpmb100m60min(struct diveplan *dp) +{ + dp->salinity = 10300; + dp->surface_pressure = 1013; + dp->bottomsac = 0; + dp->decosac = 0; + + struct gasmix bottomgas = { {180}, {450} }; + struct gasmix ean50 = { {500}, {0} }; + struct gasmix oxygen = { {1000}, {0} }; + pressure_t po2 = { 1600 }; + displayed_dive.cylinder[0].gasmix = bottomgas; + displayed_dive.cylinder[1].gasmix = ean50; + displayed_dive.cylinder[2].gasmix = oxygen; + displayed_dive.surface_pressure.mbar = 1013; + reset_cylinders(&displayed_dive, true); + free_dps(dp); + + int droptime = M_OR_FT(100, 330) * 60 / M_OR_FT(99, 330); + plan_add_segment(dp, droptime, M_OR_FT(100, 330), bottomgas, 0, 1); + plan_add_segment(dp, 60*60 - droptime, M_OR_FT(100, 330), bottomgas, 0, 1); + plan_add_segment(dp, 0, gas_mod(&ean50, po2, &displayed_dive, M_OR_FT(3,10)).mm, ean50, 0, 1); + plan_add_segment(dp, 0, gas_mod(&oxygen, po2, &displayed_dive, M_OR_FT(3,10)).mm, oxygen, 0, 1); +} + +void setupPlanVpmb100m10min(struct diveplan *dp) +{ + dp->salinity = 10300; + dp->surface_pressure = 1013; + dp->bottomsac = 0; + dp->decosac = 0; + + struct gasmix bottomgas = { {180}, {450} }; + struct gasmix ean50 = { {500}, {0} }; + struct gasmix oxygen = { {1000}, {0} }; + pressure_t po2 = { 1600 }; + displayed_dive.cylinder[0].gasmix = bottomgas; + displayed_dive.cylinder[1].gasmix = ean50; + displayed_dive.cylinder[2].gasmix = oxygen; + displayed_dive.surface_pressure.mbar = 1013; + reset_cylinders(&displayed_dive, true); + free_dps(dp); + + int droptime = M_OR_FT(100, 330) * 60 / M_OR_FT(99, 330); + plan_add_segment(dp, droptime, M_OR_FT(100, 330), bottomgas, 0, 1); + plan_add_segment(dp, 10*60 - droptime, M_OR_FT(100, 330), bottomgas, 0, 1); + plan_add_segment(dp, 0, gas_mod(&ean50, po2, &displayed_dive, M_OR_FT(3,10)).mm, ean50, 0, 1); + plan_add_segment(dp, 0, gas_mod(&oxygen, po2, &displayed_dive, M_OR_FT(3,10)).mm, oxygen, 0, 1); +} + void TestPlan::testMetric() { char *cache = NULL; @@ -117,4 +264,184 @@ void TestPlan::testImperial() QCOMPARE(displayed_dive.dc.duration.seconds, 110u * 60u - 2u); } +void TestPlan::testVpmbMetric60m30minAir() +{ + char *cache = NULL; + + setupPrefsVpmb(); + prefs.unit_system = METRIC; + prefs.units.length = units::METERS; + + struct diveplan testPlan = { 0 }; + setupPlanVpmb60m30minAir(&testPlan); + setCurrentAppState("PlanDive"); + + plan(&testPlan, &cache, 1, 0); + +#if DEBUG + free(displayed_dive.notes); + displayed_dive.notes = NULL; + save_dive(stdout, &displayed_dive); +#endif + + // check expected run time of 141 minutes + QCOMPARE(displayed_dive.dc.duration.seconds, 8480u); +} + +void TestPlan::testVpmbMetric60m30minEan50() +{ + char *cache = NULL; + + setupPrefsVpmb(); + prefs.unit_system = METRIC; + prefs.units.length = units::METERS; + + struct diveplan testPlan = { 0 }; + setupPlanVpmb60m30minEan50(&testPlan); + setCurrentAppState("PlanDive"); + + plan(&testPlan, &cache, 1, 0); + +#if DEBUG + free(displayed_dive.notes); + displayed_dive.notes = NULL; + save_dive(stdout, &displayed_dive); +#endif + + // check first gas change to EAN50 at 21m + struct event *ev = displayed_dive.dc.events; + QVERIFY(ev != NULL); + QCOMPARE(ev->gas.index, 1); + QCOMPARE(ev->value, 50); + QCOMPARE(get_depth_at_time(&displayed_dive.dc, ev->time.seconds), 21000); + // check expected run time of 95 minutes + QCOMPARE(displayed_dive.dc.duration.seconds, 5720u); +} + +void TestPlan::testVpmbMetric60m30minTx() +{ + char *cache = NULL; + + setupPrefsVpmb(); + prefs.unit_system = METRIC; + prefs.units.length = units::METERS; + + struct diveplan testPlan = { 0 }; + setupPlanVpmb60m30minTx(&testPlan); + setCurrentAppState("PlanDive"); + + plan(&testPlan, &cache, 1, 0); + +#if DEBUG + free(displayed_dive.notes); + displayed_dive.notes = NULL; + save_dive(stdout, &displayed_dive); +#endif + + // check first gas change to EAN50 at 21m + struct event *ev = displayed_dive.dc.events; + QVERIFY(ev != NULL); + QCOMPARE(ev->gas.index, 1); + QCOMPARE(ev->value, 50); + QCOMPARE(get_depth_at_time(&displayed_dive.dc, ev->time.seconds), 21000); + // check expected run time of 89 minutes + QCOMPARE(displayed_dive.dc.duration.seconds, 5360u); +} + +void TestPlan::testVpmbMetric100m60min() +{ + char *cache = NULL; + + setupPrefsVpmb(); + prefs.unit_system = METRIC; + prefs.units.length = units::METERS; + + struct diveplan testPlan = { 0 }; + setupPlanVpmb100m60min(&testPlan); + setCurrentAppState("PlanDive"); + + plan(&testPlan, &cache, 1, 0); + +#if DEBUG + free(displayed_dive.notes); + displayed_dive.notes = NULL; + save_dive(stdout, &displayed_dive); +#endif + + // check first gas change to EAN50 at 21m + struct event *ev = displayed_dive.dc.events; + QVERIFY(ev != NULL); + QCOMPARE(ev->gas.index, 1); + QCOMPARE(ev->value, 50); + QCOMPARE(get_depth_at_time(&displayed_dive.dc, ev->time.seconds), 21000); + // check second gas change to Oxygen at 6m + ev = ev->next; + QVERIFY(ev != NULL); + QCOMPARE(ev->gas.index, 2); + QCOMPARE(ev->value, 100); + QCOMPARE(get_depth_at_time(&displayed_dive.dc, ev->time.seconds), 6000); + // check expected run time of 316 minutes + QCOMPARE(displayed_dive.dc.duration.seconds, 18980u); +} + +void TestPlan::testVpmbMetricMultiLevelAir() +{ + char *cache = NULL; + + setupPrefsVpmb(); + prefs.unit_system = METRIC; + prefs.units.length = units::METERS; + + struct diveplan testPlan = { 0 }; + setupPlanVpmbMultiLevelAir(&testPlan); + setCurrentAppState("PlanDive"); + + plan(&testPlan, &cache, 1, 0); + +#if DEBUG + free(displayed_dive.notes); + displayed_dive.notes = NULL; + save_dive(stdout, &displayed_dive); +#endif + + // check expected run time of 167 minutes + QCOMPARE(displayed_dive.dc.duration.seconds, 10040u); +} + +void TestPlan::testVpmbMetric100m10min() +{ + char *cache = NULL; + + setupPrefsVpmb(); + prefs.unit_system = METRIC; + prefs.units.length = units::METERS; + + struct diveplan testPlan = { 0 }; + setupPlanVpmb100m10min(&testPlan); + setCurrentAppState("PlanDive"); + + plan(&testPlan, &cache, 1, 0); + +#if DEBUG + free(displayed_dive.notes); + displayed_dive.notes = NULL; + save_dive(stdout, &displayed_dive); +#endif + + // check first gas change to EAN50 at 21m + struct event *ev = displayed_dive.dc.events; + QVERIFY(ev != NULL); + QCOMPARE(ev->gas.index, 1); + QCOMPARE(ev->value, 50); + QCOMPARE(get_depth_at_time(&displayed_dive.dc, ev->time.seconds), 21000); + // check second gas change to Oxygen at 6m + ev = ev->next; + QVERIFY(ev != NULL); + QCOMPARE(ev->gas.index, 2); + QCOMPARE(ev->value, 100); + QCOMPARE(get_depth_at_time(&displayed_dive.dc, ev->time.seconds), 6000); + // check expected run time of 58 minutes + QCOMPARE(displayed_dive.dc.duration.seconds, 3500u); +} + QTEST_MAIN(TestPlan) diff --git a/tests/testplan.h b/tests/testplan.h index b35cd75c6..f73ad0d9a 100644 --- a/tests/testplan.h +++ b/tests/testplan.h @@ -8,6 +8,12 @@ class TestPlan : public QObject { private slots: void testImperial(); void testMetric(); + void testVpmbMetric60m30minAir(); + void testVpmbMetric60m30minEan50(); + void testVpmbMetric60m30minTx(); + void testVpmbMetricMultiLevelAir(); + void testVpmbMetric100m60min(); + void testVpmbMetric100m10min(); }; #endif // TESTPLAN_H |