diff --git a/src/libs/sqlite/sqliteexception.h b/src/libs/sqlite/sqliteexception.h index 9a60cb52e0dd54369e391ba4944c5e55b9fae942..6801ca6d7f28406fe770c83ab0208a9d36d1c8bf 100644 --- a/src/libs/sqlite/sqliteexception.h +++ b/src/libs/sqlite/sqliteexception.h @@ -34,9 +34,9 @@ namespace Sqlite { class SQLITE_EXPORT SqliteException { public: - SqliteException(Utils::SmallString &&whatErrorHasHappen, + SqliteException(const char *whatErrorHasHappen, Utils::SmallString &&sqliteErrorMessage = Utils::SmallString()) - : m_whatErrorHasHappen(std::move(whatErrorHasHappen)), + : m_whatErrorHasHappen(whatErrorHasHappen), m_sqliteErrorMessage(std::move(sqliteErrorMessage)) { } @@ -44,7 +44,7 @@ public: void printWarning() const; private: - Utils::SmallString m_whatErrorHasHappen; + const char *m_whatErrorHasHappen; Utils::SmallString m_sqliteErrorMessage; }; diff --git a/src/libs/utils/smallstring.h b/src/libs/utils/smallstring.h index 9b56a674a8ff341e6dee960dd8a6951d3166848c..59d2f03368c6663e5e66c53cd34a3c499a8f3738 100644 --- a/src/libs/utils/smallstring.h +++ b/src/libs/utils/smallstring.h @@ -242,11 +242,13 @@ public: return SmallStringView(data(), size()); } + explicit operator QString() const { return toQString(); } + explicit operator std::string() const { return std::string(data(), size()); @@ -589,100 +591,6 @@ public: return *(data() + index); } - template<size_type ArraySize> - friend bool operator==(const BasicSmallString& first, const char(&second)[ArraySize]) noexcept - { - return first == SmallStringView(second); - } - - template<size_type ArraySize> - friend bool operator==(const char(&first)[ArraySize], const BasicSmallString& second) noexcept - { - return second == first; - } - - template<typename Type, - typename = std::enable_if_t<std::is_pointer<Type>::value> - > - friend bool operator==(const BasicSmallString& first, Type second) noexcept - { - return first == SmallStringView(second); - } - - template<typename Type, - typename = std::enable_if_t<std::is_pointer<Type>::value> - > - friend bool operator==(Type first, const BasicSmallString& second) noexcept - { - return second == first; - } - - friend bool operator==(const BasicSmallString& first, const SmallStringView& second) noexcept - { - return first.size() == second.size() - && std::memcmp(first.data(), second.data(), first.size()) == 0; - } - - friend bool operator==(const SmallStringView& first, const BasicSmallString& second) noexcept - { - return second == first; - } - - friend bool operator!=(const BasicSmallString& first, const SmallStringView& second) noexcept - { - return !(first == second); - } - - friend bool operator!=(const SmallStringView& first, const BasicSmallString& second) noexcept - { - return second == first; - } - - friend bool operator!=(const BasicSmallString& first, const BasicSmallString& second) noexcept - { - return !(first == second); - } - - template<size_type ArraySize> - friend bool operator!=(const BasicSmallString& first, const char(&second)[ArraySize]) noexcept - { - return !(first == second); - } - - template<size_type ArraySize> - friend bool operator!=(const char(&first)[ArraySize], const BasicSmallString& second) noexcept - { - return second != first; - } - - template<typename Type, - typename = std::enable_if_t<std::is_pointer<Type>::value> - > - friend bool operator!=(const BasicSmallString& first, Type second) noexcept - { - return !(first == second); - } - - template<typename Type, - typename = std::enable_if_t<std::is_pointer<Type>::value> - > - friend bool operator!=(Type first, const BasicSmallString& second) noexcept - { - return second != first; - } - - friend bool operator<(const BasicSmallString& first, SmallStringView second) noexcept - { - return first.size() < second.size() - || (first.size() == second.size() && std::memcmp(first.data(), second.data(), first.size()) < 0); - } - - friend bool operator<(SmallStringView first, const BasicSmallString& second) noexcept - { - return first.size() < second.size() - || (first.size() == second.size() && std::memcmp(first.data(), second.data(), first.size()) < 0); - } - friend BasicSmallString operator+(const BasicSmallString &first, const BasicSmallString &second) { BasicSmallString text; @@ -994,29 +902,6 @@ template<template<uint> class String, uint Size> using isSameString = std::is_same<std::remove_reference_t<std::remove_cv_t<String<Size>>>, BasicSmallString<Size>>; -template<template<uint> class String, - uint SizeOne, - uint SizeTwo, - typename = std::enable_if_t<isSameString<String, SizeOne>::value - || isSameString<String, SizeTwo>::value>> -bool operator==(const String<SizeOne> &first, const String<SizeTwo> &second) noexcept -{ - return first.size() == second.size() - && std::memcmp(first.data(), second.data(), first.size()) == 0; -} - - -template<template<uint> class String, - uint SizeOne, - uint SizeTwo, - typename = std::enable_if_t<isSameString<String, SizeOne>::value - || isSameString<String, SizeTwo>::value>> -bool operator<(const String<SizeOne> &first, const String<SizeTwo> &second) noexcept -{ - return first.size() < second.size() - || (first.size() == second.size() && std::memcmp(first.data(), second.data(), first.size()) < 0); -} - template<typename Key, typename Value, typename Hash = std::hash<Key>, diff --git a/src/libs/utils/smallstringfwd.h b/src/libs/utils/smallstringfwd.h index 90af2c7b42c5d1ffe4cd57f6c964f489422d03f4..f3b343f961609b11bf67a23be1690655ea5eafe1 100644 --- a/src/libs/utils/smallstringfwd.h +++ b/src/libs/utils/smallstringfwd.h @@ -29,9 +29,15 @@ namespace Utils { using uint = unsigned int; +class SmallStringView; template <uint Size> class BasicSmallString; using SmallString = BasicSmallString<31>; using PathString = BasicSmallString<190>; +inline +int compare(SmallStringView first, SmallStringView second) noexcept; +inline +int reverseCompare(SmallStringView first, SmallStringView second) noexcept; + } // namespace Utils diff --git a/src/libs/utils/smallstringiterator.h b/src/libs/utils/smallstringiterator.h index 026a8b78b56a2cb6a40ea5f049a3a11126ac3f8f..8dd2386d36e70c33b464a7a472a347063d23251f 100644 --- a/src/libs/utils/smallstringiterator.h +++ b/src/libs/utils/smallstringiterator.h @@ -41,6 +41,7 @@ struct SmallStringIterator : public std::iterator<Category, Type, DistanceType, { SmallStringIterator() noexcept = default; + constexpr SmallStringIterator(Pointer ptr) noexcept : pointer_(ptr) { } diff --git a/src/libs/utils/smallstringliteral.h b/src/libs/utils/smallstringliteral.h index 3d5e1fef1e0d8db8add3c4dc29b44d70409da176..a62dc25259b1bce448593834b603aaadddc4fa27 100644 --- a/src/libs/utils/smallstringliteral.h +++ b/src/libs/utils/smallstringliteral.h @@ -56,12 +56,12 @@ public: { } - const char *data() const + const char *data() const noexcept { return Q_LIKELY(isShortString()) ? m_data.shortString.string : m_data.allocated.data.pointer; } - size_type size() const + size_type size() const noexcept { return Q_LIKELY(isShortString()) ? m_data.shortString.shortStringSize : m_data.allocated.data.size; } diff --git a/src/libs/utils/smallstringvector.h b/src/libs/utils/smallstringvector.h index 67290b0f5cc3fa4944f4f7f9944dccacf70b2a02..ed1acc2e7bc5426e3d797363259154c3e24265ce 100644 --- a/src/libs/utils/smallstringvector.h +++ b/src/libs/utils/smallstringvector.h @@ -138,7 +138,8 @@ public: QStringList qStringList; qStringList.reserve(int(Base::size())); - std::copy(Base::begin(), Base::end(), std::back_inserter(qStringList)); + for (const auto &entry : *this) + qStringList.push_back(QString(entry)); return qStringList; } diff --git a/src/libs/utils/smallstringview.h b/src/libs/utils/smallstringview.h index ff308372effbc686981cc54be7cec491536f3240..194616b2b44ed113f527110606b08568a81ad3dd 100644 --- a/src/libs/utils/smallstringview.h +++ b/src/libs/utils/smallstringview.h @@ -67,6 +67,12 @@ public: { } + SmallStringView(const std::string &string) noexcept + : m_pointer(string.data()), + m_size(string.size()) + { + } + static SmallStringView fromUtf8(const char *const characterPointer) { @@ -74,19 +80,19 @@ public: } constexpr - const char *data() const + const char *data() const noexcept { return m_pointer; } constexpr - size_type size() const + size_type size() const noexcept { return m_size; } constexpr - size_type isEmpty() const + size_type isEmpty() const noexcept { return m_size == 0; } @@ -140,19 +146,19 @@ private: }; inline -bool operator==(const SmallStringView& first, const SmallStringView& second) noexcept +bool operator==(SmallStringView first, SmallStringView second) noexcept { return first.size() == second.size() && std::memcmp(first.data(), second.data(), first.size()) == 0; } inline -bool operator!=(const SmallStringView& first, const SmallStringView& second) noexcept +bool operator!=(SmallStringView first, SmallStringView second) noexcept { return !(first == second); } inline -int compare(const SmallStringView& first, const SmallStringView& second) noexcept +int compare(SmallStringView first, SmallStringView second) noexcept { int sizeDifference = int(first.size() - second.size()); @@ -162,6 +168,18 @@ int compare(const SmallStringView& first, const SmallStringView& second) noexcep return sizeDifference; } +inline +bool operator<(SmallStringView first, SmallStringView second) noexcept +{ + return compare(first, second) < 0; +} + +inline +bool operator>(SmallStringView first, SmallStringView second) noexcept +{ + return second < first; +} + namespace Internal { inline int reverse_memcmp(const char *first, const char *second, size_t n) @@ -187,7 +205,7 @@ int reverse_memcmp(const char *first, const char *second, size_t n) } inline -int reverseCompare(const SmallStringView& first, const SmallStringView& second) noexcept +int reverseCompare(SmallStringView first, SmallStringView second) noexcept { int sizeDifference = int(first.size() - second.size()); diff --git a/src/plugins/clangpchmanager/pchmanagerclient.cpp b/src/plugins/clangpchmanager/pchmanagerclient.cpp index d901946fb6f3bb239808dbdaa1421d99b0614d47..60c06476534c162aaf0e625be55e5125b1c905ae 100644 --- a/src/plugins/clangpchmanager/pchmanagerclient.cpp +++ b/src/plugins/clangpchmanager/pchmanagerclient.cpp @@ -43,7 +43,7 @@ void PchManagerClient::alive() void PchManagerClient::precompiledHeadersUpdated(ClangBackEnd::PrecompiledHeadersUpdatedMessage &&message) { for (const ClangBackEnd::ProjectPartPch &projectPartPch : message.projectPartPchs()) - precompiledHeaderUpdated(projectPartPch.id(), projectPartPch.path()); + precompiledHeaderUpdated(QString(projectPartPch.id()), QString(projectPartPch.path())); } void PchManagerClient::precompiledHeaderRemoved(const QString &projectPartId) diff --git a/src/plugins/clangpchmanager/projectupdater.h b/src/plugins/clangpchmanager/projectupdater.h index 5850e0c7e9ff0558ad4af253ce1d9244653a9a40..60fd636408e31528aeff86b0dec2a5baa1c6f88f 100644 --- a/src/plugins/clangpchmanager/projectupdater.h +++ b/src/plugins/clangpchmanager/projectupdater.h @@ -25,7 +25,7 @@ #pragma once -#include <clangpchmanager_global.h> +#include "clangpchmanager_global.h" #include <filecontainerv2.h> diff --git a/src/plugins/clangrefactoring/clangqueryhoverhandler.cpp b/src/plugins/clangrefactoring/clangqueryhoverhandler.cpp index 47ca0dbe79117fa9d950a4ad9d567f2583a9f0a4..e8ce90c297c51d3af20d866165eb546c2e8e67e6 100644 --- a/src/plugins/clangrefactoring/clangqueryhoverhandler.cpp +++ b/src/plugins/clangrefactoring/clangqueryhoverhandler.cpp @@ -52,9 +52,9 @@ void ClangQueryHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorW Contexts contexts = m_highligher->contextsForLineAndColumn(uint(line), uint(column)); if (!messages.empty()) - setToolTip(QString("%1: %2").arg(messages[0].errorTypeText()).arg(messages[0].arguments().join(", "))); + setToolTip(QString("%1: %2").arg(QString(messages[0].errorTypeText())).arg(QString(messages[0].arguments().join(", ")))); else if (!contexts.empty()) - setToolTip(QString("%1: %2").arg(contexts[0].contextTypeText()).arg(contexts[0].arguments().join(", "))); + setToolTip(QString("%1: %2").arg(QString(contexts[0].contextTypeText())).arg(QString(contexts[0].arguments().join(", ")))); } } // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/refactoringclient.cpp b/src/plugins/clangrefactoring/refactoringclient.cpp index e4904b53cc8bc7c6b77a730095ee0291015356c2..189e2bd48063b3abd301c3125f27406fd08ee051 100644 --- a/src/plugins/clangrefactoring/refactoringclient.cpp +++ b/src/plugins/clangrefactoring/refactoringclient.cpp @@ -154,7 +154,7 @@ void RefactoringClient::addSearchResult(const ClangBackEnd::SourceRangeWithTextC std::unordered_map<uint, QString> &filePaths) { m_searchHandle->addResult(filePaths[sourceRangeWithText.fileHash()], - sourceRangeWithText.text(), + QString(sourceRangeWithText.text()), {{int(sourceRangeWithText.start().line()), int(sourceRangeWithText.start().column() - 1), int(sourceRangeWithText.start().offset())}, diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp index 31485b8ed17a6e9444c9e2948275e55d5647b020..4c685dc34e12549a4d22e1fc4e3dabe5fe1ac394 100644 --- a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp +++ b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp @@ -66,24 +66,24 @@ template <typename Source, typename Target> void append(Target &target, const Source &source) { + using ValueType = typename Target::value_type; Source clonedSource = source.clone(); target.reserve(target.size() + source.size()); - std::move(clonedSource.begin(), - clonedSource.end(), - std::back_inserter(target)); + for(auto &&entry : clonedSource) + target.push_back(ValueType(std::move(entry))); } template <typename Source, typename Target> void append(Target &target, Source &source) { + using ValueType = typename Target::value_type; target.reserve(target.size() + source.size()); - std::move(source.begin(), - source.end(), - std::back_inserter(target)); + for(auto &&entry : source) + target.push_back(ValueType(entry)); } template <typename GetterFunction> @@ -469,14 +469,14 @@ std::vector<uint> PchCreator::generateProjectPartPchIncludes( auto jointFile = generateFileWithContent(jointedFilePath, jointedFileContent); Utils::SmallStringVector arguments = generateProjectPartCommandLine(projectPart); arguments.push_back(jointedFilePath); - FilePath filePath(jointedFilePath.clone()); + FilePath filePath{Utils::PathString(jointedFilePath)}; IncludeCollector collector(m_filePathCache); collector.setExcludedIncludes(generateProjectPartHeaderAndSourcePaths(projectPart)); - collector.addFile(filePath.directory(), - filePath.name(), + collector.addFile(std::string(filePath.directory()), + std::string(filePath.name()), {}, arguments); @@ -581,11 +581,11 @@ std::unique_ptr<QFile> PchCreator::generateFileWithContent( const Utils::SmallString &filePath, const Utils::SmallString &content) { - std::unique_ptr<QFile> precompiledIncludeFile(new QFile(filePath)); + std::unique_ptr<QFile> precompiledIncludeFile(new QFile(QString(filePath))); precompiledIncludeFile->open(QIODevice::WriteOnly); - precompiledIncludeFile->write(content.data(), content.size()); + precompiledIncludeFile->write(content.data(), qint64(content.size())); precompiledIncludeFile->close(); return precompiledIncludeFile; diff --git a/src/tools/clangpchmanagerbackend/source/pchgenerator.h b/src/tools/clangpchmanagerbackend/source/pchgenerator.h index ca8438506fddfe1f072cc81588b9c482fab2351d..144f21bffa8129dec432d41cdf0784065a939949 100644 --- a/src/tools/clangpchmanagerbackend/source/pchgenerator.h +++ b/src/tools/clangpchmanagerbackend/source/pchgenerator.h @@ -70,8 +70,8 @@ unittest_public: Process *processPointer = process.get(); process->setProcessChannelMode(QProcess::ForwardedChannels); - process->setArguments(compilerArguments); - process->setProgram(m_environment.clangCompilerPath()); + process->setArguments(QStringList(compilerArguments)); + process->setProgram(QString(m_environment.clangCompilerPath())); connectProcess(processPointer, std::move(projectPartPch)); diff --git a/src/tools/clangrefactoringbackend/source/clangquerygatherer.cpp b/src/tools/clangrefactoringbackend/source/clangquerygatherer.cpp index 319cfaa47d1e1b0472792bec024dfc1ff91d7ed6..32c8e8694e2dc93a7dcf85eb8d249e454718b47a 100644 --- a/src/tools/clangrefactoringbackend/source/clangquerygatherer.cpp +++ b/src/tools/clangrefactoringbackend/source/clangquerygatherer.cpp @@ -50,10 +50,10 @@ ClangQueryGatherer::createSourceRangesForSource( { ClangQuery clangQuery(*filePathCache, std::move(query)); - clangQuery.addFile(source.filePath().directory(), - source.filePath().name(), - source.takeUnsavedFileContent(), - source.takeCommandLineArguments()); + clangQuery.addFile(std::string(source.filePath().directory()), + std::string(source.filePath().name()), + std::string(source.takeUnsavedFileContent()), + std::vector<std::string>(source.takeCommandLineArguments())); clangQuery.addUnsavedFiles(unsaved); diff --git a/src/tools/clangrefactoringbackend/source/clangtool.cpp b/src/tools/clangrefactoringbackend/source/clangtool.cpp index 2ffad739655e2c442eb492fe912b51c1c60d4f0c..a5ea8838fca363319ce95df19f40ebcb5f69dee5 100644 --- a/src/tools/clangrefactoringbackend/source/clangtool.cpp +++ b/src/tools/clangrefactoringbackend/source/clangtool.cpp @@ -68,7 +68,7 @@ void ClangTool::addFiles(const Container &filePaths, auto fileNameBegin = found.base(); std::vector<std::string> commandLine(arguments.begin(), arguments.end()); - commandLine.push_back(filePath); + commandLine.push_back(std::string(filePath)); addFile({filePath.begin(), std::prev(fileNameBegin)}, {fileNameBegin, filePath.end()}, diff --git a/src/tools/clangrefactoringbackend/source/findusrforcursoraction.h b/src/tools/clangrefactoringbackend/source/findusrforcursoraction.h index 65ec394e7d09512969e31e8ef1fc3b67b06eeeb4..6109db187ea647d45c5303f6435bcc6973b93a05 100644 --- a/src/tools/clangrefactoringbackend/source/findusrforcursoraction.h +++ b/src/tools/clangrefactoringbackend/source/findusrforcursoraction.h @@ -66,7 +66,7 @@ public: std::string takeSymbolName() { - return std::move(symbolName); + return std::string(symbolName); } std::vector<USRName> takeUnifiedSymbolResolutions() diff --git a/src/tools/clangrefactoringbackend/source/refactoringserver.cpp b/src/tools/clangrefactoringbackend/source/refactoringserver.cpp index ff4f06babe58751ec85e348c337ff0c758de93ed..043fa87711285779975ed597e0c2aa67dab7174f 100644 --- a/src/tools/clangrefactoringbackend/source/refactoringserver.cpp +++ b/src/tools/clangrefactoringbackend/source/refactoringserver.cpp @@ -56,10 +56,10 @@ void RefactoringServer::requestSourceLocationsForRenamingMessage(RequestSourceLo { SymbolFinder symbolFinder(message.line(), message.column()); - symbolFinder.addFile(message.filePath().directory(), - message.filePath().name(), - message.unsavedContent(), - message.commandLine()); + symbolFinder.addFile(std::string(message.filePath().directory()), + std::string(message.filePath().name()), + std::string(message.unsavedContent()), + std::vector<std::string>(message.commandLine())); symbolFinder.findSymbol(); @@ -73,10 +73,10 @@ void RefactoringServer::requestSourceRangesAndDiagnosticsForQueryMessage( { ClangQuery clangQuery(m_filePathCache, message.takeQuery()); - clangQuery.addFile(message.source().filePath().directory(), - message.source().filePath().name(), - message.source().unsavedFileContent(), - message.source().commandLineArguments()); + clangQuery.addFile(std::string(message.source().filePath().directory()), + std::string(message.source().filePath().name()), + std::string(message.source().unsavedFileContent()), + std::vector<std::string>(message.source().commandLineArguments())); clangQuery.findLocations(); diff --git a/tests/unit/unittest/clangpathwatcher-test.cpp b/tests/unit/unittest/clangpathwatcher-test.cpp index 7f2c4b7e613c11648d4c3dbbdd25a3c7d0596bb6..ebe57c3a3d8774994f45703b16580367145ea122 100644 --- a/tests/unit/unittest/clangpathwatcher-test.cpp +++ b/tests/unit/unittest/clangpathwatcher-test.cpp @@ -68,7 +68,7 @@ TEST_F(ClangPathWatcher, ConvertWatcherEntriesToQStringList) { auto convertedList = watcher.convertWatcherEntriesToQStringList({watcherEntry1, watcherEntry3}); - ASSERT_THAT(convertedList, ElementsAre(path1, path2)); + ASSERT_THAT(convertedList, ElementsAre(QString(path1), QString(path2))); } TEST_F(ClangPathWatcher, UniquePaths) @@ -89,7 +89,7 @@ TEST_F(ClangPathWatcher, NotWatchedEntries) TEST_F(ClangPathWatcher, AddIdPaths) { - EXPECT_CALL(mockQFileSytemWatcher, addPaths(QStringList{path1, path2})); + EXPECT_CALL(mockQFileSytemWatcher, addPaths(QStringList{QString(path1), QString(path2)})); watcher.updateIdPaths({{id1, {paths[0], paths[1]}}, {id2, {paths[0], paths[1]}}}); } @@ -98,7 +98,7 @@ TEST_F(ClangPathWatcher, UpdateIdPathsCallsAddPathInFileWatcher) { watcher.updateIdPaths({{id1, {paths[0]}}, {id2, {paths[0]}}}); - EXPECT_CALL(mockQFileSytemWatcher, addPaths(QStringList{path2})); + EXPECT_CALL(mockQFileSytemWatcher, addPaths(QStringList{QString(path2)})); watcher.updateIdPaths({{id1, {paths[0], paths[1]}}, {id2, {paths[0], paths[1]}}}); } @@ -107,7 +107,7 @@ TEST_F(ClangPathWatcher, UpdateIdPathsAndRemoveUnusedPathsCallsRemovePathInFileW { watcher.updateIdPaths({{id1, {paths[0], paths[1]}}, {id2, {paths[0], paths[1]}}, {id3, {paths[0]}}}); - EXPECT_CALL(mockQFileSytemWatcher, removePaths(QStringList{path2})); + EXPECT_CALL(mockQFileSytemWatcher, removePaths(QStringList{QString(path2)})); watcher.updateIdPaths({{id1, {paths[0]}}, {id2, {paths[0]}}}); } @@ -116,7 +116,7 @@ TEST_F(ClangPathWatcher, UpdateIdPathsAndRemoveUnusedPathsDoNotCallsRemovePathIn { watcher.updateIdPaths({{id1, {paths[0], paths[1]}}, {id2, {paths[0], paths[1]}}, {id3, {paths[0]}}}); - EXPECT_CALL(mockQFileSytemWatcher, removePaths(QStringList{path2})) + EXPECT_CALL(mockQFileSytemWatcher, removePaths(QStringList{QString(path2)})) .Times(0); watcher.updateIdPaths({{id1, {paths[1]}}, {id2, {paths[0]}}}); @@ -189,14 +189,14 @@ TEST_F(ClangPathWatcher, AddEmptyEntries) TEST_F(ClangPathWatcher, AddEntriesWithSameIdAndDifferentPaths) { - EXPECT_CALL(mockQFileSytemWatcher, addPaths(QStringList{path1, path2})); + EXPECT_CALL(mockQFileSytemWatcher, addPaths(QStringList{QString(path1), QString(path2)})); watcher.addEntries({watcherEntry1, watcherEntry3}); } TEST_F(ClangPathWatcher, AddEntriesWithDifferentIdAndSamePaths) { - EXPECT_CALL(mockQFileSytemWatcher, addPaths(QStringList{path1})); + EXPECT_CALL(mockQFileSytemWatcher, addPaths(QStringList{QString(path1)})); watcher.addEntries({watcherEntry1, watcherEntry2}); } @@ -205,7 +205,7 @@ TEST_F(ClangPathWatcher, DontAddNewEntriesWithSameIdAndSamePaths) { watcher.addEntries({watcherEntry1}); - EXPECT_CALL(mockQFileSytemWatcher, addPaths(QStringList{path1})) + EXPECT_CALL(mockQFileSytemWatcher, addPaths(QStringList{QString(path1)})) .Times(0); watcher.addEntries({watcherEntry1}); @@ -215,7 +215,7 @@ TEST_F(ClangPathWatcher, DontAddNewEntriesWithDifferentIdAndSamePaths) { watcher.addEntries({watcherEntry1}); - EXPECT_CALL(mockQFileSytemWatcher, addPaths(QStringList{path1})) + EXPECT_CALL(mockQFileSytemWatcher, addPaths(QStringList{QString(path1)})) .Times(0); watcher.addEntries({watcherEntry2}); @@ -252,7 +252,7 @@ TEST_F(ClangPathWatcher, RemovePathForOneId) { watcher.addEntries({watcherEntry1, watcherEntry2, watcherEntry3}); - EXPECT_CALL(mockQFileSytemWatcher, removePaths(QStringList{path2})); + EXPECT_CALL(mockQFileSytemWatcher, removePaths(QStringList{QString(path2)})); watcher.removeIds({id1}); } @@ -261,7 +261,7 @@ TEST_F(ClangPathWatcher, RemoveAllPathsForThreeId) { watcher.addEntries({watcherEntry1, watcherEntry2, watcherEntry3, watcherEntry4, watcherEntry5}); - EXPECT_CALL(mockQFileSytemWatcher, removePaths(QStringList{path1, path2})); + EXPECT_CALL(mockQFileSytemWatcher, removePaths(QStringList{QString(path1), QString(path2)})); watcher.removeIds({id1, id2, id3}); } @@ -270,7 +270,7 @@ TEST_F(ClangPathWatcher, RemoveOnePathForTwoId) { watcher.addEntries({watcherEntry1, watcherEntry2, watcherEntry3, watcherEntry4, watcherEntry5}); - EXPECT_CALL(mockQFileSytemWatcher, removePaths(QStringList{path1})); + EXPECT_CALL(mockQFileSytemWatcher, removePaths(QStringList{QString(path1)})); watcher.removeIds({id1, id2}); } diff --git a/tests/unit/unittest/clangqueryprojectfindfilter-test.cpp b/tests/unit/unittest/clangqueryprojectfindfilter-test.cpp index 824905f188194fe59a6a430f16829520f43220b8..c33b8ab38a28e6f7718c4fa1b6f55eea7cd89960 100644 --- a/tests/unit/unittest/clangqueryprojectfindfilter-test.cpp +++ b/tests/unit/unittest/clangqueryprojectfindfilter-test.cpp @@ -170,7 +170,7 @@ TEST_F(ClangQueryProjectFindFilter, CallingRequestSourceRangesAndDiagnostics) Property(&FileContainer::unsavedFileContent, exampleContent)), Property(&Message::query, queryText)))); - findFilter.requestSourceRangesAndDiagnostics(queryText, exampleContent); + findFilter.requestSourceRangesAndDiagnostics(QString(queryText), QString(exampleContent)); } std::vector<CppTools::ProjectPart::Ptr> createProjectParts() diff --git a/tests/unit/unittest/googletest.h b/tests/unit/unittest/googletest.h index 84d280d713bac14ef685f3e3266db553ff678e8a..087a5c2bcb7c1dd0f352aebea306f8496361229b 100644 --- a/tests/unit/unittest/googletest.h +++ b/tests/unit/unittest/googletest.h @@ -39,3 +39,5 @@ #endif #include "google-using-declarations.h" + +#include "unittest-matchers.h" diff --git a/tests/unit/unittest/pchcreator-test.cpp b/tests/unit/unittest/pchcreator-test.cpp index 763521da42081c32df2a644c3f4798d472945874..12cd50b8e5fdeca9f6c2c588adfbc332ee26c18a 100644 --- a/tests/unit/unittest/pchcreator-test.cpp +++ b/tests/unit/unittest/pchcreator-test.cpp @@ -51,7 +51,6 @@ using testing::AtLeast; using testing::ContainerEq; using testing::Contains; using testing::ElementsAre; -using testing::EndsWith; using testing::Eq; using testing::Field; using testing::HasSubstr; @@ -61,11 +60,12 @@ using testing::Not; using testing::Property; using testing::SizeIs; using testing::UnorderedElementsAre; +using UnitTests::EndsWith; class PchCreator: public ::testing::Test { protected: - uint id(const Utils::SmallString &path); + uint id(const Utils::PathString &path); protected: ClangBackEnd::StringCache<Utils::PathString> filePathCache; @@ -148,7 +148,7 @@ TEST_F(PchCreatorVerySlowTest, CreateGlobalPchFileContent) { auto content = creator.generateGlobalPchHeaderFileContent(); - ASSERT_THAT(content, + ASSERT_THAT(std::string(content), AllOf(HasSubstr("#include \"" TESTDATA_DIR "/includecollector_external3.h\"\n"), HasSubstr("#include \"" TESTDATA_DIR "/includecollector_external1.h\"\n"), HasSubstr("#include \"" TESTDATA_DIR "/includecollector_external2.h\"\n"))); @@ -228,7 +228,7 @@ TEST_F(PchCreatorSlowTest, CreateProjectPartPchFileContent) auto content = creator.generatePchIncludeFileContent(includes); - ASSERT_THAT(content, + ASSERT_THAT(std::string(content), AllOf(HasSubstr("#include \"" TESTDATA_DIR "/includecollector_header2.h\"\n"), HasSubstr("#include \"" TESTDATA_DIR "/includecollector_external1.h\"\n"), HasSubstr("#include \"" TESTDATA_DIR "/includecollector_external2.h\"\n"))); @@ -282,7 +282,7 @@ TEST_F(PchCreatorVerySlowTest, ProjectPartPchsExistsAfterCreation) creator.generateProjectPartPch(projectPart1); - ASSERT_TRUE(QFileInfo::exists(creator.generateProjectPathPchHeaderFilePath(projectPart1))); + ASSERT_TRUE(QFileInfo::exists(QString(creator.generateProjectPathPchHeaderFilePath(projectPart1)))); } TEST_F(PchCreatorVerySlowTest, DISABLED_CreatePartPchs) @@ -340,7 +340,7 @@ TEST_F(PchCreator, CreateProjectPartHeaderAndSourcesContent) "#include \"" TESTDATA_DIR "/includecollector_main3.cpp\"\n")); } -uint PchCreator::id(const Utils::SmallString &path) +uint PchCreator::id(const Utils::PathString &path) { return filePathCache.stringId(path); } diff --git a/tests/unit/unittest/pchmanagerclient-test.cpp b/tests/unit/unittest/pchmanagerclient-test.cpp index 6e0ac27101e470144ee648959e238f544ad072fc..3f26243cc594c66d66a55a93fea6fdd34b5c0e45 100644 --- a/tests/unit/unittest/pchmanagerclient-test.cpp +++ b/tests/unit/unittest/pchmanagerclient-test.cpp @@ -86,7 +86,8 @@ TEST_F(PchManagerClient, Remove) EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderRemoved(projectPartId.toQString())) .Times(2); - projectUpdater.removeProjectParts({projectPartId.clone(), projectPartId.clone()}); + projectUpdater.removeProjectParts({QString(projectPartId.clone()), + QString(projectPartId.clone())}); } } diff --git a/tests/unit/unittest/projectupdater-test.cpp b/tests/unit/unittest/projectupdater-test.cpp index 39ddc4ff145db7940caca106f7dd87e9888a35e4..98cb1b05d8d6e3b7624217ac04a42220b891c5d6 100644 --- a/tests/unit/unittest/projectupdater-test.cpp +++ b/tests/unit/unittest/projectupdater-test.cpp @@ -65,10 +65,10 @@ protected: Utils::SmallString projectPartId2{"project2"}; Utils::PathStringVector headerPaths = {"/path/to/header1.h", "/path/to/header2.h"}; Utils::PathStringVector sourcePaths = {"/path/to/source1.cpp", "/path/to/source2.cpp"}; - CppTools::ProjectFile header1ProjectFile{headerPaths[0], CppTools::ProjectFile::CXXHeader}; - CppTools::ProjectFile header2ProjectFile{headerPaths[1], CppTools::ProjectFile::CXXHeader}; - CppTools::ProjectFile source1ProjectFile{sourcePaths[0], CppTools::ProjectFile::CXXSource}; - CppTools::ProjectFile source2ProjectFile{sourcePaths[1], CppTools::ProjectFile::CXXSource}; + CppTools::ProjectFile header1ProjectFile{QString(headerPaths[0]), CppTools::ProjectFile::CXXHeader}; + CppTools::ProjectFile header2ProjectFile{QString(headerPaths[1]), CppTools::ProjectFile::CXXHeader}; + CppTools::ProjectFile source1ProjectFile{QString(sourcePaths[0]), CppTools::ProjectFile::CXXSource}; + CppTools::ProjectFile source2ProjectFile{QString(sourcePaths[1]), CppTools::ProjectFile::CXXSource}; CppTools::ProjectPart projectPart; ProjectPartContainer expectedContainer; FileContainer generatedFile{{"/path/to", "header1.h"}, "content", {}}; @@ -92,7 +92,7 @@ TEST_F(ProjectUpdater, CallRemovePchProjectParts) EXPECT_CALL(mockPchManagerServer, removePchProjectParts(message)); - updater.removeProjectParts({projectPartId, projectPartId2}); + updater.removeProjectParts({QString(projectPartId), QString(projectPartId2)}); } TEST_F(ProjectUpdater, CallPrecompiledHeaderRemoved) @@ -102,7 +102,7 @@ TEST_F(ProjectUpdater, CallPrecompiledHeaderRemoved) EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderRemoved(projectPartId.toQString())); EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderRemoved(projectPartId2.toQString())); - updater.removeProjectParts({projectPartId, projectPartId2}); + updater.removeProjectParts({QString(projectPartId), QString(projectPartId2)}); } TEST_F(ProjectUpdater, ConvertProjectPartToProjectPartContainer) @@ -134,7 +134,7 @@ void ProjectUpdater::SetUp() projectPart.files.push_back(header2ProjectFile); projectPart.files.push_back(source1ProjectFile); projectPart.files.push_back(source2ProjectFile); - projectPart.displayName = projectPartId; + projectPart.displayName = QString(projectPartId); Utils::SmallStringVector arguments{ClangPchManager::ProjectUpdater::compilerArguments( &projectPart)}; diff --git a/tests/unit/unittest/refactoringcompilationdatabase-test.cpp b/tests/unit/unittest/refactoringcompilationdatabase-test.cpp index 84f426cacd0a397468ff27596c449ad0167a8d7b..50d7773a63f06862cb558aad8d6a71e4cc5a62fc 100644 --- a/tests/unit/unittest/refactoringcompilationdatabase-test.cpp +++ b/tests/unit/unittest/refactoringcompilationdatabase-test.cpp @@ -69,7 +69,7 @@ TEST_F(RefactoringCompilationDatabase, GetAllFilesContainsTranslationUnit) { auto filePaths = database.getAllFiles(); - ASSERT_THAT(filePaths, Contains(temporarySourceFilePath)); + ASSERT_THAT(filePaths, Contains(std::string(temporarySourceFilePath))); } TEST_F(RefactoringCompilationDatabase, CompileCommandForFilePath) @@ -94,12 +94,12 @@ TEST_F(RefactoringCompilationDatabase, FilePaths) { auto filePaths = database.getAllFiles(); - ASSERT_THAT(filePaths, Contains(temporarySourceFilePath)); + ASSERT_THAT(filePaths, Contains(std::string(temporarySourceFilePath))); } void RefactoringCompilationDatabase::SetUp() { - database.addFile(temporaryDirectoryPath, "data.cpp", {"cc", "data.cpp", "-DNO_DEBUG"}); + database.addFile(std::string(temporaryDirectoryPath), "data.cpp", {"cc", "data.cpp", "-DNO_DEBUG"}); } } diff --git a/tests/unit/unittest/sourcerangeextractor-test.cpp b/tests/unit/unittest/sourcerangeextractor-test.cpp index 8bf676b796211f77a6b01140c1ce0ff2dc679d7a..42f2f0f724662ad62d47ce475bc694fd5528abd1 100644 --- a/tests/unit/unittest/sourcerangeextractor-test.cpp +++ b/tests/unit/unittest/sourcerangeextractor-test.cpp @@ -86,7 +86,7 @@ TEST_F(SourceRangeExtractorSlowTest, FindStartOfLineInEmptyBuffer) auto found = ::SourceRangeExtractor::findStartOfLineInBuffer(text, 0); - ASSERT_THAT(found, StrEq("")); + ASSERT_THAT(found, Eq("")); } TEST_F(SourceRangeExtractorSlowTest, FindStartOfLineInBufferInFirstLine) @@ -95,7 +95,7 @@ TEST_F(SourceRangeExtractorSlowTest, FindStartOfLineInBufferInFirstLine) auto found = ::SourceRangeExtractor::findStartOfLineInBuffer(text, 5); - ASSERT_THAT(found, StrEq("first line")); + ASSERT_THAT(found, Eq("first line")); } TEST_F(SourceRangeExtractorSlowTest, FindStartOfNewLineInBufferInSecondLine) @@ -167,7 +167,7 @@ TEST_F(SourceRangeExtractorSlowTest, EpandText) auto expandedText = ::SourceRangeExtractor::getExpandedText(text, 15, 25); - ASSERT_THAT(expandedText, StrEq("second line\nthird line")); + ASSERT_THAT(expandedText, Eq("second line\nthird line")); } void SourceRangeExtractor::SetUp() diff --git a/tests/unit/unittest/unittest-matchers.h b/tests/unit/unittest/unittest-matchers.h new file mode 100644 index 0000000000000000000000000000000000000000..4e9fc6568d1110cf72d12079f9dae89298c414b9 --- /dev/null +++ b/tests/unit/unittest/unittest-matchers.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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 <gmock/gmock-matchers.h> + +#include <utils/smallstringio.h> + +namespace UnitTests { + +template <typename StringType> +class EndsWithMatcher +{ + public: + explicit EndsWithMatcher(const StringType& suffix) : m_suffix(suffix) {} + + + template <typename CharType> + bool MatchAndExplain(CharType *s, testing::MatchResultListener *listener) const + { + return s != NULL && MatchAndExplain(StringType(s), listener); + } + + + template <typename MatcheeStringType> + bool MatchAndExplain(const MatcheeStringType& s, + testing::MatchResultListener* /* listener */) const + { + return s.endsWith(m_suffix); + } + + void DescribeTo(::std::ostream* os) const + { + *os << "ends with " << m_suffix; + } + + void DescribeNegationTo(::std::ostream* os) const + { + *os << "doesn't end with " << m_suffix; + } + + EndsWithMatcher(EndsWithMatcher const &) = default; + EndsWithMatcher &operator=(EndsWithMatcher const &) = delete; + +private: + const StringType m_suffix; +}; + +inline +testing::PolymorphicMatcher<EndsWithMatcher<Utils::SmallString> > +EndsWith(const Utils::SmallString &suffix) +{ + return testing::MakePolymorphicMatcher(EndsWithMatcher<Utils::SmallString>(suffix)); +} +}