Fix no newlines warnings. Patch by Peter Oberndorfer
[kdevelopdvcssupport.git] / veritas / test.cpp
blob140b783cc3cdbaed0df61219862dec97b54d07c2
1 /* KDevelop xUnit plugin
3 * Copyright 2006 Ernst Huber <qxrunner@systest.ch>
4 * Copyright 2008 Manuel Breugelmans <mbr.nxi@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02110-1301, USA.
22 #include "veritas/test.h"
23 #include "internal/test_p.h"
24 #include <KDebug>
26 using Veritas::Test;
27 using Veritas::TestState;
28 using Veritas::TestResult;
30 Test* Test::createRoot()
32 QList<QVariant> rootData;
33 // 4 blank column data to make sure children also get that much columns
34 return new Test(rootData << "" << "" << "" << "");
37 Test::Test(const QList<QVariant>& data, Test* parent)
38 : QObject(parent),
39 d(new Internal(this))
41 d->result = new TestResult;
42 d->itemData = data;
43 // Make sure this item has as many columns as the parent.
44 for (int i= d->itemData.count(); i < Internal::columnCount; i++) {
45 d->itemData << "";
47 if (!data.empty()) {
48 d->name = data.value(0).toString();
49 } else {
50 d->name.clear();
52 d->check();
53 d->needVerboseToggle = false;
54 d->needSelectionToggle = false;
57 Test::Test(const QString& name, Test* parent)
58 : QObject(parent),
59 d(new Internal(this))
61 d->name = name;
62 d->result = new TestResult;
63 // Make sure this item has as many columns as the parent.
64 for (int i=0; i < Internal::columnCount; i++) {
65 d->itemData << QString();
67 d->check();
68 d->needVerboseToggle = false;
69 d->needSelectionToggle = false;
72 QString Test::name() const
74 return d->name;
77 void Test::kill()
80 bool Test::needVerboseToggle() const
82 return d->needVerboseToggle;
85 void Test::setVerboseToggle(bool enabled)
87 d->needVerboseToggle = enabled;
90 bool Test::needSelectionToggle() const
92 return d->needSelectionToggle;
95 void Test::setSelectionToggle(bool enabled)
97 d->needSelectionToggle = enabled;
100 Test::~Test()
102 delete d->result;
103 qDeleteAll(d->children);
104 delete d;
107 int Test::run()
109 return 0;
112 bool Test::shouldRun() const
114 return false;
117 Test* Test::parent() const
119 return qobject_cast<Test*>(QObject::parent());
122 Test* Test::child(int row) const
124 return d->children.value(row);
127 Test* Test::childNamed(const QString& name) const
129 if (!d->childMap.contains(name))
130 return 0;
131 return d->childMap[name];
134 void Test::addChild(Test* item)
136 Test* t = qobject_cast<Test*>(item);
137 d->children.append(t);
138 d->childMap[t->name()] = t;
141 int Test::childCount() const
143 return d->children.count();
146 int Test::row() const
148 if (parent()) {
149 return parent()->d->children.indexOf(const_cast<Test*>(this));
151 return 0;
154 TestState Test::state() const
156 return d->result->state();
159 TestResult* Test::result() const
161 return d->result;
164 void Test::setResult(TestResult* res)
166 if (d->result) delete d->result;
167 d->result = res;
168 if (res) {
169 d->setData(1, res->message());
170 d->setData(2, res->file().pathOrUrl());
171 d->setData(3, res->line());
172 d->result->setOwner(this);
176 QList<Test*> Test::leafs() const
178 QList<Test*> l;
179 foreach(Test* t, d->children) {
180 if (t->childCount() == 0) {
181 l.append(t);
182 } else {
183 l += t->leafs();
186 return l;
189 void Test::signalStarted()
191 emit started(d->index());
194 void Test::signalFinished()
196 emit finished(d->index());
200 Veritas::Test::Internal* Test::internal()
202 return d;
205 #include "test.moc"