| 
									
										
										
										
											2019-12-25 16:16:15 +01:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							|  |  |  | #include "testplannershared.h"
 | 
					
						
							|  |  |  | #include "backend-shared/plannershared.h"
 | 
					
						
							| 
									
										
										
										
											2019-12-25 18:10:45 +01:00
										 |  |  | #include "core/settings/qPrefDivePlanner.h"
 | 
					
						
							|  |  |  | #include "core/settings/qPrefUnit.h"
 | 
					
						
							| 
									
										
										
										
											2019-12-25 16:16:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <QTest>
 | 
					
						
							|  |  |  | #include <QSignalSpy>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TestPlannerShared::initTestCase() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QCoreApplication::setOrganizationName("Subsurface"); | 
					
						
							|  |  |  | 	QCoreApplication::setOrganizationDomain("subsurface.hohndel.org"); | 
					
						
							|  |  |  | 	QCoreApplication::setApplicationName("SubsurfaceTestPlannerShared"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-27 16:44:30 +01:00
										 |  |  | // test values have been researched with official subsurface 4.9.3
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // research have been done by using the UI of subsurface, while
 | 
					
						
							|  |  |  | // checking the content of org.hohndel.subsurface.Subsurface.plist
 | 
					
						
							|  |  |  | // (securing UI value it not the default)
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // All test have been done on a iMac Pro with Catalina 10.15.2, values in the plist
 | 
					
						
							|  |  |  | // might be different on other systems.
 | 
					
						
							|  |  |  | // if you experience such problems, please report these so a proper adjustment can
 | 
					
						
							|  |  |  | // be made.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // meters pr time unit and feet pr time unit
 | 
					
						
							|  |  |  | // UI (meters) - plist value       UI (feet) - plist value
 | 
					
						
							|  |  |  | //    16m      -    267               33f    -     168
 | 
					
						
							|  |  |  | //     7m      -    117               27f    -     137
 | 
					
						
							|  |  |  | //     8m      -    133               40f    -     203
 | 
					
						
							|  |  |  | //    10m      -    167               35f    -     178
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // liter pr time unit and cuft pr time unit
 | 
					
						
							|  |  |  | // UI (liters) - plist value       UI (cuft) - plist value
 | 
					
						
							|  |  |  | //    30l      -    30000           0,9cuft  -   25485
 | 
					
						
							| 
									
										
										
										
											2019-12-28 22:47:50 +01:00
										 |  |  | //     5l      -     5000           0,01cuft -     283
 | 
					
						
							| 
									
										
										
										
											2019-12-27 16:44:30 +01:00
										 |  |  | //     8l      -     8000           0,4cuft  -   11327
 | 
					
						
							|  |  |  | //    10l      -    10000           0,7cuft  -   19822
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // bar pr time unit and psi pr time unit
 | 
					
						
							|  |  |  | // UI (bar) - plist value       UI (psi) - plist value
 | 
					
						
							|  |  |  | //   1,5b      -   1500           1,5psi -   1500
 | 
					
						
							|  |  |  | //   1,6b      -   1600           1,3psi -   1300
 | 
					
						
							|  |  |  | //   1,2b      -   1200           1,1psi -   1100
 | 
					
						
							|  |  |  | //   1,0b      -   1000           1,0psi -   1000
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // sac factor
 | 
					
						
							|  |  |  | // UI - plist value
 | 
					
						
							|  |  |  | //    4,2      -    420
 | 
					
						
							|  |  |  | //    3,5      -    350
 | 
					
						
							|  |  |  | //    2,8      -    280
 | 
					
						
							|  |  |  | //    2,0      -    200
 | 
					
						
							| 
									
										
										
										
											2019-12-25 16:16:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-27 16:44:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-25 16:16:15 +01:00
										 |  |  | void TestPlannerShared::test_planning() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-12-27 16:44:30 +01:00
										 |  |  | 	// Variables currently not tested
 | 
					
						
							|  |  |  | 	// dive_mode: OC, CCR, PSCR, FREEDIVE, NUM_DIVEMODE, UNDEF_COMP_TYPE
 | 
					
						
							| 
									
										
										
										
											2019-12-25 16:16:15 +01:00
										 |  |  | 	// planner_deco_mode
 | 
					
						
							|  |  |  | 	// dobailout
 | 
					
						
							|  |  |  | 	// reserve_gas
 | 
					
						
							|  |  |  | 	// safetystop
 | 
					
						
							|  |  |  | 	// gflow
 | 
					
						
							|  |  |  | 	// gfhigh
 | 
					
						
							|  |  |  | 	// vpmb_conservatism
 | 
					
						
							|  |  |  | 	// drop_stone_mode
 | 
					
						
							|  |  |  | 	// last_stop
 | 
					
						
							|  |  |  | 	// switch_at_req_stop
 | 
					
						
							|  |  |  | 	// doo2breaks
 | 
					
						
							|  |  |  | 	// min_switch_duration
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TestPlannerShared::test_gas() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	// test independent of metric/imperial
 | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_sacfactor(4.2); | 
					
						
							| 
									
										
										
										
											2020-01-21 16:16:10 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::sacfactor(), 42); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_sacfactor(3.5); | 
					
						
							| 
									
										
										
										
											2020-01-21 16:16:10 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::sacfactor(), 35); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	qPrefDivePlanner::set_sacfactor(280); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(PlannerShared::sacfactor(), 28); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	qPrefDivePlanner::set_sacfactor(200); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(PlannerShared::sacfactor(), 20); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Set system to use meters
 | 
					
						
							| 
									
										
										
										
											2020-01-07 14:31:49 +01:00
										 |  |  | 	qPrefUnits::set_unit_system(METRIC); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_bottomsac(30); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::bottomsac(), 30000); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_bottomsac(5); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::bottomsac(), 5000); | 
					
						
							|  |  |  | 	qPrefDivePlanner::set_bottomsac(8000); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(PlannerShared::bottomsac(), 8); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	qPrefDivePlanner::set_bottomsac(10000); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(PlannerShared::bottomsac(), 10); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_decosac(30); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::decosac(), 30000); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_decosac(5); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::decosac(), 5000); | 
					
						
							|  |  |  | 	qPrefDivePlanner::set_decosac(8000); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(PlannerShared::decosac(), 8); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	qPrefDivePlanner::set_decosac(10000); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(PlannerShared::decosac(), 10); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_bottompo2(1.5); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::bottompo2(), 1500); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_bottompo2(1.6); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::bottompo2(), 1600); | 
					
						
							|  |  |  | 	qPrefDivePlanner::set_bottompo2(1200); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(PlannerShared::bottompo2(), 1.2); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	qPrefDivePlanner::set_bottompo2(1000); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(PlannerShared::bottompo2(), 1.0); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_decopo2(1.5); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::decopo2(), 1500); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_decopo2(1.6); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::decopo2(), 1600); | 
					
						
							|  |  |  | 	qPrefDivePlanner::set_decopo2(1100); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(PlannerShared::decopo2(), 1.1); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	qPrefDivePlanner::set_decopo2(1000); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(PlannerShared::decopo2(), 1.0); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_bestmixend(16); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::bestmixend(), 16000); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_bestmixend(7); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::bestmixend(), 7000); | 
					
						
							|  |  |  | 	qPrefDivePlanner::set_bestmixend(8000); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(PlannerShared::bestmixend(), 8); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	qPrefDivePlanner::set_bestmixend(10000); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(PlannerShared::bestmixend(), 10); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Set system to use feet
 | 
					
						
							| 
									
										
										
										
											2020-01-07 14:31:49 +01:00
										 |  |  | 	qPrefUnits::set_unit_system(IMPERIAL); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_bottomsac(0.9); | 
					
						
							| 
									
										
										
										
											2020-01-21 16:16:10 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::bottomsac(), 255); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_bottomsac(0.01); | 
					
						
							| 
									
										
										
										
											2020-01-21 16:16:10 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::bottomsac(), 3); | 
					
						
							| 
									
										
										
										
											2019-12-30 18:29:51 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Remark return will from qPref is in m / 1000.
 | 
					
						
							|  |  |  | 	qPrefDivePlanner::set_bottomsac(2830); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(int(PlannerShared::bottomsac()), 9); | 
					
						
							| 
									
										
										
										
											2019-12-30 18:29:51 +01:00
										 |  |  | 	qPrefDivePlanner::set_bottomsac(16000); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(int(PlannerShared::bottomsac()), 56); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_decosac(0.9); | 
					
						
							| 
									
										
										
										
											2020-01-21 16:16:10 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::decosac(), 255); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_decosac(0.01); | 
					
						
							| 
									
										
										
										
											2020-01-21 16:16:10 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::decosac(), 3); | 
					
						
							| 
									
										
										
										
											2019-12-30 18:29:51 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Remark return will from qPref is in m / 1000.
 | 
					
						
							|  |  |  | 	qPrefDivePlanner::set_decosac(11500); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(int(PlannerShared::decosac()), 40); | 
					
						
							| 
									
										
										
										
											2019-12-30 18:29:51 +01:00
										 |  |  | 	qPrefDivePlanner::set_decosac(19800); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(int(PlannerShared::decosac()), 69); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-30 17:12:57 +01:00
										 |  |  | 	// Remark bottompo2 is in BAR, even though unit system is
 | 
					
						
							|  |  |  | 	// Imperial, the desktop version is like that.
 | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_bottompo2(1.5); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::bottompo2(), 1500); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_bottompo2(1.6); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::bottompo2(), 1600); | 
					
						
							|  |  |  | 	qPrefDivePlanner::set_bottompo2(1200); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(PlannerShared::bottompo2(), 1.2); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	qPrefDivePlanner::set_bottompo2(1000); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(PlannerShared::bottompo2(), 1.0); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-30 17:12:57 +01:00
										 |  |  | 	// Remark decopo2 is in BAR, even though unit system is
 | 
					
						
							|  |  |  | 	// Imperial, the desktop version is like that.
 | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_decopo2(1.5); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::decopo2(), 1500); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_decopo2(1.6); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::decopo2(), 1600); | 
					
						
							|  |  |  | 	qPrefDivePlanner::set_decopo2(1200); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | //Not implemented	QCOMPARE(PlannerShared::decopo2(), 1.2);
 | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 	qPrefDivePlanner::set_decopo2(1000); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(PlannerShared::decopo2(), 1.0); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_bestmixend(33); | 
					
						
							| 
									
										
										
										
											2019-12-30 17:44:08 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::bestmixend(), 10058); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	PlannerShared::set_bestmixend(27); | 
					
						
							| 
									
										
										
										
											2019-12-30 17:44:08 +01:00
										 |  |  | 	QCOMPARE(qPrefDivePlanner::bestmixend(), 8230); | 
					
						
							|  |  |  | 	qPrefDivePlanner::set_bestmixend(11000); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(PlannerShared::bestmixend(), 36); | 
					
						
							| 
									
										
										
										
											2019-12-30 17:44:08 +01:00
										 |  |  | 	qPrefDivePlanner::set_bestmixend(7000); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:08:35 +01:00
										 |  |  | 	QCOMPARE(PlannerShared::bestmixend(), 23); | 
					
						
							| 
									
										
										
										
											2019-12-27 18:34:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-27 16:44:30 +01:00
										 |  |  | 	// Variables currently not tested
 | 
					
						
							| 
									
										
										
										
											2019-12-25 16:16:15 +01:00
										 |  |  | 	// o2narcotic
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TestPlannerShared::test_notes() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-12-27 16:44:30 +01:00
										 |  |  | 	// Variables currently not tested
 | 
					
						
							| 
									
										
										
										
											2019-12-25 16:16:15 +01:00
										 |  |  | 	// display_runtime
 | 
					
						
							|  |  |  | 	// display_duration
 | 
					
						
							|  |  |  | 	// display_transitions
 | 
					
						
							|  |  |  | 	// verbatim_plan
 | 
					
						
							|  |  |  | 	// display_variations
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QTEST_MAIN(TestPlannerShared) |