1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
#include <qtest_kde.h>
#include <kcomponentdata.h>
#include <QDebug>
#include <KoStyleManager.h>
#include <KoParagraphStyle.h>
#include <KoCharacterStyle.h>
#include "../dialogs/StylesModel.h"
class TestStylesModel : public QObject
{
Q_OBJECT
public slots:
void init();
void cleanup();
private slots:
void testPrecalcCache();
void testSetManager();
private:
void fillManager();
KoStyleManager *manager;
};
class MockModel : public StylesModel
{
public:
MockModel(KoStyleManager *manager, QObject *parent = 0)
: StylesModel(manager, parent) { }
void publicRecalculate() {
StylesModel::recalculate();
}
QList<int> rootStyleIds() {
return m_styleList;
}
QMultiHash<int, int> relations() {
return m_relations;
}
};
void TestStylesModel::init()
{
manager = new KoStyleManager();
}
void TestStylesModel::cleanup()
{
delete manager;
}
void TestStylesModel::testPrecalcCache()
{
fillManager();
MockModel model(manager);
QCOMPARE(model.rootStyleIds().count(), 5);
KoParagraphStyle *s = manager->paragraphStyle(model.rootStyleIds().at(0));
QVERIFY(s);
QCOMPARE(s->name(), QString("Default"));
KoParagraphStyle *code = manager->paragraphStyle(model.rootStyleIds().at(2));
QVERIFY(code);
QCOMPARE(code->name(), QString("code"));
KoParagraphStyle *altered = manager->paragraphStyle(model.rootStyleIds().at(1));
QVERIFY(altered);
QCOMPARE(altered->name(), QString("altered"));
KoParagraphStyle *headers = manager->paragraphStyle(model.rootStyleIds().at(3));
QVERIFY(headers);
QCOMPARE(headers->name(), QString("headers"));
KoCharacterStyle *red = manager->characterStyle(model.rootStyleIds().at(4));
QVERIFY(red);
QCOMPARE(red->name(), QString("red"));
//only contains parent paragraph styles with links to the child.
QVERIFY(model.relations().contains(headers->styleId()));
QList<int> children = model.relations().values(headers->styleId());
QCOMPARE(children.count(), 3);
foreach(int id, children) {
KoParagraphStyle *head = manager->paragraphStyle(id);
QVERIFY(head);
QVERIFY(head->name().startsWith("Head "));
}
}
void TestStylesModel::testSetManager()
{
MockModel model(0);
QCOMPARE(model.rootStyleIds().count(), 0);
fillManager();
model.setStyleManager(manager);
QCOMPARE(model.rootStyleIds().count(), 5);
}
void TestStylesModel::fillManager()
{
KoParagraphStyle *ps = new KoParagraphStyle();
ps->setName("code");
manager->add(ps);
ps = new KoParagraphStyle();
ps->setName("altered");
manager->add(ps);
ps = new KoParagraphStyle();
ps->setName("headers");
KoParagraphStyle *head = new KoParagraphStyle();
head->setParentStyle(ps);
head->setName("Head 1");
manager->add(head);
head = new KoParagraphStyle();
head->setParentStyle(ps);
head->setName("Head 2");
manager->add(head);
manager->add(ps);
head = new KoParagraphStyle();
head->setParentStyle(ps);
head->setName("Head 3");
manager->add(head);
KoCharacterStyle *style = new KoCharacterStyle();
style->setName("red");
manager->add(style);
}
QTEST_KDEMAIN(TestStylesModel, GUI)
#include <TestStylesModel.moc>
|