2e99490779fdfe51b3c9676d2d5fc3565a70dce8
[profile/ivi/qtxmlpatterns.git] / tests / auto / xmlpatternsview / view / TestCaseView.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <QDate>
43 #include <QtDebug>
44
45 #include "UserTestCase.h"
46 #include "ui_ui_BaseLinePage.h"
47
48 #include "TestCaseView.h"
49
50 using namespace QPatternistSDK;
51
52 /**
53  * Removes all tabs in @p widget, and deletes its page widgets.
54  */
55 static void clearTabWidget(QTabWidget *const widget)
56 {
57     Q_ASSERT(widget);
58
59     /* Very annoying, we can't cache count(). */
60     /* Idea: QTabWidget::clear(bool deletePageWidgets = false); */
61     while(widget->count() != 0)
62     {
63         delete widget->widget(0);
64         widget->removeTab(0);
65     }
66
67     Q_ASSERT(widget->count() == 0);
68 }
69
70 TestCaseView::TestCaseView(QWidget *const p) : QDockWidget(QLatin1String("Test Case View"), p)
71 {
72     setObjectName(QLatin1String("TestCaseView"));
73     setWidget(new QWidget());
74     setupUi(widget());
75     displayNone();
76     clearTabWidget(baselinesTabs);
77 }
78
79 void TestCaseView::displayNone()
80 {
81     stackedWidget->setCurrentIndex(1);
82 }
83
84 void TestCaseView::displayTestCase(TestCase *const tc)
85 {
86     if(!tc)
87     {
88         displayNone();
89         return;
90     }
91
92     name->setText(tc->title());
93     description->setText(tc->description());
94     isXPath->setText(tc->isXPath() ? QLatin1String("yes") : QLatin1String("no"));
95     author->setText(tc->creator());
96     type->setText(TestCase::displayName(tc->scenario()));
97     if(tc->lastModified().isNull())
98         lastModified->setText(QLatin1String("Not specified."));
99     else
100         lastModified->setText(tc->lastModified().toString());
101
102     if(tc->contextItemSource().isValid())
103         focusDocument->setText(tc->contextItemSource().toLocalFile());
104
105     /* Not used. */
106     bool ok = false;
107
108     const QString sourceCode(tc->sourceCode(ok));
109
110     if(sourceCode.isEmpty())
111         sourceEdit->setPlainText(QLatin1String("No source code available."));
112     else
113         sourceEdit->setPlainText(sourceCode);
114
115     stackedWidget->setCurrentIndex(0);
116
117     displayBaseLines(tc);
118 }
119
120 void TestCaseView::displayBaseLines(const TestCase *const tc)
121 {
122     clearTabWidget(baselinesTabs);
123     Q_ASSERT(tc);
124     const TestBaseLine::List bs(tc->baseLines());
125     const TestBaseLine::List::const_iterator end(bs.constEnd());
126     TestBaseLine::List::const_iterator it(bs.constBegin());
127
128     for(; it != end; ++it)
129     {
130         const TestBaseLine *const bl = *it;
131         Q_ASSERT(bl);
132         const TestBaseLine::Type t = bl->type();
133
134         QString title(TestBaseLine::displayName(t));
135         const QString details(bl->details());
136
137         QWidget *const currPage = new QWidget();
138         Ui::BaseLinePage setupPage;
139         setupPage.setupUi(currPage);
140
141         /* Make this title a bit better: "ExpectedError: XPTY0004", for example. */
142         switch(t)
143         {
144             case TestBaseLine::ExpectedError:
145             {
146                 title += (QLatin1String(": ") + details);
147                 /* Fallthrough. */
148             }
149             case TestBaseLine::Ignore:
150             {
151                 setupPage.contentEdit->setEnabled(false);
152                 break;
153             }
154             default:
155             {
156                 setupPage.contentEdit->setPlainText(details);
157                 break;
158             }
159         }
160
161         baselinesTabs->addTab(currPage, title);
162     }
163
164     int tabIndex = baselinesTabs->count(); /* The tab we're about to add. */
165     baselinesTabs->addTab(new QWidget(), QLatin1String("AST Baseline"));
166     baselinesTabs->setTabToolTip(tabIndex,
167                                  QLatin1String("Expected AST baselines are not yet implemented."));
168     baselinesTabs->setTabEnabled(tabIndex, false);
169
170     ++tabIndex; /* Again, the tab we're about to add. */
171     baselinesTabs->addTab(new QWidget(), QLatin1String("Message Baseline"));
172     baselinesTabs->setTabToolTip(tabIndex,
173                                  QLatin1String("Expected Message baselines are not yet implemented."));
174     baselinesTabs->setTabEnabled(tabIndex, false);
175
176     baselinesTabs->setCurrentIndex(0);
177 }
178
179 // vim: et:ts=4:sw=4:sts=4