~ubuntu-branches/ubuntu/utopic/kdebase/utopic

« back to all changes in this revision

Viewing changes to apps/konsole/src/tests/ProfileTest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Debian Qt/KDE Maintainers, José Manuel Santamaría Lema, Modestas Vainius
  • Date: 2011-05-26 02:53:50 UTC
  • mfrom: (0.7.7 upstream) (0.4.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 296.
  • Revision ID: james.westby@ubuntu.com-20110526025350-7o10g65yegec2rnq
Tags: 4:4.6.3-1
* New upstream release.

[ José Manuel Santamaría Lema ]
* Bump kde-sc-dev-latest build dependency to 4:4.6.3.
* Bump Standards-Version to 3.9.2; no changes needed.

[ Modestas Vainius ]
* Enable DLRestrictions for libraries in this package. Requires
  libdlrestrictions-dev 0.14 and kdelibs5-dev 4:4.6.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    Copyright 2008 by Robert Knight <robertknight@gmail.com>
3
 
 
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.
8
 
 
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.
13
 
 
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
17
 
    02110-1301  USA.
18
 
*/
19
 
 
20
 
// Own
21
 
#include "ProfileTest.h"
22
 
 
23
 
// KDE
24
 
#include <qtest_kde.h>
25
 
 
26
 
// Konsole
27
 
#include "../Profile.h"
28
 
 
29
 
using namespace Konsole;
30
 
 
31
 
void ProfileTest::testProfile()
32
 
{
33
 
    // create a new profile
34
 
    Profile* parent = new Profile;
35
 
    parent->setProperty(Profile::Name, "Parent");
36
 
    parent->setProperty(Profile::Path, "FakePath");
37
 
 
38
 
    parent->setProperty(Profile::AntiAliasFonts,false);
39
 
    parent->setProperty(Profile::StartInCurrentSessionDir,false);
40
 
 
41
 
    // create a child profile
42
 
    Profile* child = new Profile(Profile::Ptr(parent));
43
 
    child->setProperty(Profile::StartInCurrentSessionDir,true);
44
 
 
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));
52
 
 
53
 
    QVERIFY(child->isPropertySet(Profile::StartInCurrentSessionDir));
54
 
    QVERIFY(!child->isPropertySet(Profile::Name));
55
 
    QVERIFY(!child->isPropertySet(Profile::AntiAliasFonts));
56
 
    QVERIFY(!child->isPropertySet(Profile::ColorScheme));
57
 
 
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());
63
 
    
64
 
    // read inheritable properties
65
 
    QVERIFY(parent->property<bool>(Profile::AntiAliasFonts) == false);
66
 
    QVERIFY(child->property<bool>(Profile::AntiAliasFonts) == false);
67
 
 
68
 
    QVERIFY(parent->property<bool>(Profile::StartInCurrentSessionDir) == false);
69
 
    QVERIFY(child->property<bool>(Profile::StartInCurrentSessionDir) == true);
70
 
 
71
 
    delete child;
72
 
}
73
 
void ProfileTest::testClone()
74
 
{
75
 
    // create source profile and parent
76
 
    Profile::Ptr parent(new Profile);
77
 
    parent->setProperty(Profile::Command,"ps");
78
 
    parent->setProperty(Profile::ColorScheme,"BlackOnWhite");
79
 
 
80
 
    Profile::Ptr source(new Profile(parent));
81
 
    source->setProperty(Profile::AntiAliasFonts,false);
82
 
    source->setProperty(Profile::HistorySize,4567);
83
 
    
84
 
    source->setProperty(Profile::Name,"SourceProfile");
85
 
    source->setProperty(Profile::Path,"SourcePath");
86
 
 
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));
94
 
 
95
 
    // clone source profile, setting only properties that differ
96
 
    // between the source and target
97
 
    target->clone(source,true);
98
 
 
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));
104
 
 
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));
110
 
 
111
 
    // check that Command property is not set in target because the values
112
 
    // are the same
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));
118
 
}
119
 
void ProfileTest::testProfileGroup()
120
 
{
121
 
    // create three new profiles
122
 
    Profile::Ptr profile[3];
123
 
    for (int i=0;i<3;i++)
124
 
    {
125
 
        profile[i] = new Profile;
126
 
        QVERIFY(!profile[i]->asGroup());
127
 
    }
128
 
 
129
 
    // set properties with different values
130
 
    profile[0]->setProperty(Profile::UseCustomCursorColor,true);
131
 
    profile[1]->setProperty(Profile::UseCustomCursorColor,false);
132
 
 
133
 
    // set properties with same values
134
 
    for (int i=0;i<3;i++)
135
 
        profile[i]->setProperty(Profile::HistorySize,1234);
136
 
 
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++)
141
 
    {
142
 
        group->addProfile(profile[i]);
143
 
        QVERIFY(group->profiles().contains(profile[i]));
144
 
    }
145
 
    group->updateValues();
146
 
 
147
 
    // read and check properties from the group
148
 
    QCOMPARE(group->property<int>(Profile::HistorySize),1234);
149
 
    QCOMPARE(group->property<QVariant>(Profile::UseCustomCursorColor),QVariant());
150
 
 
151
 
    // set and test shareable properties in the group
152
 
    group->setProperty(Profile::Command,"ssh");
153
 
    group->setProperty(Profile::AntiAliasFonts,false);
154
 
 
155
 
    QCOMPARE(profile[0]->property<QString>(Profile::Command),QString("ssh"));
156
 
    QVERIFY(profile[1]->property<bool>(Profile::AntiAliasFonts) == false);
157
 
 
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");
164
 
 
165
 
    // remove a profile from the group
166
 
    group->removeProfile(profile[0]);
167
 
    QVERIFY(!group->profiles().contains(profile[0]));
168
 
    group->updateValues();
169
 
 
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");
173
 
}
174
 
 
175
 
QTEST_KDEMAIN_CORE( ProfileTest )
176
 
 
177
 
#include "ProfileTest.moc"
178
 
 
179