• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KHTML

parser_tester.cpp

Go to the documentation of this file.
00001 /*
00002  * parser_tester.cc - Copyright 2005 Frerich Raabe <raabe@kde.org>
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  * 
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 
00014  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00015  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00016  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00017  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00018  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00019  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00020  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00021  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00022  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00023  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00024  */
00025 #include "parsedstatement.h"
00026 
00027 #include <QtXml/QDomDocument>
00028 #include <QtDebug>
00029 
00030 QString indentedTree( const QString &markup )
00031 {
00032     QDomDocument doc;
00033     doc.setContent( markup );
00034     return doc.toString( 2 );
00035 }
00036 
00037 void check( const QString &statement, const QString &expected )
00038 {
00039     QString result = ParsedStatement( statement ).dump();
00040     if ( indentedTree( result ) != indentedTree( expected ) ) {
00041         qDebug() << "ERROR! Failed to parse '" << statement << "' as expected!";
00042         qDebug() << "Expected:";
00043         qDebug() << indentedTree( expected );
00044         qDebug() << "Got:";
00045         qDebug() << indentedTree( result );
00046         exit( 1 );
00047     }
00048 }
00049 
00050 extern int xpathyydebug;
00051 int main()
00052 {
00053 //  xpathyydebug=1;
00054     check( "/book",
00055            "<locationpath absolute=\"true\"><step axis=\"child\" nodetest=\"book\"></step></locationpath>" );
00056     check( "book/self::chapter/@id",
00057            "<locationpath absolute=\"false\"><step axis=\"child\" nodetest=\"book\"></step><step axis=\"self\" nodetest=\"chapter\"></step><step axis=\"attribute\" nodetest=\"id\"></step></locationpath>" );
00058     check( "child[\"foo\"=\"bar\" ]",
00059            "<locationpath absolute=\"false\"><step axis=\"child\" nodetest=\"child\"><predicate><relationEQ><operand><string>foo</string></operand><operand><string>bar</string></operand></relationEQ></predicate></step></locationpath>" );
00060     check( "//parent[position() < last()-1]",
00061            "<locationpath absolute=\"true\"><step axis=\"descendant-or-self\" nodetest=\"node()\"></step><step axis=\"child\" nodetest=\"parent\"><predicate><relationLT><operand><function name=\"position\"/></operand><operand><subtraction><operand><function name=\"last\"/></operand><operand><number>1</number></operand></subtraction></predicate></step></locationpath>" );
00062     check( "/foo[true()][substring-after(\"First name=Joe\", \"=\") != \"Mary\"]",
00063            "<locationpath absolute=\"true\"><step axis=\"child\" nodetest=\"foo\"><predicate><function name=\"true\"/></predicate><predicate><relationNE><operand><function name=\"substring-after\"><operand><string>First name=Joe</string></operand><operand><string>=</string></operand></function></operand><operand><string>Mary</string></operand></relationNE></predicate></step></locationpath>" );
00064     check( "/foo[true()][substring-after(\"First name=Joe\", \"=\") != \"Mary\"]/child[false()][substring-before(\"First name=Joe\", '=') != 'Mary']",
00065            "<locationpath absolute=\"true\"><step axis=\"child\" nodetest=\"foo\"><predicate><function name=\"true\"/></predicate><predicate><relationNE><operand><function name=\"substring-after\"><operand><string>First name=Joe</string></operand><operand><string>=</string></operand></function></operand><operand><string>Mary</string></operand></relationNE></predicate></step> <step axis=\"child\" nodetest=\"child\"><predicate><function name=\"false\"/></predicate><predicate><relationNE><operand><function name=\"substring-before\"><operand><string>First name=Joe</string></operand><operand><string>=</string></operand></function></operand><operand><string>Mary</string></operand></relationNE></predicate></step></locationpath>" );
00066     check( "following::this[@that]",
00067            "<locationpath absolute=\"false\"><step axis=\"following\" nodetest=\"this\"><predicate><locationpath absolute=\"false\"><step axis=\"attribute\" nodetest=\"that\"/></locationpath></predicate></step></locationpath>" );
00068     check( "descendant::para[@type != $type]",
00069            "<locationpath absolute=\"false\"><step axis=\"descendant\" nodetest=\"para\"><predicate><relationNE><operand><locationpath absolute=\"false\"><step axis=\"attribute\" nodetest=\"type\"></step></locationpath></operand><operand><variablereference name=\"type\"/></operand></relationNE></predicate></step></locationpath>" );
00070     check( "child::processing-instruction()",
00071            "<locationpath absolute=\"false\"><step axis=\"child\" nodetest=\"processing-instruction\"/></locationpath>" );
00072     check( "child::processing-instruction(\"someParameter\")",
00073            "<locationpath absolute=\"false\"><step axis=\"child\" nodetest=\"processing-instruction someParameter\"/></locationpath>" );
00074     check( "*",
00075            "<locationpath absolute=\"false\"><step axis=\"child\" nodetest=\"*\"/></locationpath>" );
00076     check( "comment()",
00077            "<locationpath absolute=\"false\"><step axis=\"child\" nodetest=\"comment()\"/></locationpath>" );
00078     check( "comment() | text() | processing-instruction() | node()",
00079            "<union><operand><union><operand><union><operand><locationpath absolute=\"false\"><step nodetest=\"comment()\" axis=\"child\"/></locationpath></operand><operand><locationpath absolute=\"false\"><step axis=\"child\" nodetest=\"text()\"/></locationpath></operand></union></operand><operand><locationpath absolute=\"false\"><step axis=\"child\" nodetest=\"processing-instruction\"/></locationpath></operand></union></operand><operand><locationpath absolute=\"false\"><step axis=\"child\" nodetest=\"node()\"/></locationpath></operand></union>" );
00080     qDebug( "All OK!" );
00081 }
00082 

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal