/
testksuserdb.cpp
136 lines (109 loc) · 3.05 KB
/
testksuserdb.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* KStars class tests
SPDX-FileCopyrightText: 2020 Eric Dejouhanet <eric.dejouhanet@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "testksuserdb.h"
#include "../testhelpers.h"
#include "ksuserdb.h"
TestKSUserDB::TestKSUserDB(QObject *parent) : QObject(parent)
{
}
void TestKSUserDB::initTestCase()
{
}
void TestKSUserDB::cleanupTestCase()
{
}
void TestKSUserDB::init()
{
KTEST_BEGIN();
}
void TestKSUserDB::cleanup()
{
KTEST_END();
}
void TestKSUserDB::testInitializeDB()
{
QScopedPointer<KSUserDB> testDB(new KSUserDB());
QVERIFY(nullptr != testDB);
// If the KStars folder does not exist, database cannot be initialised
QVERIFY(QDir(KSPaths::writableLocation(QStandardPaths::AppLocalDataLocation)).removeRecursively());
QVERIFY(!testDB->Initialize());
auto fullpath = testDB->connectionName();
QVERIFY(!QFile(fullpath).exists());
// If the KStars folder has just been created, database can be initialised
QVERIFY(QDir(KSPaths::writableLocation(QStandardPaths::AppLocalDataLocation)).mkpath("."));
QVERIFY(testDB->Initialize());
fullpath = testDB->connectionName();
QVERIFY(QFile(fullpath).exists());
// Database can be initialised once again (without change?)
QVERIFY(testDB->Initialize());
QVERIFY(QFile(fullpath).exists());
// If there is garbage in the database and there is no backup, database can be initialised
QVERIFY(QFile(fullpath).exists());
{
QFile dbf(fullpath);
QVERIFY(dbf.open(QIODevice::WriteOnly));
QCOMPARE(dbf.write("garbage", 7), 7);
}
QVERIFY(testDB->Initialize());
QVERIFY(QFile(fullpath).exists());
// If there is no database file, but there is a backup, database can be initialised
QVERIFY(QFile(fullpath).exists());
QVERIFY(QFile(fullpath).rename(fullpath + ".backup"));
QVERIFY(testDB->Initialize());
QVERIFY(QFile(fullpath).exists());
// If there is garbage in the database but there is a backup, database can be initialised
QVERIFY(QFile(fullpath).exists());
{
QFile dbf(fullpath);
QVERIFY(dbf.open(QIODevice::WriteOnly));
QCOMPARE(dbf.write("garbage", 7), 7);
}
QVERIFY(testDB->Initialize());
QVERIFY(QFile(fullpath).exists());
}
void TestKSUserDB::testCreateScopes_data()
{
}
void TestKSUserDB::testCreateScopes()
{
QSKIP("Not implemented yet.");
}
void TestKSUserDB::testCreateEyepieces_data()
{
}
void TestKSUserDB::testCreateEyepieces()
{
QSKIP("Not implemented yet.");
}
void TestKSUserDB::testCreateLenses_data()
{
}
void TestKSUserDB::testCreateLenes()
{
QSKIP("Not implemented yet.");
}
void TestKSUserDB::testCreateFilters_data()
{
}
void TestKSUserDB::testCreateFilters()
{
QSKIP("Not implemented yet.");
}
void TestKSUserDB::testCreateProfiles_data()
{
}
void TestKSUserDB::testCreateProfilees()
{
QSKIP("Not implemented yet.");
}
void TestKSUserDB::testCreateDatabase()
{
QSKIP("Not implemented yet.");
}
void TestKSUserDB::testCoordinates()
{
QSKIP("Not implemented yet.");
}
QTEST_GUILESS_MAIN(TestKSUserDB)