~smartboyhw/ubuntu/raring/calligra/2.6.0-0ubuntu1

« back to all changes in this revision

Viewing changes to words/part/tests/TestRdf.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-10-23 21:09:16 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20121023210916-m82w6zxnxhaxz7va
Tags: 1:2.5.90-0ubuntu1
* New upstream alpha release (LP: #1070436)
  - Add libkactivities-dev and libopenimageio-dev to build-depends
  - Add kubuntu_build_calligraactive.diff to build calligraactive by default
  - Add package for calligraauthor and move files that are shared between
    calligrawords and calligraauthor to calligrawords-common
* Document the patches
* Remove numbers from patches so they follow the same naming scheme as
  the rest of our patches.
* calligra-data breaks replaces krita-data (<< 1:2.5.3) (LP: #1071686)

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
#include <rdf/KoRdfPrefixMapping.h>
48
48
#include <rdf/KoSopranoTableModel.h>
49
49
 
 
50
#include <KoPart.h>
50
51
#include <KoBookmark.h>
51
52
#include <KoTextInlineRdf.h>
52
53
#include <KoStore.h>
111
112
void TestRdf::basicload()
112
113
{
113
114
    RDEBUG;
114
 
 
 
115
    
115
116
    QString odt = QString(FILES_DATA_DIR) + "/weekend-hike.odt";
116
117
    KoDocumentRdf *rdf = loadDocument(odt);
117
118
    QVERIFY(rdf);
118
 
    const Soprano::Model *m = rdf->model();
 
119
    QSharedPointer<Soprano::Model> m = rdf->model();
119
120
    QVERIFY(m);
120
121
    QCOMPARE (234, m->statementCount());
121
122
 
157
158
    QString odt = QString(FILES_DATA_DIR) + "/weekend-hike.odt";
158
159
    KoDocumentRdf *rdf = loadDocument(odt);
159
160
    QVERIFY(rdf);
160
 
    const Soprano::Model *m = rdf->model();
 
161
    QSharedPointer<Soprano::Model> m = rdf->model();
161
162
    QVERIFY(m);
162
163
 
163
164
    StatementIterator it;
164
165
    QList<Statement> allStatements;
165
166
 
166
 
    const Soprano::Model * submodel = rdf->findStatements("james2");
 
167
    QSharedPointer<Soprano::Model> submodel = rdf->findStatements("james2");
167
168
    QVERIFY (submodel);
168
169
    QCOMPARE (9, submodel->statementCount());
169
170
    it = submodel->listStatements(
185
186
    QString odt = QString(FILES_DATA_DIR) + "/weekend-hike.odt";
186
187
    KoDocumentRdf *rdf = loadDocument(odt);
187
188
    QVERIFY(rdf);
188
 
    Soprano::Model *m = rdf->model();
 
189
    QSharedPointer<Soprano::Model> m = rdf->model();
189
190
    QVERIFY(m);
190
191
 
191
192
    QString nameThatRemains ("This one will remain, as it's not in the RDF");
210
211
                QVERIFY (ba.contains ("tel:123456789"));
211
212
            }
212
213
 
213
 
            QList<KoSemanticStylesheet*> systemStylesheets = f->stylesheets();
 
214
            QList<hKoSemanticStylesheet> systemStylesheets = f->stylesheets();
214
215
            QVERIFY (systemStylesheets.size()>=4);
215
216
            bool foundTextSystemStylesheet = false;
216
 
            foreach (KoSemanticStylesheet* ss, systemStylesheets)  {
 
217
            foreach (hKoSemanticStylesheet ss, systemStylesheets)  {
217
218
                if (ss->uuid() == "0dd5878d-95c5-47e5-a777-63ec36da3b9a") {
218
219
                    foundTextSystemStylesheet = true;
219
220
                    QVERIFY (ss->name()=="name, phone");
243
244
    QString odt = QString(FILES_DATA_DIR) + "/weekend-hike.odt";
244
245
    KoDocumentRdf *rdf = loadDocument(odt);
245
246
    QVERIFY(rdf);
246
 
    Soprano::Model *m = rdf->model();
 
247
    QSharedPointer<Soprano::Model> m = rdf->model();
247
248
    QVERIFY(m);
248
249
 
249
250
    QString nameThatRemains ("This one will remain, as it's not in the RDF");
270
271
                QVERIFY (ba.contains ("SUMMARY:Lets party like its 1999"));
271
272
            }
272
273
 
273
 
            QList<KoSemanticStylesheet*> systemStylesheets = f->stylesheets();
 
274
            QList<hKoSemanticStylesheet> systemStylesheets = f->stylesheets();
274
275
            QVERIFY (systemStylesheets.size()>=4);
275
276
            bool foundTextSystemStylesheet = false;
276
 
            foreach (KoSemanticStylesheet* ss, systemStylesheets)  {
 
277
            foreach (hKoSemanticStylesheet ss, systemStylesheets)  {
277
278
                if (ss->uuid() == "853242eb-031c-4a36-abb2-7ef1881c777e") {
278
279
                    foundTextSystemStylesheet = true;
279
280
                    QVERIFY (ss->name()=="summary, location");
305
306
    QString odt = QString(FILES_DATA_DIR) + "/weekend-hike.odt";
306
307
    KoDocumentRdf *rdf = loadDocument(odt);
307
308
    QVERIFY(rdf);
308
 
    const Soprano::Model *m = rdf->model();
 
309
    QSharedPointer<Soprano::Model> m = rdf->model();
309
310
    QVERIFY(m);
310
311
 
311
312
    QString nameThatRemains ("This one will remain, as it's not in the RDF");
313
314
    expectedNames << "-79.9458,40.4427";
314
315
    expectedNames << nameThatRemains;
315
316
 
316
 
    QList<KoRdfLocation*> col = rdf->locations();
 
317
    QList<hKoRdfLocation> col = rdf->locations();
317
318
    QCOMPARE (col.size(),2);
318
 
    foreach (KoRdfLocation* f, col) {
 
319
    foreach (hKoRdfLocation f, col) {
319
320
        expectedNames.remove (f->name());
320
321
 
321
322
        if (f->name()=="-79.9458,40.4427") {
329
330
                QVERIFY (ba.contains ("<latitude>40.4427</latitude>"));
330
331
            }
331
332
 
332
 
            QList<KoSemanticStylesheet*> systemStylesheets = f->stylesheets();
 
333
            QList<hKoSemanticStylesheet> systemStylesheets = f->stylesheets();
333
334
            QVERIFY (systemStylesheets.size()>=2);
334
335
            bool foundTextSystemStylesheet = false;
335
 
            foreach (KoSemanticStylesheet* ss, systemStylesheets)  {
 
336
            foreach (hKoSemanticStylesheet ss, systemStylesheets)  {
336
337
                if (ss->uuid() == "34584133-52b0-449f-8b7b-7f1ef5097b9a") {
337
338
                    foundTextSystemStylesheet = true;
338
339
                    QVERIFY (ss->name()=="name, digital latitude, digital longitude");
371
372
    QVERIFY(pm->prefexToURI ("xsd")=="http://www.w3.org/2001/XMLSchema");
372
373
}
373
374
 
374
 
static Soprano::Model *loadRDFXMLFromODT(const QString &odt)
 
375
static QSharedPointer<Soprano::Model> loadRDFXMLFromODT(const QString &odt)
375
376
{
376
377
    Soprano::Node context;
377
378
    QUrl BaseURI = QUrl(QString());
383
384
    const bool success = job->exec();
384
385
    if (!success) {
385
386
        qWarning() << "KIO failed; " << job->errorString();
386
 
        return 0;
 
387
        return QSharedPointer<Soprano::Model>(0);
387
388
    }
388
389
    QByteArray ba = job->data();
389
390
    RDEBUG << "rdfxml.sz:" << ba.size();
390
 
    Soprano::Model * ret = Soprano::createModel();
 
391
    QSharedPointer<Soprano::Model> ret(Soprano::createModel());
391
392
    QString rdfxmlData = ba;
392
393
 
393
394
    Soprano::StatementIterator it = parser->parseString(rdfxmlData, BaseURI,
406
407
    QString odt = QString(FILES_DATA_DIR) + "/weekend-hike.odt";
407
408
    KoDocumentRdf *rdf = loadDocument(odt);
408
409
    QVERIFY(rdf);
409
 
    Soprano::Model *m = const_cast<Soprano::Model*>(rdf->model());
 
410
    QSharedPointer<Soprano::Model> m = rdf->model();
410
411
    QVERIFY(m);
411
412
    QCOMPARE (234, m->statementCount());
412
413
 
471
472
    QString odt = QString(FILES_DATA_DIR) + "/weekend-hike.odt";
472
473
    KoDocumentRdf *rdf = loadDocument(odt);
473
474
    QVERIFY(rdf);
474
 
    const Soprano::Model *m = rdf->model();
 
475
    QSharedPointer<Soprano::Model> m = rdf->model();
475
476
    QVERIFY(m);
476
477
    QCOMPARE (234, m->statementCount());
477
478
 
478
 
    QList<KoRdfFoaF*> col = rdf->foaf();
479
 
    foreach (KoRdfFoaF* f, col) {
 
479
    QList<hKoRdfFoaF> col = rdf->foaf();
 
480
    foreach (hKoRdfFoaF f, col) {
480
481
        if (f->name() == "James Smith") {
481
482
 
482
 
            KoSemanticStylesheet *ss = f->findStylesheetByUuid("0dd5878d-95c5-47e5-a777-63ec36da3b9a");
 
483
            hKoSemanticStylesheet ss = f->findStylesheetByUuid("0dd5878d-95c5-47e5-a777-63ec36da3b9a");
483
484
            KoRdfSemanticItemViewSite vs(f, "james2");
484
485
            vs.setStylesheetWithoutReflow(ss);
485
486
            RDEBUG << "ss.uuid:" << ss->uuid();
498
499
    QString odt = QString(FILES_DATA_DIR) + "/weekend-hike.odt";
499
500
    KoDocumentRdf *rdf = loadDocument(odt);
500
501
    QVERIFY(rdf);
501
 
    const Soprano::Model *m = rdf->model();
 
502
    QSharedPointer<Soprano::Model> m = rdf->model();
502
503
    QVERIFY(m);
503
504
 
504
505
    // FIXME: hmm, tablemodel would need to be exported for this
514
515
    QString odt = QString(FILES_DATA_DIR) + "/weekend-hike.odt";
515
516
    KoDocumentRdf *rdf = loadDocument(odt);
516
517
    QVERIFY(rdf);
517
 
    const Soprano::Model *m = rdf->model();
 
518
    QSharedPointer<Soprano::Model> m = rdf->model();
518
519
    QVERIFY(m);
519
 
    Soprano::Model *localModel = Soprano::createModel();
 
520
    QSharedPointer<Soprano::Model> localModel(Soprano::createModel());
520
521
 
521
522
    Node uuid = Node::createResourceNode(QUrl("http://www.w3.org/2002/12/cal/test/geo1#CDC474D4-1393-11D7-9A2C-000393914268"));
522
523
    Node icaltz = Node::createResourceNode(QUrl("http://www.w3.org/2002/12/cal/icaltzd#geo"));
553
554
    QString odt = QString(FILES_DATA_DIR) + "/weekend-hike.odt";
554
555
    KoDocumentRdf *rdf = loadDocument(odt);
555
556
    QVERIFY(rdf);
556
 
    const Soprano::Model *m = rdf->model();
 
557
    QSharedPointer<Soprano::Model> m = rdf->model();
557
558
    QVERIFY(m);
558
 
    Soprano::Model *localModel = Soprano::createModel();
 
559
    QSharedPointer<Soprano::Model> localModel(Soprano::createModel());
559
560
 
560
561
    StatementIterator it;
561
562
    QList<Statement> allStatements;
590
591
    QString odt = QString(FILES_DATA_DIR) + "/weekend-hike.odt";
591
592
    KoDocumentRdf *rdf = loadDocument(odt);
592
593
    QVERIFY(rdf);
593
 
    const Soprano::Model *m = rdf->model();
 
594
    QSharedPointer<Soprano::Model> m = rdf->model();
594
595
    QVERIFY(m);
595
 
    Soprano::Model *localModel = Soprano::createModel();
 
596
    QSharedPointer<Soprano::Model> localModel(Soprano::createModel());
596
597
 
597
598
    Node rdfFirst = Node::createResourceNode(QUrl("http://www.w3.org/1999/02/22-rdf-syntax-ns#first"));
598
599
    Node rdfRest  = Node::createResourceNode(QUrl("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest"));
625
626
 
626
627
void TestRdf::serializeRDFLists()
627
628
{
628
 
    Soprano::Model *m = Soprano::createModel();
 
629
    QSharedPointer<Soprano::Model> m(Soprano::createModel());
629
630
    Soprano::Node context = Node();
630
631
 
631
632
    QList<Soprano::Node> dataBNodeList;
657
658
 
658
659
void TestRdf::removeStatementsIfTheyExist()
659
660
{
660
 
    Soprano::Model *m = Soprano::createModel();
 
661
    QSharedPointer<Soprano::Model> m(Soprano::createModel());
661
662
    Soprano::Node context = Node();
662
663
    m->addStatement(Node::createResourceNode(QUrl("uri:test1")),
663
664
                    Node::createResourceNode(QUrl("uri:test2")),
706
707
 
707
708
void TestRdf::KoTextRdfCoreTripleFunctions()
708
709
{
709
 
    Soprano::Model *m = Soprano::createModel();
 
710
    QSharedPointer<Soprano::Model> m(Soprano::createModel());
710
711
    Soprano::Node context = Node();
711
712
    m->addStatement(Node::createResourceNode(QUrl("uri:test1")),
712
713
                    Node::createResourceNode(QUrl("uri:test2")),
764
765
    QString odt = QString(FILES_DATA_DIR) + "/weekend-hike.odt";
765
766
    KoDocumentRdf *rdf = loadDocument(odt);
766
767
    QVERIFY(rdf);
767
 
    const Soprano::Model *m = rdf->model();
 
768
    QSharedPointer<Soprano::Model> m = rdf->model();
768
769
    QVERIFY(m);
769
770
 
770
 
    KoRdfSemanticItem* f = KoRdfSemanticItem::createSemanticItem(rdf, rdf, "Contact");
 
771
    hKoRdfSemanticItem f = KoRdfSemanticItem::createSemanticItem(rdf, rdf, "Contact");
771
772
    int originalUserStylesheetsSize = f->userStylesheets().size();
772
 
    KoSemanticStylesheet* ss = f->createUserStylesheet("test sheet A",
 
773
    hKoSemanticStylesheet ss = f->createUserStylesheet("test sheet A",
773
774
                                                       "%NAME% and again %NAME%");
774
775
    QCOMPARE (f->userStylesheets().size(), originalUserStylesheetsSize+1);
775
776
    QVERIFY (ss);
778
779
    QVERIFY (ss->templateString() == "%NAME% and again %NAME%");
779
780
 
780
781
    bool found = false;
781
 
    QList<KoSemanticStylesheet*> slist = f->userStylesheets();
782
 
    foreach(KoSemanticStylesheet* z, slist) {
 
782
    QList<hKoSemanticStylesheet> slist = f->userStylesheets();
 
783
    foreach(hKoSemanticStylesheet z, slist) {
783
784
        if(z->uuid()==ss->uuid()) {
784
785
            found = true;
785
786
        }
793
794
    QVERIFY (ss->templateString() == "%NAME% and then %NICK%");
794
795
    found = false;
795
796
    slist = f->userStylesheets();
796
 
    foreach(KoSemanticStylesheet* z, slist) {
 
797
    foreach(hKoSemanticStylesheet z, slist) {
797
798
        if(z->uuid()==ss->uuid()) {
798
799
            QVERIFY (z->name() == "new name");
799
800
            QVERIFY (z->templateString() == "%NAME% and then %NICK%");
802
803
    }
803
804
    QVERIFY (found);
804
805
 
805
 
    KoSemanticStylesheet *z = 0;
 
806
    hKoSemanticStylesheet z = hKoSemanticStylesheet(0);
806
807
    z = f->findStylesheetByUuid(ss->uuid());
807
808
    QVERIFY (z);
808
809
    QVERIFY (z->uuid() == ss->uuid());
834
835
    {
835
836
 
836
837
        // Get the words part and create a document
837
 
        KWDocument *doc = new KWDocument();
 
838
        KWDocument *doc = new KWDocument(new MockPart);
838
839
        Q_ASSERT(doc);
839
840
        doc->setAutoSave(0);
840
841
        doc->initEmpty();
873
874
        editor->movePosition(QTextCursor::PreviousCharacter);
874
875
        editor->insertInlineObject(startmark);
875
876
 
876
 
        KoRdfLocation *location = new KoRdfLocation(this, rdfDoc);
 
877
        hKoRdfLocation location(new KoRdfLocation(0, rdfDoc));
877
878
        location->setDlat(5.0);
878
879
        location->setDlong(10.0);
879
880
 
883
884
                    Soprano::Node::createLiteralNode(newId), // object
884
885
                    rdfDoc->manifestRdfNode()); // manifest datastore
885
886
 
886
 
        const_cast<Soprano::Model*>(rdfDoc->model())->addStatement(st);
 
887
        rdfDoc->model()->addStatement(st);
887
888
        rdfDoc->rememberNewInlineRdfObject(inlineRdf);
888
889
 
889
890
        Q_ASSERT(rdfDoc->model()->statementCount() > 0);
906
907
 
907
908
        // search for locations and check the position
908
909
        // Find the location object
909
 
        QList<KoRdfLocation*> locations = rdfDoc->locations();
 
910
        QList<hKoRdfLocation> locations = rdfDoc->locations();
910
911
        Q_ASSERT(locations.size() == 1);
911
 
        KoRdfLocation *location2 = locations[0];
 
912
        hKoRdfLocation location2 = locations[0];
912
913
        QCOMPARE(location2->dlat(), location->dlat());
913
914
        QCOMPARE(location2->dlong(), location->dlong());
914
915
 
919
920
        QCOMPARE(position.second, 497);
920
921
 
921
922
        // Save the document -- this changes all xmlid's
922
 
        doc->saveAs(url);
 
923
        doc->documentPart()->saveAs(url);
923
924
 
924
925
        // Check the position again -- this xmlid doesn't exist anymore, so
925
926
        // should be 0,0
930
931
        // Find the location object
931
932
        locations = rdfDoc->locations();
932
933
        Q_ASSERT(locations.size() == 1);
933
 
        KoRdfLocation *location3 = locations[0];
 
934
        hKoRdfLocation location3 = locations[0];
934
935
 
935
936
        QCOMPARE(location3->dlat(), location->dlat());
936
937
        QCOMPARE(location3->dlong(), location->dlong());
944
945
    }
945
946
    {
946
947
        // Load the document
947
 
        KWDocument *doc = new KWDocument();
 
948
        KWDocument *doc = new KWDocument(new MockPart);
948
949
        Q_ASSERT(doc);
949
950
        doc->setAutoSave(0);
950
951
 
968
969
        editor->updateInlineObjectPosition();
969
970
 
970
971
        // Check for the rdf statements and spans
971
 
        QList<KoRdfLocation*> locations = rdfDoc->locations();
 
972
        QList<hKoRdfLocation> locations = rdfDoc->locations();
972
973
        Q_ASSERT(locations.size() == 1);
973
 
        KoRdfLocation *location = locations[0];
 
974
        hKoRdfLocation location = locations[0];
974
975
        Q_ASSERT(location->name() == "10,5");
975
976
        Q_ASSERT(location->dlat() == 5.0);
976
977
        Q_ASSERT(location->dlong() == 10.0);
977
978
        Q_ASSERT(location->xmlIdList().length() == 1);
978
979
        QString xmlid = location->xmlIdList()[0];
979
980
        QPair<int,int> position = rdfDoc->findExtent(xmlid);
 
981
        // TODO: Why is this like the above but both - 1 ?
980
982
        Q_ASSERT(position.first == 443);
981
 
        Q_ASSERT(position.second == 546);
 
983
        Q_ASSERT(position.second == 496);
982
984
 
983
985
        // check whether the table between the bookmarks is in the right position
984
986
        // after loading