OpenCoverage

qcommandlineparser.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qcommandlineparser.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10extern void __attribute__((visibility("default"))) qt_call_post_routines();-
11-
12typedef QHash<QString, int> NameHash_t;-
13-
14class QCommandLineParserPrivate-
15{-
16public:-
17 inline QCommandLineParserPrivate()-
18 : singleDashWordOptionMode(QCommandLineParser::ParseAsCompactedShortOptions),-
19 optionsAfterPositionalArgumentsMode(QCommandLineParser::ParseAsOptions),-
20 builtinVersionOption(false),-
21 builtinHelpOption(false),-
22 needsParsing(true)-
23 { }
executed 161 times by 2 tests: end of block
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
161
24-
25 bool parse(const QStringList &args);-
26 void checkParsed(const char *method);-
27 QStringList aliases(const QString &name) const;-
28 QString helpText() const;-
29 bool registerFoundOption(const QString &optionName);-
30 bool parseOptionValue(const QString &optionName, const QString &argument,-
31 QStringList::const_iterator *argumentIterator,-
32 QStringList::const_iterator argsEnd);-
33-
34-
35 QString errorText;-
36-
37-
38 QList<QCommandLineOption> commandLineOptionList;-
39-
40-
41 NameHash_t nameHash;-
42-
43-
44 QHash<int, QStringList> optionValuesHash;-
45-
46-
47 QStringList optionNames;-
48-
49-
50 QStringList positionalArgumentList;-
51-
52-
53 QStringList unknownOptionNames;-
54-
55-
56 QString description;-
57-
58-
59 struct PositionalArgumentDefinition-
60 {-
61 QString name;-
62 QString description;-
63 QString syntax;-
64 };-
65 QVector<PositionalArgumentDefinition> positionalArgumentDefinitions;-
66-
67-
68 QCommandLineParser::SingleDashWordOptionMode singleDashWordOptionMode;-
69-
70-
71 QCommandLineParser::OptionsAfterPositionalArgumentsMode optionsAfterPositionalArgumentsMode;-
72-
73-
74 bool builtinVersionOption;-
75-
76-
77 bool builtinHelpOption;-
78-
79-
80 bool needsParsing;-
81};-
82template<> class QTypeInfo<QCommandLineParserPrivate::PositionalArgumentDefinition > { public: enum { isComplex = (((Q_MOVABLE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_MOVABLE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_MOVABLE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(QCommandLineParserPrivate::PositionalArgumentDefinition)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< QCommandLineParserPrivate::PositionalArgumentDefinition >::value, isDummy = (((Q_MOVABLE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(QCommandLineParserPrivate::PositionalArgumentDefinition) }; static inline const char *name() { return "QCommandLineParserPrivate::PositionalArgumentDefinition"; } };-
83-
84QStringList QCommandLineParserPrivate::aliases(const QString &optionName) const-
85{-
86 const NameHash_t::const_iterator it = nameHash.constFind(optionName);-
87 if (it == nameHash.cend()
it == nameHash.cend()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 507 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
) {
2-507
88 QMessageLogger(__FILE__, 133, __PRETTY_FUNCTION__).warning("QCommandLineParser: option not defined: \"%s\"", QString(optionName).toLocal8Bit().constData());-
89 return
executed 2 times by 1 test: return QStringList();
Executed by:
  • tst_QCommandLineParser
QStringList();
executed 2 times by 1 test: return QStringList();
Executed by:
  • tst_QCommandLineParser
2
90 }-
91 return
executed 507 times by 2 tests: return commandLineOptionList.at(*it).names();
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
commandLineOptionList.at(*it).names();
executed 507 times by 2 tests: return commandLineOptionList.at(*it).names();
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
507
92}-
93QCommandLineParser::QCommandLineParser()-
94 : d(new QCommandLineParserPrivate)-
95{-
96}
executed 161 times by 2 tests: end of block
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
161
97-
98-
99-
100-
101QCommandLineParser::~QCommandLineParser()-
102{-
103 delete d;-
104}
executed 161 times by 2 tests: end of block
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
161
105void QCommandLineParser::setSingleDashWordOptionMode(QCommandLineParser::SingleDashWordOptionMode singleDashWordOptionMode)-
106{-
107 d->singleDashWordOptionMode = singleDashWordOptionMode;-
108}
executed 28 times by 1 test: end of block
Executed by:
  • tst_QCommandLineParser
28
109void QCommandLineParser::setOptionsAfterPositionalArgumentsMode(QCommandLineParser::OptionsAfterPositionalArgumentsMode parsingMode)-
110{-
111 d->optionsAfterPositionalArgumentsMode = parsingMode;-
112}
executed 4 times by 1 test: end of block
Executed by:
  • tst_QCommandLineParser
4
113bool QCommandLineParser::addOption(const QCommandLineOption &option)-
114{-
115 const QStringList optionNames = option.names();-
116-
117 if (!optionNames.isEmpty()
!optionNames.isEmpty()Description
TRUEevaluated 1275 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
) {
1-1275
118 for (const QString &name : optionNames) {-
119 if (d->nameHash.contains(name)
d->nameHash.contains(name)Description
TRUEnever evaluated
FALSEevaluated 2385 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
)
0-2385
120 return
never executed: return false;
false;
never executed: return false;
0
121 }
executed 2385 times by 2 tests: end of block
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
2385
122-
123 d->commandLineOptionList.append(option);-
124-
125 const int offset = d->commandLineOptionList.size() - 1;-
126 for (const QString &name : optionNames)-
127 d->nameHash.insert(name, offset);
executed 2385 times by 2 tests: d->nameHash.insert(name, offset);
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
2385
128-
129 return
executed 1275 times by 2 tests: return true;
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
true;
executed 1275 times by 2 tests: return true;
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
1275
130 }-
131-
132 return
executed 1 time by 1 test: return false;
Executed by:
  • tst_QCommandLineParser
false;
executed 1 time by 1 test: return false;
Executed by:
  • tst_QCommandLineParser
1
133}-
134bool QCommandLineParser::addOptions(const QList<QCommandLineOption> &options)-
135{-
136-
137 bool result = true;-
138 for (QList<QCommandLineOption>::const_iterator it = options.begin(), end = options.end(); it != end
it != endDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
; ++it)
1-3
139 result &= addOption(*it);
executed 3 times by 1 test: result &= addOption(*it);
Executed by:
  • tst_QCommandLineParser
3
140 return
executed 1 time by 1 test: return result;
Executed by:
  • tst_QCommandLineParser
result;
executed 1 time by 1 test: return result;
Executed by:
  • tst_QCommandLineParser
1
141}-
142QCommandLineOption QCommandLineParser::addVersionOption()-
143{-
144 QCommandLineOption opt(QStringList() << ([]() -> QString { enum { Size = sizeof(u"" "v")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "v" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return
executed 120 times by 1 test: return qstring_literal_temp;
Executed by:
  • tst_qdbusxml2cpp - unknown status
qstring_literal_temp;
executed 120 times by 1 test: return qstring_literal_temp;
Executed by:
  • tst_qdbusxml2cpp - unknown status
}()) << ([]() -> QString { enum { Size = sizeof(u"" "version")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "version" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return
executed 120 times by 1 test: return qstring_literal_temp;
Executed by:
  • tst_qdbusxml2cpp - unknown status
qstring_literal_temp;
executed 120 times by 1 test: return qstring_literal_temp;
Executed by:
  • tst_qdbusxml2cpp - unknown status
}()), tr("Displays version information."));
120
145 addOption(opt);-
146 d->builtinVersionOption = true;-
147 return
executed 120 times by 1 test: return opt;
Executed by:
  • tst_qdbusxml2cpp - unknown status
opt;
executed 120 times by 1 test: return opt;
Executed by:
  • tst_qdbusxml2cpp - unknown status
120
148}-
149QCommandLineOption QCommandLineParser::addHelpOption()-
150{-
151 QCommandLineOption opt(QStringList()-
152-
153-
154-
155 << ([]() -> QString { enum { Size = sizeof(u"" "h")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "h" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return
executed 120 times by 1 test: return qstring_literal_temp;
Executed by:
  • tst_qdbusxml2cpp - unknown status
qstring_literal_temp;
executed 120 times by 1 test: return qstring_literal_temp;
Executed by:
  • tst_qdbusxml2cpp - unknown status
}())
120
156 << ([]() -> QString { enum { Size = sizeof(u"" "help")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "help" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return
executed 120 times by 1 test: return qstring_literal_temp;
Executed by:
  • tst_qdbusxml2cpp - unknown status
qstring_literal_temp;
executed 120 times by 1 test: return qstring_literal_temp;
Executed by:
  • tst_qdbusxml2cpp - unknown status
}()), tr("Displays this help."));
120
157 addOption(opt);-
158 d->builtinHelpOption = true;-
159 return
executed 120 times by 1 test: return opt;
Executed by:
  • tst_qdbusxml2cpp - unknown status
opt;
executed 120 times by 1 test: return opt;
Executed by:
  • tst_qdbusxml2cpp - unknown status
120
160}-
161-
162-
163-
164-
165void QCommandLineParser::setApplicationDescription(const QString &description)-
166{-
167 d->description = description;-
168}
executed 120 times by 1 test: end of block
Executed by:
  • tst_qdbusxml2cpp - unknown status
120
169-
170-
171-
172-
173QString QCommandLineParser::applicationDescription() const-
174{-
175 return
never executed: return d->description;
d->description;
never executed: return d->description;
0
176}-
177void QCommandLineParser::addPositionalArgument(const QString &name, const QString &description, const QString &syntax)-
178{-
179 QCommandLineParserPrivate::PositionalArgumentDefinition arg;-
180 arg.name = name;-
181 arg.description = description;-
182 arg.syntax = syntax.isEmpty()
syntax.isEmpty()Description
TRUEevaluated 120 times by 1 test
Evaluated by:
  • tst_qdbusxml2cpp - unknown status
FALSEevaluated 120 times by 1 test
Evaluated by:
  • tst_qdbusxml2cpp - unknown status
? name : syntax;
120
183 d->positionalArgumentDefinitions.append(arg);-
184}
executed 240 times by 1 test: end of block
Executed by:
  • tst_qdbusxml2cpp - unknown status
240
185void QCommandLineParser::clearPositionalArguments()-
186{-
187 d->positionalArgumentDefinitions.clear();-
188}
never executed: end of block
0
189bool QCommandLineParser::parse(const QStringList &arguments)-
190{-
191 return
executed 50 times by 1 test: return d->parse(arguments);
Executed by:
  • tst_QCommandLineParser
d->parse(arguments);
executed 50 times by 1 test: return d->parse(arguments);
Executed by:
  • tst_QCommandLineParser
50
192}-
193-
194-
195-
196-
197-
198QString QCommandLineParser::errorText() const-
199{-
200 if (!d->errorText.isEmpty()
!d->errorText.isEmpty()Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
)
3
201 return
executed 3 times by 1 test: return d->errorText;
Executed by:
  • tst_QCommandLineParser
d->errorText;
executed 3 times by 1 test: return d->errorText;
Executed by:
  • tst_QCommandLineParser
3
202 if (d->unknownOptionNames.count() == 1
d->unknownOpti...s.count() == 1Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
)
1-2
203 return
executed 2 times by 1 test: return tr("Unknown option '%1'.").arg(d->unknownOptionNames.first());
Executed by:
  • tst_QCommandLineParser
tr("Unknown option '%1'.").arg(d->unknownOptionNames.first());
executed 2 times by 1 test: return tr("Unknown option '%1'.").arg(d->unknownOptionNames.first());
Executed by:
  • tst_QCommandLineParser
2
204 if (d->unknownOptionNames.count() > 1
d->unknownOpti...es.count() > 1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEnever evaluated
)
0-1
205 return
executed 1 time by 1 test: return tr("Unknown options: %1.").arg(d->unknownOptionNames.join(([]() -> QString { enum { Size = sizeof(u"" ", ")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" ", " }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())));
Executed by:
  • tst_QCommandLineParser
tr("Unknown options: %1.").arg(d->unknownOptionNames.join(([]() -> QString { enum { Size = sizeof(u"" ", ")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" ", " }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return
executed 1 time by 1 test: return qstring_literal_temp;
Executed by:
  • tst_QCommandLineParser
qstring_literal_temp;
executed 1 time by 1 test: return qstring_literal_temp;
Executed by:
  • tst_QCommandLineParser
}())));
executed 1 time by 1 test: return tr("Unknown options: %1.").arg(d->unknownOptionNames.join(([]() -> QString { enum { Size = sizeof(u"" ", ")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" ", " }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())));
Executed by:
  • tst_QCommandLineParser
1
206 return
never executed: return QString();
QString();
never executed: return QString();
0
207}-
208-
209enum MessageType { UsageMessage, ErrorMessage };-
210static void showParserMessage(const QString &message, MessageType type)-
211{-
212 fputs(QString(message).toLocal8Bit().constData(), type == UsageMessage ? stdout : stderr);-
213}
never executed: end of block
0
214void QCommandLineParser::process(const QStringList &arguments)-
215{-
216 if (!d->parse(arguments)
!d->parse(arguments)Description
TRUEnever evaluated
FALSEevaluated 120 times by 1 test
Evaluated by:
  • tst_qdbusxml2cpp - unknown status
) {
0-120
217 showParserMessage(errorText() + QLatin1Char('\n'), ErrorMessage);-
218 qt_call_post_routines();-
219 ::
never executed: ::exit(1);
exit(1);
never executed: ::exit(1);
0
220 }-
221-
222 if (d->builtinVersionOption
d->builtinVersionOptionDescription
TRUEevaluated 120 times by 1 test
Evaluated by:
  • tst_qdbusxml2cpp - unknown status
FALSEnever evaluated
&& isSet(([]() -> QString { enum { Size = sizeof(u"" "version")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "version" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return
executed 120 times by 1 test: return qstring_literal_temp;
Executed by:
  • tst_qdbusxml2cpp - unknown status
qstring_literal_temp;
executed 120 times by 1 test: return qstring_literal_temp;
Executed by:
  • tst_qdbusxml2cpp - unknown status
}()))
isSet(([]() ->...al_temp; }()))Description
TRUEnever evaluated
FALSEevaluated 120 times by 1 test
Evaluated by:
  • tst_qdbusxml2cpp - unknown status
)
0-120
223 showVersion();
never executed: showVersion();
0
224-
225 if (d->builtinHelpOption
d->builtinHelpOptionDescription
TRUEevaluated 120 times by 1 test
Evaluated by:
  • tst_qdbusxml2cpp - unknown status
FALSEnever evaluated
&& isSet(([]() -> QString { enum { Size = sizeof(u"" "help")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "help" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return
executed 120 times by 1 test: return qstring_literal_temp;
Executed by:
  • tst_qdbusxml2cpp - unknown status
qstring_literal_temp;
executed 120 times by 1 test: return qstring_literal_temp;
Executed by:
  • tst_qdbusxml2cpp - unknown status
}()))
isSet(([]() ->...al_temp; }()))Description
TRUEnever evaluated
FALSEevaluated 120 times by 1 test
Evaluated by:
  • tst_qdbusxml2cpp - unknown status
)
0-120
226 showHelp(0);
never executed: showHelp(0);
0
227}
executed 120 times by 1 test: end of block
Executed by:
  • tst_qdbusxml2cpp - unknown status
120
228-
229-
230-
231-
232-
233-
234void QCommandLineParser::process(const QCoreApplication &app)-
235{-
236-
237 (void)app;;-
238 process(QCoreApplication::arguments());-
239}
executed 120 times by 1 test: end of block
Executed by:
  • tst_qdbusxml2cpp - unknown status
120
240-
241void QCommandLineParserPrivate::checkParsed(const char *method)-
242{-
243 if (needsParsing
needsParsingDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 2060 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
)
2-2060
244 QMessageLogger(__FILE__, 617, __PRETTY_FUNCTION__).warning("QCommandLineParser: call process() or parse() before %s", method);
executed 2 times by 1 test: QMessageLogger(__FILE__, 617, __PRETTY_FUNCTION__).warning("QCommandLineParser: call process() or parse() before %s", method);
Executed by:
  • tst_QCommandLineParser
2
245}
executed 2062 times by 2 tests: end of block
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
2062
246-
247-
248-
249-
250-
251-
252bool QCommandLineParserPrivate::registerFoundOption(const QString &optionName)-
253{-
254 if (nameHash.contains(optionName)
nameHash.contains(optionName)Description
TRUEevaluated 287 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
FALSEevaluated 5 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
) {
5-287
255 optionNames.append(optionName);-
256 return
executed 287 times by 2 tests: return true;
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
true;
executed 287 times by 2 tests: return true;
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
287
257 } else {-
258 unknownOptionNames.append(optionName);-
259 return
executed 5 times by 1 test: return false;
Executed by:
  • tst_QCommandLineParser
false;
executed 5 times by 1 test: return false;
Executed by:
  • tst_QCommandLineParser
5
260 }-
261}-
262bool QCommandLineParserPrivate::parseOptionValue(const QString &optionName, const QString &argument,-
263 QStringList::const_iterator *argumentIterator, QStringList::const_iterator argsEnd)-
264{-
265 const QLatin1Char assignChar('=');-
266 const NameHash_t::const_iterator nameHashIt = nameHash.constFind(optionName);-
267 if (nameHashIt != nameHash.constEnd()
nameHashIt != ...ash.constEnd()Description
TRUEevaluated 278 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
) {
1-278
268 const int assignPos = argument.indexOf(assignChar);-
269 const NameHash_t::mapped_type optionOffset = *nameHashIt;-
270 const bool withValue = !commandLineOptionList.at(optionOffset).valueName().isEmpty();-
271 if (withValue
withValueDescription
TRUEevaluated 144 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
FALSEevaluated 134 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
) {
134-144
272 if (assignPos == -1
assignPos == -1Description
TRUEevaluated 140 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
) {
4-140
273 ++(*argumentIterator);-
274 if (*
*argumentIterator == argsEndDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 139 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
argumentIterator == argsEnd
*argumentIterator == argsEndDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 139 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
) {
1-139
275 errorText = QCommandLineParser::tr("Missing value after '%1'.").arg(argument);-
276 return
executed 1 time by 1 test: return false;
Executed by:
  • tst_QCommandLineParser
false;
executed 1 time by 1 test: return false;
Executed by:
  • tst_QCommandLineParser
1
277 }-
278 optionValuesHash[optionOffset].append(*(*argumentIterator));-
279 }
executed 139 times by 2 tests: end of block
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
else {
139
280 optionValuesHash[optionOffset].append(argument.mid(assignPos + 1));-
281 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_QCommandLineParser
4
282 } else {-
283 if (assignPos != -1
assignPos != -1Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 132 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
) {
2-132
284 errorText = QCommandLineParser::tr("Unexpected value after '%1'.").arg(argument.left(assignPos));-
285 return
executed 2 times by 1 test: return false;
Executed by:
  • tst_QCommandLineParser
false;
executed 2 times by 1 test: return false;
Executed by:
  • tst_QCommandLineParser
2
286 }-
287 }
executed 132 times by 2 tests: end of block
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
132
288 }-
289 return
executed 276 times by 2 tests: return true;
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
true;
executed 276 times by 2 tests: return true;
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
276
290}-
291bool QCommandLineParserPrivate::parse(const QStringList &args)-
292{-
293 needsParsing = false;-
294 bool error = false;-
295-
296 const QString doubleDashString(([]() -> QString { enum { Size = sizeof(u"" "--")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "--" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return
executed 170 times by 2 tests: return qstring_literal_temp;
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
qstring_literal_temp;
executed 170 times by 2 tests: return qstring_literal_temp;
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
}()));
170
297 const QLatin1Char dashChar('-');-
298 const QLatin1Char assignChar('=');-
299-
300 bool forcePositional = false;-
301 errorText.clear();-
302 positionalArgumentList.clear();-
303 optionNames.clear();-
304 unknownOptionNames.clear();-
305 optionValuesHash.clear();-
306-
307 if (args.isEmpty()
args.isEmpty()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 169 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
) {
1-169
308 QMessageLogger(__FILE__, 706, __PRETTY_FUNCTION__).warning("QCommandLineParser: argument list cannot be empty, it should contain at least the executable name");-
309 return
executed 1 time by 1 test: return false;
Executed by:
  • tst_QCommandLineParser
false;
executed 1 time by 1 test: return false;
Executed by:
  • tst_QCommandLineParser
1
310 }-
311-
312 QStringList::const_iterator argumentIterator = args.begin();-
313 ++argumentIterator;-
314-
315 for (; argumentIterator != args.end()
argumentIterator != args.end()Description
TRUEevaluated 303 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
FALSEevaluated 168 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
; ++argumentIterator) {
168-303
316 QString argument = *argumentIterator;-
317-
318 if (forcePositional
forcePositionalDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 294 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
) {
9-294
319 positionalArgumentList.append(argument);-
320 }
executed 9 times by 1 test: end of block
Executed by:
  • tst_QCommandLineParser
else if (argument.startsWith(doubleDashString)
argument.start...bleDashString)Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 270 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
) {
9-270
321 if (argument.length() > 2
argument.length() > 2Description
TRUEevaluated 22 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
) {
2-22
322 QString optionName = argument.mid(2).section(assignChar, 0, 0);-
323 if (registerFoundOption(optionName)
registerFoundO...on(optionName)Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
) {
2-20
324 if (!parseOptionValue(optionName, argument, &argumentIterator, args.end())
!parseOptionVa...r, args.end())Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 19 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
)
1-19
325 error = true;
executed 1 time by 1 test: error = true;
Executed by:
  • tst_QCommandLineParser
1
326 }
executed 20 times by 1 test: end of block
Executed by:
  • tst_QCommandLineParser
else {
20
327 error = true;-
328 }
executed 2 times by 1 test: end of block
Executed by:
  • tst_QCommandLineParser
2
329 } else {-
330 forcePositional = true;-
331 }
executed 2 times by 1 test: end of block
Executed by:
  • tst_QCommandLineParser
2
332 } else if (argument.startsWith(dashChar)
argument.startsWith(dashChar)Description
TRUEevaluated 263 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
FALSEevaluated 7 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
) {
7-263
333 if (argument.size() == 1
argument.size() == 1Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 261 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
) {
2-261
334 positionalArgumentList.append(argument);-
335 continue;
executed 2 times by 1 test: continue;
Executed by:
  • tst_QCommandLineParser
2
336 }-
337 switch (singleDashWordOptionMode) {-
338 case
executed 256 times by 2 tests: case QCommandLineParser::ParseAsCompactedShortOptions:
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
QCommandLineParser::ParseAsCompactedShortOptions:
executed 256 times by 2 tests: case QCommandLineParser::ParseAsCompactedShortOptions:
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
256
339 {-
340 QString optionName;-
341 bool valueFound = false;-
342 for (int pos = 1 ; pos < argument.size()
pos < argument.size()Description
TRUEevaluated 265 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
FALSEevaluated 129 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
; ++pos) {
129-265
343 optionName = argument.mid(pos, 1);-
344 if (!registerFoundOption(optionName)
!registerFound...on(optionName)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 262 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
) {
3-262
345 error = true;-
346 }
executed 3 times by 1 test: end of block
Executed by:
  • tst_QCommandLineParser
else {
3
347 const NameHash_t::const_iterator nameHashIt = nameHash.constFind(optionName);-
348 ((!(nameHashIt != nameHash.constEnd())) ? qt_assert("nameHashIt != nameHash.constEnd()",__FILE__,746) : qt_noop());-
349 const NameHash_t::mapped_type optionOffset = *nameHashIt;-
350 const bool withValue = !commandLineOptionList.at(optionOffset).valueName().isEmpty();-
351 if (withValue
withValueDescription
TRUEevaluated 126 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
FALSEevaluated 136 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
) {
126-136
352 if (pos + 1 < argument.size()
pos + 1 < argument.size()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 124 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
) {
2-124
353 if (argument.at(pos + 1) == assignChar
argument.at(po... == assignCharDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
)
1
354 ++
executed 1 time by 1 test: ++pos;
Executed by:
  • tst_QCommandLineParser
pos;
executed 1 time by 1 test: ++pos;
Executed by:
  • tst_QCommandLineParser
1
355 optionValuesHash[optionOffset].append(argument.mid(pos + 1));-
356 valueFound = true;-
357 }
executed 2 times by 1 test: end of block
Executed by:
  • tst_QCommandLineParser
2
358 break;
executed 126 times by 2 tests: break;
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
126
359 }-
360 if (pos + 1 < argument.size()
pos + 1 < argument.size()Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 128 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
&& argument.at(pos + 1) == assignChar
argument.at(po... == assignCharDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 7 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
)
1-128
361 break;
executed 1 time by 1 test: break;
Executed by:
  • tst_QCommandLineParser
1
362 }
executed 135 times by 2 tests: end of block
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
135
363 }-
364 if (!valueFound
!valueFoundDescription
TRUEevaluated 254 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
&& !parseOptionValue(optionName, argument, &argumentIterator, args.end())
!parseOptionVa...r, args.end())Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 253 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
)
1-254
365 error = true;
executed 1 time by 1 test: error = true;
Executed by:
  • tst_QCommandLineParser
1
366 break;
executed 256 times by 2 tests: break;
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
256
367 }-
368 case
executed 5 times by 1 test: case QCommandLineParser::ParseAsLongOptions:
Executed by:
  • tst_QCommandLineParser
QCommandLineParser::ParseAsLongOptions:
executed 5 times by 1 test: case QCommandLineParser::ParseAsLongOptions:
Executed by:
  • tst_QCommandLineParser
5
369 {-
370 const QString optionName = argument.mid(1).section(assignChar, 0, 0);-
371 if (registerFoundOption(optionName)
registerFoundO...on(optionName)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEnever evaluated
) {
0-5
372 if (!parseOptionValue(optionName, argument, &argumentIterator, args.end())
!parseOptionVa...r, args.end())Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
)
1-4
373 error = true;
executed 1 time by 1 test: error = true;
Executed by:
  • tst_QCommandLineParser
1
374 }
executed 5 times by 1 test: end of block
Executed by:
  • tst_QCommandLineParser
else {
5
375 error = true;-
376 }
never executed: end of block
0
377 break;
executed 5 times by 1 test: break;
Executed by:
  • tst_QCommandLineParser
5
378 }-
379 }-
380 }
executed 261 times by 2 tests: end of block
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
else {
261
381 positionalArgumentList.append(argument);-
382 if (optionsAfterPositionalArgumentsMode == QCommandLineParser::ParseAsPositionalArguments
optionsAfterPo...ionalArgumentsDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 5 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
)
2-5
383 forcePositional = true;
executed 2 times by 1 test: forcePositional = true;
Executed by:
  • tst_QCommandLineParser
2
384 }
executed 7 times by 1 test: end of block
Executed by:
  • tst_QCommandLineParser
7
385 if (argumentIterator == args.end()
argumentIterator == args.end()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 300 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
)
1-300
386 break;
executed 1 time by 1 test: break;
Executed by:
  • tst_QCommandLineParser
1
387 }
executed 300 times by 2 tests: end of block
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
300
388 return
executed 169 times by 2 tests: return !error;
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
!error;
executed 169 times by 2 tests: return !error;
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
169
389}-
390bool QCommandLineParser::isSet(const QString &name) const-
391{-
392 d->checkParsed("isSet");-
393 if (d->optionNames.contains(name)
d->optionNames.contains(name)Description
TRUEevaluated 138 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
FALSEevaluated 509 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
)
138-509
394 return
executed 138 times by 2 tests: return true;
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
true;
executed 138 times by 2 tests: return true;
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
138
395 const QStringList aliases = d->aliases(name);-
396 for (const QString &optionName : qAsConst(d->optionNames)) {-
397 if (aliases.contains(optionName)
aliases.contains(optionName)Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 961 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
)
12-961
398 return
executed 12 times by 1 test: return true;
Executed by:
  • tst_QCommandLineParser
true;
executed 12 times by 1 test: return true;
Executed by:
  • tst_QCommandLineParser
12
399 }
executed 961 times by 2 tests: end of block
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
961
400 return
executed 497 times by 2 tests: return false;
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
false;
executed 497 times by 2 tests: return false;
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
497
401}-
402QString QCommandLineParser::value(const QString &optionName) const-
403{-
404 d->checkParsed("value");-
405 const QStringList valueList = values(optionName);-
406-
407 if (!valueList.isEmpty()
!valueList.isEmpty()Description
TRUEevaluated 154 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
FALSEevaluated 371 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
)
154-371
408 return
executed 154 times by 2 tests: return valueList.last();
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
valueList.last();
executed 154 times by 2 tests: return valueList.last();
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
154
409-
410 return
executed 371 times by 2 tests: return QString();
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
QString();
executed 371 times by 2 tests: return QString();
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
371
411}-
412QStringList QCommandLineParser::values(const QString &optionName) const-
413{-
414 d->checkParsed("values");-
415 const NameHash_t::const_iterator it = d->nameHash.constFind(optionName);-
416 if (it != d->nameHash.cend()
it != d->nameHash.cend()Description
TRUEevaluated 680 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
) {
4-680
417 const int optionOffset = *it;-
418 QStringList values = d->optionValuesHash.value(optionOffset);-
419 if (values.isEmpty()
values.isEmpty()Description
TRUEevaluated 510 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
FALSEevaluated 170 times by 2 tests
Evaluated by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
)
170-510
420 values = d->commandLineOptionList.at(optionOffset).defaultValues();
executed 510 times by 2 tests: values = d->commandLineOptionList.at(optionOffset).defaultValues();
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
510
421 return
executed 680 times by 2 tests: return values;
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
values;
executed 680 times by 2 tests: return values;
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
680
422 }-
423-
424 QMessageLogger(__FILE__, 875, __PRETTY_FUNCTION__).warning("QCommandLineParser: option not defined: \"%s\"", QString(optionName).toLocal8Bit().constData());-
425 return
executed 4 times by 1 test: return QStringList();
Executed by:
  • tst_QCommandLineParser
QStringList();
executed 4 times by 1 test: return QStringList();
Executed by:
  • tst_QCommandLineParser
4
426}-
427bool QCommandLineParser::isSet(const QCommandLineOption &option) const-
428{-
429-
430 const auto names = option.names();-
431 return
executed 368 times by 2 tests: return !names.isEmpty() && isSet(names.first());
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
!names.isEmpty() && isSet(names.first());
executed 368 times by 2 tests: return !names.isEmpty() && isSet(names.first());
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
368
432}-
433QString QCommandLineParser::value(const QCommandLineOption &option) const-
434{-
435 return
executed 480 times by 1 test: return value(option.names().constFirst());
Executed by:
  • tst_qdbusxml2cpp - unknown status
value(option.names().constFirst());
executed 480 times by 1 test: return value(option.names().constFirst());
Executed by:
  • tst_qdbusxml2cpp - unknown status
480
436}-
437QStringList QCommandLineParser::values(const QCommandLineOption &option) const-
438{-
439 return
executed 128 times by 2 tests: return values(option.names().constFirst());
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
values(option.names().constFirst());
executed 128 times by 2 tests: return values(option.names().constFirst());
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
128
440}-
441QStringList QCommandLineParser::positionalArguments() const-
442{-
443 d->checkParsed("positionalArguments");-
444 return
executed 145 times by 2 tests: return d->positionalArgumentList;
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
d->positionalArgumentList;
executed 145 times by 2 tests: return d->positionalArgumentList;
Executed by:
  • tst_QCommandLineParser
  • tst_qdbusxml2cpp - unknown status
145
445}-
446QStringList QCommandLineParser::optionNames() const-
447{-
448 d->checkParsed("optionNames");-
449 return
executed 35 times by 1 test: return d->optionNames;
Executed by:
  • tst_QCommandLineParser
d->optionNames;
executed 35 times by 1 test: return d->optionNames;
Executed by:
  • tst_QCommandLineParser
35
450}-
451QStringList QCommandLineParser::unknownOptionNames() const-
452{-
453 d->checkParsed("unknownOptionNames");-
454 return
executed 26 times by 1 test: return d->unknownOptionNames;
Executed by:
  • tst_QCommandLineParser
d->unknownOptionNames;
executed 26 times by 1 test: return d->unknownOptionNames;
Executed by:
  • tst_QCommandLineParser
26
455}-
456__attribute__((__noreturn__)) void QCommandLineParser::showVersion()-
457{-
458 showParserMessage(QCoreApplication::applicationName() + QLatin1Char(' ')-
459 + QCoreApplication::applicationVersion() + QLatin1Char('\n'),-
460 UsageMessage);-
461 qt_call_post_routines();-
462 ::
never executed: ::exit(0);
exit(0);
never executed: ::exit(0);
0
463}-
464__attribute__((__noreturn__)) void QCommandLineParser::showHelp(int exitCode)-
465{-
466 showParserMessage(d->helpText(), UsageMessage);-
467 qt_call_post_routines();-
468 ::
never executed: ::exit(exitCode);
exit(exitCode);
never executed: ::exit(exitCode);
0
469}-
470-
471-
472-
473-
474-
475-
476QString QCommandLineParser::helpText() const-
477{-
478 return
executed 1 time by 1 test: return d->helpText();
Executed by:
  • tst_QCommandLineParser
d->helpText();
executed 1 time by 1 test: return d->helpText();
Executed by:
  • tst_QCommandLineParser
1
479}-
480-
481static QString wrapText(const QString &names, int longestOptionNameString, const QString &description)-
482{-
483 const QLatin1Char nl('\n');-
484 QString text = QLatin1String(" ") + names.leftJustified(longestOptionNameString) + QLatin1Char(' ');-
485 const int indent = text.length();-
486 int lineStart = 0;-
487 int lastBreakable = -1;-
488 const int max = 79 - indent;-
489 int x = 0;-
490 const int len = description.length();-
491-
492 for (int i = 0; i < len
i < lenDescription
TRUEevaluated 30 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
; ++i) {
1-30
493 ++x;-
494 const QChar c = description.at(i);-
495 if (c.isSpace()
c.isSpace()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 26 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
)
4-26
496 lastBreakable = i;
executed 4 times by 1 test: lastBreakable = i;
Executed by:
  • tst_QCommandLineParser
4
497-
498 int breakAt = -1;-
499 int nextLineStart = -1;-
500 if (x > max
x > maxDescription
TRUEnever evaluated
FALSEevaluated 30 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
&& lastBreakable != -1
lastBreakable != -1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0-30
501-
502 breakAt = lastBreakable;-
503 nextLineStart = lastBreakable + 1;-
504 }
never executed: end of block
else if ((x > max - 1
x > max - 1Description
TRUEnever evaluated
FALSEevaluated 30 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
&& lastBreakable == -1
lastBreakable == -1Description
TRUEnever evaluated
FALSEnever evaluated
) || i == len - 1
i == len - 1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 29 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
) {
0-30
505-
506 breakAt = i + 1;-
507 nextLineStart = breakAt;-
508 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QCommandLineParser
else if (c == nl
c == nlDescription
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
) {
0-29
509-
510 breakAt = i;-
511 nextLineStart = i + 1;-
512 }
never executed: end of block
0
513-
514 if (breakAt != -1
breakAt != -1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEevaluated 29 times by 1 test
Evaluated by:
  • tst_QCommandLineParser
) {
1-29
515 const int numChars = breakAt - lineStart;-
516-
517 if (lineStart > 0
lineStart > 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
)
0-1
518 text += QString(indent, QLatin1Char(' '));
never executed: text += QString(indent, QLatin1Char(' '));
0
519 text += description.midRef(lineStart, numChars) + nl;-
520 x = 0;-
521 lastBreakable = -1;-
522 lineStart = nextLineStart;-
523 if (lineStart < len
lineStart < lenDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
&& description.at(lineStart).isSpace()
description.at...art).isSpace()Description
TRUEnever evaluated
FALSEnever evaluated
)
0-1
524 ++
never executed: ++lineStart;
lineStart;
never executed: ++lineStart;
0
525 i = lineStart;-
526 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QCommandLineParser
1
527 }
executed 30 times by 1 test: end of block
Executed by:
  • tst_QCommandLineParser
30
528-
529 return
executed 1 time by 1 test: return text;
Executed by:
  • tst_QCommandLineParser
text;
executed 1 time by 1 test: return text;
Executed by:
  • tst_QCommandLineParser
1
530}-
531-
532QString QCommandLineParserPrivate::helpText() const-
533{-
534 const QLatin1Char nl('\n');-
535 QString text;-
536 QString usage;-
537 usage += QCoreApplication::instance()->arguments().constFirst();-
538 if (!commandLineOptionList.isEmpty()
!commandLineOp...List.isEmpty()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEnever evaluated
)
0-1
539 usage += QLatin1Char(' ') + QCommandLineParser::tr("[options]");
executed 1 time by 1 test: usage += QLatin1Char(' ') + QCommandLineParser::tr("[options]");
Executed by:
  • tst_QCommandLineParser
1
540 for (const PositionalArgumentDefinition &arg : positionalArgumentDefinitions)-
541 usage += QLatin1Char(' ') + arg.syntax;
never executed: usage += QLatin1Char(' ') + arg.syntax;
0
542 text += QCommandLineParser::tr("Usage: %1").arg(usage) + nl;-
543 if (!description.isEmpty()
!description.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
)
0-1
544 text += description + nl;
never executed: text += description + nl;
0
545 text += nl;-
546 if (!commandLineOptionList.isEmpty()
!commandLineOp...List.isEmpty()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEnever evaluated
)
0-1
547 text += QCommandLineParser::tr("Options:") + nl;
executed 1 time by 1 test: text += QCommandLineParser::tr("Options:") + nl;
Executed by:
  • tst_QCommandLineParser
1
548 QStringList optionNameList;-
549 optionNameList.reserve(commandLineOptionList.size());-
550 int longestOptionNameString = 0;-
551 for (const QCommandLineOption &option : commandLineOptionList) {-
552 if (option.isHidden()
option.isHidden()Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
)
0-1
553 continue;
never executed: continue;
0
554 const QStringList optionNames = option.names();-
555 QString optionNamesString;-
556 for (const QString &optionName : optionNames) {-
557 const int numDashes = optionName.length() == 1
optionName.length() == 1Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
? 1 : 2;
0-1
558 optionNamesString += QLatin1String("--", numDashes) + optionName + QLatin1String(", ");-
559 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QCommandLineParser
1
560 if (!optionNames.isEmpty()
!optionNames.isEmpty()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEnever evaluated
)
0-1
561 optionNamesString.chop(2);
executed 1 time by 1 test: optionNamesString.chop(2);
Executed by:
  • tst_QCommandLineParser
1
562 const auto valueName = option.valueName();-
563 if (!valueName.isEmpty()
!valueName.isEmpty()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
FALSEnever evaluated
)
0-1
564 optionNamesString += QLatin1String(" <") + valueName + QLatin1Char('>');
executed 1 time by 1 test: optionNamesString += QLatin1String(" <") + valueName + QLatin1Char('>');
Executed by:
  • tst_QCommandLineParser
1
565 optionNameList.append(optionNamesString);-
566 longestOptionNameString = qMax(longestOptionNameString, optionNamesString.length());-
567 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QCommandLineParser
1
568 ++longestOptionNameString;-
569 auto optionNameIterator = optionNameList.cbegin();-
570 for (const QCommandLineOption &option : commandLineOptionList) {-
571 if (option.isHidden()
option.isHidden()Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
)
0-1
572 continue;
never executed: continue;
0
573 text += wrapText(*optionNameIterator, longestOptionNameString, option.description());-
574 ++optionNameIterator;-
575 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QCommandLineParser
1
576 if (!positionalArgumentDefinitions.isEmpty()
!positionalArg...ions.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QCommandLineParser
) {
0-1
577 if (!commandLineOptionList.isEmpty()
!commandLineOp...List.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
578 text += nl;
never executed: text += nl;
0
579 text += QCommandLineParser::tr("Arguments:") + nl;-
580 for (const PositionalArgumentDefinition &arg : positionalArgumentDefinitions)-
581 text += wrapText(arg.name, longestOptionNameString, arg.description);
never executed: text += wrapText(arg.name, longestOptionNameString, arg.description);
0
582 }
never executed: end of block
0
583 return
executed 1 time by 1 test: return text;
Executed by:
  • tst_QCommandLineParser
text;
executed 1 time by 1 test: return text;
Executed by:
  • tst_QCommandLineParser
1
584}-
585-
586-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9