Refactoring. Test functions RelativeMPath and AbsoluteMPath.
--HG-- branch : develop
This commit is contained in:
parent
82190e2917
commit
f52d609b9c
|
@ -420,41 +420,6 @@ void MainWindow::ToggleMSync(bool toggle)
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString MainWindow::RelativeMPath(const QString &patternPath, const QString &absoluteMPath) const
|
||||
{
|
||||
if (patternPath.isEmpty())
|
||||
{
|
||||
return absoluteMPath;
|
||||
}
|
||||
|
||||
if (absoluteMPath.isEmpty() || QFileInfo(absoluteMPath).isRelative())
|
||||
{
|
||||
return absoluteMPath;
|
||||
}
|
||||
|
||||
QDir dir(QFileInfo(patternPath).absoluteDir());
|
||||
return dir.relativeFilePath(absoluteMPath);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString MainWindow::AbsoluteMPath(const QString &patternPath, const QString &relativeMPath) const
|
||||
{
|
||||
if (patternPath.isEmpty())
|
||||
{
|
||||
return relativeMPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (relativeMPath.isEmpty() || QFileInfo(relativeMPath).isAbsolute())
|
||||
{
|
||||
return relativeMPath;
|
||||
}
|
||||
|
||||
return QFileInfo(QFileInfo(patternPath).absoluteDir(), relativeMPath).absoluteFilePath();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief OptionDraw help change name of pattern piece.
|
||||
|
|
|
@ -304,9 +304,6 @@ private:
|
|||
|
||||
void ToggleMSync(bool toggle);
|
||||
|
||||
QString RelativeMPath(const QString &patternPath, const QString &absoluteMPath) const;
|
||||
QString AbsoluteMPath(const QString &patternPath, const QString &relativeMPath) const;
|
||||
|
||||
bool LoadPattern(const QString &curFile, const QString &customMeasureFile = QString());
|
||||
void ReopenFilesAfterCrash(QStringList &args);
|
||||
void DoExport(const VCommandLinePtr& expParams);
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "../vpatterndb/vtranslatevars.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QDir>
|
||||
|
||||
// Keep synchronize all names with initialization in VTranslateVars class!!!!!
|
||||
//measurements
|
||||
|
@ -1681,3 +1682,40 @@ QString StrippedName(const QString &fullFileName)
|
|||
{
|
||||
return QFileInfo(fullFileName).fileName();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString RelativeMPath(const QString &patternPath, const QString &absoluteMPath)
|
||||
{
|
||||
if (patternPath.isEmpty())
|
||||
{
|
||||
return absoluteMPath;
|
||||
}
|
||||
|
||||
if (absoluteMPath.isEmpty() || QFileInfo(absoluteMPath).isRelative())
|
||||
{
|
||||
return absoluteMPath;
|
||||
}
|
||||
|
||||
QDir dir(QFileInfo(patternPath).absoluteDir());
|
||||
return dir.relativeFilePath(absoluteMPath);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString AbsoluteMPath(const QString &patternPath, const QString &relativeMPath)
|
||||
{
|
||||
if (patternPath.isEmpty())
|
||||
{
|
||||
return relativeMPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (relativeMPath.isEmpty() || QFileInfo(relativeMPath).isAbsolute())
|
||||
{
|
||||
return relativeMPath;
|
||||
}
|
||||
|
||||
return QFileInfo(QFileInfo(patternPath).absoluteDir(), relativeMPath).absoluteFilePath();
|
||||
}
|
||||
|
||||
return QString();// should never reach
|
||||
}
|
||||
|
|
|
@ -588,5 +588,7 @@ QStringList SupportedLocales();
|
|||
QStringList AllGroupNames();
|
||||
|
||||
QString StrippedName(const QString &fullFileName);
|
||||
QString RelativeMPath(const QString &patternPath, const QString &absoluteMPath);
|
||||
QString AbsoluteMPath(const QString &patternPath, const QString &relativeMPath);
|
||||
|
||||
#endif // DEF_H
|
||||
|
|
|
@ -49,7 +49,8 @@ SOURCES += \
|
|||
tst_qmutokenparser.cpp \
|
||||
tst_vmeasurements.cpp \
|
||||
tst_qmuparsererrormsg.cpp \
|
||||
tst_vlockguard.cpp
|
||||
tst_vlockguard.cpp \
|
||||
tst_misc.cpp
|
||||
|
||||
HEADERS += \
|
||||
tst_vposter.h \
|
||||
|
@ -66,7 +67,8 @@ HEADERS += \
|
|||
tst_qmutokenparser.h \
|
||||
tst_vmeasurements.h \
|
||||
tst_qmuparsererrormsg.h \
|
||||
tst_vlockguard.h
|
||||
tst_vlockguard.h \
|
||||
tst_misc.h
|
||||
|
||||
# Set using ccache. Function enable_ccache() defined in common.pri.
|
||||
$$enable_ccache()
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "tst_vmeasurements.h"
|
||||
#include "tst_qmuparsererrormsg.h"
|
||||
#include "tst_vlockguard.h"
|
||||
#include "tst_misc.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
@ -68,6 +69,7 @@ int main(int argc, char** argv)
|
|||
ASSERT_TEST(new TST_VMeasurements());
|
||||
ASSERT_TEST(new TST_QmuParserErrorMsg());
|
||||
ASSERT_TEST(new TST_VLockGuard());
|
||||
ASSERT_TEST(new TST_Misc());
|
||||
|
||||
return status;
|
||||
}
|
||||
|
|
132
src/test/ValentinaTest/tst_misc.cpp
Normal file
132
src/test/ValentinaTest/tst_misc.cpp
Normal file
|
@ -0,0 +1,132 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file tst_misc.cpp
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 31 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_misc.h"
|
||||
#include "../vmisc/def.h"
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
TST_Misc::TST_Misc(QObject *parent)
|
||||
:QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_Misc::TestRelativeFilePath_data()
|
||||
{
|
||||
QTest::addColumn<QString>("patternPath");
|
||||
QTest::addColumn<QString>("absoluteMPath");
|
||||
QTest::addColumn<QString>("output");
|
||||
|
||||
QTest::newRow("Measurements one level above")
|
||||
<< "/home/user/patterns/pattern.val" << "/home/user/measurements/m.vit" << "../measurements/m.vit";
|
||||
|
||||
QTest::newRow("Measurements one level under")
|
||||
<< "/home/user/patterns/pattern.val" << "/home/user/patterns/measurements/m.vit" << "measurements/m.vit";
|
||||
|
||||
QTest::newRow("Measurements in the same folder")
|
||||
<< "/home/user/patterns/pattern.val" << "/home/user/patterns/m.vit" << "m.vit";
|
||||
|
||||
QTest::newRow("Path to measurements is empty")
|
||||
<< "/home/user/patterns/pattern.val" << "" << "";
|
||||
|
||||
QTest::newRow("Path to a pattern file is empty. Ablosute measurements path.")
|
||||
<< "" << "/home/user/patterns/m.vit" << "/home/user/patterns/m.vit";
|
||||
|
||||
QTest::newRow("Path to a pattern file is empty. Relative measurements path.")
|
||||
<< "" << "measurements/m.vit" << "measurements/m.vit";
|
||||
|
||||
QTest::newRow("Relative measurements path.")
|
||||
<< "/home/user/patterns/pattern.val" << "../measurements/m.vit" << "../measurements/m.vit";
|
||||
|
||||
QTest::newRow("Both paths are empty") << "" << "" << "";
|
||||
|
||||
QTest::newRow("Path to measurements is relative")
|
||||
<< "/home/user/patterns/pattern.val" << "m.vit" << "m.vit";
|
||||
|
||||
QTest::newRow("Absolute pattern path.") << "/home/user/patterns" << "m.vit" << "m.vit";
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_Misc::TestRelativeFilePath()
|
||||
{
|
||||
QFETCH(QString, patternPath);
|
||||
QFETCH(QString, absoluteMPath);
|
||||
QFETCH(QString, output);
|
||||
|
||||
const QString result = RelativeMPath(patternPath, absoluteMPath);
|
||||
QCOMPARE(output, result);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_Misc::TestAbsoluteFilePath_data()
|
||||
{
|
||||
QTest::addColumn<QString>("patternPath");
|
||||
QTest::addColumn<QString>("relativeMPath");
|
||||
QTest::addColumn<QString>("output");
|
||||
|
||||
QTest::newRow("Measurements one level above")
|
||||
<< "/home/user/patterns/pattern.val" << "../measurements/m.vit" << "/home/user/measurements/m.vit";
|
||||
|
||||
QTest::newRow("Measurements one level under")
|
||||
<< "/home/user/patterns/pattern.val" << "measurements/m.vit" << "/home/user/patterns/measurements/m.vit";
|
||||
|
||||
QTest::newRow("Measurements in the same folder")
|
||||
<< "/home/user/patterns/pattern.val" << "m.vit" << "/home/user/patterns/m.vit";
|
||||
|
||||
QTest::newRow("Path to measurements is empty")
|
||||
<< "/home/user/patterns/pattern.val" << "" << "";
|
||||
|
||||
QTest::newRow("Path to a pattern file is empty. Ablosute measurements path.")
|
||||
<< "" << "/home/user/patterns/m.vit" << "/home/user/patterns/m.vit";
|
||||
|
||||
QTest::newRow("Path to a pattern file is empty. Relative measurements path.")
|
||||
<< "" << "measurements/m.vit" << "measurements/m.vit";
|
||||
|
||||
QTest::newRow("Relative measurements path.")
|
||||
<< "/home/user/patterns/pattern.val" << "../measurements/m.vit" << "/home/user/measurements/m.vit";
|
||||
|
||||
QTest::newRow("Both paths are empty") << "" << "" << "";
|
||||
|
||||
QTest::newRow("Path to measurements is relative")
|
||||
<< "/home/user/patterns/pattern.val" << "m.vit" << "/home/user/patterns/m.vit";
|
||||
|
||||
QTest::newRow("Absolute pattern path.") << "/home/user/patterns" << "m.vit" << "/home/user/m.vit";
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_Misc::TestAbsoluteFilePath()
|
||||
{
|
||||
QFETCH(QString, patternPath);
|
||||
QFETCH(QString, relativeMPath);
|
||||
QFETCH(QString, output);
|
||||
|
||||
const QString result = AbsoluteMPath(patternPath, relativeMPath);
|
||||
QCOMPARE(output, result);
|
||||
}
|
51
src/test/ValentinaTest/tst_misc.h
Normal file
51
src/test/ValentinaTest/tst_misc.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file tst_misc.h
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 31 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_MISC_H
|
||||
#define TST_MISC_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class TST_Misc :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TST_Misc(QObject *parent = nullptr);
|
||||
|
||||
private slots:
|
||||
void TestRelativeFilePath_data();
|
||||
void TestRelativeFilePath();
|
||||
|
||||
void TestAbsoluteFilePath_data();
|
||||
void TestAbsoluteFilePath();
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(TST_Misc)
|
||||
};
|
||||
|
||||
#endif // TST_MISC_H
|
Loading…
Reference in New Issue
Block a user