testhelpers.cpp 3.59 KB
Newer Older
Andreas Pakulat's avatar
Andreas Pakulat committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/* KDevelop QMake Support
 *
 * Copyright 2006 Andreas Pakulat <apaku@gmx.de>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

#include "testhelpers.h"

#include <QtCore/QList>
24
#include <QtTest/QtTest>
Andreas Pakulat's avatar
Andreas Pakulat committed
25 26
#include "qmakeast.h"

27
void matchScopeBodies( QList<QMake::StatementAST*> realbody,
Andreas Pakulat's avatar
Andreas Pakulat committed
28 29
                             QList<QMake::StatementAST*> testbody )
{
30
    QVERIFY( realbody.count() == testbody.count() );
Andreas Pakulat's avatar
Andreas Pakulat committed
31 32 33 34 35 36 37 38 39 40
    int i = 0;
    QMake::AssignmentAST* assign;
    QMake::ScopeAST* scope;
    QMake::AssignmentAST* testassign;
    QMake::ScopeAST* testscope;

    foreach( QMake::StatementAST* ast, realbody )
    {
        scope = dynamic_cast<QMake::ScopeAST*>(ast);
        testscope = dynamic_cast<QMake::ScopeAST*>( testbody.at( i ) );
41

Andreas Pakulat's avatar
Andreas Pakulat committed
42 43
        if( scope && testscope )
        {
Andreas Pakulat's avatar
Andreas Pakulat committed
44 45 46 47 48 49 50 51 52 53
            QMake::FunctionCallAST* call = dynamic_cast<QMake::FunctionCallAST*>(scope);
            QMake::FunctionCallAST* testcall = dynamic_cast<QMake::FunctionCallAST*>(testscope);
            QMake::SimpleScopeAST* simple = dynamic_cast<QMake::SimpleScopeAST*>(scope);
            QMake::SimpleScopeAST* testsimple = dynamic_cast<QMake::SimpleScopeAST*>(testscope);
            QMake::OrAST* orop = dynamic_cast<QMake::OrAST*>(scope);
            QMake::OrAST* testorop = dynamic_cast<QMake::OrAST*>(testscope);
            QVERIFY( ( call && testcall )
                || ( simple && testsimple )
                || ( orop && testorop ) );
            if( call && testcall )
54
            {
55
                TESTFUNCNAME( call, testcall->functionName()->value() )
Andreas Pakulat's avatar
Andreas Pakulat committed
56 57 58 59 60
            }else if( simple && testsimple )
            {

            }else if( orop && testorop )
            {
61 62 63 64 65 66
                for(int i = 0; i < orop->scopes().count(); i++ )
                {
                    QVERIFY( i < testorop->scopes().count() );
                    TESTFUNCNAME( orop->scopes().at(i),
                                testorop->scopes().at(i)->identifier()->value() )
                }
67 68 69
            }
            QVERIFY( ( scope->scopeBody() && testscope->scopeBody() )
                        || ( !scope->scopeBody() && !testscope->scopeBody() ) );
Andreas Pakulat's avatar
Andreas Pakulat committed
70 71 72 73 74 75
            if( scope->scopeBody() && testscope->scopeBody() )
            {
                QList<QMake::StatementAST*> bodylist;
                QList<QMake::StatementAST*> testbodylist;
                bodylist = scope->scopeBody()->statements();
                testbodylist = testscope->scopeBody()->statements();
76
                matchScopeBodies( bodylist, testbodylist );
Andreas Pakulat's avatar
Andreas Pakulat committed
77 78 79 80 81 82
            }
        }
        assign = dynamic_cast<QMake::AssignmentAST*>(ast);
        testassign = dynamic_cast<QMake::AssignmentAST*>( testbody.at( i ) );
        if( assign && testassign )
        {
83 84
            TESTASSIGNMENT( assign, testassign->variable()->value(), testassign->op()->value(),
                            testassign->values().count() )
Andreas Pakulat's avatar
Andreas Pakulat committed
85 86 87 88
        }
        i++;
    }
}
89

90
// kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on; auto-insert-doxygen on