1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
/*
Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "attachmentpropertiesdialogtest.h"
#include "qtest_messagecore.h"
#include <boost/shared_ptr.hpp>
#include <QCheckBox>
#include <KDebug>
#include <KComboBox>
#include <KLineEdit>
#include <qtest_kde.h>
#include <kmime/kmime_content.h>
using namespace KMime;
#include <messagecore/attachmentpart.h>
#include <messagecore/attachmentpropertiesdialog.h>
using namespace KPIM;
QTEST_KDEMAIN( AttachmentPropertiesDialogTest, GUI )
void AttachmentPropertiesDialogTest::testAttachmentPartReadWrite()
{
// Sample data.
const QString name = QString::fromLatin1( "old name" );
const QString newName = QString::fromLatin1( "new name" );
const QString description = QString::fromLatin1( "old description" );
const QString newDescription = QString::fromLatin1( "new description" );
const QByteArray data( "12345" );
const QByteArray mimeType( "text/plain" );
const QByteArray newMimeType( "x-weird/x-type" );
const Headers::contentEncoding encoding = Headers::CEquPr;
const Headers::contentEncoding newEncoding = Headers::CE7Bit;
const bool autoDisplay = true;
const bool encrypt = true;
const bool sign = true;
// Create the part.
AttachmentPart::Ptr part = AttachmentPart::Ptr( new AttachmentPart );
part->setName( name );
part->setDescription( description );
part->setData( data );
part->setMimeType( mimeType );
part->setEncoding( encoding );
part->setInline( autoDisplay );
part->setEncrypted( encrypt );
part->setSigned( sign );
// Show the dialog and verify that it is accurate.
AttachmentPropertiesDialog *dialog = new AttachmentPropertiesDialog( part );
dialog->show();
KLineEdit *nameEdit = dialog->findChild<KLineEdit*>( QLatin1String( "name" ) );
Q_ASSERT( nameEdit );
QCOMPARE( nameEdit->text(), name );
KLineEdit *descriptionEdit = dialog->findChild<KLineEdit*>( QLatin1String( "description" ) );
Q_ASSERT( descriptionEdit );
QCOMPARE( descriptionEdit->text(), description );
KComboBox *mimeTypeCombo = dialog->findChild<KComboBox*>( QLatin1String( "mimeType" ) );
Q_ASSERT( mimeTypeCombo );
QCOMPARE( mimeTypeCombo->currentText().toLatin1(), mimeType );
KComboBox *encodingCombo = dialog->findChild<KComboBox*>( QLatin1String( "encoding" ) );
Q_ASSERT( encodingCombo );
QCOMPARE( encodingCombo->currentIndex(), int( encoding ) );
QCheckBox *autoDisplayCheck = dialog->findChild<QCheckBox*>( QLatin1String( "autoDisplay" ) );
Q_ASSERT( autoDisplayCheck );
QCOMPARE( autoDisplayCheck->isChecked(), autoDisplay );
QCheckBox *encryptCheck = dialog->findChild<QCheckBox*>( QLatin1String( "encrypt" ) );
Q_ASSERT( encryptCheck );
QCOMPARE( encryptCheck->isChecked(), encrypt );
QCheckBox *signCheck = dialog->findChild<QCheckBox*>( QLatin1String( "sign" ) );
Q_ASSERT( signCheck );
QCOMPARE( signCheck->isChecked(), sign );
//QTest::qWait( 5000 );
// Make some changes in the dialog.
nameEdit->setText( newName );
descriptionEdit->setText( newDescription );
mimeTypeCombo->setCurrentItem( QLatin1String( newMimeType ), true );
encodingCombo->setCurrentIndex( int( newEncoding ) );
autoDisplayCheck->setChecked( !autoDisplay );
encryptCheck->setChecked( !encrypt );
signCheck->setChecked( !sign );
// Click on 'OK' and verify changes.
dialog->accept();
delete dialog;
QCOMPARE( part->name(), newName );
QCOMPARE( part->description(), newDescription );
QCOMPARE( part->data(), data ); // Unchanged.
QCOMPARE( part->mimeType(), newMimeType );
QCOMPARE( int( part->encoding() ), int( newEncoding ) );
QCOMPARE( part->isInline(), !autoDisplay );
QCOMPARE( part->isEncrypted(), !encrypt );
QCOMPARE( part->isSigned(), !sign );
}
void AttachmentPropertiesDialogTest::testAttachmentPartReadOnly()
{
// Sample data.
const QString name = QString::fromLatin1( "old name" );
const QString newName = QString::fromLatin1( "new name" );
// Create the part.
AttachmentPart::Ptr part = AttachmentPart::Ptr( new AttachmentPart );
part->setName( name );
// Show the (read-only) dialog and do some changes.
AttachmentPropertiesDialog *dialog = new AttachmentPropertiesDialog( part, 0, true );
dialog->show();
KLineEdit *nameEdit = dialog->findChild<KLineEdit*>( QLatin1String( "name" ) );
Q_ASSERT( nameEdit );
nameEdit->setText( newName );
// Click on 'OK'. No changes should have been made.
dialog->accept();
delete dialog;
QCOMPARE( part->name(), name ); // No change.
}
void AttachmentPropertiesDialogTest::testAttachmentPartCancel()
{
// Sample data.
const QString name = QString::fromLatin1( "old name" );
const QString newName = QString::fromLatin1( "new name" );
// Create the part.
AttachmentPart::Ptr part = AttachmentPart::Ptr( new AttachmentPart );
part->setName( name );
// Show the (read-write) dialog and do some changes.
AttachmentPropertiesDialog *dialog = new AttachmentPropertiesDialog( part );
dialog->show();
KLineEdit *nameEdit = dialog->findChild<KLineEdit*>( QLatin1String( "name" ) );
Q_ASSERT( nameEdit );
nameEdit->setText( newName );
// Click on 'Cancel'. No changes should have been made.
dialog->reject();
delete dialog;
QCOMPARE( part->name(), name ); // No change.
}
void AttachmentPropertiesDialogTest::testMimeContentReadOnly()
{
// Sample data.
const QString name = QString::fromLatin1( "old name" );
const QString newName = QString::fromLatin1( "new name" );
const QByteArray charset( "us-ascii" );
// Create the MIME Content.
Content *content = new Content;
content->contentType()->setName( name, charset );
const Content *constContent = content;
// Show the (read-only) dialog and do some changes.
AttachmentPropertiesDialog *dialog = new AttachmentPropertiesDialog( constContent );
dialog->show();
KLineEdit *nameEdit = dialog->findChild<KLineEdit*>( QLatin1String( "name" ) );
QVERIFY( nameEdit->isReadOnly() );
QCOMPARE( nameEdit->text(), name );
Q_ASSERT( nameEdit );
nameEdit->setText( newName );
// Click on 'OK'. The MIME Content should be untouched.
dialog->accept();
delete dialog;
QCOMPARE( content->contentType()->name(), name ); // No change.
}
#include "attachmentpropertiesdialogtest.moc"
|