F:/KPlato/koffice/libs/kotext/styles/tests/TestStyles.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KOffice project
00002  * Copyright (C) 2006 Thomas Zander <zander@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 as published by the Free Software Foundation; version 2.
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 #include "TestStyles.h"
00019 
00020 #include <styles/KoParagraphStyle.h>
00021 #include <QDebug>
00022 
00023 void TestStyles::testStyleInheritance() {
00024     KoParagraphStyle style1;
00025     style1.setTopMargin(10.0);
00026     QCOMPARE(style1.topMargin(), 10.0);
00027 
00028     KoParagraphStyle style2;
00029     style2.setParent(&style1);
00030 
00031     QCOMPARE(style2.topMargin(), 10.0);
00032     style2.setTopMargin(20.0);
00033     QCOMPARE(style2.topMargin(), 20.0);
00034     QCOMPARE(style1.topMargin(), 10.0);
00035 
00036     style1.setTopMargin(15.0);
00037     QCOMPARE(style2.topMargin(), 20.0);
00038     QCOMPARE(style1.topMargin(), 15.0);
00039 
00040     style2.setTopMargin(15.0); // the same, resetting the difference.
00041     QCOMPARE(style2.topMargin(), 15.0);
00042     QCOMPARE(style1.topMargin(), 15.0);
00043 
00044     style1.setTopMargin(12.0); // parent, so both are affected
00045     QCOMPARE(style2.topMargin(), 12.0);
00046     QCOMPARE(style1.topMargin(), 12.0);
00047 }
00048 
00049 void TestStyles::testChangeParent() {
00050     KoParagraphStyle style1;
00051     style1.setTopMargin(10);
00052 
00053     KoParagraphStyle style2;
00054     style2.setTopMargin(20);
00055 
00056     style2.setParent(&style1);
00057     QCOMPARE(style1.topMargin(), 10.0);
00058     QCOMPARE(style2.topMargin(), 20.0);
00059 
00060     KoParagraphStyle style3;
00061     style3.setParent(&style1);
00062     QCOMPARE(style1.topMargin(), 10.0);
00063     QCOMPARE(style3.topMargin(), 10.0);
00064 
00065     // test that separating will leave the child with exactly the same dataset
00066     style3.setParent(0);
00067     QCOMPARE(style1.topMargin(), 10.0);
00068     QCOMPARE(style3.topMargin(), 10.0);
00069 
00070     // test adding it to another will not destroy any data
00071     style3.setParent(&style1);
00072     QCOMPARE(style1.topMargin(), 10.0);
00073     QCOMPARE(style2.topMargin(), 20.0);
00074     QCOMPARE(style3.topMargin(), 10.0);
00075 
00076     // Due to the "don't destroy data" above style3 will no longer follow any parent.
00077     style3.setParent(&style2);
00078     QCOMPARE(style3.topMargin(), 10.0);
00079 }
00080 
00081 QTEST_MAIN(TestStyles)
00082 #include "TestStyles.moc"

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