File indexing completed on 2024-12-22 04:10:31
0001 /* 0002 * SPDX-FileCopyrightText: 2010 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef TILES_TEST_UTILS_H 0008 #define TILES_TEST_UTILS_H 0009 0010 #include <KoStore_p.h> 0011 #include <kis_paint_device_writer.h> 0012 #include <kis_debug.h> 0013 0014 class KisFakePaintDeviceWriter : public KisPaintDeviceWriter { 0015 public: 0016 KisFakePaintDeviceWriter(KoStore *store) 0017 : m_store(store) 0018 { 0019 } 0020 0021 bool write(const QByteArray &data) override { 0022 return (m_store->write(data) == data.length()); 0023 } 0024 0025 bool write(const char* data, qint64 length) override { 0026 return (m_store->write(data, length) == length); 0027 } 0028 0029 KoStore *m_store; 0030 }; 0031 0032 0033 class KoStoreFake : public KoStore 0034 { 0035 public: 0036 KoStoreFake() : KoStore(KoStore::Write) { 0037 d_ptr->stream = &m_buffer; 0038 d_ptr->isOpen = true; 0039 m_buffer.open(QIODevice::ReadWrite); 0040 } 0041 ~KoStoreFake() override { 0042 // Oh, no, please do not clean anything! :) 0043 d_ptr->stream = 0; 0044 d_ptr->isOpen = false; 0045 } 0046 0047 void startReading() { 0048 m_buffer.seek(0); 0049 d_ptr->mode = KoStore::Read; 0050 } 0051 0052 bool openWrite(const QString&) override { return true; } 0053 bool openRead(const QString&) override { return true; } 0054 bool closeRead() override { return true; } 0055 bool closeWrite() override { return true; } 0056 bool enterRelativeDirectory(const QString&) override { return true; } 0057 bool enterAbsoluteDirectory(const QString&) override { return true; } 0058 bool fileExists(const QString&) const override { return true; } 0059 private: 0060 QBuffer m_buffer; 0061 }; 0062 0063 bool memoryIsFilled(quint8 c, quint8 *mem, qint32 size) 0064 { 0065 for(; size > 0; size--) 0066 if(*(mem++) != c) { 0067 dbgKrita << "Expected" << c << "but found" << *(mem-1); 0068 return false; 0069 } 0070 0071 return true; 0072 } 0073 0074 #define TILESIZE 64*64 0075 0076 0077 #endif /* TILES_TEST_UTILS_H */