1
/* KDevelop CMake Support
3
* Copyright 2006 Matt Rogers <mattr@kde.org>
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.
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.
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
21
#include "cmake_cmakecondition_test.h"
22
#include "cmakecondition.h"
23
#include <QStringList>
25
QTEST_MAIN( CMakeConditionTest )
27
CMakeConditionTest::CMakeConditionTest()
29
m_vars=new VariableMap();
30
m_vars->insert("TRUE", QStringList("TRUE"));
31
m_vars->insert("FALSE", QStringList("FALSE"));
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"));
38
m_vars->insert("CMAKE_CURRENT_SOURCE_DIR", QStringList("./"));
40
m_macros=new MacroMap();
44
m_macros->insert("testmacro", m);
47
CMakeConditionTest::~CMakeConditionTest()
53
void CMakeConditionTest::testGoodParse()
55
QFETCH( QStringList, expression );
56
QFETCH( bool, result );
58
CMakeProjectVisitor v(QString(), 0);
59
v.setVariableMap( m_vars );
60
v.setMacroMap( m_macros );
62
CMakeCondition cond(&v);
63
QCOMPARE( cond.condition(expression), result );
66
void CMakeConditionTest::testGoodParse_data()
68
QTest::addColumn<QStringList>( "expression" );
69
QTest::addColumn<bool>( "result" );
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;
84
QTest::newRow( "not+and+exists" ) << QString("NOT;ZERO;AND;EXISTS;./cmake-cmakecondition.exe").split(";") << true;
86
QTest::newRow( "not+and+exists" ) << QString("NOT;ZERO;AND;EXISTS;./cmake-cmakecondition").split(";") << true;
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;
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;
114
QTest::newRow( "case" ) << QString("NOT settings.kcfgc STREQUAL GENERATE_MOC AND NOT settings.kcfgc STREQUAL USE_RELATIVE_PATH").split(" ") << true;
117
void CMakeConditionTest::testBadParse()
119
QFETCH( QStringList, expression );
121
CMakeProjectVisitor v(QString(), 0);
122
v.setVariableMap( m_vars );
123
v.setMacroMap( m_macros );
125
CMakeCondition cond(&v);
126
QCOMPARE( cond.condition(expression), false );
129
void CMakeConditionTest::testBadParse_data()
131
QTest::addColumn<QStringList>( "expression" );
132
QTest::newRow( "missing operator" ) << QString("MATCHES STUFF").split(" ");
135
#include "cmake_cmakecondition_test.moc"