diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/timeline/timelinerenderpass/tst_timelinerenderpass.cpp | 4 | ||||
-rw-r--r-- | tests/auto/utils/settings/tst_settings.cpp | 16 | ||||
-rw-r--r-- | tests/unit/mockup/texteditor/refactoringchanges.h | 7 | ||||
-rw-r--r-- | tests/unit/unittest/gmock_dependency.pri | 14 | ||||
-rw-r--r-- | tests/unit/unittest/googletest.h | 2 | ||||
-rw-r--r-- | tests/unit/unittest/gtest-creator-printing.cpp | 29 | ||||
-rw-r--r-- | tests/unit/unittest/gtest-creator-printing.h | 19 | ||||
-rw-r--r-- | tests/unit/unittest/mockrefactoringclientcallback.h | 39 | ||||
-rw-r--r-- | tests/unit/unittest/refactoringclient-test.cpp | 37 | ||||
-rw-r--r-- | tests/unit/unittest/refactoringdatabaseinitializer-test.cpp | 12 | ||||
-rw-r--r-- | tests/unit/unittest/sqlitedatabase-test.cpp | 7 | ||||
-rw-r--r-- | tests/unit/unittest/storagesqlitestatementfactory-test.cpp | 1 | ||||
-rw-r--r-- | tests/unit/unittest/unittest.pro | 1 |
13 files changed, 95 insertions, 93 deletions
diff --git a/tests/auto/timeline/timelinerenderpass/tst_timelinerenderpass.cpp b/tests/auto/timeline/timelinerenderpass/tst_timelinerenderpass.cpp index 383ceebd7d..2eec7bbefd 100644 --- a/tests/auto/timeline/timelinerenderpass/tst_timelinerenderpass.cpp +++ b/tests/auto/timeline/timelinerenderpass/tst_timelinerenderpass.cpp @@ -34,7 +34,7 @@ public: static bool s_dtorRan; State *update(const TimelineAbstractRenderer *renderer, const TimelineRenderState *parentState, - State *state, int indexFrom, int indexTo, bool stateChanged, qreal spacing) const; + State *state, int indexFrom, int indexTo, bool stateChanged, float spacing) const; ~DummyRenderPass(); }; @@ -43,7 +43,7 @@ bool DummyRenderPass::s_dtorRan = false; TimelineRenderPass::State *DummyRenderPass::update(const TimelineAbstractRenderer *renderer, const TimelineRenderState *parentState, State *state, int indexFrom, int indexTo, - bool stateChanged, qreal spacing) const + bool stateChanged, float spacing) const { Q_UNUSED(renderer); Q_UNUSED(parentState); diff --git a/tests/auto/utils/settings/tst_settings.cpp b/tests/auto/utils/settings/tst_settings.cpp index 292c9d8bbc..43809e7aef 100644 --- a/tests/auto/utils/settings/tst_settings.cpp +++ b/tests/auto/utils/settings/tst_settings.cpp @@ -72,10 +72,8 @@ class BasicTestSettingsAccessor : public Utils::SettingsAccessor public: BasicTestSettingsAccessor(const Utils::FileName &baseName = Utils::FileName::fromString("/foo/bar"), const QByteArray &id = QByteArray(TESTACCESSOR_DEFAULT_ID)) : - Utils::SettingsAccessor(baseName, "TestData") + Utils::SettingsAccessor(baseName, "TestData", TESTACCESSOR_DN, TESTACCESSOR_APPLICATION_DN) { - setDisplayName(TESTACCESSOR_DN); - setApplicationDisplayName(TESTACCESSOR_APPLICATION_DN); setSettingsId(id); } }; @@ -486,7 +484,7 @@ void tst_SettingsAccessor::findIssues_ok() const QVariantMap data = versionedMap(6, TESTACCESSOR_DEFAULT_ID); const Utils::FileName path = Utils::FileName::fromString("/foo/baz.user"); - const Utils::optional<Utils::SettingsAccessor::IssueInfo> info = accessor.findIssues(data, path); + const Utils::optional<Utils::SettingsAccessor::Issue> info = accessor.findIssues(data, path); QVERIFY(!info); } @@ -497,7 +495,7 @@ void tst_SettingsAccessor::findIssues_emptyData() const QVariantMap data; const Utils::FileName path = Utils::FileName::fromString("/foo/bar.user"); - const Utils::optional<Utils::SettingsAccessor::IssueInfo> info = accessor.findIssues(data, path); + const Utils::optional<Utils::SettingsAccessor::Issue> info = accessor.findIssues(data, path); QVERIFY(bool(info)); } @@ -508,7 +506,7 @@ void tst_SettingsAccessor::findIssues_tooNew() const QVariantMap data = versionedMap(42, TESTACCESSOR_DEFAULT_ID); const Utils::FileName path = Utils::FileName::fromString("/foo/bar.user"); - const Utils::optional<Utils::SettingsAccessor::IssueInfo> info = accessor.findIssues(data, path); + const Utils::optional<Utils::SettingsAccessor::Issue> info = accessor.findIssues(data, path); QVERIFY(bool(info)); } @@ -519,7 +517,7 @@ void tst_SettingsAccessor::findIssues_tooOld() const QVariantMap data = versionedMap(2, TESTACCESSOR_DEFAULT_ID); const Utils::FileName path = Utils::FileName::fromString("/foo/bar.user"); - const Utils::optional<Utils::SettingsAccessor::IssueInfo> info = accessor.findIssues(data, path); + const Utils::optional<Utils::SettingsAccessor::Issue> info = accessor.findIssues(data, path); QVERIFY(bool(info)); } @@ -530,7 +528,7 @@ void tst_SettingsAccessor::findIssues_wrongId() const QVariantMap data = versionedMap(6, "foo"); const Utils::FileName path = Utils::FileName::fromString("/foo/bar.user"); - const Utils::optional<Utils::SettingsAccessor::IssueInfo> info = accessor.findIssues(data, path); + const Utils::optional<Utils::SettingsAccessor::Issue> info = accessor.findIssues(data, path); QVERIFY(bool(info)); } @@ -541,7 +539,7 @@ void tst_SettingsAccessor::findIssues_nonDefaultPath() const QVariantMap data = versionedMap(6, TESTACCESSOR_DEFAULT_ID); const Utils::FileName path = Utils::FileName::fromString("/foo/bar.user.foobar"); - const Utils::optional<Utils::SettingsAccessor::IssueInfo> info = accessor.findIssues(data, path); + const Utils::optional<Utils::SettingsAccessor::Issue> info = accessor.findIssues(data, path); QVERIFY(bool(info)); } diff --git a/tests/unit/mockup/texteditor/refactoringchanges.h b/tests/unit/mockup/texteditor/refactoringchanges.h index 9911bab3cd..53eda6288e 100644 --- a/tests/unit/mockup/texteditor/refactoringchanges.h +++ b/tests/unit/mockup/texteditor/refactoringchanges.h @@ -25,6 +25,8 @@ #pragma once +#include "googletest.h" + #include <QFile> #include <QSharedPointer> #include <QTextBlock> @@ -35,11 +37,6 @@ #include <memory> -#include "gtest/gtest.h" -#include "gmock/gmock-matchers.h" -#include "gmock/gmock.h" -#include "gtest-qt-printing.h" - QT_BEGIN_NAMESPACE class QString; QT_END_NAMESPACE diff --git a/tests/unit/unittest/gmock_dependency.pri b/tests/unit/unittest/gmock_dependency.pri index a78f11b6a8..1af7b95f09 100644 --- a/tests/unit/unittest/gmock_dependency.pri +++ b/tests/unit/unittest/gmock_dependency.pri @@ -33,7 +33,19 @@ requires(exists($$GTEST_SRC_DIR):exists($$GMOCK_SRC_DIR)) DEFINES += \ GTEST_HAS_STD_INITIALIZER_LIST_ \ - GTEST_LANG_CXX11 + GTEST_LANG_CXX11 \ + GTEST_HAS_STD_TUPLE_ \ + GTEST_HAS_STD_TYPE_TRAITS_ \ + GTEST_HAS_STD_FUNCTION_ \ + GTEST_HAS_RTTI \ + GTEST_HAS_STD_BEGIN_AND_END_ \ + GTEST_HAS_STD_UNIQUE_PTR_ \ + GTEST_HAS_EXCEPTIONS \ + GTEST_HAS_STREAM_REDIRECTION \ + GTEST_HAS_TYPED_TEST \ + GTEST_HAS_TYPED_TEST_P \ + GTEST_HAS_PARAM_TEST \ + GTEST_HAS_DEATH_TEST INCLUDEPATH *= \ $$GTEST_INCLUDE_DIR \ diff --git a/tests/unit/unittest/googletest.h b/tests/unit/unittest/googletest.h index 550fdf4375..6b01852fe2 100644 --- a/tests/unit/unittest/googletest.h +++ b/tests/unit/unittest/googletest.h @@ -28,7 +28,7 @@ #include <gmock/gmock.h> #include <gmock/gmock-matchers.h> #include <gtest/gtest.h> - +#include <gtest/gtest-printers.h> #include "compare-operators.h" #include "conditionally-disabled-tests.h" diff --git a/tests/unit/unittest/gtest-creator-printing.cpp b/tests/unit/unittest/gtest-creator-printing.cpp index 1bcf5f2b07..dc8edee24b 100644 --- a/tests/unit/unittest/gtest-creator-printing.cpp +++ b/tests/unit/unittest/gtest-creator-printing.cpp @@ -41,6 +41,7 @@ #include <sourcelocationentry.h> #include <sourcelocationscontainer.h> #include <tokeninfos.h> +#include <filepathview.h> #include <tooltipinfo.h> #include <cpptools/usages.h> @@ -49,6 +50,11 @@ #include <coreplugin/find/searchresultitem.h> +void PrintTo(const Utf8String &text, ::std::ostream *os) +{ + *os << text; +} + namespace Core { namespace Search { @@ -113,6 +119,11 @@ void PrintTo(const Utils::SmallString &text, ::std::ostream *os) *os << text; } +void PrintTo(const Utils::PathString &text, ::std::ostream *os) +{ + *os << text; +} + } // namespace Utils namespace ClangBackEnd { @@ -122,6 +133,16 @@ std::ostream &operator<<(std::ostream &out, const FilePathId &id) return out << "(" << id.directoryId << ", " << id.fileNameId << ")"; } +std::ostream &operator<<(std::ostream &out, const FilePathView &filePathView) +{ + return out << "(" << filePathView.toStringView() << ", " << filePathView.slashIndex() << ")"; +} + +std::ostream &operator<<(std::ostream &out, const NativeFilePathView &nativeFilePathView) +{ + return out << "(" << nativeFilePathView.toStringView() << ", " << nativeFilePathView.slashIndex() << ")"; +} + std::ostream &operator<<(std::ostream &out, const IdPaths &idPaths) { out << "(" @@ -764,14 +785,14 @@ std::ostream &operator<<(std::ostream &out, const FilePath &filePath) return out << "(" << filePath.path() << ", " << filePath.slashIndex() << ")"; } -void PrintTo(const FilePathId &id, ::std::ostream *os) +void PrintTo(const FilePath &filePath, ::std::ostream *os) { - *os << id; + *os << filePath; } -void PrintTo(const FilePath &filePath, ::std::ostream *os) +void PrintTo(const FilePathView &filePathView, ::std::ostream *os) { - *os << filePath; + *os << filePathView; } namespace V2 { diff --git a/tests/unit/unittest/gtest-creator-printing.h b/tests/unit/unittest/gtest-creator-printing.h index d58daaf40c..73848ba854 100644 --- a/tests/unit/unittest/gtest-creator-printing.h +++ b/tests/unit/unittest/gtest-creator-printing.h @@ -33,6 +33,11 @@ #include <iosfwd> +#include <gtest/gtest-printers.h> + +class Utf8String; +void PrintTo(const Utf8String &text, ::std::ostream *os); + namespace Core { namespace Search { @@ -57,6 +62,7 @@ std::ostream &operator<<(std::ostream &out, const Macro ¯o); namespace Utils { void PrintTo(const Utils::SmallString &text, ::std::ostream *os); +void PrintTo(const Utils::PathString &text, ::std::ostream *os); } // namespace ProjectExplorer namespace ClangBackEnd { @@ -116,12 +122,15 @@ class UpdateVisibleTranslationUnitsMessage; class FilePath; class TokenInfo; class TokenInfos; +template <char WindowsSlash> +class AbstractFilePathView; +using FilePathView = AbstractFilePathView<'/'>; +using NativeFilePathView = AbstractFilePathView<'\\'>; class ToolTipInfo; std::ostream &operator<<(std::ostream &out, const SourceLocationEntry &entry); std::ostream &operator<<(std::ostream &out, const IdPaths &idPaths); std::ostream &operator<<(std::ostream &out, const WatcherEntry &entry); -std::ostream &operator<<(std::ostream &out, const FilePath &filePath); std::ostream &operator<<(std::ostream &out, const SourceLocationsContainer &container); std::ostream &operator<<(std::ostream &out, const RegisterProjectPartsForEditorMessage &message); std::ostream &operator<<(std::ostream &out, const CancelMessage &message); @@ -174,8 +183,14 @@ std::ostream &operator<<(std::ostream &out, const UpdatePchProjectPartsMessage & std::ostream &operator<<(std::ostream &out, const UpdateTranslationUnitsForEditorMessage &message); std::ostream &operator<<(std::ostream &out, const UpdateVisibleTranslationUnitsMessage &message); std::ostream &operator<<(std::ostream &out, const FilePath &filePath); +std::ostream &operator<<(std::ostream &out, const FilePathId &filePathId); std::ostream &operator<<(std::ostream &out, const TokenInfo& tokenInfo); std::ostream &operator<<(std::ostream &out, const TokenInfos &tokenInfos); +std::ostream &operator<<(std::ostream &out, const FilePathView &filePathView); +std::ostream &operator<<(std::ostream &out, const NativeFilePathView &nativeFilePathView); + +void PrintTo(const FilePath &filePath, ::std::ostream *os); +void PrintTo(const FilePathView &filePathView, ::std::ostream *os); namespace V2 { class FileContainer; @@ -189,8 +204,6 @@ std::ostream &operator<<(std::ostream &out, const SourceLocationContainer &conta std::ostream &operator<<(std::ostream &out, const SourceRangeContainer &container); } // namespace V2 -void PrintTo(const FilePathId &id, ::std::ostream *os); -void PrintTo(const FilePath &filePath, ::std::ostream *os); } // namespace ClangBackEnd namespace ClangRefactoring { diff --git a/tests/unit/unittest/mockrefactoringclientcallback.h b/tests/unit/unittest/mockrefactoringclientcallback.h deleted file mode 100644 index a3486c366c..0000000000 --- a/tests/unit/unittest/mockrefactoringclientcallback.h +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include "googletest.h" - -#include <sourcelocationscontainer.h> - -class MockRefactoringClientCallBack -{ -public: - MOCK_METHOD3(localRenaming, - void(const QString &, - const ClangBackEnd::SourceLocationsContainer &, - int)); -}; diff --git a/tests/unit/unittest/refactoringclient-test.cpp b/tests/unit/unittest/refactoringclient-test.cpp index c6ed203a55..936b51a94e 100644 --- a/tests/unit/unittest/refactoringclient-test.cpp +++ b/tests/unit/unittest/refactoringclient-test.cpp @@ -24,7 +24,6 @@ ****************************************************************************/ #include "googletest.h" -#include "mockrefactoringclientcallback.h" #include "mocksearchhandle.h" #include "mockfilepathcaching.h" #include "mocksymbolquery.h" @@ -57,11 +56,6 @@ using ClangBackEnd::SourceLocationsForRenamingMessage; using ClangBackEnd::SourceRangesAndDiagnosticsForQueryMessage; using ClangBackEnd::SourceRangesForQueryMessage; -using testing::_; -using testing::Pair; -using testing::Contains; -using testing::NiceMock; - using Utils::PathString; using Utils::SmallString; using Utils::SmallStringVector; @@ -74,8 +68,10 @@ protected: NiceMock<MockFilePathCaching> mockFilePathCaching; NiceMock<MockSearchHandle> mockSearchHandle; NiceMock<MockSymbolQuery> mockSymbolQuery; - MockRefactoringClientCallBack callbackMock; QBuffer ioDevice; + MockFunction<void(const QString &, + const ClangBackEnd::SourceLocationsContainer &, + int)> mockLocalRenaming; ClangRefactoring::RefactoringClient client; ClangBackEnd::RefactoringServerProxy serverProxy{&client, &ioDevice}; RefactoringEngine engine{serverProxy, client, mockFilePathCaching, mockSymbolQuery}; @@ -98,32 +94,19 @@ protected: TEST_F(RefactoringClient, SourceLocationsForRenaming) { - client.setLocalRenamingCallback([&] (const QString &symbolName, - const ClangBackEnd::SourceLocationsContainer &sourceLocations, - int textDocumentRevision) { - callbackMock.localRenaming(symbolName, - sourceLocations, - textDocumentRevision); - }); - - EXPECT_CALL(callbackMock, localRenaming(renameMessage.symbolName().toQString(), - renameMessage.sourceLocations(), - renameMessage.textDocumentRevision())) - .Times(1); + client.setLocalRenamingCallback(mockLocalRenaming.AsStdFunction()); + + EXPECT_CALL(mockLocalRenaming, Call(renameMessage.symbolName().toQString(), + renameMessage.sourceLocations(), + renameMessage.textDocumentRevision())); client.sourceLocationsForRenamingMessage(std::move(renameMessage)); } TEST_F(RefactoringClient, AfterSourceLocationsForRenamingEngineIsUsableAgain) { - client.setLocalRenamingCallback([&] (const QString &symbolName, - const ClangBackEnd::SourceLocationsContainer &sourceLocations, - int textDocumentRevision) { - callbackMock.localRenaming(symbolName, - sourceLocations, - textDocumentRevision); - }); - EXPECT_CALL(callbackMock, localRenaming(_,_,_)); + client.setLocalRenamingCallback(mockLocalRenaming.AsStdFunction()); + EXPECT_CALL(mockLocalRenaming, Call(_,_,_)); client.sourceLocationsForRenamingMessage(std::move(renameMessage)); diff --git a/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp b/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp index 4687140dab..ab5691d4ec 100644 --- a/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp +++ b/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp @@ -79,9 +79,19 @@ TEST_F(RefactoringDatabaseInitializer, AddDirectoriesTable) EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS directories(directoryId INTEGER PRIMARY KEY, directoryPath TEXT)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_directories_directoryPath ON directories(directoryPath)"))); + initializer.createDirectoriesTable(); } +TEST_F(RefactoringDatabaseInitializer, AddProjectPartsTable) +{ + InSequence s; + + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectParts(projectPartId INTEGER PRIMARY KEY, projectPartName TEXT, compilerArguments TEXT)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_projectParts_projectPartName ON projectParts(projectPartName)"))); + + initializer.createProjectPartsTable(); +} TEST_F(RefactoringDatabaseInitializer, CreateInTheContructor) { @@ -97,6 +107,8 @@ TEST_F(RefactoringDatabaseInitializer, CreateInTheContructor) EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_sources_sourceName ON sources(sourceName)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS directories(directoryId INTEGER PRIMARY KEY, directoryPath TEXT)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_directories_directoryPath ON directories(directoryPath)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectParts(projectPartId INTEGER PRIMARY KEY, projectPartName TEXT, compilerArguments TEXT)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_projectParts_projectPartName ON projectParts(projectPartName)"))); EXPECT_CALL(mockDatabase, execute(Eq("COMMIT"))); EXPECT_CALL(mockMutex, unlock()); diff --git a/tests/unit/unittest/sqlitedatabase-test.cpp b/tests/unit/unittest/sqlitedatabase-test.cpp index 98b1435945..73f3a42724 100644 --- a/tests/unit/unittest/sqlitedatabase-test.cpp +++ b/tests/unit/unittest/sqlitedatabase-test.cpp @@ -133,6 +133,13 @@ TEST_F(SqliteDatabase, TableIsReadyAfterOpenDatabase) ASSERT_TRUE(table.isReady()); } +TEST_F(SqliteDatabase, LastRowId) +{ + database.setLastInsertedRowId(42); + + ASSERT_THAT(database.lastInsertedRowId(), 42); +} + void SqliteDatabase::SetUp() { database.setJournalMode(JournalMode::Memory); diff --git a/tests/unit/unittest/storagesqlitestatementfactory-test.cpp b/tests/unit/unittest/storagesqlitestatementfactory-test.cpp index b8575c5fc2..d118570ea9 100644 --- a/tests/unit/unittest/storagesqlitestatementfactory-test.cpp +++ b/tests/unit/unittest/storagesqlitestatementfactory-test.cpp @@ -62,7 +62,6 @@ TEST_F(StorageSqliteStatementFactory, AddNewSymbolsTable) factory.createNewSymbolsTable(); } - TEST_F(StorageSqliteStatementFactory, AddNewLocationsTable) { InSequence s; diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro index b6a698361a..257a83370c 100644 --- a/tests/unit/unittest/unittest.pro +++ b/tests/unit/unittest/unittest.pro @@ -233,7 +233,6 @@ HEADERS += \ !isEmpty(LIBTOOLING_LIBS) { HEADERS += \ gtest-clang-printing.h \ - mockrefactoringclientcallback.h \ mockrefactoringclient.h \ mockrefactoringserver.h \ testclangtool.h \ |