C++: Add test cases for Qt's QObject

The Qt library requires client code to call `new` but not `delete`.
This commit is contained in:
Jonas Jensen
2019-03-21 12:00:01 +01:00
parent 5a56740ee6
commit a59a9f6075
2 changed files with 28 additions and 0 deletions

View File

@@ -14,6 +14,9 @@
| ListDelete.cpp:21:3:21:21 | ... = ... | Resource first is acquired by class MyThingColection but not released anywhere in this class. |
| NoDestructor.cpp:23:3:23:20 | ... = ... | Resource n is acquired by class MyClass5 but not released anywhere in this class. |
| PlacementNew.cpp:36:3:36:36 | ... = ... | Resource p1 is acquired by class MyTestForPlacementNew but not released anywhere in this class. |
| QObject.cpp:16:5:16:46 | ... = ... | Resource noParent is acquired by class MyQtUser but not released anywhere in this class. |
| QObject.cpp:20:5:20:54 | ... = ... | Resource constructorParent is acquired by class MyQtUser but not released anywhere in this class. |
| QObject.cpp:22:5:22:49 | ... = ... | Resource laterParent is acquired by class MyQtUser but not released anywhere in this class. |
| SelfRegistering.cpp:25:3:25:24 | ... = ... | Resource side is acquired by class MyOwner but not released anywhere in this class. |
| Variants.cpp:25:3:25:13 | ... = ... | Resource f is acquired by class MyClass4 but not released anywhere in this class. |
| Variants.cpp:65:3:65:17 | ... = ... | Resource a is acquired by class MyClass6 but not released anywhere in this class. |

View File

@@ -0,0 +1,25 @@
struct QObject {
QObject(QObject *parent);
void setParent(QObject *parent);
};
struct DerivedFromQObject : public QObject {
DerivedFromQObject(QObject *parent);
};
class MyQtUser {
DerivedFromQObject *noParent, *constructorParent, *laterParent;
MyQtUser(QObject *parent) {
// This object sets its parent pointer to null and thus must be deleted
// manually.
noParent = new DerivedFromQObject(nullptr); // BAD
// This object does not need to be deleted because it will be deleted by
// its parent object when the time is right.
constructorParent = new DerivedFromQObject(parent); // GOOD [FALSE POSITIVE]
laterParent = new DerivedFromQObject(nullptr); // GOOD [FALSE POSITIVE]
laterParent->setParent(parent);
}
};