~ubuntu-branches/ubuntu/gutsy/soprano/gutsy

« back to all changes in this revision

Viewing changes to test/errortest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-10-12 14:43:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071012144348-yajzi51v4k23ahxf
Tags: 1.95.0~beta2-1ubuntu1
* Sync with Debian
* Add versioned build-dep on raptor

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of Soprano Project.
 
3
 *
 
4
 * Copyright (C) 2007 Sebastian Trueg <trueg@kde.org>
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Library General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Library General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Library General Public License
 
17
 * along with this library; see the file COPYING.LIB.  If not, write to
 
18
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
19
 * Boston, MA 02110-1301, USA.
 
20
 */
 
21
 
 
22
#include "errortest.h"
 
23
#include "../soprano/error.h"
 
24
#include "../soprano/locator.h"
 
25
 
 
26
#include <QtTest/QTest>
 
27
#include <QtCore/QDebug>
 
28
 
 
29
using namespace Soprano::Error;
 
30
 
 
31
void ErrorTest::testErrorCopy()
 
32
{
 
33
    Error e1( "e1", 2 );
 
34
    Error e2( e1 );
 
35
 
 
36
    QCOMPARE( e1.message(), QString( "e1" ) );
 
37
    QCOMPARE( e1.code(), 2 );
 
38
 
 
39
    QCOMPARE( e1.message(), e2.message() );
 
40
    QCOMPARE( e1.code(), e2.code() );
 
41
}
 
42
 
 
43
void ErrorTest::testOperator()
 
44
{
 
45
    Error e1( "e1", 2 );
 
46
    Error e2 = e1;
 
47
 
 
48
    QCOMPARE( e1.message(), e2.message() );
 
49
    QCOMPARE( e1.code(), e2.code() );
 
50
 
 
51
    Error error;
 
52
    error = Error( "test error" );
 
53
 
 
54
    QCOMPARE( error.message(), QString( "test error" ) );
 
55
    QCOMPARE( error.code(), ( int )error.code() );
 
56
}
 
57
 
 
58
 
 
59
static const int line = 4;
 
60
static const int col = 9;
 
61
 
 
62
void ErrorTest::testParserErrorCopy()
 
63
{
 
64
    ParserError p1( Locator( line, col ), "p1" );
 
65
    ParserError p2( p1 );
 
66
 
 
67
    QCOMPARE( p1.message(), QString( "p1" ) );
 
68
    QCOMPARE( p1.code(), ( int )Soprano::Error::ErrorParsingFailed );
 
69
    QCOMPARE( p1.locator().line(), line );
 
70
    QCOMPARE( p1.locator().column(), col );
 
71
 
 
72
    QCOMPARE( p1.message(), p2.message() );
 
73
    QCOMPARE( p1.code(), p2.code() );
 
74
    QCOMPARE( p1.locator().line(), p2.locator().line() );
 
75
    QCOMPARE( p1.locator().column(), p2.locator().column() );
 
76
}
 
77
 
 
78
void ErrorTest::testParserErrorOperator()
 
79
{
 
80
    ParserError p1( Locator( line, col ), "p1" );
 
81
    ParserError p2 = p1;
 
82
 
 
83
    QCOMPARE( p1.message(), QString( "p1" ) );
 
84
    QCOMPARE( p1.code(), ( int )Soprano::Error::ErrorParsingFailed );
 
85
    QCOMPARE( p1.locator().line(), line );
 
86
    QCOMPARE( p1.locator().column(), col );
 
87
 
 
88
    QCOMPARE( p1.message(), p2.message() );
 
89
    QCOMPARE( p1.code(), p2.code() );
 
90
    QCOMPARE( p1.locator().line(), p2.locator().line() );
 
91
    QCOMPARE( p1.locator().column(), p2.locator().column() );
 
92
}
 
93
 
 
94
void ErrorTest::testParserErrorConversion()
 
95
{
 
96
    ParserError p1( Locator( line, col ), "p1" );
 
97
    Error ep1 = p1;
 
98
 
 
99
    QCOMPARE( p1.message(), ep1.message() );
 
100
    QCOMPARE( p1.code(), ep1.code() );
 
101
 
 
102
    ParserError pep1 = ep1;
 
103
 
 
104
    QCOMPARE( p1.message(), pep1.message() );
 
105
    QCOMPARE( p1.code(), pep1.code() );
 
106
    QCOMPARE( p1.locator().line(), pep1.locator().line() );
 
107
    QCOMPARE( p1.locator().column(), pep1.locator().column() );
 
108
}
 
109
 
 
110
QTEST_MAIN( ErrorTest )
 
111
 
 
112
#include "errortest.moc"