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

« back to all changes in this revision

Viewing changes to projectmanagers/cmake/tests/cmakeparsertest.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 "cmakeparsertest.h"
 
22
 
 
23
#include <KTemporaryFile>
 
24
#include "cmListFileLexer.h"
 
25
#include "cmakelistsparser.h"
 
26
#include "cmakeast.h"
 
27
 
 
28
QTEST_MAIN( CMakeParserTest )
 
29
 
 
30
CMakeParserTest::CMakeParserTest()
 
31
{}
 
32
 
 
33
CMakeParserTest::~CMakeParserTest()
 
34
{}
 
35
 
 
36
void CMakeParserTest::testLexerCreation()
 
37
{
 
38
    cmListFileLexer* lexer = cmListFileLexer_New();
 
39
    QVERIFY( lexer != 0 );
 
40
    cmListFileLexer_Delete( lexer );
 
41
}
 
42
 
 
43
void CMakeParserTest::testLexerWithFile()
 
44
{
 
45
    QTemporaryFile tempFile;
 
46
    tempFile.setAutoRemove( false );
 
47
    tempFile.open();
 
48
    if ( !QFile::exists( tempFile.fileName() ) )
 
49
         QFAIL( "Unable to open temporary file" );
 
50
 
 
51
    QString tempName = tempFile.fileName();
 
52
    tempFile.close(); //hacks to the get name of the file
 
53
 
 
54
    cmListFileLexer* lexer = cmListFileLexer_New();
 
55
    if ( !lexer )
 
56
        QFAIL( "unable to create lexer" );
 
57
    QVERIFY( cmListFileLexer_SetFileName( lexer, qPrintable( tempName ) ) );
 
58
    cmListFileLexer_Delete( lexer );
 
59
    tempFile.remove();
 
60
}
 
61
 
 
62
void CMakeParserTest::testParserWithGoodData()
 
63
{
 
64
//    QFAIL( "the magic is missing" );
 
65
    QFETCH( QString, text );
 
66
    QTemporaryFile tempFile;
 
67
    tempFile.setAutoRemove( false );
 
68
    tempFile.open();
 
69
    if ( !QFile::exists( tempFile.fileName() ) )
 
70
        QFAIL( "Unable to open temporary file" );
 
71
 
 
72
    tempFile.write( text.toUtf8() );
 
73
    QString tempName = tempFile.fileName();
 
74
    tempFile.close(); //hacks to the get name of the file
 
75
//    CMakeAst* ast = new CMakeAst;
 
76
//    bool parseError = CMakeListsParser::parseCMakeFile( ast, qPrintable( tempName ) );
 
77
//    delete ast;
 
78
//    QVERIFY( parseError == false );
 
79
    tempFile.remove();
 
80
}
 
81
 
 
82
void CMakeParserTest::testParserWithGoodData_data()
 
83
{
 
84
    QTest::addColumn<QString>( "text" );
 
85
    QTest::newRow( "good data1" ) << "project(foo)\nset(foobar_SRCS foo.h foo.c)";
 
86
    QTest::newRow( "good data2" ) << "set(foobar_SRCS foo.h foo.c)\n"
 
87
                                     "add_executable( foo ${foobar_SRCS})";
 
88
}
 
89
 
 
90
void CMakeParserTest::testParserWithBadData()
 
91
{
 
92
    QFETCH( QString, text );
 
93
    QTemporaryFile tempFile;
 
94
    tempFile.setAutoRemove( false );
 
95
    tempFile.open();
 
96
    if ( !QFile::exists( tempFile.fileName() ) )
 
97
        QFAIL( "Unable to open temporary file" );
 
98
 
 
99
    tempFile.write( text.toUtf8() );
 
100
    QString tempName = tempFile.fileName();
 
101
    tempFile.close(); //hacks to the get name of the file
 
102
//    CMakeAst* ast = new CMakeAst;
 
103
//    bool parseError = CMakeListsParser::parseCMakeFile( ast, qPrintable( tempName ) );
 
104
//    delete ast;
 
105
//    QVERIFY( parseError == true );
 
106
    tempFile.remove();
 
107
}
 
108
 
 
109
void CMakeParserTest::testParserWithBadData_data()
 
110
{
 
111
    QTest::addColumn<QString>( "text" );
 
112
 
 
113
    //just plain wrong. :)
 
114
    QTest::newRow( "bad data 1" ) << "foo bar baz zippedy do dah";
 
115
 
 
116
    //missing right parenthesis
 
117
    QTest::newRow( "bad data 2" ) << "set(mysrcs_SRCS foo.c\n\n\n";
 
118
 
 
119
    //extra identifiers between functions. cmake doesn't allow plain identifiers
 
120
    QTest::newRow( "bad data 3" ) << "the(quick) brown fox jumped(over) the lazy dog";
 
121
 
 
122
    //invalid due to no newline before next command
 
123
    QTest::newRow( "bad data 4" ) << "project(foo) set(mysrcs_SRCS foo.c)";
 
124
}
 
125
 
 
126
// void CMakeParserTest::testAstCreation()
 
127
// {
 
128
 
 
129
// }
 
130
 
 
131
#include "cmakeparsertest.moc"
 
132