1
/****************************************************************************
2
**
3
** Copyright (C) 2012 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 <QtTest/QtTest>
44
45
#include <qapplication.h>
46
#include <qdebug.h>
47
#include <q3progressbar.h>
48
#include "../../shared/util.h"
49
50
//TESTED_CLASS=
51
//TESTED_FILES=
52
53
class tst_Q3ProgressBar : public QObject
54
{
55
Q_OBJECT
56
57
public:
58
    tst_Q3ProgressBar();
59
    virtual ~tst_Q3ProgressBar();
60
61
private slots:
62
    void getSetCheck();
63
    void setProgress();
64
};
65
66
tst_Q3ProgressBar::tst_Q3ProgressBar()
67
{
68
}
69
70
tst_Q3ProgressBar::~tst_Q3ProgressBar()
71
{
72
}
73
74
// Testing get/set functions
75
void tst_Q3ProgressBar::getSetCheck()
76
{
77
    Q3ProgressBar obj1;
78
    // bool Q3ProgressBar::centerIndicator()
79
    // void Q3ProgressBar::setCenterIndicator(bool)
80
    obj1.setCenterIndicator(false);
81
    QCOMPARE(false, obj1.centerIndicator());
82
    obj1.setCenterIndicator(true);
83
    QCOMPARE(true, obj1.centerIndicator());
84
}
85
86
class MyCustomProgressBar : public Q3ProgressBar
87
{
88
    public :
89
        MyCustomProgressBar() : Q3ProgressBar()
90
        {
91
            paintNumber = 0;
92
        }
93
94
        void paintEvent(QPaintEvent * event)
95
        {
96
            paintNumber++;
97
            qDebug() << "PAINT EVENT:" << paintNumber;
98
            Q3ProgressBar::paintEvent(event);
99
        }
100
        int paintNumber;
101
};
102
103
/*
104
  Maybe this test should be redesigned.
105
 */
106
void tst_Q3ProgressBar::setProgress()
107
{
108
    MyCustomProgressBar * m_progressBar = new MyCustomProgressBar();
109
    m_progressBar->show();
110
    QTest::qWaitForWindowShown(m_progressBar);
111
112
    //case with total steps = 0
113
    m_progressBar->setTotalSteps(0);
114
    int oldValue = m_progressBar->progress();
115
    m_progressBar->paintNumber = 0;
116
    m_progressBar->setProgress(m_progressBar->progress() + 1);
117
    QCOMPARE(oldValue + 1,m_progressBar->progress());
118
119
    // It might be > 1 because it is animated.
120
    QTRY_VERIFY(m_progressBar->paintNumber >= 1);
121
    qDebug() << "Animation test: paintNumber =" << m_progressBar->paintNumber;
122
    
123
    //standard case
124
    m_progressBar->setTotalSteps(3);
125
    m_progressBar->setProgress(0);
126
    m_progressBar->paintNumber = 0;
127
    m_progressBar->setProgress(m_progressBar->progress() + 1);
128
129
    // It might be > 1 because other events might cause painting.
130
    QTRY_VERIFY(m_progressBar->paintNumber >= 1);
131
    qDebug() << "Standard test: paintNumber =" << m_progressBar->paintNumber;
132
}
133
134
QTEST_MAIN(tst_Q3ProgressBar)
135
#include "tst_q3progressbar.moc"