| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). |
| 4 |
** All rights reserved. |
| 5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
| 6 |
** |
| 7 |
** This file is part of the test suite of the Qt Toolkit. |
| 8 |
** |
| 9 |
** $QT_BEGIN_LICENSE:LGPL$ |
| 10 |
** GNU Lesser General Public License Usage |
| 11 |
** This file may be used under the terms of the GNU Lesser General Public |
| 12 |
** License version 2.1 as published by the Free Software Foundation and |
| 13 |
** appearing in the file LICENSE.LGPL included in the packaging of this |
| 14 |
** file. Please review the following information to ensure the GNU Lesser |
| 15 |
** General Public License version 2.1 requirements will be met: |
| 16 |
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 17 |
** |
| 18 |
** In addition, as a special exception, Nokia gives you certain additional |
| 19 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
| 20 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 21 |
** |
| 22 |
** GNU General Public License Usage |
| 23 |
** Alternatively, this file may be used under the terms of the GNU General |
| 24 |
** Public License version 3.0 as published by the Free Software Foundation |
| 25 |
** and appearing in the file LICENSE.GPL included in the packaging of this |
| 26 |
** file. Please review the following information to ensure the GNU General |
| 27 |
** Public License version 3.0 requirements will be met: |
| 28 |
** http://www.gnu.org/copyleft/gpl.html. |
| 29 |
** |
| 30 |
** Other Usage |
| 31 |
** Alternatively, this file may be used in accordance with the terms and |
| 32 |
** conditions contained in a signed written agreement between you and Nokia. |
| 33 |
** |
| 34 |
** |
| 35 |
** |
| 36 |
** |
| 37 |
** |
| 38 |
** $QT_END_LICENSE$ |
| 39 |
** |
| 40 |
****************************************************************************/ |
| 41 |
|
| 42 |
|
| 43 |
#include <QApplication> |
| 44 |
#include <QGroupBox> |
| 45 |
#include <Q3GroupBox> |
| 46 |
#include <QLabel> |
| 47 |
#include <QVBoxLayout> |
| 48 |
#include <QDebug> |
| 49 |
#include <QtTest/QtTest> |
| 50 |
|
| 51 |
class tst_q3groupbox : public QObject |
| 52 |
{ |
| 53 |
Q_OBJECT |
| 54 |
private slots: |
| 55 |
void getSetCheck(); |
| 56 |
void groupBoxHeight(); |
| 57 |
}; |
| 58 |
|
| 59 |
// Testing get/set functions |
| 60 |
void tst_q3groupbox::getSetCheck() |
| 61 |
{ |
| 62 |
Q3GroupBox obj1; |
| 63 |
// int Q3GroupBox::insideMargin() |
| 64 |
// void Q3GroupBox::setInsideMargin(int) |
| 65 |
obj1.setInsideMargin(0); |
| 66 |
QCOMPARE(0, obj1.insideMargin()); |
| 67 |
obj1.setInsideMargin(INT_MIN); |
| 68 |
QCOMPARE(INT_MIN, obj1.insideMargin()); |
| 69 |
obj1.setInsideMargin(INT_MAX); |
| 70 |
QCOMPARE(INT_MAX, obj1.insideMargin()); |
| 71 |
|
| 72 |
// int Q3GroupBox::insideSpacing() |
| 73 |
// void Q3GroupBox::setInsideSpacing(int) |
| 74 |
obj1.setInsideSpacing(0); |
| 75 |
QCOMPARE(0, obj1.insideSpacing()); |
| 76 |
obj1.setInsideSpacing(INT_MIN); |
| 77 |
QCOMPARE(INT_MIN, obj1.insideSpacing()); |
| 78 |
obj1.setInsideSpacing(INT_MAX); |
| 79 |
QCOMPARE(INT_MAX, obj1.insideSpacing()); |
| 80 |
} |
| 81 |
|
| 82 |
/* |
| 83 |
Test that a Q3GroupBox has a reasonable height compared to a QGroupBox. |
| 84 |
*/ |
| 85 |
void tst_q3groupbox::groupBoxHeight() |
| 86 |
{ |
| 87 |
QWidget w; |
| 88 |
|
| 89 |
// Create group boxes. |
| 90 |
Q3GroupBox * const g3 = new Q3GroupBox(1000, Qt::Vertical, "Q3 Group Box", &w); |
| 91 |
new QLabel("Row 1", g3); |
| 92 |
|
| 93 |
QGroupBox * const g4 = new QGroupBox(&w, "QGroupBox"); |
| 94 |
g4->setTitle("QGroupBox"); |
| 95 |
QVBoxLayout * const g4Layout = new QVBoxLayout(g4); |
| 96 |
g4Layout->addWidget(new QLabel("QT4 Row 1")); |
| 97 |
|
| 98 |
// Add them to a layout. |
| 99 |
QVBoxLayout * const layout = new QVBoxLayout(&w, 5, 5); |
| 100 |
layout->addWidget(g3); |
| 101 |
layout->addWidget(g4); |
| 102 |
layout->addWidget(new QLabel("Label at Bottom")); |
| 103 |
w.show(); |
| 104 |
|
| 105 |
// Measure height and test. |
| 106 |
const int q3height = g3->height(); |
| 107 |
const int q4height = g4->height(); |
| 108 |
|
| 109 |
const double withinReason = 0.5; // Up to 50% off is OK. |
| 110 |
const int minimum = int(q4height * (1.0 - withinReason)); |
| 111 |
const int maximum = int(q4height * (1.0 + withinReason)); |
| 112 |
|
| 113 |
QVERIFY(q3height > minimum); |
| 114 |
QVERIFY(q3height < maximum); |
| 115 |
} |
| 116 |
|
| 117 |
QTEST_MAIN(tst_q3groupbox) |
| 118 |
#include "tst_q3groupbox.moc" |