void FavoriteTest::testGetNote() { QDateTime date = QDateTime::fromString("2016-07-02 16:35:12", "yyyy-MM-dd HH:mm:ss"); Favorite fav("fate/stay_night", 50, date); QCOMPARE(fav.getNote(), 50); }
void FavoriteTest::testGetImagePath() { QDateTime date = QDateTime::fromString("2016-07-02 16:35:12", "yyyy-MM-dd HH:mm:ss"); Favorite fav("fate/stay_night", 50, date, "test/test.jpg"); QCOMPARE(fav.getImagePath(), QString("test/test.jpg")); }
void FavoriteTest::testToString() { QDateTime date = QDateTime::fromString("2016-07-02 16:35:12", "yyyy-MM-dd HH:mm:ss"); Favorite fav("fate/stay_night", 50, date); QCOMPARE(fav.toString(), QString("fate/stay_night|50|2016-07-02T16:35:12")); }
void FavoriteTest::testSetLastViewed() { QDateTime date = QDateTime::fromString("2016-07-02 16:35:12", "yyyy-MM-dd HH:mm:ss"); Favorite fav("fate/stay_night", 50, QDateTime::currentDateTime()); fav.setLastViewed(date); QCOMPARE(fav.getLastViewed(), date); }
void FavoriteTest::testBasicConstructor() { Favorite fav("test"); QCOMPARE(fav.getName(), QString("test")); QCOMPARE(fav.getNote(), 50); QVERIFY(fav.getLastViewed() > QDateTime::currentDateTime().addSecs(-60) && fav.getLastViewed() < QDateTime::currentDateTime().addSecs(60)); }
void FavoriteTest::testGetImageNotExists() { QFile file(savePath("thumbs/tag1.png")); if (file.exists()) file.remove(); QDateTime date = QDateTime::fromString("2016-07-02 16:35:12", "yyyy-MM-dd HH:mm:ss"); Favorite fav("tag1", 50, date); QPixmap img = fav.getImage(); QCOMPARE(img.isNull(), true); }
void FavoriteTest::testGetImageResize() { QFile file(savePath("thumbs/tag1.png")); if (file.exists()) file.remove(); QDateTime date = QDateTime::fromString("2016-07-02 16:35:12", "yyyy-MM-dd HH:mm:ss"); Favorite fav("tag1", 50, date, QDir::currentPath() + "/tests/resources/image_200x200.png"); QPixmap actual = fav.getImage(); QCOMPARE(file.exists(), true); QCOMPARE(actual.isNull(), false); QCOMPARE(actual.size(), QSize(150, 150)); }
void FavoriteTest::testSetImageFirst() { QFile file(savePath("thumbs/tag1.png")); if (file.exists()) file.remove(); QDateTime date = QDateTime::fromString("2016-07-02 16:35:12", "yyyy-MM-dd HH:mm:ss"); Favorite fav("tag1", 50, date); QPixmap img(QDir::currentPath() + "/tests/resources/image_200x200.png"); fav.setImage(img); QCOMPARE(file.exists(), true); }
void ProfileTest::testRemoveFavoriteThumb() { Favorite fav("tag_1", 20, QDateTime(QDate(2016, 9, 1), QTime(9, 23, 17))); QDir(m_profile->getPath()).mkdir("thumb"); QFile thumb(m_profile->getPath() + "/thumbs/" + fav.getName(true) + ".png"); thumb.open(QFile::WriteOnly | QFile::Truncate); thumb.write(QString("test").toUtf8()); thumb.close(); QVERIFY(thumb.exists()); m_profile->removeFavorite(fav); QVERIFY(!thumb.exists()); }
void zoomWindow::setfavorite() { if (!QDir(savePath("thumbs")).exists()) { QDir(savePath()).mkdir("thumbs"); } if (image != nullptr) { Favorite fav(link, 50, QDateTime::currentDateTime()); fav.setImage(*image); } _mainwindow->updateFavorites(); _mainwindow->updateFavoritesDock(); }
void ProfileTest::testAddFavorite() { Favorite fav("tag_3", 70, QDateTime(QDate(2016, 7, 1), QTime(9, 12, 17))); m_profile->addFavorite(fav); m_profile->sync(); QFile f("tests/resources/favorites.txt"); f.open(QFile::ReadOnly | QFile::Text); QStringList lines = QString(f.readAll()).split("\n", QString::SkipEmptyParts); f.close(); QCOMPARE(lines.count(), 3); QCOMPARE(lines[0], Favorite("tag_1", 20, QDateTime(QDate(2016, 9, 1), QTime(9, 23, 17))).toString()); QCOMPARE(lines[1], Favorite("tag_2", 100, QDateTime(QDate(2016, 10, 1), QTime(12, 23, 17))).toString()); QCOMPARE(lines[2], fav.toString()); }