File indexing completed on 2025-01-05 05:23:50
0001 /* 0002 This file is part of the Okteta Kasten module, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2007 Friedrich W. H. Kossebau <kossebau@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "bytearraydocumenttest.hpp" 0010 0011 // test object 0012 #include <bytearraydocument.hpp> 0013 // Okteta core 0014 #include <Okteta/PieceTableByteArrayModel> 0015 // Qt 0016 #include <QTest> 0017 #include <QSignalSpy> 0018 #include <QByteArray> 0019 0020 namespace Kasten { 0021 0022 static constexpr char Title[] = "title"; 0023 0024 void ByteArrayDocumentTest::testCreateNew() 0025 { 0026 auto* document = new ByteArrayDocument(QStringLiteral("New created for test.")); 0027 0028 QVERIFY(document != nullptr); 0029 QCOMPARE(document->contentFlags(), Kasten::ContentStateNormal); 0030 0031 auto* byteArray = qobject_cast<Okteta::PieceTableByteArrayModel*>(document->content()); 0032 QVERIFY(byteArray != nullptr); 0033 QCOMPARE(byteArray->size(), 0); 0034 QVERIFY(!byteArray->isModified()); 0035 0036 delete document; 0037 } 0038 0039 void ByteArrayDocumentTest::testSetTitle() 0040 { 0041 auto* document = new ByteArrayDocument(QStringLiteral("New created for test.")); 0042 auto* titleChangeSpy = new QSignalSpy(document, SIGNAL(titleChanged(QString))); 0043 0044 const QLatin1String title(Title); 0045 document->setTitle(title); 0046 QCOMPARE(document->title(), title); 0047 QVERIFY(titleChangeSpy->isValid()); 0048 QCOMPARE(titleChangeSpy->size(), 1); 0049 const QList<QVariant> arguments = titleChangeSpy->takeFirst(); 0050 QCOMPARE(arguments.at(0).toString(), title); 0051 0052 delete document; 0053 delete titleChangeSpy; 0054 } 0055 0056 } 0057 0058 QTEST_GUILESS_MAIN(Kasten::ByteArrayDocumentTest) 0059 0060 #include "moc_bytearraydocumenttest.cpp"