1
/* This file is part of the KDE project
3
* This library is free software; you can redistribute it and/or
4
* modify it under the terms of the GNU Library General Public
5
* License as published by the Free Software Foundation; either
6
* version 2 of the License, or (at your option) any later version.
8
* This library is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
* Library General Public License for more details.
13
* You should have received a copy of the GNU Library General Public License
14
* along with this library; see the file COPYING.LIB. If not, write to
15
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
* Boston, MA 02110-1301, USA.
19
#include "session_test.h"
20
#include "katesession.h"
23
#include <KConfigGroup>
25
#include <QtTestWidgets>
26
#include <QTemporaryFile>
29
QTEST_MAIN(KateSessionTest)
31
void KateSessionTest::initTestCase() {}
33
void KateSessionTest::cleanupTestCase() {}
35
void KateSessionTest::init()
37
m_tmpfile = new QTemporaryFile;
38
QVERIFY(m_tmpfile->open());
41
void KateSessionTest::cleanup()
46
void KateSessionTest::create()
48
const QString name = QString::fromLatin1("session name");
49
KateSession::Ptr s = KateSession::create(m_tmpfile->fileName(), name);
50
QCOMPARE(s->name(), name);
51
QCOMPARE((int)s->documents(), 0);
52
QCOMPARE(s->isAnonymous(), false);
53
QCOMPARE(s->config()->name(), m_tmpfile->fileName());
56
void KateSessionTest::createAnonymous()
58
KateSession::Ptr s = KateSession::createAnonymous(m_tmpfile->fileName());
59
QCOMPARE(s->name(), QString());
60
QCOMPARE((int)s->documents(), 0);
61
QCOMPARE(s->isAnonymous(), true);
62
QCOMPARE(s->config()->name(), m_tmpfile->fileName());
65
void KateSessionTest::createAnonymousFrom()
68
KateSession::Ptr s = KateSession::create(m_tmpfile->fileName(), QLatin1String("session name"));
70
const QString groupName = QString::fromLatin1("test group");
71
QTemporaryFile newFile;
75
s->config()->group(groupName).writeEntry("foo", "bar");
77
// Create Anon from Other
78
ns = KateSession::createAnonymousFrom(s, newFile.fileName());
79
QCOMPARE(ns->name(), QString());
80
QCOMPARE((int)ns->documents(), 0);
81
QCOMPARE(ns->isAnonymous(), true);
82
QCOMPARE(ns->config()->name(), newFile.fileName());
83
QCOMPARE(ns->config()->group(groupName).readEntry("foo"), QLatin1String("bar"));
86
void KateSessionTest::createFrom()
88
KateSession::Ptr s = KateSession::create(m_tmpfile->fileName(), QLatin1String("session name"));
90
const QString newName = QString::fromLatin1("new session name");
91
const QString groupName = QString::fromLatin1("test group");
93
QTemporaryFile newFile;
97
s->config()->group(groupName).writeEntry("foo", "bar");
99
ns = KateSession::createFrom(s, newFile.fileName(), newName);
100
QCOMPARE(ns->name(), newName);
101
QCOMPARE((int)ns->documents(), 0);
102
QCOMPARE(ns->isAnonymous(), false);
103
QCOMPARE(ns->config()->name(), newFile.fileName());
104
QCOMPARE(ns->config()->group(groupName).readEntry("foo"), QLatin1String("bar"));
107
void KateSessionTest::documents()
109
KateSession::Ptr s = KateSession::create(m_tmpfile->fileName(), QLatin1String("session name"));
112
QCOMPARE((int)s->documents(), 42);
115
KConfig c(m_tmpfile->fileName());
116
QCOMPARE(c.group("Open Documents").readEntry<int>("Count", 0), 42);
119
void KateSessionTest::setFile()
121
KateSession::Ptr s = KateSession::create(m_tmpfile->fileName(), QLatin1String("session name"));
122
s->config()->group("test").writeEntry("foo", "bar");
124
QTemporaryFile file2;
127
s->setFile(file2.fileName());
128
QCOMPARE(s->config()->name(), file2.fileName());
129
QCOMPARE(s->config()->group("test").readEntry("foo"), QLatin1String("bar"));
132
void KateSessionTest::timestamp()
134
QFileInfo i(m_tmpfile->fileName());
135
KateSession::Ptr s = KateSession::create(m_tmpfile->fileName(), QLatin1String("session name"));
137
QCOMPARE(s->timestamp(), i.lastModified());
140
void KateSessionTest::setName()
142
KateSession::Ptr s = KateSession::create(m_tmpfile->fileName(), QLatin1String("session name"));
143
const QString newName = QString::fromLatin1("bar");
145
QCOMPARE(s->name(), newName);
146
QCOMPARE(s->file(), m_tmpfile->fileName()); // on purpose, orthogonal
149
#include "session_test.moc"