Commit 94aba11d authored by Albert Astals Cid's avatar Albert Astals Cid

Bring back unit test improvements from the KConfig repo

REVIEW: 121879
parent 559c53a8
......@@ -23,12 +23,12 @@
#include <kconfig.h>
#include <kdebug.h>
#include <kstandarddirs.h>
#include <QtGui/QFont>
QTEST_KDEMAIN( KConfigSkeletonTest, GUI )
#define DEFAULT_SETTING1 false
#define DEFAULT_SETTING2 QColor(1,2,3)
#define DEFAULT_SETTING3 QFont("helvetica",12)
......@@ -39,61 +39,96 @@ QTEST_KDEMAIN( KConfigSkeletonTest, GUI )
#define WRITE_SETTING3 QFont("helvetica",14)
#define WRITE_SETTING4 QString("KDE")
void KConfigSkeletonTest::init()
{
const QString path = KStandardDirs::locateLocal("config", "kconfigskeletontestrc");
QFile::remove(path);
s = new KConfigSkeleton("kconfigskeletontestrc");
s->setCurrentGroup("MyGroup");
itemBool = s->addItemBool("MySetting1", mMyBool, DEFAULT_SETTING1);
s->addItemColor("MySetting2", mMyColor, DEFAULT_SETTING2);
s->setCurrentGroup("MyOtherGroup");
s->addItemFont("MySetting3", mMyFont, DEFAULT_SETTING3);
s->addItemString("MySetting4", mMyString, DEFAULT_SETTING4);
QCOMPARE(mMyBool, DEFAULT_SETTING1);
QCOMPARE(mMyColor, DEFAULT_SETTING2);
QCOMPARE(mMyFont, DEFAULT_SETTING3);
QCOMPARE(mMyString, DEFAULT_SETTING4);
}
void KConfigSkeletonTest::cleanup()
{
delete s;
}
void KConfigSkeletonTest::initTestCase()
void KConfigSkeletonTest::testSimple()
{
mMyBool = WRITE_SETTING1;
mMyColor = WRITE_SETTING2;
mMyFont = WRITE_SETTING3;
mMyString = WRITE_SETTING4;
setCurrentGroup("MyGroup");
addItemBool("MySetting1",mMyBool,DEFAULT_SETTING1);
addItemColor("MySetting2",mMyColor,DEFAULT_SETTING2);
s->writeConfig();
setCurrentGroup("MyOtherGroup");
addItemFont("MySetting3",mMyFont,DEFAULT_SETTING3);
addItemString("MySetting4",mMyString,DEFAULT_SETTING4);
mMyBool = false;
mMyColor = QColor();
mMyString.clear();
mMyFont = QFont();
QCOMPARE( mMyBool, DEFAULT_SETTING1 );
QCOMPARE( mMyColor, DEFAULT_SETTING2 );
QCOMPARE( mMyFont, DEFAULT_SETTING3 );
QCOMPARE( mMyString, DEFAULT_SETTING4 );
s->readConfig();
QCOMPARE(mMyBool, WRITE_SETTING1);
QCOMPARE(mMyColor, WRITE_SETTING2);
QCOMPARE(mMyFont, WRITE_SETTING3);
QCOMPARE(mMyString, WRITE_SETTING4);
}
void KConfigSkeletonTest::testSimple()
void KConfigSkeletonTest::testDefaults()
{
mMyBool=WRITE_SETTING1;
mMyColor=WRITE_SETTING2;
mMyFont=WRITE_SETTING3;
mMyString=WRITE_SETTING4;
mMyBool = WRITE_SETTING1;
mMyColor = WRITE_SETTING2;
mMyFont = WRITE_SETTING3;
mMyString = WRITE_SETTING4;
writeConfig ();
s->writeConfig();
mMyBool=false;
mMyColor=QColor();
mMyString.clear();
mMyFont=QFont();
s->setDefaults();
readConfig ();
QCOMPARE(mMyBool, DEFAULT_SETTING1);
QCOMPARE(mMyColor, DEFAULT_SETTING2);
QCOMPARE(mMyFont, DEFAULT_SETTING3);
QCOMPARE(mMyString, DEFAULT_SETTING4);
QCOMPARE( mMyBool, WRITE_SETTING1 );
QCOMPARE( mMyColor, WRITE_SETTING2 );
QCOMPARE( mMyFont, WRITE_SETTING3 );
QCOMPARE( mMyString, WRITE_SETTING4 );
s->writeConfig();
}
void KConfigSkeletonTest::testKConfigDirty()
{
itemBool->setValue(true);
itemBool->writeConfig(s->config());
QVERIFY(s->config()->isDirty());
s->writeConfig();
QVERIFY(!s->config()->isDirty());
itemBool->setValue(false);
itemBool->writeConfig(s->config());
QVERIFY(s->config()->isDirty());
s->writeConfig();
QVERIFY(!s->config()->isDirty());
}
void KConfigSkeletonTest::cleanupTestCase()
void KConfigSkeletonTest::testSaveRead()
{
setDefaults ();
itemBool->setValue(true);
s->writeConfig();
QCOMPARE( mMyBool, DEFAULT_SETTING1 );
QCOMPARE( mMyColor, DEFAULT_SETTING2 );
QCOMPARE( mMyFont, DEFAULT_SETTING3 );
QCOMPARE( mMyString, DEFAULT_SETTING4 );
itemBool->setValue(false);
s->writeConfig();
writeConfig();
mMyBool = true;
s->readConfig();
QCOMPARE(mMyBool, false);
}
......@@ -21,22 +21,26 @@
#include <kconfigskeleton.h>
class KConfigSkeletonTest : public KConfigSkeleton
class KConfigSkeletonTest : public QObject
{
Q_OBJECT
public:
public:
private Q_SLOTS:
void initTestCase();
void init();
void cleanup();
void testSimple();
void cleanupTestCase();
void testDefaults();
void testKConfigDirty();
void testSaveRead();
private:
bool mMyBool;
QColor mMyColor;
QFont mMyFont;
QString mMyString;
KConfigSkeleton *s;
KConfigSkeleton::ItemBool *itemBool;
bool mMyBool;
QColor mMyColor;
QFont mMyFont;
QString mMyString;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment