aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2020-10-08 12:35:14 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2020-10-09 08:06:56 +0000
commit2287def85e0b0a5415c879fc38dd3aeecf142185 (patch)
tree6ba9a25aa24343a3df65860ee1d3e728ebd6d61f /tests
parent94b9b33a17e3f7760cbbf9abd021984839106647 (diff)
clangbackend: Fix crash
We cannot assume that a Q_PROPERTY name is on the same line as the keyword. Fixes: QTCREATORBUG-24746 Change-Id: Ic2e02291e24c1abbaf72881b540a26c82899cb2c Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/unittest/data/highlightingmarks.cpp32
-rw-r--r--tests/unit/unittest/tokenprocessor-test.cpp36
2 files changed, 68 insertions, 0 deletions
diff --git a/tests/unit/unittest/data/highlightingmarks.cpp b/tests/unit/unittest/data/highlightingmarks.cpp
index 2476cabfb2..33dfbe91de 100644
--- a/tests/unit/unittest/data/highlightingmarks.cpp
+++ b/tests/unit/unittest/data/highlightingmarks.cpp
@@ -699,3 +699,35 @@ private:
template <int i, int j> struct S { };
template <int i> using spec = S<i, 1>;
spec<2> s;
+
+class Property {
+ Q_PROPERTY(
+
+ const
+
+ volatile
+
+ unsigned
+
+ long
+
+ long
+
+ *
+
+ prop
+
+ READ
+
+ getProp
+
+ WRITE
+
+ setProp
+
+ NOTIFY
+
+ propChanged
+
+ )
+};
diff --git a/tests/unit/unittest/tokenprocessor-test.cpp b/tests/unit/unittest/tokenprocessor-test.cpp
index 786b980f22..37c76d8ce6 100644
--- a/tests/unit/unittest/tokenprocessor-test.cpp
+++ b/tests/unit/unittest/tokenprocessor-test.cpp
@@ -146,6 +146,7 @@ public:
static void TearDownTestCase();
SourceRange sourceRange(uint line, uint columnEnd) const;
+ SourceRange sourceRangeMultiLine(uint firstLine, uint lastLine, uint columnEnd) const;
protected:
static Data *d;
@@ -1574,6 +1575,14 @@ TEST_F(TokenProcessor, QtPropertyName)
ASSERT_THAT(infos[8], HasOnlyType(HighlightingType::QtProperty));
}
+TEST_F(TokenProcessor, QtPropertyNameMultiLine)
+{
+ const auto infos = translationUnit.fullTokenInfosInRange(sourceRangeMultiLine(704, 732, 14));
+
+ ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::PreprocessorExpansion));
+ ASSERT_THAT(infos[8], HasOnlyType(HighlightingType::QtProperty));
+}
+
TEST_F(TokenProcessor, QtPropertyFunction)
{
const auto infos = translationUnit.fullTokenInfosInRange(sourceRange(599, 103));
@@ -1581,6 +1590,13 @@ TEST_F(TokenProcessor, QtPropertyFunction)
ASSERT_THAT(infos[10], HasOnlyType(HighlightingType::Function));
}
+TEST_F(TokenProcessor, QtPropertyFunctionMultiLine)
+{
+ const auto infos = translationUnit.fullTokenInfosInRange(sourceRangeMultiLine(704, 732, 14));
+
+ ASSERT_THAT(infos[10], HasOnlyType(HighlightingType::Function));
+}
+
TEST_F(TokenProcessor, QtPropertyInternalKeyword)
{
const auto infos = translationUnit.fullTokenInfosInRange(sourceRange(599, 103));
@@ -1588,6 +1604,13 @@ TEST_F(TokenProcessor, QtPropertyInternalKeyword)
ASSERT_THAT(infos[9], HasOnlyType(HighlightingType::Invalid));
}
+TEST_F(TokenProcessor, QtPropertyInternalKeywordMultiLine)
+{
+ const auto infos = translationUnit.fullTokenInfosInRange(sourceRangeMultiLine(704, 732, 14));
+
+ ASSERT_THAT(infos[9], HasOnlyType(HighlightingType::Invalid));
+}
+
TEST_F(TokenProcessor, QtPropertyLastToken)
{
const auto infos = translationUnit.fullTokenInfosInRange(sourceRange(599, 103));
@@ -1595,6 +1618,13 @@ TEST_F(TokenProcessor, QtPropertyLastToken)
ASSERT_THAT(infos[14], HasOnlyType(HighlightingType::Function));
}
+TEST_F(TokenProcessor, QtPropertyLastTokenMultiLine)
+{
+ const auto infos = translationUnit.fullTokenInfosInRange(sourceRangeMultiLine(704, 732, 14));
+
+ ASSERT_THAT(infos[14], HasOnlyType(HighlightingType::Function));
+}
+
TEST_F(TokenProcessor, QtPropertyType)
{
const auto infos = translationUnit.fullTokenInfosInRange(sourceRange(600, 46));
@@ -1747,4 +1777,10 @@ ClangBackEnd::SourceRange TokenProcessor::sourceRange(uint line, uint columnEnd)
return translationUnit.sourceRange(line, 1, line, columnEnd);
}
+ClangBackEnd::SourceRange TokenProcessor::sourceRangeMultiLine(uint firstLine, uint lastLine,
+ uint columnEnd) const
+{
+ return translationUnit.sourceRange(firstLine, 1, lastLine, columnEnd);
+}
+
}