Class for testing run valentina.exe.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-10-04 15:20:12 +03:00
parent f03d5f515d
commit 852bd63fe1
9 changed files with 279 additions and 10 deletions

View File

@ -3133,8 +3133,15 @@ bool MainWindow::LoadPattern(const QString &fileName, const QString& customMeasu
{
qCCritical(vMainWindow, "%s", qUtf8Printable(tr("This file already opened in another window.")));
Clear();
if (VApplication::CheckGUI())
{
return false;
}
else
{
std::exit(V_EX_NOINPUT);
}
}
}
// On this stage scene empty. Fit scene size to view size
@ -3189,8 +3196,15 @@ bool MainWindow::LoadPattern(const QString &fileName, const QString& customMeasu
qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
Clear();
if (VApplication::CheckGUI())
{
return false;
}
else
{
std::exit(V_EX_NOINPUT);
}
}
#ifdef Q_OS_WIN32
qt_ntfs_permission_lookup--; // turn it off again

View File

@ -44,7 +44,8 @@ SOURCES += \
tst_varc.cpp \
stable.cpp \
tst_measurementregexp.cpp \
tst_tapecommandline.cpp
tst_tapecommandline.cpp \
tst_valentinacommandline.cpp
HEADERS += \
tst_vposter.h \
@ -56,7 +57,8 @@ HEADERS += \
tst_varc.h \
stable.h \
tst_measurementregexp.h \
tst_tapecommandline.h
tst_tapecommandline.h \
tst_valentinacommandline.h
# Set using ccache. Function enable_ccache() defined in common.pri.
$$enable_ccache()
@ -192,9 +194,14 @@ TAPE_TEST_FILES += \
tst_tape/broken3.vit \
tst_tape/broken4.vit
VALENTINA_TEST_FILES += \
tst_valentina/empty.val \
tst_valentina/issue_372.val
# Compilation will fail without this files after we added them to this section.
OTHER_FILES += \
$$TAPE_TEST_FILES
$$TAPE_TEST_FILES \
$$VALENTINA_TEST_FILES
for(DIR, TAPE_TEST_FILES) {
#add these absolute paths to a variable which
@ -203,3 +210,11 @@ for(DIR, TAPE_TEST_FILES) {
}
copyToDestdir($$tape_path, $$shell_path($${OUT_PWD}/$$DESTDIR/tst_tape))
for(DIR, VALENTINA_TEST_FILES) {
#add these absolute paths to a variable which
#ends up as 'mkcommands = path1 path2 path3 ...'
valentina_path += $${PWD}/$$DIR
}
copyToDestdir($$valentina_path, $$shell_path($${OUT_PWD}/$$DESTDIR/tst_valentina))

View File

@ -55,7 +55,7 @@ QString AbstractTest::ValentinaPath() const
{
const QString path = QStringLiteral("/../../../app/valentina/bin/valentina");
#ifdef Q_OS_WIN
return QApplication::applicationDirPath() + path + QStringLiteral(".exe");
return QApplication::applicationDirPath() + path + QLatin1Literal(".exe");
#else
return QApplication::applicationDirPath() + path;
#endif
@ -66,14 +66,14 @@ QString AbstractTest::TapePath() const
{
const QString path = QStringLiteral("/../../../app/tape/bin/tape");
#ifdef Q_OS_WIN
return QApplication::applicationDirPath() + path + QStringLiteral(".exe");
return QApplication::applicationDirPath() + path + QLatin1Literal(".exe");
#else
return QApplication::applicationDirPath() + path;
#endif
}
//---------------------------------------------------------------------------------------------------------------------
bool AbstractTest::Run(bool showWarn, int &exitCode, const QString &program, const QStringList &arguments)
bool AbstractTest::Run(bool showWarn, int &exitCode, const QString &program, const QStringList &arguments, int msecs)
{
const QString parameters = QString("Program: %1 \nArguments: %2.").arg(program).arg(arguments.join(", "));
@ -90,7 +90,7 @@ bool AbstractTest::Run(bool showWarn, int &exitCode, const QString &program, con
process->setWorkingDirectory(info.absoluteDir().absolutePath());
process->start(program, arguments);
if (not process->waitForFinished())// 30 sec
if (not process->waitForFinished(msecs))
{
const QString msg = QString("The operation timed out or an error occurred.\n%1").arg(parameters);
QWARN(qUtf8Printable(msg));

View File

@ -48,7 +48,7 @@ protected:
QString ValentinaPath() const;
QString TapePath() const;
bool Run(bool showWarn, int &exitCode, const QString &program, const QStringList &arguments);
bool Run(bool showWarn, int &exitCode, const QString &program, const QStringList &arguments, int msecs = 30000);
bool CopyRecursively(const QString &srcFilePath, const QString &tgtFilePath) const;
};

View File

@ -36,6 +36,7 @@
#include "tst_varc.h"
#include "tst_measurementregexp.h"
#include "tst_tapecommandline.h"
#include "tst_valentinacommandline.h"
int main(int argc, char** argv)
{
@ -56,6 +57,7 @@ int main(int argc, char** argv)
ASSERT_TEST(new TST_VArc());
ASSERT_TEST(new TST_MeasurementRegExp());
ASSERT_TEST(new TST_TapeCommandLine());
ASSERT_TEST(new TST_ValentinaCommandLine());
return status;
}

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<pattern>
<!--Pattern created with Valentina (http://www.valentina-project.org/).-->
<version>0.2.0</version>
<unit>cm</unit>
<author/>
<description/>
<notes/>
<measurements/>
<increments/>
<draw name="Pattern piece 1">
<calculation>
<point type="single" x="0.926042" y="1.05833" id="1" name="A" mx="0.132292" my="0.264583"/>
</calculation>
<modeling/>
<details/>
</draw>
</pattern>

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<pattern>
<!--Pattern created with Valentina (http://www.valentina-project.org/).-->
<version>0.2.0</version>
<unit>cm</unit>
<author/>
<description/>
<notes/>
<measurements/>
<increments/>
<draw name="Чертеж 1">
<calculation>
<point type="single" x="0.926042" y="1.05833" id="1" name="A" mx="0.132292" my="0.264583"/>
<point type="endLine" typeLine="hair" id="2" name="A1" basePoint="1" mx="0.132292" lineColor="black" my="0.264583" angle="0" length="3"/>
<point type="endLine" typeLine="hair" id="3" name="A2" basePoint="2" mx="0.132292" lineColor="black" my="0.264583" angle="270" length="3"/>
<line typeLine="hair" id="4" firstPoint="1" secondPoint="3" lineColor="black"/>
</calculation>
<modeling>
<point type="modeling" id="5" idObject="1" mx="0.132292" my="0.264583"/>
<point type="modeling" id="6" idObject="2" mx="0.132292" my="0.264583"/>
<point type="modeling" id="7" idObject="3" mx="0.132292" my="0.264583"/>
<point type="modeling" id="8" idObject="1" mx="0.132292" my="0.264583"/>
</modeling>
<details>
<detail closed="1" id="9" name="Деталь" supplement="1" mx="0.608542" width="1" my="0.608542">
<node type="NodePoint" nodeType="Contour" idObject="5" mx="0" my="0"/>
<node type="NodePoint" nodeType="Contour" idObject="6" mx="0" my="0"/>
<node type="NodePoint" nodeType="Contour" idObject="7" mx="0" my="0"/>
<node type="NodePoint" nodeType="Contour" idObject="8" mx="0" my="0"/>
</detail>
</details>
</draw>
</pattern>

View File

@ -0,0 +1,135 @@
/************************************************************************
**
** @file tst_valentinacommandline.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 4 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
** <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_valentinacommandline.h"
#include "../vmisc/vsysexits.h"
#include <QtTest>
const QString tmpTestFolder = QStringLiteral("tst_valentina_tmp");
TST_ValentinaCommandLine::TST_ValentinaCommandLine(QObject *parent)
:AbstractTest(parent)
{
}
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
void TST_ValentinaCommandLine::init()
{
QDir tmpDir(tmpTestFolder);
if (not tmpDir.removeRecursively())
{
QFAIL("Fail to remove temp directory.");
}
if (not CopyRecursively(QApplication::applicationDirPath() + QLatin1Char('/') + QLatin1Literal("tst_valentina"),
QApplication::applicationDirPath() + QLatin1Char('/') + tmpTestFolder))
{
QFAIL("Fail to prepare files for testing.");
}
}
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
void TST_ValentinaCommandLine::OpenPatterns_data() const
{
QTest::addColumn<QString>("file");
QTest::addColumn<bool>("result");
QTest::addColumn<int>("exitCode");
// The file doesn't exist!
QTest::newRow("Send wrong path to a file") << "wrongPath.val"
<< false
<< V_EX_NOINPUT;
QTest::newRow("Measurement independent empty file") << "empty.val"
<< true
<< V_EX_OK;
}
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
void TST_ValentinaCommandLine::OpenPatterns()
{
QFETCH(QString, file);
QFETCH(bool, result);
QFETCH(int, exitCode);
int exit;
const bool res = Run(result, exit, ValentinaPath(), QStringList() << "--test"
<< QApplication::applicationDirPath() + QLatin1Char('/') + tmpTestFolder + QLatin1Char('/') + file);
QCOMPARE(res, result);
QCOMPARE(exit, exitCode);
}
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
void TST_ValentinaCommandLine::ExportMode_data() const
{
QTest::addColumn<QString>("file");
QTest::addColumn<QString>("arguments");
QTest::addColumn<bool>("result");
QTest::addColumn<int>("exitCode");
QTest::newRow("Issue #372")<< "issue_372.val"
<< "-p;;0;;-o;;output"
<< true
<< V_EX_OK;
}
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
void TST_ValentinaCommandLine::ExportMode()
{
QFETCH(QString, file);
QFETCH(QString, arguments);
QFETCH(bool, result);
QFETCH(int, exitCode);
int exit;
const QStringList arg = QStringList() << QApplication::applicationDirPath() + QLatin1Char('/') + tmpTestFolder +
QLatin1Char('/') + file
<< arguments.split(";;");
const bool res = Run(result, exit, ValentinaPath(), arg);
QCOMPARE(res, result);
QCOMPARE(exit, exitCode);
}
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
void TST_ValentinaCommandLine::cleanup()
{
QDir tmpDir(tmpTestFolder);
if (not tmpDir.removeRecursively())
{
QWARN("Fail to remove temp directory.");
}
}

View File

@ -0,0 +1,52 @@
/************************************************************************
**
** @file tst_valentinacommandline.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 4 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
** <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_VALENTINACOMMANDLINE_H
#define TST_VALENTINACOMMANDLINE_H
#include "abstracttest.h"
class TST_ValentinaCommandLine : public AbstractTest
{
Q_OBJECT
public:
TST_ValentinaCommandLine(QObject *parent = 0);
private slots:
void init();
void OpenPatterns_data() const;
void OpenPatterns();
void ExportMode_data() const;
void ExportMode();
void cleanup();
private:
Q_DISABLE_COPY(TST_ValentinaCommandLine)
};
#endif // TST_VALENTINACOMMANDLINE_H