VPoster tests.
--HG-- branch : develop
This commit is contained in:
parent
8bfc9d1ca3
commit
edaafb7c6a
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -29,9 +29,12 @@
|
|||
#include <QtTest>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
|
93
src/test/ValentinaTest/tst_vposter.cpp
Normal file
93
src/test/ValentinaTest/tst_vposter.cpp
Normal file
|
@ -0,0 +1,93 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file tst_vposter.cpp
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @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
|
||||
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#include "tst_vposter.h"
|
||||
#include "../../libs/vlayout/vposter.h"
|
||||
|
||||
#include <QImage>
|
||||
#include <QPrinter>
|
||||
#include <QtTest>
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
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<QImage> 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<QImage> 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.
|
||||
}
|
54
src/test/ValentinaTest/tst_vposter.h
Normal file
54
src/test/ValentinaTest/tst_vposter.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file tst_vposter.h
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @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
|
||||
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef TST_VPOSTER_H
|
||||
#define TST_VPOSTER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
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
|
Loading…
Reference in New Issue
Block a user