File indexing completed on 2024-04-28 15:11:57

0001 /*  KStars class tests
0002     SPDX-FileCopyrightText: 2020 Eric Dejouhanet <eric.dejouhanet@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "testksuserdb.h"
0008 #include "../testhelpers.h"
0009 #include "ksuserdb.h"
0010 
0011 TestKSUserDB::TestKSUserDB(QObject *parent) : QObject(parent)
0012 {
0013 }
0014 
0015 void TestKSUserDB::initTestCase()
0016 {
0017 }
0018 
0019 void TestKSUserDB::cleanupTestCase()
0020 {
0021 }
0022 
0023 void TestKSUserDB::init()
0024 {
0025     KTEST_BEGIN();
0026 }
0027 
0028 void TestKSUserDB::cleanup()
0029 {
0030     KTEST_END();
0031 }
0032 
0033 void TestKSUserDB::testInitializeDB()
0034 {
0035     QScopedPointer<KSUserDB> testDB(new KSUserDB());
0036     QVERIFY(nullptr != testDB);
0037 
0038     // If the KStars folder does not exist, database cannot be initialised
0039     QVERIFY(QDir(KSPaths::writableLocation(QStandardPaths::AppLocalDataLocation)).removeRecursively());
0040     QVERIFY(!testDB->Initialize());
0041     auto fullpath = testDB->connectionName();
0042     QVERIFY(!QFile(fullpath).exists());
0043 
0044     // If the KStars folder has just been created, database can be initialised
0045     QVERIFY(QDir(KSPaths::writableLocation(QStandardPaths::AppLocalDataLocation)).mkpath("."));
0046     QVERIFY(testDB->Initialize());
0047     fullpath = testDB->connectionName();
0048     QVERIFY(QFile(fullpath).exists());
0049 
0050     // Database can be initialised once again (without change?)
0051     QVERIFY(testDB->Initialize());
0052     QVERIFY(QFile(fullpath).exists());
0053 
0054     // If there is garbage in the database and there is no backup, database can be initialised
0055     QVERIFY(QFile(fullpath).exists());
0056     {
0057         QFile dbf(fullpath);
0058         QVERIFY(dbf.open(QIODevice::WriteOnly));
0059         QCOMPARE(dbf.write("garbage", 7), 7);
0060     }
0061     QVERIFY(testDB->Initialize());
0062     QVERIFY(QFile(fullpath).exists());
0063 
0064     // If there is no database file, but there is a backup, database can be initialised
0065     QVERIFY(QFile(fullpath).exists());
0066     QVERIFY(QFile(fullpath).rename(fullpath + ".backup"));
0067     QVERIFY(testDB->Initialize());
0068     QVERIFY(QFile(fullpath).exists());
0069 
0070     // If there is garbage in the database but there is a backup, database can be initialised
0071     QVERIFY(QFile(fullpath).exists());
0072     {
0073         QFile dbf(fullpath);
0074         QVERIFY(dbf.open(QIODevice::WriteOnly));
0075         QCOMPARE(dbf.write("garbage", 7), 7);
0076     }
0077     QVERIFY(testDB->Initialize());
0078     QVERIFY(QFile(fullpath).exists());
0079 }
0080 
0081 void TestKSUserDB::testCreateScopes_data()
0082 {
0083 }
0084 
0085 void TestKSUserDB::testCreateScopes()
0086 {
0087     QSKIP("Not implemented yet.");
0088 }
0089 
0090 void TestKSUserDB::testCreateEyepieces_data()
0091 {
0092 }
0093 
0094 void TestKSUserDB::testCreateEyepieces()
0095 {
0096     QSKIP("Not implemented yet.");
0097 }
0098 
0099 void TestKSUserDB::testCreateLenses_data()
0100 {
0101 }
0102 
0103 void TestKSUserDB::testCreateLenes()
0104 {
0105     QSKIP("Not implemented yet.");
0106 }
0107 
0108 void TestKSUserDB::testCreateFilters_data()
0109 {
0110 }
0111 
0112 void TestKSUserDB::testCreateFilters()
0113 {
0114     QSKIP("Not implemented yet.");
0115 }
0116 
0117 void TestKSUserDB::testCreateProfiles_data()
0118 {
0119 }
0120 
0121 void TestKSUserDB::testCreateProfilees()
0122 {
0123     QSKIP("Not implemented yet.");
0124 }
0125 
0126 void TestKSUserDB::testCreateDatabase()
0127 {
0128     QSKIP("Not implemented yet.");
0129 }
0130 
0131 void TestKSUserDB::testCoordinates()
0132 {
0133     QSKIP("Not implemented yet.");
0134 }
0135 
0136 QTEST_GUILESS_MAIN(TestKSUserDB)