File indexing completed on 2024-04-28 05:52:31

0001 /*
0002     This file is part of the Okteta Core library, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2006 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 #ifndef ABSTRACTBYTEARRAYMODELIFTEST_HPP
0010 #define ABSTRACTBYTEARRAYMODELIFTEST_HPP
0011 
0012 // lib
0013 #include <addressrange.hpp>
0014 // Qt
0015 #include <QObject>
0016 
0017 class QSignalSpy;
0018 
0019 namespace Okteta {
0020 class AbstractByteArrayModel;
0021 
0022 class AbstractByteArrayModelIfTest : public QObject
0023 {
0024     Q_OBJECT
0025 
0026 protected:
0027     AbstractByteArrayModelIfTest();
0028 
0029 protected: // our API
0030     virtual AbstractByteArrayModel* createByteArrayModel() = 0;
0031     virtual void deleteByteArrayModel(AbstractByteArrayModel* byteArrayModel) = 0;
0032     virtual bool byteArrayModelSizeCanBeChanged() const;
0033 
0034 private:
0035     void checkContentsReplaced(Address offset, Size removeLength, int insertLength);
0036     void checkContentsReplaced(const AddressRange& removeRange, int insertLength);
0037     void checkContentsSwapped(Address firstStart, Address secondStart, Size secondLength);
0038     void checkContentsSwapped(Address firstStart, const AddressRange& secondSection);
0039     void clearSignalSpys();
0040 
0041     struct KTestData* prepareTestInsert();
0042 
0043 private Q_SLOTS: // test functions
0044     void init();
0045     void cleanup();
0046 
0047     void testModified();
0048     void testSetReadOnly();
0049     void testCopyTo();
0050     void testFill();
0051     void testSetGet();
0052 
0053     void testRemove();
0054     void testInsertAtBegin();
0055     void testInsertAtMid();
0056     void testInsertAtEnd();
0057     // void testReplace();
0058     void testSwap();
0059     void testReplaceEqual();
0060     void testReplaceLess();
0061     void testReplaceMore();
0062 
0063 private: // used in all tests
0064     /** pointer to the model to test */
0065     AbstractByteArrayModel* mByteArrayModel = nullptr;
0066 
0067     QSignalSpy* ContentsChangeListSpy = nullptr;
0068 };
0069 
0070 inline AbstractByteArrayModelIfTest::AbstractByteArrayModelIfTest() = default;
0071 
0072 }
0073 
0074 #endif