/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include
#include
#include
#include
#ifdef Q_WS_MAC
#include
#endif
//TESTED_FILES=
class tst_Q3RichText : public QObject
{
Q_OBJECT
public:
tst_Q3RichText();
virtual ~tst_Q3RichText();
public slots:
void initTestCase();
void cleanupTestCase();
private slots:
void richtext();
void append_data();
void append();
void cursorPosition();
void moveCursor();
void keyPressEvent();
};
tst_Q3RichText::tst_Q3RichText()
{
}
tst_Q3RichText::~tst_Q3RichText()
{
}
void tst_Q3RichText::initTestCase()
{
// create a default mainwindow
// If you run a widget test, this will be replaced in the testcase by the
// widget under test
QWidget *w = new QWidget(0,"mainWidget");
w->setFixedSize( 200, 200 );
qApp->setMainWidget( w );
w->show();
}
void tst_Q3RichText::cleanupTestCase()
{
delete qApp->mainWidget();
}
void tst_Q3RichText::richtext()
{
Q3TextEdit* textedit = new Q3TextEdit();
QString result( "\n"
"k k k
\n"
"\n" );
QFont font = textedit->font();
result = result.arg( QString::number(font.pointSize()) + "pt" ).arg( font.family() ).arg( "" ).arg( "" ).arg( "" );
textedit->setTextFormat( Qt::RichText );
QKeyEvent ke( QEvent::KeyPress, Qt::Key_K, 107, Qt::NoButton, "k" );
QApplication::sendEvent( textedit->viewport(), &ke );
ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Space, 32, Qt::NoButton, " " );
QApplication::sendEvent( textedit->viewport(), &ke );
textedit->setCurrentFont( QFont( "Arial", 20 ) );
ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Space, 32, Qt::NoButton, " " );
QApplication::sendEvent( textedit->viewport(), &ke );
ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Space, 32, Qt::NoButton, " " );
QApplication::sendEvent( textedit->viewport(), &ke );
ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Space, 32, Qt::NoButton, " " );
QApplication::sendEvent( textedit->viewport(), &ke );
textedit->setCurrentFont( QFont( "Arial", 15 ) );
ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Space, 32, Qt::NoButton, " " );
QApplication::sendEvent( textedit->viewport(), &ke );
ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Space, 32, Qt::NoButton, " " );
QApplication::sendEvent( textedit->viewport(), &ke );
textedit->setCurrentFont( QFont( "Arial", 20 ) );
ke = QKeyEvent( QEvent::KeyPress, Qt::Key_K, 107, Qt::NoButton, "k" );
QApplication::sendEvent( textedit->viewport(), &ke );
ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Space, 32, Qt::NoButton, " " );
QApplication::sendEvent( textedit->viewport(), &ke );
ke = QKeyEvent( QEvent::KeyPress, Qt::Key_K, 107, Qt::NoButton, "k" );
QApplication::sendEvent( textedit->viewport(), &ke );
ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Space, 32, Qt::NoButton, " " );
QApplication::sendEvent( textedit->viewport(), &ke );
ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Space, 32, Qt::NoButton, " " );
QApplication::sendEvent( textedit->viewport(), &ke );
QCOMPARE( textedit->text(), result );
delete textedit;
}
void tst_Q3RichText::append_data()
{
// should we catch bad alloc or something if it fails?
// Being this is a test.
QTest::addColumn("firstString");
QTest::addColumn("secondString");
QTest::addColumn("result");
QTest::addColumn("textFormat");
QTest::newRow( "data0" ) << QString("Hello World...") << QString("First Time")
<< QString("Hello World...\nFirst Time")
<< int(Qt::PlainText);
QTest::newRow( "data1" ) << QString("Hello World...") << QString("Second Time")
<< QString("Hello World...
\nSecond Time
\n