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
Marco Bubke
flatpak-qt-creator
Commits
893dd21a
Commit
893dd21a
authored
Dec 15, 2008
by
Roberto Raggi
Browse files
Testing C++ initializer of function declarations.
parent
33bf1525
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/auto/cplusplus/ast/tst_ast.cpp
View file @
893dd21a
...
...
@@ -31,7 +31,7 @@ public:
private
slots
:
void
if_statement
();
void
if_else_statement
();
void
cpp_initializer
();
void
cpp_initializer
_or_function_declaration
();
};
void
tst_AST
::
if_statement
()
...
...
@@ -78,13 +78,89 @@ void tst_AST::if_else_statement()
QVERIFY
(
stmt
->
statement
!=
0
);
QCOMPARE
(
stmt
->
else_token
,
7U
);
QVERIFY
(
stmt
->
else_statement
!=
0
);
// check the `then' statement
ExpressionStatementAST
*
then_stmt
=
stmt
->
statement
->
asExpressionStatement
();
QVERIFY
(
then_stmt
!=
0
);
QVERIFY
(
then_stmt
->
expression
!=
0
);
QCOMPARE
(
then_stmt
->
semicolon_token
,
6U
);
SimpleNameAST
*
a_id_expr
=
then_stmt
->
expression
->
asSimpleName
();
QVERIFY
(
a_id_expr
!=
0
);
QCOMPARE
(
a_id_expr
->
identifier_token
,
5U
);
// check the `then' statement
ExpressionStatementAST
*
else_stmt
=
stmt
->
else_statement
->
asExpressionStatement
();
QVERIFY
(
else_stmt
!=
0
);
QVERIFY
(
else_stmt
->
expression
!=
0
);
QCOMPARE
(
else_stmt
->
semicolon_token
,
9U
);
SimpleNameAST
*
b_id_expr
=
else_stmt
->
expression
->
asSimpleName
();
QVERIFY
(
b_id_expr
!=
0
);
QCOMPARE
(
b_id_expr
->
identifier_token
,
8U
);
}
void
tst_AST
::
cpp_initializer
()
void
tst_AST
::
cpp_initializer
_or_function_declaration
()
{
QSharedPointer
<
TranslationUnit
>
unit
(
parseStatement
(
"QFileInfo fileInfo(foo);"
));
AST
*
ast
=
unit
->
ast
();
QVERIFY
(
ast
!=
0
);
DeclarationStatementAST
*
stmt
=
ast
->
asDeclarationStatement
();
QVERIFY
(
stmt
!=
0
);
QVERIFY
(
stmt
->
declaration
!=
0
);
SimpleDeclarationAST
*
simple_decl
=
stmt
->
declaration
->
asSimpleDeclaration
();
QVERIFY
(
simple_decl
!=
0
);
QVERIFY
(
simple_decl
->
decl_specifier_seq
!=
0
);
QVERIFY
(
simple_decl
->
decl_specifier_seq
->
next
==
0
);
QVERIFY
(
simple_decl
->
declarators
!=
0
);
QVERIFY
(
simple_decl
->
declarators
->
next
==
0
);
QCOMPARE
(
simple_decl
->
semicolon_token
,
6U
);
NamedTypeSpecifierAST
*
named_ty
=
simple_decl
->
decl_specifier_seq
->
asNamedTypeSpecifier
();
QVERIFY
(
named_ty
!=
0
);
QVERIFY
(
named_ty
->
name
!=
0
);
SimpleNameAST
*
simple_named_ty
=
named_ty
->
name
->
asSimpleName
();
QVERIFY
(
simple_named_ty
!=
0
);
QCOMPARE
(
simple_named_ty
->
identifier_token
,
1U
);
DeclaratorAST
*
declarator
=
simple_decl
->
declarators
->
declarator
;
QVERIFY
(
declarator
!=
0
);
QVERIFY
(
declarator
->
core_declarator
!=
0
);
QVERIFY
(
declarator
->
postfix_declarators
!=
0
);
QVERIFY
(
declarator
->
postfix_declarators
->
next
==
0
);
QVERIFY
(
declarator
->
initializer
==
0
);
DeclaratorIdAST
*
decl_id
=
declarator
->
core_declarator
->
asDeclaratorId
();
QVERIFY
(
decl_id
!=
0
);
QVERIFY
(
decl_id
->
name
!=
0
);
QVERIFY
(
decl_id
->
name
->
asSimpleName
()
!=
0
);
QCOMPARE
(
decl_id
->
name
->
asSimpleName
()
->
identifier_token
,
2U
);
FunctionDeclaratorAST
*
fun_declarator
=
declarator
->
postfix_declarators
->
asFunctionDeclarator
();
QVERIFY
(
fun_declarator
!=
0
);
QCOMPARE
(
fun_declarator
->
lparen_token
,
3U
);
QVERIFY
(
fun_declarator
->
parameters
!=
0
);
QCOMPARE
(
fun_declarator
->
rparen_token
,
5U
);
// check the formal arguments
ParameterDeclarationClauseAST
*
param_clause
=
fun_declarator
->
parameters
;
QVERIFY
(
param_clause
->
parameter_declarations
!=
0
);
QVERIFY
(
param_clause
->
parameter_declarations
->
next
==
0
);
QCOMPARE
(
param_clause
->
dot_dot_dot_token
,
0U
);
// check the parameter
ParameterDeclarationAST
*
param
=
param_clause
->
parameter_declarations
->
asParameterDeclaration
();
QVERIFY
(
param
->
type_specifier
!=
0
);
QVERIFY
(
param
->
type_specifier
->
next
==
0
);
QVERIFY
(
param
->
type_specifier
->
asNamedTypeSpecifier
()
!=
0
);
QVERIFY
(
param
->
type_specifier
->
asNamedTypeSpecifier
()
->
name
!=
0
);
QVERIFY
(
param
->
type_specifier
->
asNamedTypeSpecifier
()
->
name
->
asSimpleName
()
!=
0
);
QCOMPARE
(
param
->
type_specifier
->
asNamedTypeSpecifier
()
->
name
->
asSimpleName
()
->
identifier_token
,
4U
);
}
...
...
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