From 75767c456a2889d213621866a9f7fbb108f3366d Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 10 May 2019 19:51:43 +0200 Subject: Turn application state into enum The application state was encoded in a QByteArray. Thus, there was no compile-time checking. Typos would lead to silent failures. Turn the application state into an enum. Use the enum-class construct, so that the values don't polute the global namespace. Moreover, this makes them strongly typed, i.e. they don't auto-convert to integers. A disadvantage is that the enums now have to be cast to int explicitly when used to index an array. Replace two hash-maps in MainWindow to arrays of fixed sizes. Move the application-state details into their own files. Signed-off-by: Berthold Stoeger --- tests/testplan.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'tests/testplan.cpp') diff --git a/tests/testplan.cpp b/tests/testplan.cpp index 1d32aacfb..7f48dbef2 100644 --- a/tests/testplan.cpp +++ b/tests/testplan.cpp @@ -5,6 +5,7 @@ #include "core/qthelper.h" #include "core/subsurfacestartup.h" #include "core/units.h" +#include "core/applicationstate.h" #include #define DEBUG 1 @@ -469,7 +470,7 @@ void TestPlan::testVpmbMetric45m30minTx() struct diveplan testPlan = {}; setupPlanVpmb45m30mTx(&testPlan); - setCurrentAppState("PlanDive"); + setAppState(ApplicationState::PlanDive); plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); @@ -500,7 +501,7 @@ void TestPlan::testVpmbMetric60m10minTx() struct diveplan testPlan = {}; setupPlanVpmb60m10mTx(&testPlan); - setCurrentAppState("PlanDive"); + setAppState(ApplicationState::PlanDive); plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); @@ -531,7 +532,7 @@ void TestPlan::testVpmbMetric60m30minAir() struct diveplan testPlan = {}; setupPlanVpmb60m30minAir(&testPlan); - setCurrentAppState("PlanDive"); + setAppState(ApplicationState::PlanDive); plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); @@ -562,7 +563,7 @@ void TestPlan::testVpmbMetric60m30minEan50() struct diveplan testPlan = {}; setupPlanVpmb60m30minEan50(&testPlan); - setCurrentAppState("PlanDive"); + setAppState(ApplicationState::PlanDive); plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); @@ -599,7 +600,7 @@ void TestPlan::testVpmbMetric60m30minTx() struct diveplan testPlan = {}; setupPlanVpmb60m30minTx(&testPlan); - setCurrentAppState("PlanDive"); + setAppState(ApplicationState::PlanDive); plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); @@ -636,7 +637,7 @@ void TestPlan::testVpmbMetric100m60min() struct diveplan testPlan = {}; setupPlanVpmb100m60min(&testPlan); - setCurrentAppState("PlanDive"); + setAppState(ApplicationState::PlanDive); plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); @@ -680,7 +681,7 @@ void TestPlan::testMultipleGases() struct diveplan testPlan = {}; setupPlanSeveralGases(&testPlan); - setCurrentAppState("PlanDive"); + setAppState(ApplicationState::PlanDive); plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); @@ -706,7 +707,7 @@ void TestPlan::testVpmbMetricMultiLevelAir() struct diveplan testPlan = {}; setupPlanVpmbMultiLevelAir(&testPlan); - setCurrentAppState("PlanDive"); + setAppState(ApplicationState::PlanDive); plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); @@ -737,7 +738,7 @@ void TestPlan::testVpmbMetric100m10min() struct diveplan testPlan = {}; setupPlanVpmb100m10min(&testPlan); - setCurrentAppState("PlanDive"); + setAppState(ApplicationState::PlanDive); plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); @@ -784,7 +785,7 @@ void TestPlan::testVpmbMetricRepeat() struct diveplan testPlan = {}; setupPlanVpmb30m20min(&testPlan); - setCurrentAppState("PlanDive"); + setAppState(ApplicationState::PlanDive); plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); -- cgit v1.2.3-70-g09d2