Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a function to split strings on spaces, respecting quotes.
- Loading branch information
1 parent
43086b0
commit 6f8d618
Showing
7 changed files
with
164 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test_mythmiscutil |
63 changes: 63 additions & 0 deletions
63
mythtv/libs/libmythbase/test/test_mythmiscutil/test_mythmiscutil.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Class TestMiscUtil | ||
* | ||
* Copyright (c) David Hampton 2018 | ||
* | ||
* This program 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 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
#include <iostream> | ||
#include "test_mythmiscutil.h" | ||
|
||
void TestMiscUtil::test_parse_cmdline_data(void) | ||
{ | ||
QTest::addColumn<QString>("input"); | ||
QTest::addColumn<QStringList>("expectedOutput"); | ||
|
||
QTest::newRow("simple") | ||
<< R"(This is a test string)" | ||
<< QStringList({"This", "is", "a", "test", "string"}); | ||
QTest::newRow("simplequotes") | ||
<< R"(cmd "whatever" "goes" here)" | ||
<< QStringList({R"(cmd)", | ||
R"("whatever")", | ||
R"("goes")", | ||
R"(here)"}); | ||
QTest::newRow("multiword") | ||
<< R"(cmd "whatever" "multi-word argument" arg3)" | ||
<< QStringList({R"(cmd)", | ||
R"("whatever")", | ||
R"("multi-word argument")", | ||
R"(arg3)"}); | ||
QTest::newRow("mixedargs") | ||
<< R"(cmd --arg1="whatever" --arg2="multi-word argument" --arg3)" | ||
<< QStringList({R"(cmd)", | ||
R"(--arg1="whatever")", | ||
R"(--arg2="multi-word argument")", | ||
R"(--arg3)"}); | ||
} | ||
|
||
void TestMiscUtil::test_parse_cmdline(void) | ||
{ | ||
QFETCH(QString, input); | ||
QFETCH(QStringList, expectedOutput); | ||
|
||
QStringList output = MythSplitCommandString(input); | ||
// std::cerr << "Expected: " << qPrintable(expectedOutput.join("|")) << std::endl; | ||
// std::cerr << "Actual: " << qPrintable(output.join("|")) << std::endl; | ||
QCOMPARE(output, expectedOutput); | ||
} | ||
|
||
|
||
QTEST_APPLESS_MAIN(TestMiscUtil) |
33 changes: 33 additions & 0 deletions
33
mythtv/libs/libmythbase/test/test_mythmiscutil/test_mythmiscutil.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Class TestMiscUtil | ||
* | ||
* Copyright (c) David Hampton 2020 | ||
* | ||
* This program 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 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#include <QtTest/QtTest> | ||
#include <iostream> | ||
|
||
#include "mythmiscutil.h" | ||
|
||
class TestMiscUtil : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
private slots: | ||
static void test_parse_cmdline_data(void); | ||
static void test_parse_cmdline(void); | ||
}; |
26 changes: 26 additions & 0 deletions
26
mythtv/libs/libmythbase/test/test_mythmiscutil/test_mythmiscutil.pro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
include ( ../../../../settings.pro ) | ||
|
||
QT += testlib | ||
|
||
TEMPLATE = app | ||
TARGET = test_mythmiscutil | ||
DEPENDPATH += . ../.. ../../logging | ||
INCLUDEPATH += . ../.. ../../logging | ||
LIBS += -L../.. -lmythbase-$$LIBVERSION | ||
LIBS += -Wl,$$_RPATH_$${PWD}/../.. | ||
|
||
contains(QMAKE_CXX, "g++") { | ||
QMAKE_CXXFLAGS += -O0 -fprofile-arcs -ftest-coverage | ||
QMAKE_LFLAGS += -fprofile-arcs | ||
} | ||
|
||
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../.. | ||
|
||
# Input | ||
HEADERS += test_mythmiscutil.h | ||
SOURCES += test_mythmiscutil.cpp | ||
|
||
QMAKE_CLEAN += $(TARGET) | ||
QMAKE_CLEAN += ; ( cd $(OBJECTS_DIR) && rm -f *.gcov *.gcda *.gcno ) | ||
|
||
LIBS += $$EXTRA_LIBS $$LATE_LIBS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters