File: testhelpers.h

package info (click to toggle)
kdevelop 4%3A25.04.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 73,508 kB
  • sloc: cpp: 291,803; python: 4,322; javascript: 3,518; sh: 1,316; ansic: 703; xml: 414; php: 95; lisp: 66; makefile: 31; sed: 12
file content (119 lines) | stat: -rw-r--r-- 4,180 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
    SPDX-FileCopyrightText: 2006 Andreas Pakulat <apaku@gmx.de>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#ifndef QMAKETESTMACROS_H
#define QMAKETESTMACROS_H

namespace QMake{
    class StatementAST;
}

template <typename T> class QList;

#define FUNCDEF( funcname )\
        void  funcname();\
        void  funcname##_data();

#define DATAFUNCIMPL( classname, funcname, data ) \
void classname::funcname##_data()\
{\
    QTest::addColumn<QString>( "project" );\
    QTest::addColumn<QString>( "output" );\
    QTest::newRow( "row1" ) << data << data; \
}

#define BEGINTESTFUNCIMPL( classname, funcname, astcount ) \
void classname::funcname()\
{\
    qDebug() << "Beginning Test Function"; \
    QFETCH( QString, project );\
    QMake::Driver d; \
    d.setContent( project ); \
    bool ret = d.parse( &ast );\
    QVERIFY( ret );\
    QVERIFY( ast->statements.count() == astcount );

#define BEGINTESTFAILFUNCIMPL( classname, funcname, comment ) \
void classname::funcname()\
{\
    qDebug() << "Beginning Test FAIL Function"; \
    QFETCH( QString, project );\
    QMake::Driver d; \
    d.setContent( project ); \
    bool ret = d.parse( &ast );\
    QEXPECT_FAIL( "", comment, Continue );\
    QVERIFY( ret );


#define ENDTESTFUNCIMPL }

#define TESTASSIGNMENT( ast, var, opval, valcount ) \
    QVERIFY( ast != nullptr );\
    QVERIFY( ast->identifier->value == var );\
    QVERIFY( ast->op->value == opval );\
    QVERIFY( ast->values.count() == valcount );

#define TESTFUNCNAME( scopeast, funcname ) \
    QVERIFY( scopeast ); \
    if( QMake::SimpleScopeAST* simpleast = dynamic_cast<QMake::SimpleScopeAST*>( scopeast ) ) \
    { \
        QVERIFY( simpleast->identifier->value == funcname );\
    } else if( QMake::FunctionCallAST* funast = dynamic_cast<QMake::FunctionCallAST*>( scopeast ) ) \
    { \
        QVERIFY( funast->identifier->value == funcname );\
    }

#define TESTSCOPENAME( scopeast, scopename ) \
    QVERIFY( scopeast ); \
    QVERIFY( scopeast->identifier->value == scopename );

#define TESTOROP( scopeast, funclist ) \
    for( int i = 0; i < funclist.size(); i++) \
    {\
        QVERIFY( i < scopeast->scopes.count() );\
        if( QMake::SimpleScopeAST* simpleast = dynamic_cast<QMake::SimpleScopeAST*>( scopeast->scopes.at(i) ) ) \
        { \
            QVERIFY( simpleast->identifier->value == funclist.at(i) );\
        } else if( QMake::FunctionCallAST* funast = dynamic_cast<QMake::FunctionCallAST*>( scopeast->scopes.at(i) ) ) \
        { \
            QVERIFY( funast->identifier->value == funclist.at(i) );\
        } \
    }

#define TESTSCOPEBODY(scope, teststmts, stmtcount)                                                                     \
    QVERIFY(scope->body != nullptr);                                                                                   \
    QVERIFY(scope->body->ifStatements.count() == stmtcount);                                                           \
    matchScopeBodies(scope->body->ifStatements, teststmts);                                                            \
    qDeleteAll(teststmts);

#define TESTSCOPEAST( scope, testscope ) \
    QVERIFY( scope ); \
    QVERIFY( testscope ); \
    QMake::SimpleScopeAST* simple = dynamic_cast<QMake::SimpleScopeAST*>( scope ); \
    QMake::SimpleScopeAST* testsimple = dynamic_cast<QMake::SimpleScopeAST*>( scope ); \
    QMake::FunctionCallAST* fun = dynamic_cast<QMake::FunctionCallAST*>( scope ); \
    QMake::FunctionCallAST* testfun = dynamic_cast<QMake::FunctionCallAST*>( scope ); \
    QVERIFY( ( simple && testsimple ) || ( fun && testfun ) ); \
    if( simple ) \
    { \
        QVERIFY( simple->identifier->value == testsimple->identifier->value ); \
    } else \
    { \
        QVERIFY( fun->identifier->value == testfun->identifier->value ); \
    }

#define TESTOROPAST(orop,testorop) \
    for(int i = 0; i < orop->scopes.count(); i++ ) \
    { \
        QVERIFY( i < testorop->scopes.count() ); \
        TESTSCOPEAST( orop->scopes.at(i), testorop->scopes.at(i) ) \
    }

void matchScopeBodies(const QList<QMake::StatementAST*>&,
                             const QList<QMake::StatementAST*>& );

#endif