From 9545db280d52211180de0abac19141bfb1468eed Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 9 Nov 2015 20:02:38 +0200 Subject: [PATCH] Test that all command line option names are unique. --HG-- branch : develop --- src/app/valentina/core/vcmdexport.cpp | 73 +---------- src/libs/vmisc/commandoptions.cpp | 135 ++++++++++++++++++++ src/libs/vmisc/commandoptions.h | 110 ++++++++++++++++ src/libs/vmisc/vmisc.pri | 6 +- src/test/ValentinaTest/ValentinaTest.pro | 6 +- src/test/ValentinaTest/qttestmainlambda.cpp | 2 + src/test/ValentinaTest/tst_vcommandline.cpp | 54 ++++++++ src/test/ValentinaTest/tst_vcommandline.h | 47 +++++++ 8 files changed, 357 insertions(+), 76 deletions(-) create mode 100644 src/libs/vmisc/commandoptions.cpp create mode 100644 src/libs/vmisc/commandoptions.h create mode 100644 src/test/ValentinaTest/tst_vcommandline.cpp create mode 100644 src/test/ValentinaTest/tst_vcommandline.h diff --git a/src/app/valentina/core/vcmdexport.cpp b/src/app/valentina/core/vcmdexport.cpp index f1b5ac38a..75da98da7 100644 --- a/src/app/valentina/core/vcmdexport.cpp +++ b/src/app/valentina/core/vcmdexport.cpp @@ -3,81 +3,10 @@ #include "dialogs/dialogsavelayout.h" #include "xml/vdomdocument.h" #include "../vformat/vmeasurements.h" +#include "../vmisc/commandoptions.h" VCommandLinePtr VCommandLine::instance = nullptr; -const static auto LONG_OPTION_BASENAME = QStringLiteral("basename"); -const static auto SINGLE_OPTION_BASENAME = QStringLiteral("b"); - -const static auto LONG_OPTION_DESTINATION = QStringLiteral("destination"); -const static auto SINGLE_OPTION_DESTINATION = QStringLiteral("d"); - -const static auto LONG_OPTION_MEASUREFILE = QStringLiteral("mfile"); -const static auto SINGLE_OPTION_MEASUREFILE = QStringLiteral("m"); - -const static auto LONG_OPTION_PAGETEMPLATE = QStringLiteral("pageformat"); -const static auto SINGLE_OPTION_PAGETEMPLATE = QStringLiteral("p"); - -const static auto LONG_OPTION_EXP2FORMAT = QStringLiteral("format"); -const static auto SINGLE_OPTION_EXP2FORMAT = QStringLiteral("f"); - -const static auto LONG_OPTION_ROTATE = QStringLiteral("rotate"); -const static auto SINGLE_OPTION_ROTATE = QStringLiteral("r"); - -const static auto LONG_OPTION_CROP = QStringLiteral("crop"); -const static auto SINGLE_OPTION_CROP = QStringLiteral("c"); - -const static auto LONG_OPTION_UNITE = QStringLiteral("unite"); -const static auto SINGLE_OPTION_UNITE = QStringLiteral("u"); - -const static auto LONG_OPTION_PAGEW = QStringLiteral("pagew"); -const static auto SINGLE_OPTION_PAGEW = QStringLiteral("W"); - -const static auto LONG_OPTION_PAGEH = QStringLiteral("pageh"); -const static auto SINGLE_OPTION_PAGEH = QStringLiteral("H"); - -const static auto LONG_OPTION_PAGEUNITS = QStringLiteral("pageunits"); -const static auto SINGLE_OPTION_PAGEUNITS = QStringLiteral("U"); - -const static auto LONG_OPTION_SAVELENGTH = QStringLiteral("savelen"); -const static auto SINGLE_OPTION_SAVELENGTH = QStringLiteral("S"); - -const static auto LONG_OPTION_SHIFTLENGTH = QStringLiteral("shiftlen"); -const static auto SINGLE_OPTION_SHIFTLENGTH = QStringLiteral("s"); - -const static auto LONG_OPTION_SHIFTUNITS = QStringLiteral("layounits"); -const static auto SINGLE_OPTION_SHIFTUNITS = QStringLiteral("l"); - -const static auto LONG_OPTION_GAPWIDTH = QStringLiteral("gapwidth"); -const static auto SINGLE_OPTION_GAPWIDTH = QStringLiteral("G"); - -const static auto LONG_OPTION_GROUPPING = QStringLiteral("groups"); -const static auto SINGLE_OPTION_GROUPPING = QStringLiteral("g"); - -const static auto LONG_OPTION_TEST = QStringLiteral("test"); -const static auto SINGLE_OPTION_TEST = QStringLiteral("t"); - -const static auto LONG_OPTION_GRADATIONSIZE = QStringLiteral("gsize"); -const static auto SINGLE_OPTION_GRADATIONSIZE = QStringLiteral("x"); - -const static auto LONG_OPTION_GRADATIONHEIGHT = QStringLiteral("gheight"); -const static auto SINGLE_OPTION_GRADATIONHEIGHT = QStringLiteral("e"); - -const static auto LONG_OPTION_IGNORE_MARGINS = QStringLiteral("ignoremargins"); -const static auto SINGLE_OPTION_IGNORE_MARGINS = QStringLiteral("i"); - -const static auto LONG_OPTION_LEFT_MARGIN = QStringLiteral("lmargin"); -const static auto SINGLE_OPTION_LEFT_MARGIN = QStringLiteral("L"); - -const static auto LONG_OPTION_RIGHT_MARGIN = QStringLiteral("rmargin"); -const static auto SINGLE_OPTION_RIGHT_MARGIN = QStringLiteral("R"); - -const static auto LONG_OPTION_TOP_MARGIN = QStringLiteral("tmargin"); -const static auto SINGLE_OPTION_TOP_MARGIN = QStringLiteral("T"); - -const static auto LONG_OPTION_BOTTOM_MARGIN = QStringLiteral("bmargin"); -const static auto SINGLE_OPTION_BOTTOM_MARGIN = QStringLiteral("B"); - #define translate(context, source) QCoreApplication::translate((context), (source)) //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vmisc/commandoptions.cpp b/src/libs/vmisc/commandoptions.cpp new file mode 100644 index 000000000..058f59588 --- /dev/null +++ b/src/libs/vmisc/commandoptions.cpp @@ -0,0 +1,135 @@ +/************************************************************************ + ** + ** @file commandoptions.cpp + ** @author Roman Telezhynskyi + ** @date 9 11, 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 "commandoptions.h" + +#include + +const QString LONG_OPTION_BASENAME = QStringLiteral("basename"); +const QString SINGLE_OPTION_BASENAME = QStringLiteral("b"); + +const QString LONG_OPTION_DESTINATION = QStringLiteral("destination"); +const QString SINGLE_OPTION_DESTINATION = QStringLiteral("d"); + +const QString LONG_OPTION_MEASUREFILE = QStringLiteral("mfile"); +const QString SINGLE_OPTION_MEASUREFILE = QStringLiteral("m"); + +const QString LONG_OPTION_PAGETEMPLATE = QStringLiteral("pageformat"); +const QString SINGLE_OPTION_PAGETEMPLATE = QStringLiteral("p"); + +const QString LONG_OPTION_EXP2FORMAT = QStringLiteral("format"); +const QString SINGLE_OPTION_EXP2FORMAT = QStringLiteral("f"); + +const QString LONG_OPTION_ROTATE = QStringLiteral("rotate"); +const QString SINGLE_OPTION_ROTATE = QStringLiteral("r"); + +const QString LONG_OPTION_CROP = QStringLiteral("crop"); +const QString SINGLE_OPTION_CROP = QStringLiteral("c"); + +const QString LONG_OPTION_UNITE = QStringLiteral("unite"); +const QString SINGLE_OPTION_UNITE = QStringLiteral("u"); + +const QString LONG_OPTION_PAGEW = QStringLiteral("pagew"); +const QString SINGLE_OPTION_PAGEW = QStringLiteral("W"); + +const QString LONG_OPTION_PAGEH = QStringLiteral("pageh"); +const QString SINGLE_OPTION_PAGEH = QStringLiteral("H"); + +const QString LONG_OPTION_PAGEUNITS = QStringLiteral("pageunits"); +const QString SINGLE_OPTION_PAGEUNITS = QStringLiteral("U"); + +const QString LONG_OPTION_SAVELENGTH = QStringLiteral("savelen"); +const QString SINGLE_OPTION_SAVELENGTH = QStringLiteral("S"); + +const QString LONG_OPTION_SHIFTLENGTH = QStringLiteral("shiftlen"); +const QString SINGLE_OPTION_SHIFTLENGTH = QStringLiteral("s"); + +const QString LONG_OPTION_SHIFTUNITS = QStringLiteral("layounits"); +const QString SINGLE_OPTION_SHIFTUNITS = QStringLiteral("l"); + +const QString LONG_OPTION_GAPWIDTH = QStringLiteral("gapwidth"); +const QString SINGLE_OPTION_GAPWIDTH = QStringLiteral("G"); + +const QString LONG_OPTION_GROUPPING = QStringLiteral("groups"); +const QString SINGLE_OPTION_GROUPPING = QStringLiteral("g"); + +const QString LONG_OPTION_TEST = QStringLiteral("test"); +const QString SINGLE_OPTION_TEST = QStringLiteral("t"); + +const QString LONG_OPTION_GRADATIONSIZE = QStringLiteral("gsize"); +const QString SINGLE_OPTION_GRADATIONSIZE = QStringLiteral("x"); + +const QString LONG_OPTION_GRADATIONHEIGHT = QStringLiteral("gheight"); +const QString SINGLE_OPTION_GRADATIONHEIGHT = QStringLiteral("e"); + +const QString LONG_OPTION_IGNORE_MARGINS = QStringLiteral("ignoremargins"); +const QString SINGLE_OPTION_IGNORE_MARGINS = QStringLiteral("i"); + +const QString LONG_OPTION_LEFT_MARGIN = QStringLiteral("lmargin"); +const QString SINGLE_OPTION_LEFT_MARGIN = QStringLiteral("L"); + +const QString LONG_OPTION_RIGHT_MARGIN = QStringLiteral("rmargin"); +const QString SINGLE_OPTION_RIGHT_MARGIN = QStringLiteral("R"); + +const QString LONG_OPTION_TOP_MARGIN = QStringLiteral("tmargin"); +const QString SINGLE_OPTION_TOP_MARGIN = QStringLiteral("T"); + +const QString LONG_OPTION_BOTTOM_MARGIN = QStringLiteral("bmargin"); +const QString SINGLE_OPTION_BOTTOM_MARGIN = QStringLiteral("B"); + +//--------------------------------------------------------------------------------------------------------------------- +QStringList AllKeys() +{ + QStringList list; + list << LONG_OPTION_BASENAME << SINGLE_OPTION_BASENAME + << LONG_OPTION_DESTINATION << SINGLE_OPTION_DESTINATION + << LONG_OPTION_MEASUREFILE << SINGLE_OPTION_MEASUREFILE + << LONG_OPTION_PAGETEMPLATE << SINGLE_OPTION_PAGETEMPLATE + << LONG_OPTION_EXP2FORMAT << SINGLE_OPTION_EXP2FORMAT + << LONG_OPTION_ROTATE << SINGLE_OPTION_ROTATE + << LONG_OPTION_CROP << SINGLE_OPTION_CROP + << LONG_OPTION_UNITE << SINGLE_OPTION_UNITE + << LONG_OPTION_PAGEW << SINGLE_OPTION_PAGEW + << LONG_OPTION_PAGEH << SINGLE_OPTION_PAGEH + << LONG_OPTION_PAGEUNITS << SINGLE_OPTION_PAGEUNITS + << LONG_OPTION_SAVELENGTH << SINGLE_OPTION_SAVELENGTH + << LONG_OPTION_SHIFTLENGTH << SINGLE_OPTION_SHIFTLENGTH + << LONG_OPTION_SHIFTUNITS << SINGLE_OPTION_SHIFTUNITS + << LONG_OPTION_GAPWIDTH << SINGLE_OPTION_GAPWIDTH + << LONG_OPTION_GROUPPING << SINGLE_OPTION_GROUPPING + << LONG_OPTION_TEST << SINGLE_OPTION_TEST + << LONG_OPTION_GRADATIONSIZE << SINGLE_OPTION_GRADATIONSIZE + << LONG_OPTION_GRADATIONHEIGHT << SINGLE_OPTION_GRADATIONHEIGHT + << LONG_OPTION_IGNORE_MARGINS << SINGLE_OPTION_IGNORE_MARGINS + << LONG_OPTION_LEFT_MARGIN << SINGLE_OPTION_LEFT_MARGIN + << LONG_OPTION_RIGHT_MARGIN << SINGLE_OPTION_RIGHT_MARGIN + << LONG_OPTION_TOP_MARGIN << SINGLE_OPTION_TOP_MARGIN + << LONG_OPTION_BOTTOM_MARGIN << SINGLE_OPTION_BOTTOM_MARGIN; + + return list; +} diff --git a/src/libs/vmisc/commandoptions.h b/src/libs/vmisc/commandoptions.h new file mode 100644 index 000000000..67730387a --- /dev/null +++ b/src/libs/vmisc/commandoptions.h @@ -0,0 +1,110 @@ +/************************************************************************ + ** + ** @file commandoptions.h + ** @author Roman Telezhynskyi + ** @date 9 11, 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 COMMANDOPTIONS_H +#define COMMANDOPTIONS_H + +#include + +class QStringList; + +extern const QString LONG_OPTION_BASENAME; +extern const QString SINGLE_OPTION_BASENAME; + +extern const QString LONG_OPTION_DESTINATION; +extern const QString SINGLE_OPTION_DESTINATION; + +extern const QString LONG_OPTION_MEASUREFILE; +extern const QString SINGLE_OPTION_MEASUREFILE; + +extern const QString LONG_OPTION_PAGETEMPLATE; +extern const QString SINGLE_OPTION_PAGETEMPLATE; + +extern const QString LONG_OPTION_EXP2FORMAT; +extern const QString SINGLE_OPTION_EXP2FORMAT; + +extern const QString LONG_OPTION_ROTATE; +extern const QString SINGLE_OPTION_ROTATE; + +extern const QString LONG_OPTION_CROP; +extern const QString SINGLE_OPTION_CROP; + +extern const QString LONG_OPTION_UNITE; +extern const QString SINGLE_OPTION_UNITE; + +extern const QString LONG_OPTION_PAGEW; +extern const QString SINGLE_OPTION_PAGEW; + +extern const QString LONG_OPTION_PAGEH; +extern const QString SINGLE_OPTION_PAGEH; + +extern const QString LONG_OPTION_PAGEUNITS; +extern const QString SINGLE_OPTION_PAGEUNITS; + +extern const QString LONG_OPTION_SAVELENGTH; +extern const QString SINGLE_OPTION_SAVELENGTH; + +extern const QString LONG_OPTION_SHIFTLENGTH; +extern const QString SINGLE_OPTION_SHIFTLENGTH; + +extern const QString LONG_OPTION_SHIFTUNITS; +extern const QString SINGLE_OPTION_SHIFTUNITS; + +extern const QString LONG_OPTION_GAPWIDTH; +extern const QString SINGLE_OPTION_GAPWIDTH; + +extern const QString LONG_OPTION_GROUPPING; +extern const QString SINGLE_OPTION_GROUPPING; + +extern const QString LONG_OPTION_TEST; +extern const QString SINGLE_OPTION_TEST; + +extern const QString LONG_OPTION_GRADATIONSIZE; +extern const QString SINGLE_OPTION_GRADATIONSIZE; + +extern const QString LONG_OPTION_GRADATIONHEIGHT; +extern const QString SINGLE_OPTION_GRADATIONHEIGHT; + +extern const QString LONG_OPTION_IGNORE_MARGINS; +extern const QString SINGLE_OPTION_IGNORE_MARGINS; + +extern const QString LONG_OPTION_LEFT_MARGIN; +extern const QString SINGLE_OPTION_LEFT_MARGIN; + +extern const QString LONG_OPTION_RIGHT_MARGIN; +extern const QString SINGLE_OPTION_RIGHT_MARGIN; + +extern const QString LONG_OPTION_TOP_MARGIN; +extern const QString SINGLE_OPTION_TOP_MARGIN; + +extern const QString LONG_OPTION_BOTTOM_MARGIN; +extern const QString SINGLE_OPTION_BOTTOM_MARGIN; + +QStringList AllKeys(); + +#endif // COMMANDOPTIONS_H diff --git a/src/libs/vmisc/vmisc.pri b/src/libs/vmisc/vmisc.pri index 4b665749d..c85a099c4 100644 --- a/src/libs/vmisc/vmisc.pri +++ b/src/libs/vmisc/vmisc.pri @@ -11,7 +11,8 @@ SOURCES += \ $$PWD/projectversion.cpp \ $$PWD/vcommonsettings.cpp \ $$PWD/vtapesettings.cpp \ - $$PWD/backport/qmarginsf.cpp + $$PWD/backport/qmarginsf.cpp \ + $$PWD/commandoptions.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp @@ -32,4 +33,5 @@ HEADERS += \ $$PWD/vlockguard.h \ $$PWD/vsysexits.h \ $$PWD/backport/qmarginsf.h \ - $$PWD/vmargins.h + $$PWD/vmargins.h \ + $$PWD/commandoptions.h diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index 13cf5a921..27bf2e5d6 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -50,7 +50,8 @@ SOURCES += \ tst_vmeasurements.cpp \ tst_qmuparsererrormsg.cpp \ tst_vlockguard.cpp \ - tst_misc.cpp + tst_misc.cpp \ + tst_vcommandline.cpp HEADERS += \ tst_vposter.h \ @@ -68,7 +69,8 @@ HEADERS += \ tst_vmeasurements.h \ tst_qmuparsererrormsg.h \ tst_vlockguard.h \ - tst_misc.h + tst_misc.h \ + tst_vcommandline.h # Set using ccache. Function enable_ccache() defined in common.pri. $$enable_ccache() diff --git a/src/test/ValentinaTest/qttestmainlambda.cpp b/src/test/ValentinaTest/qttestmainlambda.cpp index 76fb6a09e..a31e10d36 100644 --- a/src/test/ValentinaTest/qttestmainlambda.cpp +++ b/src/test/ValentinaTest/qttestmainlambda.cpp @@ -42,6 +42,7 @@ #include "tst_qmuparsererrormsg.h" #include "tst_vlockguard.h" #include "tst_misc.h" +#include "tst_vcommandline.h" int main(int argc, char** argv) { @@ -70,6 +71,7 @@ int main(int argc, char** argv) ASSERT_TEST(new TST_QmuParserErrorMsg()); ASSERT_TEST(new TST_VLockGuard()); ASSERT_TEST(new TST_Misc()); + ASSERT_TEST(new TST_VCommandLine()); return status; } diff --git a/src/test/ValentinaTest/tst_vcommandline.cpp b/src/test/ValentinaTest/tst_vcommandline.cpp new file mode 100644 index 000000000..627462849 --- /dev/null +++ b/src/test/ValentinaTest/tst_vcommandline.cpp @@ -0,0 +1,54 @@ +/************************************************************************ + ** + ** @file tst_vcommandline.cpp + ** @author Roman Telezhynskyi + ** @date 9 11, 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_vcommandline.h" +#include "../vmisc/commandoptions.h" +#include "../vmisc/logging.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +TST_VCommandLine::TST_VCommandLine(QObject *parent) + :QObject(parent) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +void TST_VCommandLine::UniqueKeys() +{ + const QStringList options = AllKeys(); + QSet unique; + + foreach(const QString &str, options) + { + const QString message = QString("Options '%1' is not unique!").arg(str); + QVERIFY2(not unique.contains(str), qUtf8Printable(message)); + unique.insert(str); + } +} diff --git a/src/test/ValentinaTest/tst_vcommandline.h b/src/test/ValentinaTest/tst_vcommandline.h new file mode 100644 index 000000000..f7df5c0b6 --- /dev/null +++ b/src/test/ValentinaTest/tst_vcommandline.h @@ -0,0 +1,47 @@ +/************************************************************************ + ** + ** @file tst_vcommandline.h + ** @author Roman Telezhynskyi + ** @date 9 11, 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_VCOMMANDLINE_H +#define TST_VCOMMANDLINE_H + +#include + +class TST_VCommandLine : public QObject +{ + Q_OBJECT +public: + explicit TST_VCommandLine(QObject *parent = nullptr); + +private slots: + void UniqueKeys(); + +private: + Q_DISABLE_COPY(TST_VCommandLine) +}; + +#endif // TST_VCOMMANDLINE_H