~ubuntu-branches/ubuntu/vivid/kate/vivid-updates

« back to all changes in this revision

Viewing changes to kate/autotests/session_test.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-12-04 16:49:41 UTC
  • mfrom: (1.6.6)
  • Revision ID: package-import@ubuntu.com-20141204164941-l3qbvsly83hhlw2v
Tags: 4:14.11.97-0ubuntu1
* New upstream release
* Update build-deps and use pkg-kde v3 for Qt 5 build
* kate-data now kate5-data for co-installability

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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.
 
17
 */
 
18
 
 
19
#include "session_test.h"
 
20
#include "katesession.h"
 
21
 
 
22
#include <KConfig>
 
23
#include <KConfigGroup>
 
24
 
 
25
#include <QtTestWidgets>
 
26
#include <QTemporaryFile>
 
27
#include <QFileInfo>
 
28
 
 
29
QTEST_MAIN(KateSessionTest)
 
30
 
 
31
void KateSessionTest::initTestCase() {}
 
32
 
 
33
void KateSessionTest::cleanupTestCase() {}
 
34
 
 
35
void KateSessionTest::init()
 
36
{
 
37
    m_tmpfile = new QTemporaryFile;
 
38
    QVERIFY(m_tmpfile->open());
 
39
}
 
40
 
 
41
void KateSessionTest::cleanup()
 
42
{
 
43
    delete m_tmpfile;
 
44
}
 
45
 
 
46
void KateSessionTest::create()
 
47
{
 
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());
 
54
}
 
55
 
 
56
void KateSessionTest::createAnonymous()
 
57
{
 
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());
 
63
}
 
64
 
 
65
void KateSessionTest::createAnonymousFrom()
 
66
{
 
67
    // Regular
 
68
    KateSession::Ptr s = KateSession::create(m_tmpfile->fileName(), QLatin1String("session name"));
 
69
 
 
70
    const QString groupName = QString::fromLatin1("test group");
 
71
    QTemporaryFile newFile;
 
72
    newFile.open();
 
73
    KateSession::Ptr ns;
 
74
 
 
75
    s->config()->group(groupName).writeEntry("foo", "bar");
 
76
 
 
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"));
 
84
}
 
85
 
 
86
void KateSessionTest::createFrom()
 
87
{
 
88
    KateSession::Ptr s = KateSession::create(m_tmpfile->fileName(), QLatin1String("session name"));
 
89
 
 
90
    const QString newName = QString::fromLatin1("new session name");
 
91
    const QString groupName = QString::fromLatin1("test group");
 
92
 
 
93
    QTemporaryFile newFile;
 
94
    newFile.open();
 
95
    KateSession::Ptr ns;
 
96
 
 
97
    s->config()->group(groupName).writeEntry("foo", "bar");
 
98
 
 
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"));
 
105
}
 
106
 
 
107
void KateSessionTest::documents()
 
108
{
 
109
    KateSession::Ptr s = KateSession::create(m_tmpfile->fileName(), QLatin1String("session name"));
 
110
 
 
111
    s->setDocuments(42);
 
112
    QCOMPARE((int)s->documents(), 42);
 
113
 
 
114
    s->config()->sync();
 
115
    KConfig c(m_tmpfile->fileName());
 
116
    QCOMPARE(c.group("Open Documents").readEntry<int>("Count", 0), 42);
 
117
}
 
118
 
 
119
void KateSessionTest::setFile()
 
120
{
 
121
    KateSession::Ptr s = KateSession::create(m_tmpfile->fileName(), QLatin1String("session name"));
 
122
    s->config()->group("test").writeEntry("foo", "bar");
 
123
 
 
124
    QTemporaryFile file2;
 
125
    file2.open();
 
126
 
 
127
    s->setFile(file2.fileName());
 
128
    QCOMPARE(s->config()->name(), file2.fileName());
 
129
    QCOMPARE(s->config()->group("test").readEntry("foo"), QLatin1String("bar"));
 
130
}
 
131
 
 
132
void KateSessionTest::timestamp()
 
133
{
 
134
    QFileInfo i(m_tmpfile->fileName());
 
135
    KateSession::Ptr s = KateSession::create(m_tmpfile->fileName(), QLatin1String("session name"));
 
136
 
 
137
    QCOMPARE(s->timestamp(), i.lastModified());
 
138
}
 
139
 
 
140
void KateSessionTest::setName()
 
141
{
 
142
    KateSession::Ptr s = KateSession::create(m_tmpfile->fileName(), QLatin1String("session name"));
 
143
    const QString newName = QString::fromLatin1("bar");
 
144
    s->setName(newName);
 
145
    QCOMPARE(s->name(), newName);
 
146
    QCOMPARE(s->file(), m_tmpfile->fileName()); // on purpose, orthogonal
 
147
}
 
148
 
 
149
#include "session_test.moc"
 
150