summaryrefslogtreecommitdiff
path: root/tests/unit/unittest/refactoringengine-test.cpp
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2019-08-22 16:10:38 +0200
committerMarco Bubke <marco.bubke@qt.io>2019-08-27 11:53:45 +0000
commit9f805b7e8aad04f72203828b89f389f73a5ffcd7 (patch)
tree914959e9a44677f10be6481de659db363bd0a1e9 /tests/unit/unittest/refactoringengine-test.cpp
parentc174eb378a7957b8b123e2054cce0e166842a8aa (diff)
downloadqt-creator-9f805b7e8aad04f72203828b89f389f73a5ffcd7.tar.gz
ClangRefactoring: Improve follow symbol and usage
Change-Id: Idb42010443e4560489ef067e54d05b4e567598e9 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'tests/unit/unittest/refactoringengine-test.cpp')
-rw-r--r--tests/unit/unittest/refactoringengine-test.cpp91
1 files changed, 81 insertions, 10 deletions
diff --git a/tests/unit/unittest/refactoringengine-test.cpp b/tests/unit/unittest/refactoringengine-test.cpp
index 280a240942..0648cca8e0 100644
--- a/tests/unit/unittest/refactoringengine-test.cpp
+++ b/tests/unit/unittest/refactoringengine-test.cpp
@@ -65,13 +65,15 @@ protected:
commandLine = Utils::SmallStringVector(
optionsBuilder.build(projectFile.kind, CppTools::UsePrecompiledHeaders::No));
commandLine.push_back(qStringFilePath);
+ ON_CALL(mockFilePathCaching, filePathId(Eq(clangBackEndFilePath))).WillByDefault(Return(12));
+ cursor.setPosition(11);
}
protected:
NiceMock<MockFilePathCaching> mockFilePathCaching;
MockRefactoringServer mockRefactoringServer;
MockRefactoringClient mockRefactoringClient;
- MockSymbolQuery mockSymbolQuery;
+ NiceMock<MockSymbolQuery> mockSymbolQuery;
ClangRefactoring::RefactoringEngine engine{mockRefactoringServer,
mockRefactoringClient,
mockFilePathCaching,
@@ -85,27 +87,96 @@ protected:
SmallStringVector commandLine;
ProjectExplorer::Project project;
CppTools::ProjectPart::Ptr projectPart;
+ CppTools::Usages usages{{"/path1", 1, 3}, {"/path2", 4, 5}};
CppTools::ProjectFile projectFile{qStringFilePath, CppTools::ProjectFile::CXXSource};
};
-TEST_F(RefactoringEngine, ExpectSourceUsagesAtInFindUsages)
+TEST_F(RefactoringEngine, FindUsages)
{
- cursor.setPosition(11);
+ ON_CALL(mockSymbolQuery, sourceUsagesAt(Eq(12), 2, 5)).WillByDefault(Return(usages));
+ NiceMock<MockFunction<void(const CppTools::Usages &)>> mockCallback;
- EXPECT_CALL(mockSymbolQuery, sourceUsagesAt(_, 2, 5));
+ EXPECT_CALL(mockCallback, Call(usages));
- engine.findUsages(CppTools::CursorInEditor{cursor, filePath},
- [](const CppTools::Usages &) {});
+ engine.findUsages(CppTools::CursorInEditor{cursor, filePath}, mockCallback.AsStdFunction());
}
-TEST_F(RefactoringEngine, ExpectSourceUsagesAtInGlobalRename)
+TEST_F(RefactoringEngine, CallFindUsages)
{
- cursor.setPosition(11);
+ EXPECT_CALL(mockSymbolQuery, sourceUsagesAt(Eq(12), 2, 5));
- EXPECT_CALL(mockSymbolQuery, sourceUsagesAt(_, 2, 5));
+ engine.findUsages(CppTools::CursorInEditor{cursor, filePath}, [](const CppTools::Usages &) {});
+}
+
+TEST_F(RefactoringEngine, FindUsagesWithInvalidCursor)
+{
+ EXPECT_CALL(mockSymbolQuery, sourceUsagesAt(_, _, _)).Times(0);
+
+ engine.findUsages(CppTools::CursorInEditor{{}, filePath}, [](const CppTools::Usages &) {});
+}
+
+TEST_F(RefactoringEngine, CallSourceUsagesInInGlobalRename)
+{
+ EXPECT_CALL(mockSymbolQuery, sourceUsagesAt(Eq(12), 2, 5));
engine.globalRename(CppTools::CursorInEditor{cursor, filePath},
- [](const CppTools::Usages &) {}, QString());
+ [](const CppTools::Usages &) {},
+ {});
+}
+
+TEST_F(RefactoringEngine, CallSourceUsagesInInGlobalRenameWithInvalidCursor)
+{
+ EXPECT_CALL(mockSymbolQuery, sourceUsagesAt(_, _, _)).Times(0);
+
+ engine.globalRename(CppTools::CursorInEditor{{}, filePath}, [](const CppTools::Usages &) {}, {});
+}
+
+TEST_F(RefactoringEngine, CallDeclarationsAtInInGlobalFollowSymbol)
+{
+
+ EXPECT_CALL(mockSymbolQuery, declarationsAt(Eq(12), 2, 5));
+
+ engine.globalFollowSymbol(
+ CppTools::CursorInEditor{cursor, filePath}, [](const Utils::Link &) {}, {}, {}, {}, {});
+}
+
+TEST_F(RefactoringEngine, CallDeclarationsAtInInGlobalFollowSymbolWithInvalidCursor)
+{
+ EXPECT_CALL(mockSymbolQuery, declarationsAt(_, _, _)).Times(0);
+
+ engine.globalFollowSymbol(
+ CppTools::CursorInEditor{{}, filePath}, [](const Utils::Link &) {}, {}, {}, {}, {});
+}
+
+TEST_F(RefactoringEngine, InGlobalFollowSymbol)
+{
+ using Utils::Link;
+ NiceMock<MockFunction<void(const Link &)>> mockCallback;
+ ON_CALL(mockSymbolQuery, declarationsAt(Eq(12), 2, 5)).WillByDefault(Return(usages));
+
+ EXPECT_CALL(mockCallback,
+ Call(AllOf(Field(&Link::targetFileName, Eq("/path1")),
+ Field(&Link::targetLine, Eq(1)),
+ Field(&Link::targetColumn, Eq(2)))));
+
+ engine.globalFollowSymbol(
+ CppTools::CursorInEditor{cursor, filePath}, mockCallback.AsStdFunction(), {}, {}, {}, {});
+}
+
+TEST_F(RefactoringEngine, InGlobalFollowSymbolSkipCurrentFile)
+{
+ using Utils::Link;
+ NiceMock<MockFunction<void(const Link &)>> mockCallback;
+ CppTools::Usages usages{{clangBackEndFilePath, 1, 3}, {"/path2", 4, 5}};
+ ON_CALL(mockSymbolQuery, declarationsAt(Eq(12), 2, 5)).WillByDefault(Return(usages));
+
+ EXPECT_CALL(mockCallback,
+ Call(AllOf(Field(&Link::targetFileName, Eq("/path2")),
+ Field(&Link::targetLine, Eq(4)),
+ Field(&Link::targetColumn, Eq(4)))));
+
+ engine.globalFollowSymbol(
+ CppTools::CursorInEditor{cursor, filePath}, mockCallback.AsStdFunction(), {}, {}, {}, {});
}
TEST_F(RefactoringEngine, EngineIsNotUsableForUnusableServer)