From 93d63ef8cafa1fdb84f13da7b452baa382df06cb Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 16 Oct 2015 11:13:23 +0300 Subject: [PATCH] Two new tests. Check if empty standard/individual measurement file is valid. --HG-- branch : develop --- src/test/ValentinaTest/ValentinaTest.pro | 17 ++- src/test/ValentinaTest/qttestmainlambda.cpp | 4 + src/test/ValentinaTest/tst_vmeasurements.cpp | 116 +++++++++++++++++++ src/test/ValentinaTest/tst_vmeasurements.h | 46 ++++++++ 4 files changed, 180 insertions(+), 3 deletions(-) create mode 100644 src/test/ValentinaTest/tst_vmeasurements.cpp create mode 100644 src/test/ValentinaTest/tst_vmeasurements.h diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index 0a7b6eec8..956656501 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -4,7 +4,7 @@ # #------------------------------------------------- -QT += testlib gui printsupport +QT += testlib gui printsupport xml xmlpatterns TARGET = ValentinaTests @@ -46,7 +46,8 @@ SOURCES += \ tst_measurementregexp.cpp \ tst_tapecommandline.cpp \ tst_valentinacommandline.cpp \ - tst_qmutokenparser.cpp + tst_qmutokenparser.cpp \ + tst_vmeasurements.cpp HEADERS += \ tst_vposter.h \ @@ -60,7 +61,8 @@ HEADERS += \ tst_measurementregexp.h \ tst_tapecommandline.h \ tst_valentinacommandline.h \ - tst_qmutokenparser.h + tst_qmutokenparser.h \ + tst_vmeasurements.h # Set using ccache. Function enable_ccache() defined in common.pri. $$enable_ccache() @@ -124,6 +126,15 @@ CONFIG(debug, debug|release){ } } +# VFormat static library (depend on VPatternDB, IFC) +unix|win32: LIBS += -L$$OUT_PWD/../../libs/vformat/$${DESTDIR}/ -lvformat + +INCLUDEPATH += $$PWD/../../libs/vformat +DEPENDPATH += $$PWD/../../libs/vformat + +win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vformat/$${DESTDIR}/vformat.lib +else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vformat/$${DESTDIR}/libvformat.a + #VPatternDB static library (depend on vgeometry, vmisc, VLayout) unix|win32: LIBS += -L$$OUT_PWD/../../libs/vpatterndb/$${DESTDIR} -lvpatterndb diff --git a/src/test/ValentinaTest/qttestmainlambda.cpp b/src/test/ValentinaTest/qttestmainlambda.cpp index 4564bb571..abc305b92 100644 --- a/src/test/ValentinaTest/qttestmainlambda.cpp +++ b/src/test/ValentinaTest/qttestmainlambda.cpp @@ -38,9 +38,12 @@ #include "tst_tapecommandline.h" #include "tst_valentinacommandline.h" #include "tst_qmutokenparser.h" +#include "tst_vmeasurements.h" int main(int argc, char** argv) { + Q_INIT_RESOURCE(schema); + QApplication app( argc, argv );// For QPrinter int status = 0; @@ -60,6 +63,7 @@ int main(int argc, char** argv) ASSERT_TEST(new TST_TapeCommandLine()); ASSERT_TEST(new TST_ValentinaCommandLine()); ASSERT_TEST(new TST_QmuTokenParser()); + ASSERT_TEST(new TST_VMeasurements()); return status; } diff --git a/src/test/ValentinaTest/tst_vmeasurements.cpp b/src/test/ValentinaTest/tst_vmeasurements.cpp new file mode 100644 index 000000000..f6fc00b62 --- /dev/null +++ b/src/test/ValentinaTest/tst_vmeasurements.cpp @@ -0,0 +1,116 @@ +/************************************************************************ + ** + ** @file tst_vmeasurements.cpp + ** @author Roman Telezhynskyi + ** @date 16 10, 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_vmeasurements.h" +#include "../vformat/vmeasurements.h" +#include "../ifc/xml/vvstconverter.h" +#include "../ifc/xml/vvitconverter.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +TST_VMeasurements::TST_VMeasurements(QObject *parent) : + QObject(parent) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief CreateEmptyStandardFile check if empty standard measurement file is valid. + */ +void TST_VMeasurements::CreateEmptyStandardFile() +{ + Unit mUnit = Unit::Cm; + const int height = 176; + const int size = 50; + + QSharedPointer data = QSharedPointer(new VContainer(nullptr, &mUnit)); + data->SetHeight(height); + data->SetSize(size); + + QSharedPointer m = + QSharedPointer(new VMeasurements(mUnit, size, height, data.data())); + + QTemporaryFile file; + if (file.open()) + { + QString error; + const bool result = m->SaveDocument(file.fileName(), error); + + QVERIFY2(result, error.toUtf8().constData()); + } + else + { + QFAIL("Can't open temporary file."); + } + + try + { + VDomDocument::ValidateXML(VVSTConverter::CurrentSchema, file.fileName()); + } + catch (VException &e) + { + QFAIL(e.ErrorMessage().toUtf8().constData()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief CreateEmptyIndividualFile check if empty individual measurement file is valid. + */ +void TST_VMeasurements::CreateEmptyIndividualFile() +{ + Unit mUnit = Unit::Cm; + + QSharedPointer data = QSharedPointer(new VContainer(nullptr, &mUnit)); + + QSharedPointer m = + QSharedPointer(new VMeasurements(mUnit, data.data())); + + QTemporaryFile file; + if (file.open()) + { + QString error; + const bool result = m->SaveDocument(file.fileName(), error); + + QVERIFY2(result, error.toUtf8().constData()); + } + else + { + QFAIL("Can't open temporary file."); + } + + try + { + VDomDocument::ValidateXML(VVITConverter::CurrentSchema, file.fileName()); + } + catch (VException &e) + { + QFAIL(e.ErrorMessage().toUtf8().constData()); + } +} diff --git a/src/test/ValentinaTest/tst_vmeasurements.h b/src/test/ValentinaTest/tst_vmeasurements.h new file mode 100644 index 000000000..bbf482fe9 --- /dev/null +++ b/src/test/ValentinaTest/tst_vmeasurements.h @@ -0,0 +1,46 @@ +/************************************************************************ + ** + ** @file tst_vmeasurements.h + ** @author Roman Telezhynskyi + ** @date 16 10, 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_VMEASUREMENTS_H +#define TST_VMEASUREMENTS_H + +#include + +class TST_VMeasurements : public QObject +{ + Q_OBJECT +public: + explicit TST_VMeasurements(QObject *parent = nullptr); + +private slots: + void CreateEmptyStandardFile(); + void CreateEmptyIndividualFile(); + +}; + +#endif // TST_VMEASUREMENTS_H