summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-02-25 13:51:41 +0100
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2018-03-14 13:55:36 +0200
commitb72cc1f31784346884c8552c22f1e4c3c6d5ed1d (patch)
tree00a04967dc56ccdc69ee998058c13911292ecef7 /tests
parent4e44fe7598430f9879736ec2d00b99b15dc05451 (diff)
downloadsubsurface-b72cc1f31784346884c8552c22f1e4c3c6d5ed1d.tar.gz
Cleanup: consistently use qPrintable()
Replace constructs of the kind s.toUtf8().data(), s.toUtf8().constData(), s.toLocal8Bit().data(), s.toLocal8Bit.constData() or qUtf8Printable(s) by qPrintable(s). This is concise, consistent and - in principle - more performant than the .data() versions. Sadly, owing to a suboptimal implementation, qPrintable(s) currently is a pessimization compared to s.toUtf8().data(). A fix is scheduled for new Qt versions: https://codereview.qt-project.org/#/c/221331/ Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'tests')
-rw-r--r--tests/testgitstorage.cpp62
1 files changed, 33 insertions, 29 deletions
diff --git a/tests/testgitstorage.cpp b/tests/testgitstorage.cpp
index 2edc8e305..d6a460edf 100644
--- a/tests/testgitstorage.cpp
+++ b/tests/testgitstorage.cpp
@@ -12,6 +12,7 @@
#include <QTextStream>
#include <QNetworkProxy>
#include <QSettings>
+#include <QTextCodec>
#include <QDebug>
// this is a local helper function in git-access.c
@@ -19,6 +20,9 @@ extern "C" char *get_local_dir(const char *remote, const char *branch);
void TestGitStorage::initTestCase()
{
+ // Set UTF8 text codec as in real applications
+ QTextCodec::setCodecForLocale(QTextCodec::codecForMib(106));
+
// first, setup the preferences an proxy information
copy_prefs(&default_prefs, &prefs);
QCoreApplication::setOrganizationName("Subsurface");
@@ -39,7 +43,7 @@ void TestGitStorage::initTestCase()
QString gitUrl(prefs.cloud_base_url);
if (gitUrl.right(1) != "/")
gitUrl += "/";
- prefs.cloud_git_url = strdup(qUtf8Printable(gitUrl + "git"));
+ prefs.cloud_git_url = strdup(qPrintable(gitUrl + "git"));
s.endGroup();
prefs.cloud_storage_email_encoded = strdup("ssrftest@hohndel.org");
prefs.cloud_storage_password = strdup("geheim");
@@ -93,11 +97,11 @@ void TestGitStorage::testGitStorageLocal()
QCOMPARE(QDir().mkdir(testDirName), true);
QString repoNameRead = prefixRead + testDirName;
QString repoNameWrite = prefixWrite + testDirName;
- QCOMPARE(git_repository_init(&repo, qUtf8Printable(testDirName), false), 0);
- QCOMPARE(save_dives(qUtf8Printable(repoNameWrite + "[test]")), 0);
+ QCOMPARE(git_repository_init(&repo, qPrintable(testDirName), false), 0);
+ QCOMPARE(save_dives(qPrintable(repoNameWrite + "[test]")), 0);
QCOMPARE(save_dives("./SampleDivesV3.ssrf"), 0);
clear_dive_file_data();
- QCOMPARE(parse_file(qUtf8Printable(repoNameRead + "[test]")), 0);
+ QCOMPARE(parse_file(qPrintable(repoNameRead + "[test]")), 0);
QCOMPARE(save_dives("./SampleDivesV3viagit.ssrf"), 0);
QFile org("./SampleDivesV3.ssrf");
org.open(QFile::ReadOnly);
@@ -117,9 +121,9 @@ void TestGitStorage::testGitStorageCloud()
// and repeat the same test as before with the local git storage
QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]");
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf"), 0);
- QCOMPARE(save_dives(qUtf8Printable(cloudTestRepo)), 0);
+ QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data();
- QCOMPARE(parse_file(qUtf8Printable(cloudTestRepo)), 0);
+ QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0);
QCOMPARE(save_dives("./SampleDivesV3viacloud.ssrf"), 0);
QFile org("./SampleDivesV3.ssrf");
org.open(QFile::ReadOnly);
@@ -140,17 +144,17 @@ void TestGitStorage::testGitStorageCloudOfflineSync()
QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org"));
QString localCacheRepo = localCacheDir + "[ssrftest@hohndel.org]";
// read the local repo from the previous test and add dive 10
- QCOMPARE(parse_file(qUtf8Printable(localCacheRepo)), 0);
+ QCOMPARE(parse_file(qPrintable(localCacheRepo)), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test10.xml"), 0);
// calling process_dive() sorts the table, but calling it with
// is_imported == true causes it to try to update the window title... let's not do that
process_dives(false, false);
// now save only to the local cache but not to the remote server
- QCOMPARE(save_dives(qUtf8Printable(localCacheRepo)), 0);
+ QCOMPARE(save_dives(qPrintable(localCacheRepo)), 0);
QCOMPARE(save_dives("./SampleDivesV3plus10local.ssrf"), 0);
clear_dive_file_data();
// open the cloud storage and compare
- QCOMPARE(parse_file(qUtf8Printable(cloudTestRepo)), 0);
+ QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0);
QCOMPARE(save_dives("./SampleDivesV3plus10viacloud.ssrf"), 0);
QFile org("./SampleDivesV3plus10local.ssrf");
org.open(QFile::ReadOnly);
@@ -162,13 +166,13 @@ void TestGitStorage::testGitStorageCloudOfflineSync()
QString written = outS.readAll();
QCOMPARE(readin, written);
// write back out to cloud storage, move away the local cache, open again and compare
- QCOMPARE(save_dives(qUtf8Printable(cloudTestRepo)), 0);
+ QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data();
QDir localCacheDirectory(localCacheDir);
QDir localCacheDirectorySave(localCacheDir + "save");
QCOMPARE(localCacheDirectorySave.removeRecursively(), true);
QCOMPARE(localCacheDirectory.rename(localCacheDir, localCacheDir + "save"), true);
- QCOMPARE(parse_file(qUtf8Printable(cloudTestRepo)), 0);
+ QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0);
QCOMPARE(save_dives("./SampleDivesV3plus10fromcloud.ssrf"), 0);
org.close();
org.open(QFile::ReadOnly);
@@ -189,17 +193,17 @@ void TestGitStorage::testGitStorageCloudMerge()
QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]");
QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org"));
QString localCacheRepoSave = localCacheDir + "save[ssrftest@hohndel.org]";
- QCOMPARE(parse_file(qUtf8Printable(localCacheRepoSave)), 0);
+ QCOMPARE(parse_file(qPrintable(localCacheRepoSave)), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml"), 0);
process_dives(false, false);
- QCOMPARE(save_dives(qUtf8Printable(localCacheRepoSave)), 0);
+ QCOMPARE(save_dives(qPrintable(localCacheRepoSave)), 0);
clear_dive_file_data();
// now we open the cloud storage repo and add a different dive to it
- QCOMPARE(parse_file(qUtf8Printable(cloudTestRepo)), 0);
+ QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml"), 0);
process_dives(false, false);
- QCOMPARE(save_dives(qUtf8Printable(cloudTestRepo)), 0);
+ QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data();
// now we move the saved local cache into place and try to open the cloud repo
@@ -208,7 +212,7 @@ void TestGitStorage::testGitStorageCloudMerge()
QCOMPARE(localCacheDirectory.removeRecursively(), true);
QDir localCacheDirectorySave(localCacheDir + "save");
QCOMPARE(localCacheDirectory.rename(localCacheDir + "save", localCacheDir), true);
- QCOMPARE(parse_file(qUtf8Printable(cloudTestRepo)), 0);
+ QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0);
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12-merged.ssrf"), 0);
clear_dive_file_data();
QCOMPARE(parse_file("./SampleDivesV3plus10local.ssrf"), 0);
@@ -236,12 +240,12 @@ void TestGitStorage::testGitStorageCloudMerge2()
QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]");
QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org"));
QString localCacheRepo = localCacheDir + "[ssrftest@hohndel.org]";
- QCOMPARE(parse_file(qUtf8Printable(localCacheRepo)), 0);
+ QCOMPARE(parse_file(qPrintable(localCacheRepo)), 0);
process_dives(false, false);
struct dive *dive = get_dive(1);
delete_single_dive(1);
QCOMPARE(save_dives("./SampleDivesMinus1.ssrf"), 0);
- QCOMPARE(save_dives(qUtf8Printable(localCacheRepo)), 0);
+ QCOMPARE(save_dives(qPrintable(localCacheRepo)), 0);
clear_dive_file_data();
// move the local cache away
@@ -252,13 +256,13 @@ void TestGitStorage::testGitStorageCloudMerge2()
QCOMPARE(localCacheDirectory.rename(localCacheDir, localCacheDir + "save"), true);
}
// now we open the cloud storage repo and modify that first dive
- QCOMPARE(parse_file(qUtf8Printable(cloudTestRepo)), 0);
+ QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0);
process_dives(false, false);
dive = get_dive(1);
QVERIFY(dive != NULL);
free(dive->notes);
dive->notes = strdup("These notes have been modified by TestGitStorage");
- QCOMPARE(save_dives(qUtf8Printable(cloudTestRepo)), 0);
+ QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data();
// now we move the saved local cache into place and try to open the cloud repo
@@ -268,9 +272,9 @@ void TestGitStorage::testGitStorageCloudMerge2()
QCOMPARE(localCacheDirectory.removeRecursively(), true);
QCOMPARE(localCacheDirectorySave.rename(localCacheDir + "save", localCacheDir), true);
- QCOMPARE(parse_file(qUtf8Printable(cloudTestRepo)), 0);
+ QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0);
QCOMPARE(save_dives("./SampleDivesMinus1-merged.ssrf"), 0);
- QCOMPARE(save_dives(qUtf8Printable(cloudTestRepo)), 0);
+ QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
QFile org("./SampleDivesMinus1-merged.ssrf");
org.open(QFile::ReadOnly);
QFile out("./SampleDivesMinus1.ssrf");
@@ -292,7 +296,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]");
QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org"));
QString localCacheRepo = localCacheDir + "[ssrftest@hohndel.org]";
- QCOMPARE(parse_file(qUtf8Printable(cloudTestRepo)), 0);
+ QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0);
process_dives(false, false);
struct dive *dive = get_dive(0);
QVERIFY(dive != 0);
@@ -301,10 +305,10 @@ void TestGitStorage::testGitStorageCloudMerge3()
dive->notes = strdup("Create multi line dive notes\nLine 2\nLine 3\nLine 4\nLine 5\nThat should be enough");
dive = get_dive(2);
dive->notes = strdup("Create multi line dive notes\nLine 2\nLine 3\nLine 4\nLine 5\nThat should be enough");
- QCOMPARE(save_dives(qUtf8Printable(cloudTestRepo)), 0);
+ QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data();
- QCOMPARE(parse_file(qUtf8Printable(localCacheRepo)), 0);
+ QCOMPARE(parse_file(qPrintable(localCacheRepo)), 0);
process_dives(false, false);
dive = get_dive(0);
dive->notes = strdup("Create multi line dive notes\nDifferent line 2 and removed 3-5\n\nThat should be enough");
@@ -312,7 +316,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
dive->notes = strdup("Line 2\nLine 3\nLine 4\nLine 5"); // keep the middle, remove first and last");
dive = get_dive(2);
dive->notes = strdup("single line dive notes");
- QCOMPARE(save_dives(qUtf8Printable(localCacheRepo)), 0);
+ QCOMPARE(save_dives(qPrintable(localCacheRepo)), 0);
clear_dive_file_data();
// move the local cache away
@@ -323,7 +327,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
QCOMPARE(localCacheDirectory.rename(localCacheDir, localCacheDir + "save"), true);
}
// now we open the cloud storage repo and modify those first dive notes differently
- QCOMPARE(parse_file(qUtf8Printable(cloudTestRepo)), 0);
+ QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0);
process_dives(false, false);
dive = get_dive(0);
dive->notes = strdup("Completely different dive notes\nBut also multi line");
@@ -331,7 +335,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
dive->notes = strdup("single line dive notes");
dive = get_dive(2);
dive->notes = strdup("Line 2\nLine 3\nLine 4\nLine 5"); // keep the middle, remove first and last");
- QCOMPARE(save_dives(qUtf8Printable(cloudTestRepo)), 0);
+ QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data();
// now we move the saved local cache into place and try to open the cloud repo
@@ -341,7 +345,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
QCOMPARE(localCacheDirectory.removeRecursively(), true);
QCOMPARE(localCacheDirectorySave.rename(localCacheDir + "save", localCacheDir), true);
- QCOMPARE(parse_file(qUtf8Printable(cloudTestRepo)), 0);
+ QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0);
QCOMPARE(save_dives("./SampleDivesMerge3.ssrf"), 0);
// we are not trying to compare this to a pre-determined result... what this test
// checks is that there are no parsing errors with the merge