aboutsummaryrefslogtreecommitdiffstats
path: root/tests/incorrect-emit
diff options
context:
space:
mode:
authorSergio Martins <smartins@kde.org>2016-12-18 16:17:54 +0000
committerSergio Martins <smartins@kde.org>2016-12-18 16:46:05 +0000
commit58068bfa2b4ad44cdb5d7f5d6d4ef573f5e65f74 (patch)
tree1ba793535e360be6ff9fec35bcb3ec49a0cfefa8 /tests/incorrect-emit
parentdaacfdfc31d5019664788831338f0640fa799065 (diff)
Introducing incorrect-emit check
Warns when using emit on non-signal or when not using emit on signal.
Diffstat (limited to 'tests/incorrect-emit')
-rw-r--r--tests/incorrect-emit/config.json7
-rw-r--r--tests/incorrect-emit/main.cpp50
-rw-r--r--tests/incorrect-emit/main.cpp.expected5
3 files changed, 62 insertions, 0 deletions
diff --git a/tests/incorrect-emit/config.json b/tests/incorrect-emit/config.json
new file mode 100644
index 00000000..e7e6e0cb
--- /dev/null
+++ b/tests/incorrect-emit/config.json
@@ -0,0 +1,7 @@
+{
+ "tests" : [
+ {
+ "filename" : "main.cpp"
+ }
+ ]
+}
diff --git a/tests/incorrect-emit/main.cpp b/tests/incorrect-emit/main.cpp
new file mode 100644
index 00000000..0a804596
--- /dev/null
+++ b/tests/incorrect-emit/main.cpp
@@ -0,0 +1,50 @@
+#include <QtCore/QObject>
+
+class MyObject;
+
+MyObject* somefunc()
+{
+ return nullptr;
+}
+
+static MyObject * s_obj;
+
+class MyObject : public QObject
+{
+public:
+ void pub();
+ MyObject* memberFunc() const;
+ MyObject *another;
+
+private:
+ void priv();
+
+public slots:
+ void pubSlot();
+
+signals:
+ void sig();
+
+private Q_SLOTS:
+ void privSlot();
+
+protected:
+ void prot();
+};
+
+void MyObject::pub()
+{
+ emit prot(); // Warning: emit on non slot.
+ sig(); // Warning: missing emit
+ prot(); // OK
+ pub(); // OK
+ priv(); // OK
+ privSlot(); // OK
+ Q_EMIT privSlot(); // Warning
+ Q_EMIT somefunc()->sig(); // OK
+ somefunc()->sig(); // Warning
+ Q_EMIT memberFunc()->sig(); // OK
+ memberFunc()->sig(); // Warning
+ emit another->sig(); // OK
+ emit s_obj->sig(); // OK
+}
diff --git a/tests/incorrect-emit/main.cpp.expected b/tests/incorrect-emit/main.cpp.expected
new file mode 100644
index 00000000..1b3f0660
--- /dev/null
+++ b/tests/incorrect-emit/main.cpp.expected
@@ -0,0 +1,5 @@
+incorrect-emit/main.cpp:37:11: warning: Emit keyword being used with non-signal MyObject::prot [-Wclazy-incorrect-emit]
+incorrect-emit/main.cpp:38:5: warning: Missing emit keyword on signal call MyObject::sig; main.cpp [-Wclazy-incorrect-emit]
+incorrect-emit/main.cpp:43:12: warning: Emit keyword being used with non-signal MyObject::privSlot [-Wclazy-incorrect-emit]
+incorrect-emit/main.cpp:45:5: warning: Missing emit keyword on signal call MyObject::sig; main.cpp [-Wclazy-incorrect-emit]
+incorrect-emit/main.cpp:47:5: warning: Missing emit keyword on signal call MyObject::sig; main.cpp [-Wclazy-incorrect-emit]