diff options
Diffstat (limited to 'tests/unit/unittest/refactoringengine-test.cpp')
-rw-r--r-- | tests/unit/unittest/refactoringengine-test.cpp | 91 |
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) |