2017-04-27 20:21:27 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								// SPDX-License-Identifier: GPL-2.0
							 | 
						
					
						
							
								
									
										
										
										
											2014-04-17 12:21:39 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include "testprofile.h"
							 | 
						
					
						
							
								
									
										
										
										
											2020-10-17 12:32:22 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include "core/device.h"
							 | 
						
					
						
							
								
									
										
										
										
											2019-03-04 23:20:29 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include "core/divesite.h"
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-31 16:09:14 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include "core/trip.h"
							 | 
						
					
						
							
								
									
										
										
										
											2019-03-03 22:29:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include "core/file.h"
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-02 21:38:55 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include "core/save-profiledata.h"
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-26 14:03:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include "core/pref.h"
							 | 
						
					
						
							
								
									
										
										
										
											2014-04-17 12:21:39 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-05 14:39:44 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								// This test compares the content of struct profile against a known reference version for a list
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// of dives to prevent accidental regressions. Thus is you change anything in the profile this
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// test will fail. If this change was intentional, run the test manually. Make sure only the
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// indended fields change (for example by computing a diff between exportprofile.csv and
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// ..dives/exportprofilereference.csv) and copy the former over the later and commit that change
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// as well.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-16 06:47:51 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void TestProfile::init()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// Set UTF8 text codec as in real applications
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									QTextCodec::setCodecForLocale(QTextCodec::codecForMib(106));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// first, setup the preferences
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// normally we should be able to do this - but it makes this test fail because the reference data
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// assume that the prefs are all 0 / false
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// copy_prefs(&default_prefs, &prefs);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// instead we just set up the cloud_base_url to prevent parse_file() from crashing
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									prefs.cloud_base_url = strdup(default_prefs.cloud_base_url);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									QCoreApplication::setOrganizationName("Subsurface");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									QCoreApplication::setApplicationName("Subsurface");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-02 21:38:55 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void TestProfile::testProfileExport()
							 | 
						
					
						
							
								
									
										
										
										
											2014-04-17 12:21:39 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-26 14:03:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									prefs.planner_deco_mode = BUEHLMANN;
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-24 11:47:48 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									parse_file(SUBSURFACE_TEST_DATA "/dives/abitofeverything.ssrf", &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table);
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-02 21:38:55 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									save_profiledata("exportprofile.csv", false);
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-24 11:47:48 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									QFile org(SUBSURFACE_TEST_DATA "/dives/exportprofilereference.csv");
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-26 14:03:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									QCOMPARE(org.open(QFile::ReadOnly), true);
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-02 21:38:55 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									QFile out("exportprofile.csv");
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-26 14:03:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									QCOMPARE(out.open(QFile::ReadOnly), true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									QTextStream orgS(&org);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									QTextStream outS(&out);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									QString readin = orgS.readAll();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									QString written = outS.readAll();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									QCOMPARE(readin, written);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								void TestProfile::testProfileExportVPMB()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									prefs.planner_deco_mode = VPMB;
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-24 11:47:48 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									parse_file(SUBSURFACE_TEST_DATA "/dives/abitofeverything.ssrf", &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table);
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-26 14:03:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									save_profiledata("exportprofileVPMB.csv", false);
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-24 11:47:48 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									QFile org(SUBSURFACE_TEST_DATA "/dives/exportprofilereferenceVPMB.csv");
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-26 14:03:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									QCOMPARE(org.open(QFile::ReadOnly), true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									QFile out("exportprofileVPMB.csv");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									QCOMPARE(out.open(QFile::ReadOnly), true);
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-02 21:38:55 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									QTextStream orgS(&org);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									QTextStream outS(&out);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									QString readin = orgS.readAll();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									QString written = outS.readAll();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									QCOMPARE(readin, written);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2014-04-17 12:21:39 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-05 23:26:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								QTEST_GUILESS_MAIN(TestProfile)
							 |