Warning, file /graphics/krita/plugins/impex/exr/tests/kis_exr_test.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * SPDX-FileCopyrightText: 2007 Cyrille Berger <cberger@cberger.net> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kis_exr_test.h" 0008 0009 #include <simpletest.h> 0010 #include <QCoreApplication> 0011 0012 #include <testui.h> 0013 0014 #include <half.h> 0015 #include <KisMimeDatabase.h> 0016 #include "filestest.h" 0017 0018 #ifndef FILES_DATA_DIR 0019 #error "FILES_DATA_DIR not set. A directory with the data used for testing the importing of files in krita" 0020 #endif 0021 0022 const QString ExrMimetype = "application/x-extension-exr"; 0023 0024 void KisExrTest::testFiles() 0025 { 0026 TestUtil::testFiles(QString(FILES_DATA_DIR) + "/sources", QStringList(), QString(), 5); 0027 } 0028 0029 void KisExrTest::testImportFromWriteonly() 0030 { 0031 TestUtil::testImportFromWriteonly(ExrMimetype); 0032 } 0033 0034 void KisExrTest::testExportToReadonly() 0035 { 0036 TestUtil::testExportToReadonly(ExrMimetype); 0037 } 0038 0039 void KisExrTest::testImportIncorrectFormat() 0040 { 0041 TestUtil::testImportIncorrectFormat(ExrMimetype); 0042 } 0043 0044 void KisExrTest::testRoundTrip() 0045 { 0046 QString inputFileName(TestUtil::fetchDataFileLazy("CandleGlass.exr")); 0047 0048 KisDocument *doc1 = KisPart::instance()->createDocument(); 0049 0050 doc1->setFileBatchMode(true); 0051 bool r = doc1->importDocument(inputFileName); 0052 0053 QVERIFY(r); 0054 QVERIFY(doc1->errorMessage().isEmpty()); 0055 QVERIFY(doc1->image()); 0056 0057 QTemporaryFile savedFile(QDir::tempPath() + QLatin1String("/krita_XXXXXX") + QLatin1String(".exr")); 0058 savedFile.setAutoRemove(true); 0059 savedFile.open(); 0060 0061 QString savedFileName(savedFile.fileName()); 0062 0063 QString typeName = KisMimeDatabase::mimeTypeForFile(savedFileName, false); 0064 QByteArray mimeType(typeName.toLatin1()); 0065 0066 r = doc1->exportDocumentSync(savedFileName, mimeType); 0067 QVERIFY(r); 0068 QVERIFY(QFileInfo(savedFileName).exists()); 0069 0070 { 0071 KisDocument *doc2 = KisPart::instance()->createDocument(); 0072 doc2->setFileBatchMode(true); 0073 r = doc2->importDocument(savedFileName); 0074 0075 QVERIFY(r); 0076 QVERIFY(doc2->errorMessage().isEmpty()); 0077 QVERIFY(doc2->image()); 0078 0079 doc1->image()->root()->firstChild()->paintDevice()->convertToQImage(0).save("1.png"); 0080 doc2->image()->root()->firstChild()->paintDevice()->convertToQImage(0).save("2.png"); 0081 0082 QVERIFY(TestUtil::comparePaintDevicesClever<half>( 0083 doc1->image()->root()->firstChild()->paintDevice(), 0084 doc2->image()->root()->firstChild()->paintDevice(), 0085 0.01 /* meaningless alpha */)); 0086 0087 delete doc2; 0088 } 0089 0090 savedFile.close(); 0091 0092 delete doc1; 0093 0094 } 0095 0096 KISTEST_MAIN(KisExrTest) 0097 0098