Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
KDevelop
KDevelop
Commits
b5b16f6a
Commit
b5b16f6a
authored
Oct 14, 2022
by
Igor Kushnir
Browse files
Test MacroDefinition
parent
df5d2822
Changes
2
Hide whitespace changes
Inline
Side-by-side
plugins/clang/tests/test_duchain.cpp
View file @
b5b16f6a
...
...
@@ -39,6 +39,7 @@
#include
"duchain/clangparsingenvironment.h"
#include
"duchain/parsesession.h"
#include
"duchain/clanghelpers.h"
#include
"duchain/macrodefinition.h"
#include
"testprovider.h"
...
...
@@ -48,6 +49,7 @@
#include
<QSignalSpy>
#include
<QLoggingCategory>
#include
<QThread>
#include
<QVector>
#include
<QVersionNumber>
QTEST_MAIN
(
TestDUChain
)
...
...
@@ -208,6 +210,65 @@ void TestDUChain::testElaboratedType_data()
<<
AbstractType
::
TypeAlias
;
}
void
TestDUChain
::
testMacroDefinition
()
{
QFETCH
(
QString
,
code
);
QFETCH
(
QString
,
definition
);
QFETCH
(
bool
,
isFunctionLike
);
QFETCH
(
QVector
<
QString
>
,
parameters
);
TestFile
file
(
code
,
QStringLiteral
(
"cpp"
));
QVERIFY
(
file
.
parseAndWait
());
DUChainReadLocker
lock
;
auto
top
=
file
.
topContext
();
QVERIFY
(
top
);
QCOMPARE
(
top
->
localDeclarations
().
size
(),
1
);
const
auto
decl
=
top
->
localDeclarations
().
constFirst
();
QVERIFY
(
decl
);
const
auto
macro
=
dynamic_cast
<
const
MacroDefinition
*>
(
decl
);
QVERIFY
(
macro
);
QCOMPARE
(
macro
->
definition
().
str
(),
definition
);
QCOMPARE
(
macro
->
isFunctionLike
(),
isFunctionLike
);
QCOMPARE
(
macro
->
parametersSize
(),
parameters
.
size
());
const
IndexedString
*
actualParam
=
macro
->
parameters
();
for
(
const
auto
&
expectedParam
:
parameters
)
{
QCOMPARE
(
actualParam
->
str
(),
expectedParam
);
++
actualParam
;
}
}
void
TestDUChain
::
testMacroDefinition_data
()
{
QTest
::
addColumn
<
QString
>
(
"code"
);
QTest
::
addColumn
<
QString
>
(
"definition"
);
QTest
::
addColumn
<
bool
>
(
"isFunctionLike"
);
QTest
::
addColumn
<
QVector
<
QString
>>
(
"parameters"
);
const
auto
addTest
=
[](
const
QString
&
code
,
const
QString
&
definition
,
bool
isFunctionLike
=
false
,
const
QVector
<
QString
>&
parameters
=
{})
{
QTest
::
addRow
(
"%s"
,
qPrintable
(
code
))
<<
QString
{
"#define "
+
code
}
<<
definition
<<
isFunctionLike
<<
parameters
;
};
addTest
(
"m1 1"
,
"1"
);
addTest
(
"m int x"
,
"int x"
);
addTest
(
"m (u + v)"
,
"(u + v)"
);
addTest
(
"mac(x) x"
,
"x"
,
true
,
{
"x"
});
addTest
(
"mc(u)
\t
u *2
\t
/ Limit"
,
"u *2
\t
/ Limit"
,
true
,
{
"u"
});
addTest
(
"XYZ_(...) __VA_ARGS__"
,
"__VA_ARGS__"
,
true
,
{
"..."
});
addTest
(
"m(x,
\t
y)
\t
x"
,
"x"
,
true
,
{
"x"
,
"y"
});
addTest
(
"m(x, y) x / y"
,
"x / y"
,
true
,
{
"x"
,
"y"
});
addTest
(
"M_N(X, ...) f(X __VA_OPT__(,) __VA_ARGS__)"
,
"f(X __VA_OPT__(,) __VA_ARGS__)"
,
true
,
{
"X"
,
"..."
});
}
void
TestDUChain
::
testInclude
()
{
TestFile
header
(
QStringLiteral
(
"int foo() { return 42; }
\n
"
),
QStringLiteral
(
"h"
));
...
...
plugins/clang/tests/test_duchain.h
View file @
b5b16f6a
...
...
@@ -33,6 +33,9 @@ private Q_SLOTS:
void
testElaboratedType
();
void
testElaboratedType_data
();
void
testMacroDefinition
();
void
testMacroDefinition_data
();
void
testInclude
();
void
testMissingInclude
();
void
testIncludeLocking
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment