2017-04-18 18:04:27 +02:00
|
|
|
|
|
|
|
// Test library configuration for qt.cfg
|
|
|
|
//
|
|
|
|
// Usage:
|
2017-04-18 18:47:35 +02:00
|
|
|
// $ cppcheck --check-library --enable=information --inconclusive --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr --library=qt test/cfg/qt.cpp
|
2017-04-18 18:04:27 +02:00
|
|
|
// =>
|
|
|
|
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
|
|
|
|
//
|
|
|
|
|
2019-01-07 14:40:21 +01:00
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
#include <QtPlugin>
|
2019-02-06 13:23:05 +01:00
|
|
|
#include <QFile>
|
2019-02-12 10:21:56 +01:00
|
|
|
#include <cstdio>
|
2019-01-07 14:40:21 +01:00
|
|
|
|
2017-04-18 18:04:27 +02:00
|
|
|
|
2017-04-20 17:43:28 +02:00
|
|
|
void QString1(QString s)
|
|
|
|
{
|
|
|
|
for (int i = 0; i <= s.size(); ++i) {
|
|
|
|
// cppcheck-suppress stlOutOfBounds
|
|
|
|
s[i] = 'x';
|
|
|
|
}
|
2017-04-18 18:04:27 +02:00
|
|
|
}
|
2017-04-18 18:47:35 +02:00
|
|
|
|
2017-04-20 17:43:28 +02:00
|
|
|
int QString2()
|
|
|
|
{
|
|
|
|
QString s;
|
2019-01-25 17:03:16 +01:00
|
|
|
// FIXME cppcheck-suppress reademptycontainer
|
2017-04-20 17:43:28 +02:00
|
|
|
return s.size();
|
2017-04-18 19:26:54 +02:00
|
|
|
}
|
2019-01-07 14:40:21 +01:00
|
|
|
|
|
|
|
// Verify that Qt macros do not result in syntax errors, false positives or other issues.
|
|
|
|
class MacroTest1: public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PLUGIN_METADATA(IID "com.foo.bar" FILE "test.json")
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit MacroTest1(QObject *parent = 0);
|
|
|
|
~MacroTest1();
|
|
|
|
};
|
2019-02-06 13:23:05 +01:00
|
|
|
|
2019-02-07 12:27:25 +01:00
|
|
|
void validCode(int * pIntPtr)
|
2019-02-06 13:23:05 +01:00
|
|
|
{
|
2019-02-07 12:27:25 +01:00
|
|
|
if (QFile::exists("test")) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pIntPtr != Q_NULLPTR) {
|
|
|
|
*pIntPtr = 5;
|
|
|
|
}
|
2019-02-11 16:35:01 +01:00
|
|
|
|
|
|
|
if (pIntPtr && *pIntPtr == 1) {
|
|
|
|
forever {
|
|
|
|
}
|
|
|
|
} else if (pIntPtr && *pIntPtr == 2) {
|
|
|
|
Q_FOREVER {
|
|
|
|
}
|
|
|
|
}
|
2019-02-12 08:21:49 +01:00
|
|
|
|
|
|
|
if (Q_LIKELY(pIntPtr)) {}
|
|
|
|
if (Q_UNLIKELY(!pIntPtr)) {}
|
2019-02-12 10:21:56 +01:00
|
|
|
|
|
|
|
printf(QT_TR_NOOP("Hi"));
|
2019-02-06 13:23:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ignoredReturnValue()
|
|
|
|
{
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
QFile::exists("test");
|
|
|
|
QFile file1("test");
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
file1.exists();
|
|
|
|
}
|
2019-02-07 12:27:25 +01:00
|
|
|
|
|
|
|
void nullPointer(int * pIntPtr)
|
|
|
|
{
|
|
|
|
int * pNullPtr = Q_NULLPTR;
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
*pNullPtr = 1;
|
|
|
|
|
|
|
|
if (pIntPtr != Q_NULLPTR) {
|
|
|
|
*pIntPtr = 2;
|
|
|
|
} else {
|
|
|
|
// cppcheck-suppress nullPointerRedundantCheck
|
|
|
|
*pIntPtr = 3;
|
|
|
|
}
|
|
|
|
}
|