File indexing completed on 2024-09-15 10:46:05
0001 /* 0002 * KTechLab: An IDE for microcontrollers and electronics 0003 * Copyright 2018 Zoltan Padrah <zoltan_padrah@users.sf.net> 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 as 0007 * published by the Free Software Foundation; either version 2 of 0008 * the License or (at your option) version 3 or any later version 0009 * accepted by the membership of KDE e.V. (or its successor approved 0010 * by the membership of KDE e.V.), which shall act as a proxy 0011 * defined in Section 14 of version 3 of the license. 0012 * 0013 * This program is distributed in the hope that it will be useful, 0014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0016 * GNU General Public License for more details. 0017 * 0018 * You should have received a copy of the GNU General Public License 0019 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0020 * 0021 */ 0022 0023 #include "../src/ktechlab.h" 0024 #include "config.h" 0025 #include "docmanager.h" 0026 #include "electronics/circuitdocument.h" 0027 0028 #include <KAboutData> 0029 #include <KLocalizedString> 0030 0031 #include <QDebug> 0032 #include <QTest> 0033 #include <QTemporaryFile> 0034 #include <QApplication> 0035 #include <QCommandLineParser> 0036 0037 #include <ktechlab_version.h> 0038 0039 0040 class KtlTestsAppFixture : public QObject { 0041 Q_OBJECT 0042 0043 public: 0044 QApplication *app; 0045 KTechlab *ktechlab; 0046 0047 private slots: 0048 void initTestCase() { 0049 int argc = 1; 0050 char argv0[] = "tests_app"; 0051 char *argv[] = { argv0, nullptr }; 0052 0053 app = new QApplication(argc, argv); 0054 0055 KAboutData aboutData("ktechlab", i18n("KTechLab"), KTECHLAB_VERSION_STRING, 0056 i18n("An IDE for microcontrollers and electronics"), 0057 KAboutLicense::GPL_V2, i18n("(C) 2003-2017, The KTechLab developers"), 0058 "", "https://userbase.kde.org/KTechlab", "ktechlab-devel@kde.org" ); 0059 KAboutData::setApplicationData(aboutData); 0060 0061 QCommandLineParser parser; 0062 aboutData.setupCommandLine(&parser); 0063 parser.process(*app); 0064 aboutData.processCommandLine(&parser); 0065 0066 ktechlab = new KTechlab; 0067 0068 } 0069 void cleanupTestCase() { 0070 delete ktechlab; 0071 ktechlab = nullptr; 0072 //delete app; // this crashes apparently 0073 app = nullptr; 0074 } 0075 0076 void testDocumentOpen() { 0077 DocManager::self()->closeAll(); 0078 QCOMPARE( DocManager::self()->m_documentList.size(), 0); 0079 QFile exFile(SRC_TESTS_DATA_DIR "test-document-draw-1.circuit"); 0080 QUrl exUrl = QUrl::fromLocalFile(exFile.fileName()); 0081 qDebug() << "open example: " << exUrl; 0082 DocManager::self()->openURL(exUrl, nullptr); 0083 QCOMPARE( DocManager::self()->m_documentList.size(), 1); 0084 Document *doc = DocManager::self()->m_documentList.first(); 0085 QVERIFY( doc != nullptr ); 0086 QCOMPARE( doc->type(), Document::dt_circuit ); 0087 CircuitDocument *circDoc = static_cast<CircuitDocument*>( doc ); 0088 QVERIFY( circDoc != nullptr ); 0089 QVERIFY( circDoc->m_canvas ); 0090 qDebug() << "item list size " << circDoc->m_itemList.size(); 0091 0092 //QRect saveArea = circDoc->m_canvas->rect(); // is empty 0093 QRect resizeArea(0, -500, 400, 1080); 0094 qDebug() << " resizeArea " << resizeArea; 0095 circDoc->m_canvas->resize(resizeArea); 0096 0097 QRect saveArea(-500, -500, 1040, 1080); 0098 qDebug() << "save area " << saveArea; 0099 QPixmap *outputImage = new QPixmap( saveArea.size() ); 0100 outputImage->fill(Qt::green); 0101 0102 circDoc->exportToImageDraw(saveArea, *outputImage); 0103 0104 QImage img = dynamic_cast<QPixmap*>(outputImage)->toImage(); 0105 img = img.copy(); 0106 QTemporaryFile imgFile("testDocumentOpen_output_XXXXXX.png"); 0107 imgFile.setAutoRemove(false); 0108 imgFile.open(); 0109 qDebug() << "imgFile.fileName() = " << imgFile.fileName(); 0110 bool saveResult = img.save(imgFile.fileName()); 0111 QCOMPARE( saveResult, true ); 0112 0113 delete outputImage; 0114 0115 DocManager::self()->closeAll(); 0116 QCOMPARE( DocManager::self()->m_documentList.size(), 0); 0117 } 0118 }; 0119 0120 QTEST_MAIN(KtlTestsAppFixture) 0121 #include "tests_app.moc"