/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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, Digia gives you certain additional
** rights. These rights are described in the Digia 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.
**
**
** $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