Beispiel #1
0
void MusicBrainzFetcherTest::testPerson() {
  Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Album, Tellico::Fetch::Person,
                                       m_fieldValues.value(QLatin1String("artist")));
  Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::MusicBrainzFetcher(this));

  Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 20);

  QVERIFY(results.size() > 0);
  Tellico::Data::EntryPtr entry;  //  results can be randomly ordered, loop until we find the one we want
  foreach(Tellico::Data::EntryPtr test, results) {
    if(test->field(QLatin1String("title")).toLower() == m_fieldValues.value(QLatin1String("title"))) {
      entry = test;
      break;
    } else {
      qDebug() << "skipping" << test->title();
    }
  }
  QVERIFY(entry);

  QHashIterator<QString, QString> i(m_fieldValues);
  while(i.hasNext()) {
    i.next();
    QString result = entry->field(i.key()).toLower();
    QCOMPARE(result, i.value().toLower());
  }
  QVERIFY(!entry->field(QLatin1String("track")).isEmpty());
  QVERIFY(!entry->field(QLatin1String("cover")).isEmpty());
}
void GoogleBookFetcherTest::compareEntry(Tellico::Data::EntryPtr entry) {
  QCOMPARE(entry->field(QLatin1String("title")), QLatin1String("Practical RDF"));
  QCOMPARE(entry->field(QLatin1String("isbn")), QLatin1String("0-596-55051-0"));
  QCOMPARE(entry->field(QLatin1String("author")), QLatin1String("Shelley Powers"));
  QCOMPARE(entry->field(QLatin1String("publisher")), QLatin1String("O'Reilly Media, Inc."));
  QCOMPARE(entry->field(QLatin1String("pages")), QLatin1String("352"));
  QCOMPARE(entry->field(QLatin1String("pub_year")), QLatin1String("2003"));
  QVERIFY(entry->field(QLatin1String("keyword")).contains(QLatin1String("Computers")));
  QVERIFY(entry->field(QLatin1String("keyword")).contains(QLatin1String("XML")));
  QVERIFY(!entry->field(QLatin1String("cover")).isEmpty());
  QVERIFY(!entry->field(QLatin1String("comments")).isEmpty());
}
Beispiel #3
0
void AnimenfoFetcherTest::testGhost() {
  KConfig config(QFINDTESTDATA("tellicotest.config"), KConfig::SimpleConfig);
  QString groupName = QLatin1String("AnimeNfo.com");
  if(!config.hasGroup(groupName)) {
    QSKIP("This test requires a config file.", SkipAll);
  }
  KConfigGroup cg(&config, groupName);

  Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::Keyword, "Ghost in the Shell");
  Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::AnimeNfoFetcher(this));
  fetcher->readConfig(cg, cg.name());

  Tellico::Data::EntryList results = DO_FETCH(fetcher, request);

  QCOMPARE(results.size(), 1);

  // the first entry had better be the right one
  Tellico::Data::EntryPtr entry = results.at(0);
  QVERIFY(entry);

  QCOMPARE(entry->field("title"), QLatin1String("Kokaku Kido Tai"));
  QCOMPARE(entry->field("pub_year"), QLatin1String("1991"));
  QCOMPARE(entry->field("genre"), QLatin1String("Action; Science-Fiction"));
  QCOMPARE(entry->field("publisher"), QLatin1String("Kodansha"));
  QCOMPARE(entry->field("origtitle"), QString::fromUtf8("攻殻機動隊"));
  QCOMPARE(entry->field("author"), QString::fromUtf8("Shiro Masamune (士郎 正宗)"));
  QCOMPARE(entry->field("alttitle"), QLatin1String("Ghost in the Shell"));
  QVERIFY(!entry->field("cover").isEmpty());
  QVERIFY(!entry->field("animenfo").isEmpty());
}
Beispiel #4
0
void AnimenfoFetcherTest::testMegami() {
  KConfig config(QFINDTESTDATA("tellicotest.config"), KConfig::SimpleConfig);
  QString groupName = QLatin1String("AnimeNfo.com");
  if(!config.hasGroup(groupName)) {
    QSKIP("This test requires a config file.", SkipAll);
  }
  KConfigGroup cg(&config, groupName);

  Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Keyword, "Aa! Megami-sama!");
  Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::AnimeNfoFetcher(this));
  fetcher->readConfig(cg, cg.name());

  Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);

  QCOMPARE(results.size(), 1);

  // the first entry had better be the right one
  Tellico::Data::EntryPtr entry = results.at(0);
  QVERIFY(entry);

  QCOMPARE(entry->field("title"), QLatin1String("Aa! Megami-sama!: Together Forever"));
  QCOMPARE(entry->field("year"), QLatin1String("2011"));
  QCOMPARE(entry->field("episodes"), QLatin1String("2"));
  QCOMPARE(entry->field("studio"), QLatin1String("AIC (Anime International Company)"));
  QCOMPARE(entry->field("origtitle"), QString::fromUtf8("ああっ女神さまっ ~ いつも二人で"));
  QVERIFY(entry->field("plot").startsWith(QLatin1String("Keiichi finds out")));
  QVERIFY(!entry->field("cover").isEmpty());
}
Beispiel #5
0
void MusicBrainzFetcherTest::testTitle() {
  Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Album, Tellico::Fetch::Title,
                                       m_fieldValues.value(QLatin1String("title")));
  Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::MusicBrainzFetcher(this));

  Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);

  QCOMPARE(results.size(), 1);

  Tellico::Data::EntryPtr entry = results.at(0);
  QHashIterator<QString, QString> i(m_fieldValues);
  while(i.hasNext()) {
    i.next();
    QString result = entry->field(i.key()).toLower();
    QCOMPARE(result, i.value().toLower());
  }
  QVERIFY(!entry->field(QLatin1String("track")).isEmpty());
  QVERIFY(!entry->field(QLatin1String("cover")).isEmpty());
}
Beispiel #6
0
void MusicBrainzFetcherTest::testKeyword() {
  // the total test case ends up exceeding the throttle limit so pause for a second
  QTest::qWait(1000);

  Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Album, Tellico::Fetch::Keyword,
                                       m_fieldValues.value(QLatin1String("title")));
  Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::MusicBrainzFetcher(this));

  Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);

  QCOMPARE(results.size(), 1);

  Tellico::Data::EntryPtr entry = results.at(0);
  QHashIterator<QString, QString> i(m_fieldValues);
  while(i.hasNext()) {
    i.next();
    QString result = entry->field(i.key()).toLower();
    QCOMPARE(result, i.value().toLower());
  }
  QVERIFY(!entry->field(QLatin1String("track")).isEmpty());
  QVERIFY(!entry->field(QLatin1String("cover")).isEmpty());
}
Beispiel #7
0
// test grabbing cover art from coverartarchive.org
void MusicBrainzFetcherTest::testCoverArt() {
  Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Album, Tellico::Fetch::Title,
                                       QLatin1String("Laulut ja tarinat"));
  Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::MusicBrainzFetcher(this));

  Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);

  QVERIFY(!results.isEmpty());

  Tellico::Data::EntryPtr entry = results.at(0);
  QCOMPARE(entry->title(), QLatin1String("Laulut ja tarinat"));
  QEXPECT_FAIL("", "MusicBrainz covers from coverartarchive are failing", Abort);
  QVERIFY(!entry->field(QLatin1String("cover")).isEmpty());
}
Beispiel #8
0
void RisTest::testImport() {
  KUrl url(QString::fromLatin1(KDESRCDIR) + "/data/test.ris");
  KUrl::List urls;
  urls << url;
  Tellico::Import::RISImporter importer(urls);
  Tellico::Data::CollPtr coll = importer.collection();

  QVERIFY(!coll.isNull());
  QCOMPARE(coll->type(), Tellico::Data::Collection::Bibtex);
  QCOMPARE(coll->entryCount(), 2);
  QCOMPARE(coll->title(), QLatin1String("Bibliography"));

  Tellico::Data::EntryPtr entry = coll->entryById(2);
  QVERIFY(!entry.isNull());
  QCOMPARE(entry->field("entry-type"), QLatin1String("article"));
  QCOMPARE(entry->field("year"), QLatin1String("2002"));
  QCOMPARE(entry->field("pages"), QLatin1String("1057-1119"));
  QCOMPARE(Tellico::FieldFormat::splitValue(entry->field("author")).count(), 3);
  QCOMPARE(Tellico::FieldFormat::splitValue(entry->field("author")).first(), QLatin1String("Koglin,M."));

  Tellico::Data::BibtexCollection* bColl = dynamic_cast<Tellico::Data::BibtexCollection*>(coll.data());
  QVERIFY(bColl);
  QCOMPARE(bColl->fieldByBibtexName("entry-type")->name(), QLatin1String("entry-type"));
}
Beispiel #9
0
void DeliciousTest::testMusic2() {
  QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/delicious2_music.xml"));
  Tellico::Import::DeliciousImporter importer(url);
  Tellico::Data::CollPtr coll = importer.collection();

  QVERIFY(coll);
  QCOMPARE(coll->type(), Tellico::Data::Collection::Album);
  QCOMPARE(coll->entryCount(), 3);

  Tellico::Data::EntryPtr entry = coll->entryById(2);
  QVERIFY(entry);
  QCOMPARE(entry->field("title"), QLatin1String("The Ultimate Sin"));
  QCOMPARE(entry->field("artist"), QLatin1String("Ozzy Osbourne"));
  QCOMPARE(entry->field("year"), QLatin1String("1987"));
  QCOMPARE(entry->field("medium"), QLatin1String("Compact Disc"));
  QCOMPARE(entry->field("label"), QLatin1String("Epic Aus/Zoom"));
  QCOMPARE(entry->field("pur_price"), QLatin1String("$15.98"));
  QCOMPARE(entry->field("pur_date"), QLatin1String("2009-01-17"));
  QCOMPARE(entry->field("rating"), QLatin1String("3.5"));
  QCOMPARE(entry->field("keyword"), QLatin1String("Hard Rock & Metal; Rock"));
}
Beispiel #10
0
void DBLPFetcherTest::testArticle() {
    Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Keyword,
                                         QLatin1String("Nontrivial independent sets of bipartite graphs"));
    Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::DBLPFetcher(this));

    Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);

    QCOMPARE(results.size(), 1);

    Tellico::Data::EntryPtr entry = results.at(0);
    QCOMPARE(entry->field(QLatin1String("title")), QLatin1String("Nontrivial independent sets of bipartite graphs and cross-intersecting families."));
    QCOMPARE(entry->field(QLatin1String("author")), QLatin1String("Jun Wang; Huajun Zhang"));
    QCOMPARE(entry->field(QLatin1String("year")), QLatin1String("2013"));
    QCOMPARE(entry->field(QLatin1String("pages")), QLatin1String("129-141"));
    QCOMPARE(entry->field(QLatin1String("volume")), QLatin1String("120"));
    QCOMPARE(entry->field(QLatin1String("number")), QLatin1String("1"));
    QCOMPARE(entry->field(QLatin1String("journal")), QLatin1String("J. Comb. Theory, Ser. A (JCT)"));
    QCOMPARE(entry->field(QLatin1String("booktitle")), QLatin1String(""));
    QCOMPARE(entry->field(QLatin1String("url")), QLatin1String("http://dx.doi.org/10.1016/j.jcta.2012.07.005"));
    QCOMPARE(entry->field(QLatin1String("doi")), QLatin1String("10.1016/j.jcta.2012.07.005"));
    QCOMPARE(entry->field(QLatin1String("entry-type")), QLatin1String("article"));
    QCOMPARE(entry->field(QLatin1String("bibtex-key")), QLatin1String("WangZ13"));
}
Beispiel #11
0
void DeliciousTest::testGames1() {
  QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/delicious1_games.xml"));
  Tellico::Import::DeliciousImporter importer(url);
  Tellico::Data::CollPtr coll = importer.collection();

  QVERIFY(coll);
  QCOMPARE(coll->type(), Tellico::Data::Collection::Game);
  QCOMPARE(coll->entryCount(), 2);

  // first a movie
  Tellico::Data::EntryPtr entry = coll->entryById(1);
  QVERIFY(entry);
  QCOMPARE(entry->field("title"), QLatin1String("Spider-Man 2: The Movie 2"));
  QCOMPARE(entry->field("certification"), QLatin1String("Teen"));
  QCOMPARE(entry->field("platform"), QLatin1String("GameCube"));
  QCOMPARE(entry->field("year"), QLatin1String("2004"));
  QCOMPARE(entry->field("pur_price"), QLatin1String("$49.99"));
  QCOMPARE(entry->field("pur_date"), QLatin1String("25-03-2006"));
  QCOMPARE(entry->field("rating"), QLatin1String("4.5"));
  QCOMPARE(entry->field("publisher"), QLatin1String("Activision"));
}
Beispiel #12
0
void DeliciousTest::testMusic1() {
  QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/delicious1_music.xml"));
  Tellico::Import::DeliciousImporter importer(url);
  Tellico::Data::CollPtr coll = importer.collection();

  QVERIFY(coll);
  QCOMPARE(coll->type(), Tellico::Data::Collection::Album);
  QCOMPARE(coll->entryCount(), 3);

  // first a movie
  Tellico::Data::EntryPtr entry = coll->entryById(1);
  QVERIFY(entry);
  QCOMPARE(entry->field("title"), QLatin1String("Are You Listening?"));
  QCOMPARE(entry->field("artist"), QLatin1String("Dolores O'Riordan"));
  QCOMPARE(entry->field("year"), QLatin1String("2007"));
  QCOMPARE(entry->field("medium"), QLatin1String("Compact Disc"));
  QCOMPARE(entry->field("label"), QLatin1String("Sanctuary Records"));
  QCOMPARE(ROWS(entry, "track").count(), 12);
  QCOMPARE(ROWS(entry, "track").first(), QLatin1String("Ordinary Day"));
  QCOMPARE(entry->field("pur_price"), QLatin1String("$15.98"));
  QCOMPARE(entry->field("pur_date"), QLatin1String("27-06-2008"));
  QCOMPARE(entry->field("rating"), QLatin1String("4.5"));
}
Beispiel #13
0
void DBLPFetcherTest::testProceedings() {
    Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Keyword,
                                         QLatin1String("Chip and PIN is Broken"));
    Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::DBLPFetcher(this));

    Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);

    QCOMPARE(results.size(), 1);

    Tellico::Data::EntryPtr entry = results.at(0);
    QCOMPARE(entry->field(QLatin1String("title")), QLatin1String("Chip and PIN is Broken."));
    QCOMPARE(entry->field(QLatin1String("author")), QLatin1String("Steven J. Murdoch; Saar Drimer; Ross J. Anderson; Mike Bond"));
    QCOMPARE(entry->field(QLatin1String("year")), QLatin1String("2010"));
    QCOMPARE(entry->field(QLatin1String("pages")), QLatin1String("433-446"));
    QCOMPARE(entry->field(QLatin1String("booktitle")), QLatin1String("IEEE Symposium on Security and Privacy"));
    QCOMPARE(entry->field(QLatin1String("url")), QLatin1String("http://dx.doi.org/10.1109/SP.2010.33"));
    QCOMPARE(entry->field(QLatin1String("doi")), QLatin1String("10.1109/SP.2010.33"));
    QCOMPARE(entry->field(QLatin1String("entry-type")), QLatin1String("inproceedings"));
    QCOMPARE(entry->field(QLatin1String("bibtex-key")), QLatin1String("MurdochDAB10"));
}
Beispiel #14
0
void AnimenfoFetcherTest::testHachimitsu() {
  KConfig config(QFINDTESTDATA("tellicotest.config"), KConfig::SimpleConfig);
  QString groupName = QLatin1String("AnimeNfo.com");
  if(!config.hasGroup(groupName)) {
    QSKIP("This test requires a config file.", SkipAll);
  }
  KConfigGroup cg(&config, groupName);

  Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Keyword, "Hachimitsu to Clover");
  Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::AnimeNfoFetcher(this));
  fetcher->readConfig(cg, cg.name());

  Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);

  QCOMPARE(results.size(), 1);

  // the first entry had better be the right one
  Tellico::Data::EntryPtr entry = results.at(0);
  QVERIFY(entry);

  QCOMPARE(entry->field("title"), QLatin1String("Hachimitsu to Clover"));
  QCOMPARE(entry->field("year"), QLatin1String("2005"));
  QCOMPARE(entry->field("episodes"), QLatin1String("26"));
  QCOMPARE(entry->field("keyword"), QLatin1String("TV"));
  QCOMPARE(entry->field("genre"), QLatin1String("Comedy; Drama; Romance"));
  QCOMPARE(entry->field("studio"), QLatin1String("J.C.STAFF"));
  QCOMPARE(entry->field("origtitle"), QString::fromUtf8("ハチミツとクローバー"));
  QCOMPARE(entry->field("director"), QString::fromUtf8("Kasai Kenichi (カサヰ ケンイチ)"));
  QCOMPARE(entry->field("writer"), QString::fromUtf8("Kuroda Yosuke (黒田洋介)"));
  QCOMPARE(entry->field("alttitle"), QLatin1String("Honey and Clover"));
  QCOMPARE(entry->field("animenfo-rating"), QLatin1String("9"));
  QVERIFY(entry->field("plot").startsWith(QLatin1String("Takemoto, Mayama, and Morita are students")));
  QVERIFY(!entry->field("cover").isEmpty());
  QVERIFY(!entry->field("animenfo").isEmpty());
  QStringList castList = Tellico::FieldFormat::splitTable(entry->field("cast"));
  QCOMPARE(castList.count(), 7);
  QCOMPARE(castList.at(0), QString::fromUtf8("Kudo Haruka (工藤晴香)::Hanamoto Hagumi"));
}
Beispiel #15
0
void DeliciousTest::testMovies2() {
  QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/delicious2_movies.xml"));
  Tellico::Import::DeliciousImporter importer(url);
  Tellico::Data::CollPtr coll = importer.collection();

  QVERIFY(coll);
  QCOMPARE(coll->type(), Tellico::Data::Collection::Video);
  QCOMPARE(coll->entryCount(), 4);

  Tellico::Data::EntryPtr entry = coll->entryById(2);
  QVERIFY(entry);
  QCOMPARE(entry->field("title"), QLatin1String("2001 - A Space Odyssey"));
  QCOMPARE(entry->field("certification"), QLatin1String("G (USA)"));
  QCOMPARE(entry->field("nationality"), QLatin1String("USA"));
  QCOMPARE(entry->field("aspect-ratio"), QLatin1String("2.35:1"));
  QCOMPARE(entry->field("audio-track"), QLatin1String("Dolby"));
  QCOMPARE(entry->field("widescreen"), QLatin1String("true"));
  QCOMPARE(entry->field("director"), QLatin1String("Stanley Kubrick"));
  QCOMPARE(entry->field("color"), QLatin1String("Color"));
  QCOMPARE(entry->field("format"), QLatin1String("NTSC"));
  QCOMPARE(entry->field("medium"), QLatin1String("DVD"));
  QCOMPARE(entry->field("running-time"), QLatin1String("148"));
  QCOMPARE(entry->field("rating"), QLatin1String("4"));
  QCOMPARE(entry->field("year"), QLatin1String("1968"));
  QCOMPARE(entry->field("pur_date"), QLatin1String("2007-12-19"));
  QCOMPARE(entry->field("cdate"), QLatin1String("2007-12-20"));
  QCOMPARE(entry->field("mdate"), QLatin1String("2009-06-11"));

  entry = coll->entryById(4);
  QVERIFY(entry);
  QCOMPARE(entry->field("region"), QLatin1String("Region 1"));
}
Beispiel #16
0
int EntryComparison::score(Tellico::Data::EntryPtr e1, Tellico::Data::EntryPtr e2, Tellico::Data::FieldPtr f) {
  if(!e1 || !e2 || !f) {
    return 0;
  }
  QString s1 = e1->field(f).toLower();
  QString s2 = e2->field(f).toLower();
  if(s1.isEmpty() || s2.isEmpty()) {
    return 0;
  }
  // complicated string matching, here are the cases I want to match
  // "bend it like beckham" == "bend it like beckham (widescreen edition)"
  // "the return of the king" == "return of the king"
  if(s1 == s2) {
    return 5;
  }
  // special case for isbn
  if(f->name() == QLatin1String("isbn") && ISBNValidator::isbn10(s1) == ISBNValidator::isbn10(s2)) {
    return 5;
  }
  if(f->name() == QLatin1String("lccn") && LCCNValidator::formalize(s1) == LCCNValidator::formalize(s2)) {
    return 5;
  }
  if(f->name() == QLatin1String("url") && e1->collection() && e1->collection()->type() == Data::Collection::File) {
    // versions before 1.2.7 could have saved the url without the protocol
    if(QUrl(s1) == QUrl(s2) ||
       (f->property(QLatin1String("relative")) == QLatin1String("true") &&
        s_documentUrl.resolved(QUrl(s1)) == s_documentUrl.resolved(QUrl(s2)))) {
      return 5;
    }
  }
  if (f->name() == QLatin1String("imdb")) {
    // imdb might be a different host since we query akas.imdb.com and normally it is www.imdb.com
    QUrl us1 = QUrl::fromUserInput(s1);
    QUrl us2 = QUrl::fromUserInput(s2);
    us1.setHost(QString());
    us2.setHost(QString());
    if(us1 == us2) {
      return 5;
    }
  }
  if(f->name() == QLatin1String("arxiv")) {
    // normalize and unVersion arxiv ID
    s1.remove(QRegExp(QLatin1String("^arxiv:")));
    s1.remove(QRegExp(QLatin1String("v\\d+$")));
    s2.remove(QRegExp(QLatin1String("^arxiv:")));
    s2.remove(QRegExp(QLatin1String("v\\d+$")));
    if(s1 == s2) {
      return 5;
    }
  }
  if(f->formatType() == FieldFormat::FormatName) {
    const QString s1n = e1->formattedField(f, FieldFormat::ForceFormat);
    const QString s2n = e2->formattedField(f, FieldFormat::ForceFormat);
    if(s1n == s2n) {
      return 5;
    }
  }
  // try removing punctuation
  QRegExp notAlphaNum(QLatin1String("[^\\s\\w]"));
  QString s1a = s1;
  s1a.remove(notAlphaNum);
  QString s2a = s2;
  s2a.remove(notAlphaNum);
  if(!s1a.isEmpty() && s1a == s2a) {
//    myDebug() << "match without punctuation";
    return 5;
  }
  FieldFormat::stripArticles(s1);
  FieldFormat::stripArticles(s2);
  if(!s1.isEmpty() && s1 == s2) {
//    myDebug() << "match without articles";
    return 3;
  }
  // try removing everything between parentheses
  QRegExp rx(QLatin1String("\\s*\\(.*\\)\\s*"));
  s1.remove(rx);
  s2.remove(rx);
  if(!s1.isEmpty() && s1 == s2) {
//    myDebug() << "match without parentheses";
    return 2;
  }
  if(f->hasFlag(Data::Field::AllowMultiple)) {
    QStringList sl1 = FieldFormat::splitValue(e1->field(f));
    QStringList sl2 = FieldFormat::splitValue(e2->field(f));
    int matches = 0;
    for(QStringList::ConstIterator it = sl1.constBegin(); it != sl1.constEnd(); ++it) {
      matches += sl2.count(*it);
    }
    if(matches == 0 && f->formatType() == FieldFormat::FormatName) {
      sl1 = FieldFormat::splitValue(e1->formattedField(f, FieldFormat::ForceFormat));
      sl2 = FieldFormat::splitValue(e2->formattedField(f, FieldFormat::ForceFormat));
      for(QStringList::ConstIterator it = sl1.constBegin(); it != sl1.constEnd(); ++it) {
        matches += sl2.count(*it);
      }
    }
    return matches;
  }
  return 0;
}
Beispiel #17
0
void DocumentTest::testImageLocalDirectory() {
  Tellico::Config::setImageLocation(Tellico::Config::ImagesInLocalDir);
  // the default collection will use a temporary directory as a local image dir
  QVERIFY(!Tellico::ImageFactory::localDir().isEmpty());

  QString tempDirName;

  QTemporaryDir tempDir;
  QVERIFY(tempDir.isValid());
  tempDir.setAutoRemove(true);
  tempDirName = tempDir.path();
  QString fileName = tempDirName + "/with-image.tc";
  QString imageDirName = tempDirName + "/with-image_files/";

  // copy a collection file that includes an image into the temporary directory
  QVERIFY(QFile::copy(QFINDTESTDATA("data/with-image.tc"), fileName));

  Tellico::Data::Document* doc = Tellico::Data::Document::self();
  QVERIFY(doc->openDocument(QUrl::fromLocalFile(fileName)));
  QCOMPARE(Tellico::ImageFactory::localDir(), imageDirName);

  Tellico::Data::CollPtr coll = doc->collection();
  QVERIFY(coll);
  QCOMPARE(coll->type(), Tellico::Data::Collection::Book);
  QCOMPARE(coll->title(), QLatin1String("My Books"));
  QCOMPARE(coll->entries().size(), 1);

  Tellico::Data::EntryPtr e = coll->entries().at(0);
  QVERIFY(e);
  QCOMPARE(e->field(QLatin1String("cover")), QLatin1String("17b54b2a742c6d342a75f122d615a793.jpeg"));

  // save the document, so the images get copied out of the .tc file into the local image directory
  QVERIFY(doc->saveDocument(QUrl::fromLocalFile(fileName)));
  // verify that backup file gets created
  QVERIFY(QFile::exists(fileName + '~'));

  // check that the local image directory is created with the image file inside
  QDir imageDir(imageDirName);
  QVERIFY(imageDir.exists());
  QVERIFY(imageDir.exists(e->field(QLatin1String("cover"))));

  // clear the internal image cache
  Tellico::ImageFactory::clean(true);

  // verify that the images are copied from the old directory when saving to a new file
  QString fileName2 = tempDirName + "/with-image2.tc";
  QString imageDirName2 = tempDirName + "/with-image2_files/";
  QVERIFY(doc->saveDocument(QUrl::fromLocalFile(fileName2)));
  QVERIFY(QFile::exists(fileName2));
  QDir imageDir2(imageDirName2);
  QVERIFY(imageDir2.exists());
  QVERIFY(imageDir2.exists(e->field(QLatin1String("cover"))));

  /*************************************************************************/
  /* now also verify image directory when file name has multiple periods */
  /* see https://bugs.kde.org/show_bug.cgi?id=348088 */
  /* also have to check backwards compatibility with prior behavior */
  /*************************************************************************/

  QString fileName3 = tempDirName + "/with-image.1.tc";
  QString imageDirName3 = tempDirName + "/with-image.1_files/";

  // copy the collection file, which no longer contains the images inside
  QVERIFY(QFile::copy(fileName, fileName3));
  QVERIFY(doc->openDocument(QUrl::fromLocalFile(fileName3)));
  QCOMPARE(Tellico::ImageFactory::localDir(), imageDirName3);
  QDir imageDir3(imageDirName3);

  // verify that the images can be loaded from the image directory that does NOT have multiple periods
  // since that was the behavior prior to the bug being fixed
  coll = doc->collection();
  e = coll->entries().at(0);
  // image should not be in the next image dir yet since we haven't saved
  QVERIFY(!imageDir3.exists(e->field(QLatin1String("cover"))));
  QVERIFY(!Tellico::ImageFactory::imageById(e->field("cover")).isNull());

  // now remove the first image from the first image directory, save the document, and verify that
  // the proper image exists and is written
  QVERIFY(imageDir.remove(e->field("cover")));
  QVERIFY(!imageDir.exists(e->field(QLatin1String("cover"))));
  QVERIFY(doc->saveDocument(QUrl::fromLocalFile(fileName3)));
  // now the file should exist in the proper location
  QVERIFY(imageDir3.exists(e->field(QLatin1String("cover"))));
  // clear the cache
  Tellico::ImageFactory::clean(true);
  QVERIFY(!Tellico::ImageFactory::imageById(e->field("cover")).isNull());

  // sanity check, the directory should not exists after QTemporaryDir destruction
  tempDir.remove();
  QVERIFY(!QDir(tempDirName).exists());
}
Beispiel #18
0
void DeliciousTest::testBooks2() {
  QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/delicious2_books.xml"));
  Tellico::Import::DeliciousImporter importer(url);
  Tellico::Data::CollPtr coll = importer.collection();

  QVERIFY(coll);
  QCOMPARE(coll->type(), Tellico::Data::Collection::Book);
  QCOMPARE(coll->entryCount(), 7);

  Tellico::Data::EntryPtr entry = coll->entryById(1);
  QVERIFY(entry);
  QCOMPARE(entry->field("title"), QLatin1String("The Restaurant at the End of the Universe"));
  QCOMPARE(entry->field("isbn"), QLatin1String("0517545357"));
  QCOMPARE(entry->field("cdate"), QLatin1String("2007-12-19"));
  QCOMPARE(entry->field("mdate"), QLatin1String("2009-06-11"));
  QCOMPARE(FIELDS(entry, "author").count(), 1);
  QCOMPARE(FIELDS(entry, "author").first(), QLatin1String("Douglas Adams"));
  QCOMPARE(entry->field("binding"), QLatin1String("Hardback"));
  QCOMPARE(entry->field("rating"), QLatin1String("4.5")); // visually, this gets shown as 4 stars
  QCOMPARE(entry->field("pages"), QLatin1String("250"));
  QCOMPARE(entry->field("pub_year"), QLatin1String("1982"));
  QCOMPARE(entry->field("publisher"), QLatin1String("Harmony"));
  QCOMPARE(entry->field("pur_date"), QLatin1String("2007-12-18"));
  QCOMPARE(entry->field("pur_price"), QLatin1String("$12.95"));
  QCOMPARE(entry->field("signed"), QLatin1String("true"));
  QCOMPARE(entry->field("condition"), QLatin1String("Used"));
}
Beispiel #19
0
void DeliciousTest::testBooks1() {
  QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/delicious1_books.xml"));
  Tellico::Import::DeliciousImporter importer(url);
  Tellico::Data::CollPtr coll = importer.collection();

  QVERIFY(coll);
  QCOMPARE(coll->type(), Tellico::Data::Collection::Book);
  QCOMPARE(coll->entryCount(), 5);

  Tellico::Data::EntryPtr entry = coll->entryById(1);
  QVERIFY(entry);
  QCOMPARE(entry->field("title"), QLatin1String("Lost in Translation"));
  QCOMPARE(entry->field("pub_year"), QLatin1String("1998"));
  QCOMPARE(entry->field("author"), QLatin1String("Nicole Mones; Robby Stephenson"));
  QCOMPARE(entry->field("publisher"), QLatin1String("Delacorte Press"));
  QCOMPARE(entry->field("isbn"), QLatin1String("0385319347"));
  QCOMPARE(entry->field("binding"), QLatin1String("Hardback"));
  QCOMPARE(entry->field("keyword"), QLatin1String("United States; Contemporary & Robby"));
  QCOMPARE(entry->field("pages"), QLatin1String("384"));
  QCOMPARE(entry->field("rating"), QLatin1String("4"));
  QCOMPARE(entry->field("pur_price"), QLatin1String("$23.95"));
  QCOMPARE(entry->field("pur_date"), QLatin1String("07-08-2006"));
  QVERIFY(entry->field("comments").startsWith(QLatin1String("<p><span style=\"font-size:12pt;\">Nicole Mones doesn't")));
}
Beispiel #20
0
void DeliciousTest::testMovies1() {
  QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/delicious1_movies.xml"));
  Tellico::Import::DeliciousImporter importer(url);
  Tellico::Data::CollPtr coll = importer.collection();

  QVERIFY(coll);
  QCOMPARE(coll->type(), Tellico::Data::Collection::Video);
  QCOMPARE(coll->entryCount(), 4);

  // first a movie
  Tellico::Data::EntryPtr entry = coll->entryById(2);
  QVERIFY(entry);
  QCOMPARE(entry->field("title"), QLatin1String("Driving Miss Daisy"));
  QCOMPARE(entry->field("year"), QLatin1String("1990"));
  QCOMPARE(entry->field("nationality"), QLatin1String("USA"));
  QCOMPARE(entry->field("director"), QLatin1String("Bruce Beresford"));
  QStringList cast = QStringList() << "Morgan Freeman" << "Jessica Tandy" << "Dan Aykroyd" << "Patti LuPone" << "Esther Rolle";
  QCOMPARE(entry->field("cast"), cast.join(Tellico::FieldFormat::rowDelimiterString()));
  QCOMPARE(entry->field("format"), QLatin1String("NTSC"));
  QCOMPARE(entry->field("medium"), QLatin1String("DVD"));
  QCOMPARE(entry->field("color"), QLatin1String("Color"));
  QCOMPARE(entry->field("aspect-ratio"), QLatin1String("1.85:1"));
  QCOMPARE(entry->field("audio-track"), QLatin1String("Dolby"));
  QCOMPARE(entry->field("widescreen"), QLatin1String("true"));
  QCOMPARE(entry->field("running-time"), QLatin1String("99"));
  QCOMPARE(entry->field("certification"), QLatin1String("PG (USA)"));
  QCOMPARE(entry->field("region"), QLatin1String("Region 1"));
  QCOMPARE(entry->field("rating"), QLatin1String("4.5"));
  QCOMPARE(entry->field("pur_price"), QLatin1String("$14.98"));
  QCOMPARE(entry->field("pur_date"), QLatin1String("25-03-2006"));
  QVERIFY(entry->field("keyword").startsWith(QLatin1String("Period Piece; Race Relations")));

  // check the TV show, too
  entry = coll->entryById(4);
  QVERIFY(entry);
  QCOMPARE(entry->field("title"), QLatin1String("South Park - The Complete Sixth Season"));
  QCOMPARE(entry->field("year"), QLatin1String("1997"));
  QCOMPARE(entry->field("nationality"), QLatin1String("USA"));
  QCOMPARE(entry->field("studio"), QLatin1String("Comedy Central"));
  QCOMPARE(entry->field("director"), QLatin1String("Trey Parker; Matt Stone"));
  // the shelf name gets added to keyword list
  QVERIFY(entry->field("keyword").contains(QLatin1String("TV Shows")));

  Tellico::FilterList filters = coll->filters();
  QCOMPARE(filters.count(), 1);

  Tellico::FilterPtr filter = filters.first();
  QVERIFY(filter);
  QCOMPARE(filter->name(), QLatin1String("TV Shows"));
  QVERIFY(filter->matches(entry));
}