1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
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 https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28#include <QtTest/QtTest>
29#include <QErrorMessage>
30#include <QDebug>
31#include <QCheckBox>
32
33class tst_QErrorMessage : public QObject
34{
35 Q_OBJECT
36
37private slots:
38 void dontShowAgain();
39 void dontShowCategoryAgain();
40
41};
42
43void tst_QErrorMessage::dontShowAgain()
44{
45 QString plainString = QLatin1String("foo");
46 QString htmlString = QLatin1String("foo<br>bar");
47 QCheckBox *checkBox = 0;
48
49 QErrorMessage errorMessageDialog(0);
50
51 // show an error with plain string
52 errorMessageDialog.showMessage(message: plainString);
53 QVERIFY(errorMessageDialog.isVisible());
54 checkBox = errorMessageDialog.findChild<QCheckBox*>();
55 QVERIFY(checkBox);
56 QVERIFY(checkBox->isChecked());
57 errorMessageDialog.close();
58
59 errorMessageDialog.showMessage(message: plainString);
60 QVERIFY(errorMessageDialog.isVisible());
61 checkBox = errorMessageDialog.findChild<QCheckBox*>();
62 QVERIFY(checkBox);
63 QVERIFY(checkBox->isChecked());
64 checkBox->setChecked(false);
65 errorMessageDialog.close();
66
67 errorMessageDialog.showMessage(message: plainString);
68 QVERIFY(!errorMessageDialog.isVisible());
69
70 // show an error with an html string
71 errorMessageDialog.showMessage(message: htmlString);
72 QVERIFY(errorMessageDialog.isVisible());
73 checkBox = errorMessageDialog.findChild<QCheckBox*>();
74 QVERIFY(checkBox);
75 QVERIFY(!checkBox->isChecked());
76 checkBox->setChecked(true);
77 errorMessageDialog.close();
78
79 errorMessageDialog.showMessage(message: htmlString);
80 QVERIFY(errorMessageDialog.isVisible());
81 checkBox = errorMessageDialog.findChild<QCheckBox*>();
82 QVERIFY(checkBox);
83 QVERIFY(checkBox->isChecked());
84 checkBox->setChecked(false);
85 errorMessageDialog.close();
86
87 errorMessageDialog.showMessage(message: htmlString);
88 QVERIFY(!errorMessageDialog.isVisible());
89}
90
91void tst_QErrorMessage::dontShowCategoryAgain()
92{
93 QString htmlString = QLatin1String("foo<br>bar");
94 QString htmlString2 = QLatin1String("foo2<br>bar2");
95 QCheckBox *checkBox = 0;
96
97 QErrorMessage errorMessageDialog(0);
98
99 errorMessageDialog.showMessage(message: htmlString,type: "Cat 1");
100 QVERIFY(errorMessageDialog.isVisible());
101 checkBox = errorMessageDialog.findChild<QCheckBox*>();
102 QVERIFY(checkBox);
103 QVERIFY(checkBox->isChecked());
104 checkBox->setChecked(true);
105 errorMessageDialog.close();
106
107 errorMessageDialog.showMessage(message: htmlString,type: "Cat 1");
108 QVERIFY(errorMessageDialog.isVisible());
109 checkBox = errorMessageDialog.findChild<QCheckBox*>();
110 QVERIFY(checkBox);
111 QVERIFY(checkBox->isChecked());
112 checkBox->setChecked(true);
113 errorMessageDialog.close();
114
115 errorMessageDialog.showMessage(message: htmlString2,type: "Cat 1");
116 QVERIFY(errorMessageDialog.isVisible());
117 checkBox = errorMessageDialog.findChild<QCheckBox*>();
118 QVERIFY(checkBox);
119 QVERIFY(checkBox->isChecked());
120 checkBox->setChecked(true);
121 errorMessageDialog.close();
122
123 errorMessageDialog.showMessage(message: htmlString,type: "Cat 1");
124 QVERIFY(errorMessageDialog.isVisible());
125 checkBox = errorMessageDialog.findChild<QCheckBox*>();
126 QVERIFY(checkBox);
127 QVERIFY(checkBox->isChecked());
128 checkBox->setChecked(false);
129 errorMessageDialog.close();
130
131 errorMessageDialog.showMessage(message: htmlString2,type: "Cat 1");
132 QVERIFY(!errorMessageDialog.isVisible());
133
134 errorMessageDialog.showMessage(message: htmlString,type: "Cat 1");
135 QVERIFY(!errorMessageDialog.isVisible());
136
137 errorMessageDialog.showMessage(message: htmlString);
138 QVERIFY(errorMessageDialog.isVisible());
139
140 errorMessageDialog.showMessage(message: htmlString,type: "Cat 2");
141 QVERIFY(errorMessageDialog.isVisible());
142}
143
144QTEST_MAIN(tst_QErrorMessage)
145#include "tst_qerrormessage.moc"
146

source code of qtbase/tests/auto/widgets/dialogs/qerrormessage/tst_qerrormessage.cpp