2
Copyright 2008 by Robert Knight <robertknight@gmail.com>
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
#include "ProfileTest.h"
24
#include <qtest_kde.h>
27
#include "../Profile.h"
29
using namespace Konsole;
31
void ProfileTest::testProfile()
33
// create a new profile
34
Profile* parent = new Profile;
35
parent->setProperty(Profile::Name, "Parent");
36
parent->setProperty(Profile::Path, "FakePath");
38
parent->setProperty(Profile::AntiAliasFonts,false);
39
parent->setProperty(Profile::StartInCurrentSessionDir,false);
41
// create a child profile
42
Profile* child = new Profile(Profile::Ptr(parent));
43
child->setProperty(Profile::StartInCurrentSessionDir,true);
45
// check which properties are set
46
QVERIFY(parent->isPropertySet(Profile::Name));
47
QVERIFY(parent->isPropertySet(Profile::Path));
48
QVERIFY(parent->isPropertySet(Profile::AntiAliasFonts));
49
QVERIFY(!parent->isPropertySet(Profile::Icon));
50
QVERIFY(!parent->isPropertySet(Profile::Command));
51
QVERIFY(!parent->isPropertySet(Profile::Arguments));
53
QVERIFY(child->isPropertySet(Profile::StartInCurrentSessionDir));
54
QVERIFY(!child->isPropertySet(Profile::Name));
55
QVERIFY(!child->isPropertySet(Profile::AntiAliasFonts));
56
QVERIFY(!child->isPropertySet(Profile::ColorScheme));
58
// read non-inheritable properties
59
QCOMPARE(parent->property<QString>(Profile::Name),QString("Parent"));
60
QCOMPARE(child->property<QVariant>(Profile::Name),QVariant());
61
QCOMPARE(parent->property<QString>(Profile::Path),QString("FakePath"));
62
QCOMPARE(child->property<QVariant>(Profile::Path),QVariant());
64
// read inheritable properties
65
QVERIFY(parent->property<bool>(Profile::AntiAliasFonts) == false);
66
QVERIFY(child->property<bool>(Profile::AntiAliasFonts) == false);
68
QVERIFY(parent->property<bool>(Profile::StartInCurrentSessionDir) == false);
69
QVERIFY(child->property<bool>(Profile::StartInCurrentSessionDir) == true);
73
void ProfileTest::testClone()
75
// create source profile and parent
76
Profile::Ptr parent(new Profile);
77
parent->setProperty(Profile::Command,"ps");
78
parent->setProperty(Profile::ColorScheme,"BlackOnWhite");
80
Profile::Ptr source(new Profile(parent));
81
source->setProperty(Profile::AntiAliasFonts,false);
82
source->setProperty(Profile::HistorySize,4567);
84
source->setProperty(Profile::Name,"SourceProfile");
85
source->setProperty(Profile::Path,"SourcePath");
87
// create target to clone source and parent
88
Profile::Ptr targetParent(new Profile);
89
// same value as source parent
90
targetParent->setProperty(Profile::Command,"ps");
91
// different value from source parent
92
targetParent->setProperty(Profile::ColorScheme,"BlackOnGrey");
93
Profile::Ptr target(new Profile(parent));
95
// clone source profile, setting only properties that differ
96
// between the source and target
97
target->clone(source,true);
99
// check that properties from source have been cloned into target
100
QCOMPARE(source->property<bool>(Profile::AntiAliasFonts),
101
target->property<bool>(Profile::AntiAliasFonts));
102
QCOMPARE(source->property<int>(Profile::HistorySize),
103
target->property<int>(Profile::HistorySize));
105
// check that Name and Path properties are handled specially and not cloned
106
QVERIFY(source->property<QString>(Profile::Name) !=
107
target->property<QString>(Profile::Name));
108
QVERIFY(source->property<QString>(Profile::Path) !=
109
target->property<QString>(Profile::Path));
111
// check that Command property is not set in target because the values
113
QVERIFY(!target->isPropertySet(Profile::Command));
114
// check that ColorScheme property is cloned because the inherited values
115
// from the source parent and target parent differ
116
QCOMPARE(source->property<QString>(Profile::ColorScheme),
117
target->property<QString>(Profile::ColorScheme));
119
void ProfileTest::testProfileGroup()
121
// create three new profiles
122
Profile::Ptr profile[3];
123
for (int i=0;i<3;i++)
125
profile[i] = new Profile;
126
QVERIFY(!profile[i]->asGroup());
129
// set properties with different values
130
profile[0]->setProperty(Profile::UseCustomCursorColor,true);
131
profile[1]->setProperty(Profile::UseCustomCursorColor,false);
133
// set properties with same values
134
for (int i=0;i<3;i++)
135
profile[i]->setProperty(Profile::HistorySize,1234);
137
// create a group profile
138
ProfileGroup::Ptr group = ProfileGroup::Ptr(new ProfileGroup);
139
QVERIFY(group->asGroup());
140
for (int i=0;i<3;i++)
142
group->addProfile(profile[i]);
143
QVERIFY(group->profiles().contains(profile[i]));
145
group->updateValues();
147
// read and check properties from the group
148
QCOMPARE(group->property<int>(Profile::HistorySize),1234);
149
QCOMPARE(group->property<QVariant>(Profile::UseCustomCursorColor),QVariant());
151
// set and test shareable properties in the group
152
group->setProperty(Profile::Command,"ssh");
153
group->setProperty(Profile::AntiAliasFonts,false);
155
QCOMPARE(profile[0]->property<QString>(Profile::Command),QString("ssh"));
156
QVERIFY(profile[1]->property<bool>(Profile::AntiAliasFonts) == false);
158
// set and test non-sharable properties in the group
159
// (should have no effect)
160
group->setProperty(Profile::Name,"NewName");
161
group->setProperty(Profile::Path,"NewPath");
162
QVERIFY(profile[1]->property<QString>(Profile::Name) != "NewName");
163
QVERIFY(profile[2]->property<QString>(Profile::Path) != "NewPath");
165
// remove a profile from the group
166
group->removeProfile(profile[0]);
167
QVERIFY(!group->profiles().contains(profile[0]));
168
group->updateValues();
170
// check that profile is no longer affected by group
171
group->setProperty(Profile::Command,"fish");
172
QVERIFY(profile[0]->property<QString>(Profile::Command) != "fish");
175
QTEST_KDEMAIN_CORE( ProfileTest )
177
#include "ProfileTest.moc"