~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to projectmanagers/cmake/tests/cmake_cmakecondition_test.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* KDevelop CMake Support
 
2
 *
 
3
 * Copyright 2006 Matt Rogers <mattr@kde.org>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License
 
7
 * as published by the Free Software Foundation; either version 2
 
8
 * of the License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
18
 * 02110-1301, USA.
 
19
 */
 
20
 
 
21
#include "cmake_cmakecondition_test.h"
 
22
#include "cmakecondition.h"
 
23
#include <QStringList>
 
24
 
 
25
QTEST_MAIN( CMakeConditionTest )
 
26
 
 
27
CMakeConditionTest::CMakeConditionTest()
 
28
{
 
29
    m_vars=new VariableMap();
 
30
    m_vars->insert("TRUE", QStringList("TRUE"));
 
31
    m_vars->insert("FALSE", QStringList("FALSE"));
 
32
    
 
33
    m_vars->insert("EMPTY", QStringList());
 
34
    m_vars->insert("ZERO", QStringList("0"));
 
35
    m_vars->insert("ONE", QStringList("1"));
 
36
    m_vars->insert("EXP", QStringList("-llala -lexpression"));
 
37
    
 
38
    m_vars->insert("CMAKE_CURRENT_SOURCE_DIR", QStringList("./"));
 
39
    
 
40
    m_macros=new MacroMap();
 
41
    Macro m;
 
42
    m.name = "testmacro";
 
43
    m.isFunction=false;
 
44
    m_macros->insert("testmacro", m);
 
45
}
 
46
 
 
47
CMakeConditionTest::~CMakeConditionTest()
 
48
{
 
49
    delete m_vars;
 
50
    delete m_macros;
 
51
}
 
52
 
 
53
void CMakeConditionTest::testGoodParse()
 
54
{
 
55
    QFETCH( QStringList, expression );
 
56
    QFETCH( bool, result );
 
57
    
 
58
    CMakeProjectVisitor v(QString(), 0);
 
59
    v.setVariableMap( m_vars );
 
60
    v.setMacroMap( m_macros );
 
61
    
 
62
    CMakeCondition cond(&v);
 
63
    QCOMPARE( cond.condition(expression), result );
 
64
}
 
65
 
 
66
void CMakeConditionTest::testGoodParse_data()
 
