F:/KPlato/koffice/libs/kofficecore/tests/kooasissettingstest.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 David Faure <faure@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016  * Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include <KoXmlReader.h>
00020 #include <KoOasisSettings.h>
00021 #include <KoDom.h>
00022 #include <kdebug.h>
00023 #include <assert.h>
00024 //Added by qt3to4:
00025 #include <Q3CString>
00026 
00027 void testSelectItemSet( KoOasisSettings& settings )
00028 {
00029     KoOasisSettings::Items items = settings.itemSet( "notexist" );
00030     assert( items.isNull() );
00031     items = settings.itemSet( "view-settings" );
00032     assert( !items.isNull() );
00033     kDebug() << "testSelectItemSet OK" << endl;
00034 }
00035 
00036 void testParseConfigItemString( KoOasisSettings& settings )
00037 {
00038     KoOasisSettings::Items viewSettings = settings.itemSet( "view-settings" );
00039     const QString unit = viewSettings.parseConfigItemString( "unit" );
00040     qDebug( "%s", qPrintable( unit ) );
00041     assert( unit == "mm" );
00042     kDebug() << "testParseConfigItemString OK" << endl;
00043 }
00044 
00045 void testIndexedMap( KoOasisSettings& settings )
00046 {
00047     KoOasisSettings::Items viewSettings = settings.itemSet( "view-settings" );
00048     assert( !viewSettings.isNull() );
00049     KoOasisSettings::IndexedMap viewMap = viewSettings.indexedMap( "Views" );
00050     assert( !viewMap.isNull() );
00051     KoOasisSettings::Items firstView = viewMap.entry( 0 );
00052     assert( !firstView.isNull() );
00053     const short zoomFactor = firstView.parseConfigItemShort( "ZoomFactor" );
00054     assert( zoomFactor == 100 );
00055     KoOasisSettings::Items secondView = viewMap.entry( 1 );
00056     assert( secondView.isNull() );
00057     kDebug() << "testIndexedMap OK" << endl;
00058 }
00059 
00060 void testNamedMap( KoOasisSettings& settings )
00061 {
00062     KoOasisSettings::Items viewSettings = settings.itemSet( "view-settings" );
00063     assert( !viewSettings.isNull() );
00064     KoOasisSettings::NamedMap viewMap = viewSettings.namedMap( "NamedMap" );
00065     assert( !viewMap.isNull() );
00066     KoOasisSettings::Items foo = viewMap.entry( "foo" );
00067     assert( !foo.isNull() );
00068     const int zoomFactor = foo.parseConfigItemShort( "ZoomFactor" );
00069     assert( zoomFactor == 100 );
00070     KoOasisSettings::Items secondView = viewMap.entry( "foobar" );
00071     assert( secondView.isNull() );
00072     kDebug() << "testNamedMap OK" << endl;
00073 }
00074 
00075 int main( int, char** ) {
00076 
00077     const Q3CString xml = "\
00078 <?xml version=\"1.0\" encoding=\"UTF-8\"?> \
00079 <office:document-settings xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" xmlns:config=\"urn:oasis:names:tc:opendocument:xmlns:config:1.0\"> \
00080  <office:settings> \
00081   <config:config-item-set config:name=\"view-settings\"> \
00082     <config:config-item config:name=\"unit\" config:type=\"string\">mm</config:config-item> \
00083     <config:config-item-map-indexed config:name=\"Views\"> \
00084       <config:config-item-map-entry> \
00085         <config:config-item config:name=\"ZoomFactor\" config:type=\"short\">100</config:config-item> \
00086       </config:config-item-map-entry> \
00087     </config:config-item-map-indexed> \
00088     <config:config-item-map-named config:name=\"NamedMap\"> \
00089       <config:config-item-map-entry config:name=\"foo\"> \
00090         <config:config-item config:name=\"ZoomFactor\" config:type=\"int\">100</config:config-item> \
00091       </config:config-item-map-entry> \
00092     </config:config-item-map-named> \
00093   </config:config-item-set> \
00094  </office:settings> \
00095 </office:document-settings> \
00096 ";
00097 
00098     KoXmlDocument doc;
00099     bool ok = doc.setContent( xml, true /* namespace processing */ );
00100     assert( ok );
00101 
00102     KoOasisSettings settings( doc );
00103 
00104     testSelectItemSet( settings );
00105     testParseConfigItemString( settings );
00106     testIndexedMap( settings );
00107     testNamedMap( settings );
00108     return 0;
00109 }

Généré le Wed Nov 22 23:41:04 2006 pour KPlato par  doxygen 1.5.1-p1