1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
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  */
clearTabWidget(QTabWidget * const widget)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 
TestCaseView(QWidget * const p)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 
displayNone()79 void TestCaseView::displayNone()
80 {
81     stackedWidget->setCurrentIndex(1);
82 }
83 
displayTestCase(TestCase * const tc)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 
displayBaseLines(const TestCase * const tc)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
180