67
{
 
68
    QTest::addColumn<QStringList>( "expression" );
 
69
    QTest::addColumn<bool>( "result" );
 
70
    
 
71
    QTest::newRow( "one" ) << QString("1").split(" ") << true;
 
72
    QTest::newRow( "undefinedvar" ) << QStringList("IAMUNDEFINED") << false;
 
73
    QTest::newRow( "variable check" ) << QStringList("ONE") << true;
 
74
    QTest::newRow( "false variable check" ) << QStringList("ZERO") << false;
 
75
    QTest::newRow( "not" ) << QString("NOT;ZERO").split(";") << true;
 
76
    QTest::newRow( "not1" ) << QString("NOT;ONE").split(";") << false;
 
77
    QTest::newRow( "and" ) << QString("ONE;AND;ONE").split(";") << true;
 
78
    QTest::newRow( "false+and" ) << QString("ZERO;AND;ONE").split(";") << false;
 
79
    QTest::newRow( "and+false" ) << QString("ONE;AND;ZERO").split(";") << false;
 
80
    QTest::newRow( "not+and" ) << QString("NOT;ZERO;AND;ONE").split(";") << true;
 
81
    QTest::newRow( "not+and+command" ) << QString("NOT;ZERO;AND;COMMAND;testmacro").split(";") << true;
 
82
    QTest::newRow( "not+and+command" ) << QString("COMMAND;add_library").split(";") << true;
 
83
#ifdef Q_OS_WIN
 
84
    QTest::newRow( "not+and+exists" ) << QString("NOT;ZERO;AND;EXISTS;./cmake-cmakecondition.exe").split(";") << true;
 
85
#else
 
86
    QTest::newRow( "not+and+exists" ) << QString("NOT;ZERO;AND;EXISTS;./cmake-cmakecondition").split(";") << true;
 
87
#endif
 
88
    QTest::newRow( "or" ) << QString("ONE;OR;ONE").split(";") << true;
 
89
    QTest::newRow( "false+or" ) << QString("ZERO;OR;ONE").split(";") << true;
 
90
    QTest::newRow( "false+or+false" ) << QString("ZERO;OR;ZERO").split(";") << false;
 
91
    QTest::newRow( "strequal" ) << QString("HOLA;STREQUAL;HOLA").split(";") << true;
 
92
    QTest::newRow( "not+streq" ) << QString("NOT;HOLA;STREQUAL;HOLA").split(";") << false;
 
93
    QTest::newRow( "not+or" ) << QString("NOT;ZERO;OR;ZERO").split(";") << true;
 
94
    QTest::newRow( "matches" ) << QString("-lapr-1;MATCHES;^-l").split(";") << true;
 
95
    QTest::newRow( "less" ) << QString("5;LESS;9").split(";") << true;
 
96
    QTest::newRow( "not+less" ) << QString("NOT;5;LESS;9").split(";") << false;
 
97
    QTest::newRow( "not+or+not" ) << QString("NOT;TRUE;OR;NOT;TRUE").split(";") << false;
 
98
    QTest::newRow( "empty" ) << QString("EMPTY").split(";") << false;
 
99
    QTest::newRow( "not+empty" ) << QString("NOT;EMPTY").split(";") << true;
 
100
    QTest::newRow( "empty+strequal" ) << QString("NOT;;STREQUAL;").split(";") << false;
 
101
    QTest::newRow( "weirdmatch" ) << QString("EXP MATCHES expression").split(" ") << true;
 
102
    QTest::newRow( "isabsolute+true" ) << QString("IS_ABSOLUTE /foo/bar").split(" ") << true;
 
103
    QTest::newRow( "isabsolute+false" ) << QString("IS_ABSOLUTE ../bar").split(" ") << false;
 
104
 
 
105
    //parentheses: 2.6.3
 
106
    QTest::newRow( "parenthese0" ) << QString("ONE AND ( NOT ZERO OR ZERO )").split(" ") << true;
 
107
    QTest::newRow( "parenthese01" ) << QString("ZERO AND ( ZERO OR ZERO )").split(" ") << false;
 
108
    QTest::newRow( "parenthese1" ) << QString("( ONE AND NOT ZERO ) OR ZERO").split(" ") << true;
 
109
    QTest::newRow( "parenthese2" ) << QString("( ZERO AND NOT ZERO ) OR ZERO").split(" ") << false;
 
110
    QTest::newRow( "parenthese3" ) << QString("( ZERO AND ZERO ) OR ONE").split(" ") << true;
 
111
    QTest::newRow( "parenthese4" ) << QString("( ZERO AND ZERO ) OR ZERO").split(" ") << false;
 
112
    QTest::newRow( "parenthese5" ) << QString("( ONE AND ZERO ) OR ( ZERO OR ONE )").split(" ") << true;
 
113
    
 
114
    QTest::newRow( "case" ) << QString("NOT settings.kcfgc STREQUAL GENERATE_MOC AND NOT settings.kcfgc STREQUAL USE_RELATIVE_PATH").split(" ") << true;
 
115
}
 
116
 
 
117
void CMakeConditionTest::testBadParse()
 
118
{
 
119
    QFETCH( QStringList, expression );
 
120
    
 
121
    CMakeProjectVisitor v(QString(), 0);
 
122
    v.setVariableMap( m_vars );
 
123
    v.setMacroMap( m_macros );
 
124
    
 
125
    CMakeCondition cond(&v);
 
126
    QCOMPARE( cond.condition(expression), false );
 
127
}
 
128
 
 
129
void CMakeConditionTest::testBadParse_data()
 
130
{
 
131
    QTest::addColumn<QStringList>( "expression" );
 
132
    QTest::newRow( "missing operator" ) << QString("MATCHES STUFF").split(" ");
 
133
}
 
134
 
 
135
#include "cmake_cmakecondition_test.moc"