aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorVolodymyr Zibarov <gogan419@gmail.com>2020-06-15 10:52:29 +0300
committerVolodymyr Zibarov <gogan419@gmail.com>2020-06-15 13:19:51 +0000
commit9be4a5f8392e13deb202f7573a3bc9035f891de5 (patch)
tree8770b6c8c619562359a814f225912d767200120f /tests/auto
parent48be20cf48396446d2d98ee1898537523a7632a0 (diff)
C++: Fix Find Usages false positive results for function arguments
Code snippet: void bar(); // call find usages for bar from here void foo(int bar); // bar from here should not be in results Add test for member function false positives, that is part of QTCREATORBUG-2176. That was already fixed before. Fixes: QTCREATORBUG-2176 Change-Id: I9a079caa83bbaea1edb7ba6aeb151d4d4c77952f Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/cplusplus/findusages/tst_findusages.cpp113
1 files changed, 113 insertions, 0 deletions
diff --git a/tests/auto/cplusplus/findusages/tst_findusages.cpp b/tests/auto/cplusplus/findusages/tst_findusages.cpp
index 9af88ad39c..b09e2cc47f 100644
--- a/tests/auto/cplusplus/findusages/tst_findusages.cpp
+++ b/tests/auto/cplusplus/findusages/tst_findusages.cpp
@@ -84,6 +84,9 @@ private Q_SLOTS:
void shadowedNames_2();
void staticVariables();
+ void functionNameFoundInArguments();
+ void memberFunctionFalsePositives_QTCREATORBUG2176();
+
// Qt keywords
void qproperty_1();
@@ -352,6 +355,116 @@ void tst_FindUsages::staticVariables()
QCOMPARE(findUsages.usages().size(), 5);
}
+void tst_FindUsages::functionNameFoundInArguments()
+{
+ const QByteArray src =
+ R"(
+void bar(); // call find usages for bar from here. This is 1st result
+void foo(int bar); // should not be found
+void foo(int bar){} // should not be found
+void foo2(int b=bar()); // 2nd result
+void foo2(int b=bar()){} // 3rd result
+)";
+
+ Document::Ptr doc = Document::create("functionNameFoundInArguments");
+ doc->setUtf8Source(src);
+ doc->parse();
+ doc->check();
+
+ QVERIFY(doc->diagnosticMessages().isEmpty());
+ QVERIFY(doc->globalSymbolCount() >= 1);
+
+ Symbol *s = doc->globalSymbolAt(0);
+ QCOMPARE(s->name()->identifier()->chars(), "bar");
+
+ Snapshot snapshot;
+ snapshot.insert(doc);
+
+ FindUsages find(src, doc, snapshot);
+ find(s);
+
+ QCOMPARE(find.usages().size(), 3);
+
+ QCOMPARE(find.usages()[0].line, 1);
+ QCOMPARE(find.usages()[0].col, 5);
+
+ QCOMPARE(find.usages()[1].line, 4);
+ QCOMPARE(find.usages()[1].col, 16);
+
+ QCOMPARE(find.usages()[2].line, 5);
+ QCOMPARE(find.usages()[2].col, 16);
+}
+
+void tst_FindUsages::memberFunctionFalsePositives_QTCREATORBUG2176()
+{
+ const QByteArray src =
+ R"(
+void otherFunction(int value){}
+struct Struct{
+ static int foo(){return 1;}
+ int bar(){
+ int foo=Struct::foo();
+ otherFunction(foo);
+ }
+};
+)";
+
+ Document::Ptr doc = Document::create("memberFunctionFalsePositives");
+ doc->setUtf8Source(src);
+ doc->parse();
+ doc->check();
+
+ QVERIFY(doc->diagnosticMessages().isEmpty());
+ QCOMPARE(doc->globalSymbolCount(), 2);
+
+ Class *s = doc->globalSymbolAt(1)->asClass();
+ QVERIFY(s);
+ QCOMPARE(s->name()->identifier()->chars(), "Struct");
+ QCOMPARE(s->memberCount(), 2);
+
+ Symbol *memberFunctionFoo = s->memberAt(0);
+ QVERIFY(memberFunctionFoo);
+ QCOMPARE(memberFunctionFoo->name()->identifier()->chars(), "foo");
+ QVERIFY(memberFunctionFoo->asFunction());
+
+ Function* bar = s->memberAt(1)->asFunction();
+ QVERIFY(bar);
+ QCOMPARE(bar->name()->identifier()->chars(), "bar");
+ QCOMPARE(bar->memberCount(), 1);
+
+ Block* block = bar->memberAt(0)->asBlock();
+ QVERIFY(block);
+ QCOMPARE(block->memberCount(), 1);
+
+ Symbol *variableFoo = block->memberAt(0);
+ QVERIFY(variableFoo);
+ QCOMPARE(variableFoo->name()->identifier()->chars(), "foo");
+ QVERIFY(variableFoo->asDeclaration());
+
+ Snapshot snapshot;
+ snapshot.insert(doc);
+
+ FindUsages find(src, doc, snapshot);
+
+ find(memberFunctionFoo);
+ QCOMPARE(find.usages().size(), 2);
+
+ QCOMPARE(find.usages()[0].line, 3);
+ QCOMPARE(find.usages()[0].col, 15);
+
+ QCOMPARE(find.usages()[1].line, 5);
+ QCOMPARE(find.usages()[1].col, 24);
+
+ find(variableFoo);
+ QCOMPARE(find.usages().size(), 2);
+
+ QCOMPARE(find.usages()[0].line, 5);
+ QCOMPARE(find.usages()[0].col, 12);
+
+ QCOMPARE(find.usages()[1].line, 6);
+ QCOMPARE(find.usages()[1].col, 22);
+}
+
#if 0
@interface Clazz {} +(void)method:(int)arg; @end
@implementation Clazz +(void)method:(int)arg {