2 Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 #include "attachmentpropertiesdialogtest.h"
21 #include "qtest_messagecore.h"
25 #include "messagecore_debug.h"
30 #include <kmime/kmime_content.h>
31 using namespace KMime
;
33 #include <MessageCore/AttachmentPart>
34 #include <MessageCore/AttachmentPropertiesDialog>
35 using namespace MessageCore
;
37 QTEST_MAIN(AttachmentPropertiesDialogTest
)
39 void AttachmentPropertiesDialogTest::testAttachmentPartReadWrite()
42 const QString name
= QStringLiteral("old name");
43 const QString newName
= QStringLiteral("new name");
44 const QString description
= QStringLiteral("old description");
45 const QString newDescription
= QStringLiteral("new description");
46 const QByteArray
data("12345");
47 const QByteArray
mimeType("text/plain");
48 const QByteArray
newMimeType("x-weird/x-type");
49 const Headers::contentEncoding encoding
= Headers::CEquPr
;
50 const Headers::contentEncoding newEncoding
= Headers::CE7Bit
;
51 const bool autoDisplay
= true;
52 const bool encrypt
= true;
53 const bool sign
= true;
56 AttachmentPart::Ptr part
= AttachmentPart::Ptr(new AttachmentPart
);
58 part
->setDescription(description
);
60 part
->setMimeType(mimeType
);
61 part
->setEncoding(encoding
);
62 part
->setInline(autoDisplay
);
63 part
->setEncrypted(encrypt
);
64 part
->setSigned(sign
);
66 // Show the dialog and verify that it is accurate.
67 AttachmentPropertiesDialog
*dialog
= new AttachmentPropertiesDialog(part
);
69 QLineEdit
*nameEdit
= dialog
->findChild
<QLineEdit
*>(QStringLiteral("name"));
71 QCOMPARE(nameEdit
->text(), name
);
72 QLineEdit
*descriptionEdit
= dialog
->findChild
<QLineEdit
*>(QStringLiteral("description"));
73 Q_ASSERT(descriptionEdit
);
74 QCOMPARE(descriptionEdit
->text(), description
);
75 KComboBox
*mimeTypeCombo
= dialog
->findChild
<KComboBox
*>(QStringLiteral("mimeType"));
76 Q_ASSERT(mimeTypeCombo
);
77 QCOMPARE(mimeTypeCombo
->currentText().toLatin1(), mimeType
);
78 KComboBox
*encodingCombo
= dialog
->findChild
<KComboBox
*>(QStringLiteral("encoding"));
79 Q_ASSERT(encodingCombo
);
80 QCOMPARE(encodingCombo
->currentIndex(), int(encoding
));
81 QCheckBox
*autoDisplayCheck
= dialog
->findChild
<QCheckBox
*>(QStringLiteral("autoDisplay"));
82 Q_ASSERT(autoDisplayCheck
);
83 QCOMPARE(autoDisplayCheck
->isChecked(), autoDisplay
);
84 QCheckBox
*encryptCheck
= dialog
->findChild
<QCheckBox
*>(QStringLiteral("encrypt"));
85 Q_ASSERT(encryptCheck
);
86 QCOMPARE(encryptCheck
->isChecked(), encrypt
);
87 QCheckBox
*signCheck
= dialog
->findChild
<QCheckBox
*>(QStringLiteral("sign"));
89 QCOMPARE(signCheck
->isChecked(), sign
);
90 //QTest::qWait( 5000 );
92 // Make some changes in the dialog.
93 nameEdit
->setText(newName
);
94 descriptionEdit
->setText(newDescription
);
95 mimeTypeCombo
->setCurrentItem(QString::fromLatin1(newMimeType
), true);
96 encodingCombo
->setCurrentIndex(int(newEncoding
));
97 autoDisplayCheck
->setChecked(!autoDisplay
);
98 encryptCheck
->setChecked(!encrypt
);
99 signCheck
->setChecked(!sign
);
101 // Click on 'OK' and verify changes.
104 QCOMPARE(part
->name(), newName
);
105 QCOMPARE(part
->description(), newDescription
);
106 QCOMPARE(part
->data(), data
); // Unchanged.
107 QCOMPARE(part
->mimeType(), newMimeType
);
108 QCOMPARE(int(part
->encoding()), int(newEncoding
));
109 QCOMPARE(part
->isInline(), !autoDisplay
);
110 QCOMPARE(part
->isEncrypted(), !encrypt
);
111 QCOMPARE(part
->isSigned(), !sign
);
114 void AttachmentPropertiesDialogTest::testAttachmentPartReadOnly()
117 const QString name
= QStringLiteral("old name");
118 const QString newName
= QStringLiteral("new name");
121 AttachmentPart::Ptr part
= AttachmentPart::Ptr(new AttachmentPart
);
124 // Show the (read-only) dialog and do some changes.
125 AttachmentPropertiesDialog
*dialog
= new AttachmentPropertiesDialog(part
, true, 0);
127 // Click on 'OK'. No changes should have been made.
130 QCOMPARE(part
->name(), name
); // No change.
133 void AttachmentPropertiesDialogTest::testAttachmentPartCancel()
136 const QString name
= QStringLiteral("old name");
137 const QString newName
= QStringLiteral("new name");
140 AttachmentPart::Ptr part
= AttachmentPart::Ptr(new AttachmentPart
);
143 // Show the (read-write) dialog and do some changes.
144 AttachmentPropertiesDialog
*dialog
= new AttachmentPropertiesDialog(part
);
146 QLineEdit
*nameEdit
= dialog
->findChild
<QLineEdit
*>(QStringLiteral("name"));
148 nameEdit
->setText(newName
);
150 // Click on 'Cancel'. No changes should have been made.
153 QCOMPARE(part
->name(), name
); // No change.
156 void AttachmentPropertiesDialogTest::testMimeContentReadOnly()
159 const QString name
= QStringLiteral("old name");
160 const QString newName
= QStringLiteral("new name");
161 const QByteArray
charset("us-ascii");
163 // Create the MIME Content.
164 Content
*content
= new Content
;
165 content
->contentType()->setName(name
, charset
);
166 const Content
*constContent
= content
;
168 // Show the (read-only) dialog and do some changes.
169 AttachmentPropertiesDialog
*dialog
= new AttachmentPropertiesDialog(constContent
);
172 // Click on 'OK'. The MIME Content should be untouched.
175 QCOMPARE(content
->contentType()->name(), name
); // No change.