From edaafb7c6a7599fb83029b01039fdda998dad05c Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 15 Apr 2015 15:11:13 +0300 Subject: [PATCH] VPoster tests. --HG-- branch : develop --- Valentina.pri | 7 +- src/test/ValentinaTest/ValentinaTest.pro | 68 +++++++++++++-- src/test/ValentinaTest/qttestmainlambda.cpp | 5 +- src/test/ValentinaTest/tst_vposter.cpp | 93 +++++++++++++++++++++ src/test/ValentinaTest/tst_vposter.h | 54 ++++++++++++ 5 files changed, 219 insertions(+), 8 deletions(-) create mode 100644 src/test/ValentinaTest/tst_vposter.cpp create mode 100644 src/test/ValentinaTest/tst_vposter.h diff --git a/Valentina.pri b/Valentina.pri index 7d1a0fd8c..ce81c6859 100644 --- a/Valentina.pri +++ b/Valentina.pri @@ -100,7 +100,8 @@ ISYSTEM += \ -isystem "$$[QT_INSTALL_HEADERS]/QtXml" \ -isystem "$$[QT_INSTALL_HEADERS]/QtGui" \ -isystem "$$[QT_INSTALL_HEADERS]/QtXmlPatterns" \ - -isystem "$$[QT_INSTALL_HEADERS]/QtCore" + -isystem "$$[QT_INSTALL_HEADERS]/QtCore" \ + -isystem "$$[QT_INSTALL_HEADERS]/QtTest" } else { ISYSTEM += \ -isystem "$$[QT_INSTALL_LIBS]/QtWidgets.framework/Headers/" \ @@ -112,7 +113,9 @@ ISYSTEM += \ -isystem "$$[QT_INSTALL_LIBS]/QtXmlPatterns.framework/Headers/" \ -isystem "$$[QT_INSTALL_LIBS]/QtXmlPatterns.framework/Versions/5/Headers/" \ -isystem "$$[QT_INSTALL_LIBS]/QtCore.framework/Headers/" \ - -isystem "$$[QT_INSTALL_LIBS]/QtCore.framework/Versions/5/Headers/" + -isystem "$$[QT_INSTALL_LIBS]/QtCore.framework/Versions/5/Headers/" \ + -isystem "$$[QT_INSTALL_LIBS]/QtTest.framework/Headers/" \ + -isystem "$$[QT_INSTALL_LIBS]/QtTest.framework/Versions/5/Headers/" } # Usefull GCC warnings keys. diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index 842767403..f08b48fad 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -4,12 +4,13 @@ # #------------------------------------------------- -QT += testlib - -QT -= gui +QT += testlib gui printsupport TARGET = tst_test +# File with common stuff for whole project +include(../../../Valentina.pri) + # CONFIG += testcase adds a 'make check' which is great. But by default it also # adds a 'make install' that installs the test cases, which we do not want. # Can configure it not to do that with 'no_testcase_installs' @@ -34,7 +35,64 @@ DEFINES += SRCDIR=\\\"$$PWD/\\\" SOURCES += \ qttestmainlambda.cpp \ - tst_test.cpp + tst_test.cpp \ + tst_vposter.cpp HEADERS += \ - tst_test.h + tst_test.h \ + tst_vposter.h + +CONFIG(debug, debug|release){ + # Debug mode + unix { + #Turn on compilers warnings. + *-g++{ + QMAKE_CXXFLAGS += \ + # Key -isystem disable checking errors in system headers. + -isystem "$${OUT_PWD}/$${UI_DIR}" \ + -isystem "$${OUT_PWD}/$${MOC_DIR}" \ + -isystem "$${OUT_PWD}/$${RCC_DIR}" \ + $$GCC_DEBUG_CXXFLAGS # See Valentina.pri for more details. + + #gcc’s 4.8.0 Address Sanitizer + #http://blog.qt.digia.com/blog/2013/04/17/using-gccs-4-8-0-address-sanitizer-with-qt/ + QMAKE_CFLAGS+=-fsanitize=address -fno-omit-frame-pointer + QMAKE_LFLAGS+=-fsanitize=address + } + clang*{ + QMAKE_CXXFLAGS += \ + # Key -isystem disable checking errors in system headers. + -isystem "$${OUT_PWD}/$${UI_DIR}" \ + -isystem "$${OUT_PWD}/$${MOC_DIR}" \ + -isystem "$${OUT_PWD}/$${RCC_DIR}" \ + $$CLANG_DEBUG_CXXFLAGS # See Valentina.pri for more details. + } + } else { + *-g++{ + QMAKE_CXXFLAGS += $$GCC_DEBUG_CXXFLAGS # See Valentina.pri for more details. + } + } +}else{ + # Release mode + DEFINES += V_NO_ASSERT + !unix:*-g++{ + QMAKE_CXXFLAGS += -fno-omit-frame-pointer # Need for exchndl.dll + } + + # Turn on debug symbols in release mode on Unix systems. + # On Mac OS X temporarily disabled. Need find way how to strip binary file. + !macx:!win32-msvc*{ + QMAKE_CXXFLAGS_RELEASE += -g -gdwarf-3 + QMAKE_CFLAGS_RELEASE += -g -gdwarf-3 + QMAKE_LFLAGS_RELEASE = + } +} + +# VLayout static library +unix|win32: LIBS += -L$$OUT_PWD/../../libs/vlayout/$${DESTDIR} -lvlayout + +INCLUDEPATH += $$PWD/../../libs/vlayout +DEPENDPATH += $$PWD/../../libs/vlayout + +win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/vlayout.lib +else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/libvlayout.a diff --git a/src/test/ValentinaTest/qttestmainlambda.cpp b/src/test/ValentinaTest/qttestmainlambda.cpp index a688b2df6..3bc8fcf41 100644 --- a/src/test/ValentinaTest/qttestmainlambda.cpp +++ b/src/test/ValentinaTest/qttestmainlambda.cpp @@ -29,9 +29,12 @@ #include #include "tst_test.h" +#include "tst_vposter.h" int main(int argc, char** argv) { + QApplication app( argc, argv );// For QPrinter + int status = 0; auto ASSERT_TEST = [&status, argc, argv](QObject* obj) { @@ -40,7 +43,7 @@ int main(int argc, char** argv) }; ASSERT_TEST(new Test()); - //ASSERT_TEST(new Test2()); + ASSERT_TEST(new TST_VPoster()); return status; } diff --git a/src/test/ValentinaTest/tst_vposter.cpp b/src/test/ValentinaTest/tst_vposter.cpp new file mode 100644 index 000000000..31c95aa13 --- /dev/null +++ b/src/test/ValentinaTest/tst_vposter.cpp @@ -0,0 +1,93 @@ +/************************************************************************ + ** + ** @file tst_vposter.cpp + ** @author Roman Telezhynskyi + ** @date 15 4, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "tst_vposter.h" +#include "../../libs/vlayout/vposter.h" + +#include +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +TST_VPoster::TST_VPoster(QObject *parent) : + QObject(parent) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VPoster::BigPoster() +{ + QPrinter printer; + printer.setResolution(96);// By default + printer.setPaperSize(QPrinter::A4); + + const QImage image(2622, 3178, QImage::Format_RGB32); // Little bit bigger than A1 + VPoster posterazor(&printer); + const QVector poster = posterazor.Generate(image, 1, 1); + + QCOMPARE(poster.size(), 16); + + for (int i=0; i < poster.size(); i++) + { + QCOMPARE(poster.at(i).rect().size(), PageRect(printer).size()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VPoster::SmallPoster() +{ + QPrinter printer; + printer.setResolution(96);// By default + printer.setPaperSize(QPrinter::A4); + + const QImage image(700, 1000, QImage::Format_RGB32); // Little bit less than A4 + VPoster posterazor(&printer); + const QVector poster = posterazor.Generate(image, 1, 1); + + QCOMPARE(poster.size(), 1); + + QCOMPARE(poster.at(0).rect().size(), PageRect(printer).size()); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRect TST_VPoster::PageRect(const QPrinter &printer) const +{ + // Because the Point unit is defined to be 1/72th of an inch + // we can't use method pageRect(QPrinter::Point). Our dpi different can be different. + // We convert value yourself to pixels. + const QRectF rect = printer.pageRect(QPrinter::Millimeter); + QRect pageRect(qFloor(ToPixel(rect.x(), printer)), qFloor(ToPixel(rect.y(), printer)), + qFloor(ToPixel(rect.width(), printer)), qFloor(ToPixel(rect.height(), printer))); + return pageRect; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal TST_VPoster::ToPixel(qreal val, const QPrinter &printer) const +{ + return val / 25.4 * printer.resolution(); // Mm to pixels with current dpi. +} diff --git a/src/test/ValentinaTest/tst_vposter.h b/src/test/ValentinaTest/tst_vposter.h new file mode 100644 index 000000000..6fd218d1f --- /dev/null +++ b/src/test/ValentinaTest/tst_vposter.h @@ -0,0 +1,54 @@ +/************************************************************************ + ** + ** @file tst_vposter.h + ** @author Roman Telezhynskyi + ** @date 15 4, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef TST_VPOSTER_H +#define TST_VPOSTER_H + +#include + +class QPrinter; + +class TST_VPoster : public QObject +{ + Q_OBJECT + +public: + explicit TST_VPoster(QObject *parent = 0); + +signals: + +private slots: + void BigPoster(); + void SmallPoster(); + +private: + qreal ToPixel(qreal val, const QPrinter &printer) const; + QRect PageRect(const QPrinter &printer) const; +}; + +#endif // TST_VPOSTER_H