File indexing completed on 2024-05-12 04:19:58

0001 /*
0002 Gwenview: an image viewer
0003 Copyright 2007 Aurélien Gâteau <agateau@kde.org>
0004 
0005 This program is free software; you can redistribute it and/or
0006 modify it under the terms of the GNU General Public License
0007 as published by the Free Software Foundation; either version 2
0008 of the License, or (at your option) any later version.
0009 
0010 This program is distributed in the hope that it will be useful,
0011 but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 GNU General Public License for more details.
0014 
0015 You should have received a copy of the GNU General Public License
0016 along with this program; if not, write to the Free Software
0017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0018 
0019 */
0020 #ifndef DOCUMENTTEST_H
0021 #define DOCUMENTTEST_H
0022 
0023 // Qt
0024 #include <QApplication>
0025 #include <QDebug>
0026 #include <QObject>
0027 
0028 // KF
0029 #include <KJob>
0030 
0031 // Local
0032 #include "../lib/document/document.h"
0033 
0034 class LoadingStateSpy : public QObject
0035 {
0036     Q_OBJECT
0037 public:
0038     LoadingStateSpy(const Gwenview::Document::Ptr &doc)
0039         : mDocument(doc)
0040         , mCallCount(0)
0041     {
0042     }
0043 
0044 public Q_SLOTS:
0045     void readState()
0046     {
0047         mCallCount++;
0048         mState = mDocument->loadingState();
0049     }
0050 
0051 public:
0052     Gwenview::Document::Ptr mDocument;
0053     int mCallCount;
0054     Gwenview::Document::LoadingState mState;
0055 };
0056 
0057 class JobWatcher : public QObject
0058 {
0059     Q_OBJECT
0060 public:
0061     JobWatcher(KJob *job)
0062         : mDone(false)
0063         , mError(0)
0064     {
0065         connect(job, &KJob::result, this, &JobWatcher::slotResult);
0066         connect(job, &QObject::destroyed, this, &JobWatcher::slotDestroyed);
0067     }
0068 
0069     void wait()
0070     {
0071         while (!mDone) {
0072             QApplication::processEvents();
0073         }
0074     }
0075 
0076     int error() const
0077     {
0078         return mError;
0079     }
0080 
0081 private Q_SLOTS:
0082     void slotResult(KJob *job)
0083     {
0084         mError = job->error();
0085         mDone = true;
0086     }
0087 
0088     void slotDestroyed()
0089     {
0090         qWarning() << "Destroyed";
0091         mError = -1;
0092         mDone = true;
0093     }
0094 
0095 private:
0096     bool mDone;
0097     int mError;
0098 };
0099 
0100 class DocumentTest : public QObject
0101 {
0102     Q_OBJECT
0103 
0104 private Q_SLOTS:
0105     void testLoad();
0106     void testLoad_data();
0107     void testLoadTwoPasses();
0108     void testLoadEmpty();
0109     void testLoadDownSampled();
0110     void testLoadDownSampled_data();
0111     void testLoadDownSampledPng();
0112     void testLoadRemote();
0113     void testLoadAnimated();
0114     void testPrepareDownSampledAfterFailure();
0115     void testDeleteWhileLoading();
0116     void testLoadRotated();
0117     void testMultipleLoads();
0118     void testSaveAs();
0119     void testSaveRemote();
0120     void testLosslessSave();
0121     void testLosslessRotate();
0122     void testModifyAndSaveAs();
0123     void testMetaInfoJpeg();
0124     void testMetaInfoBmp();
0125     void testForgetModifiedDocument();
0126     void testModifiedAndSavedSignals();
0127     void testJobQueue();
0128     void testCheckDocumentEditor();
0129     void testUndoStackPush();
0130     void testUndoRedo();
0131 
0132     void initTestCase();
0133     void init();
0134 };
0135 
0136 #endif // DOCUMENTTEST_H