Exemple #1
0
TEST(DurationTest, Format) {
    Duration d = Duration::fromNanos(255);
    EXPECT_QSTRING_EQ("255 ns", d.formatNanosWithUnit());

    d = Duration::fromNanos(-255);
    // Formatted as -255 in two's-complement.
    EXPECT_QSTRING_EQ("-255 ns", d.formatNanosWithUnit());

    d = Duration::fromNanos(1e9);
    EXPECT_QSTRING_EQ("1000000000 ns", d.formatNanosWithUnit());
}
Exemple #2
0
TEST_F(SkinContextTest, NoVariable) {
    // Test that converting a node to string with no variable reference works.
    QDomDocument doc;
    QDomElement test = doc.createElement("Test");
    test.appendChild(doc.createTextNode("Hello There"));
    EXPECT_QSTRING_EQ("Hello There", m_context.nodeToString(test));
}
Exemple #3
0
    void loadCoverFromFile(QString trackLocation, QString coverLocation, QString absoluteCoverLocation) {
        QImage img = QImage(absoluteCoverLocation);

        CoverInfo info;
        info.type = CoverInfo::FILE;
        info.source = CoverInfo::GUESSED;
        info.coverLocation = coverLocation;
        info.trackLocation = trackLocation;
        info.hash = 4321; // fake cover hash

        CoverArtCache::FutureResult res;
        res = CoverArtCache::loadCover(info, NULL, 1234, 0, false);
        EXPECT_EQ(1234, res.requestReference);
        EXPECT_QSTRING_EQ(info.coverLocation, res.cover.info.coverLocation);
        EXPECT_QSTRING_EQ(info.hash, res.cover.info.hash);
        EXPECT_FALSE(img.isNull());
        EXPECT_EQ(img, res.cover.image);
    }
Exemple #4
0
    void loadCoverFromMetadata(QString trackLocation) {
        CoverInfo info;
        info.type = CoverInfo::METADATA;
        info.source = CoverInfo::GUESSED;
        info.coverLocation = QString();
        info.trackLocation = trackLocation;

        CoverArtCache::FutureResult res;
        res = CoverArtCache::loadCover(info, NULL, 1234, 0, false);
        EXPECT_EQ(1234, res.requestReference);
        EXPECT_QSTRING_EQ(QString(), res.cover.info.coverLocation);
        EXPECT_QSTRING_EQ(info.hash, res.cover.info.hash);

        SecurityTokenPointer securityToken = Sandbox::openSecurityToken(
            QDir(trackLocation), true);
        TrackPointer pTrack(new TrackInfoObject(trackLocation, securityToken));
        QImage img(SoundSourceProxy(pTrack).parseCoverImage());
        EXPECT_FALSE(img.isNull());
        EXPECT_EQ(img, res.cover.image);
    }
Exemple #5
0
TEST_F(SkinContextTest, VariableByName) {
    // Evaluate a variable by name.
    QDomDocument doc;
    QDomElement test = doc.createElement("Test");
    test.appendChild(doc.createTextNode("Hello "));
    QDomElement variableNode = doc.createElement("Variable");
    variableNode.setAttribute("name", "name");
    test.appendChild(variableNode);
    m_context.setVariable("name", "Mixxx");
    EXPECT_QSTRING_EQ("Hello Mixxx", m_context.nodeToString(test));
}
Exemple #6
0
TEST_F(SkinContextTest, VariableWithFormat) {
    // Evaluate a variable with a format string.
    QDomDocument doc;
    QDomElement test = doc.createElement("Test");
    test.appendChild(doc.createTextNode("Hello "));
    QDomElement variableNode = doc.createElement("Variable");
    variableNode.setAttribute("name", "name");
    variableNode.setAttribute("format", "-%1-");
    test.appendChild(variableNode);
    m_context.setVariable("name", "Mixxx");
    EXPECT_QSTRING_EQ("Hello -Mixxx-", m_context.nodeToString(test));
}
Exemple #7
0
TEST_F(SkinContextTest, UpdateVariables) {
    // Verify that updateVariables works on all 3 types of <SetVariable> nodes.
    m_context.setVariable("test", "asdf");
    m_context.setVariable("test2", "1234");
    m_context.setVariable("test3", "foo");
    m_context.setVariable("test4", "bar");

    QDomDocument doc;
    QDomElement tmpl = doc.createElement("Template");

    // Set test to 'zxcv'.
    QDomElement var1 = doc.createElement("SetVariable");
    var1.setAttribute("name", "test");
    var1.appendChild(doc.createTextNode("zxcv"));
    tmpl.appendChild(var1);

    // Set test2 to the pattern %1_%1.
    QDomElement var2 = doc.createElement("SetVariable");
    var2.setAttribute("name", "test2");
    var2.setAttribute("format", "%1_%1");
    tmpl.appendChild(var2);

    // Set test5 to the result of test3 + test4.
    QDomElement var3 = doc.createElement("SetVariable");
    var3.setAttribute("name", "test5");
    var3.setAttribute("expression", "test3 + test4");
    tmpl.appendChild(var3);

    m_context.updateVariables(tmpl);

    EXPECT_QSTRING_EQ("zxcv", m_context.variable("test"));
    EXPECT_QSTRING_EQ("1234_1234", m_context.variable("test2"));
    EXPECT_QSTRING_EQ("foo", m_context.variable("test3"));
    EXPECT_QSTRING_EQ("bar", m_context.variable("test4"));
    EXPECT_QSTRING_EQ("foobar", m_context.variable("test5"));
}
Exemple #8
0
TEST_F(SkinContextTest, VariableWithExpression) {
    // Evaluate an ECMAScript expression in the current context.
    QDomDocument doc;
    QDomElement test = doc.createElement("Test");
    test.appendChild(doc.createTextNode("Hello "));
    QDomElement variableNode = doc.createElement("Variable");
    variableNode.setAttribute(
        "expression", "'Mixxx, value + 1 = ' + (parseInt(value) + 1)");
    test.appendChild(variableNode);
    test.appendChild(doc.createTextNode(". Isn't that great?"));
    m_context.setVariable("name", "Mixxx");
    m_context.setVariable("value", "2");
    EXPECT_QSTRING_EQ("Hello Mixxx, value + 1 = 3. Isn't that great?",
                      m_context.nodeToString(test));
}
Exemple #9
0
TEST_F(SkinContextTest, UpdateVariables_EmbeddedVariable) {
    // Check that an embedded <Variable> node inside a <SetVariable> node is
    // evaluated before assigning the variable.
    m_context.setVariable("test", "asdf");
    QDomDocument doc;
    QDomElement tmpl = doc.createElement("Template");
    QDomElement outerVar = doc.createElement("SetVariable");
    outerVar.setAttribute("name", "test2");
    outerVar.appendChild(doc.createTextNode("zxcv"));
    QDomElement innerVar = doc.createElement("Variable");
    innerVar.setAttribute("name", "test");
    outerVar.appendChild(innerVar);
    tmpl.appendChild(outerVar);

    m_context.updateVariables(tmpl);

    EXPECT_QSTRING_EQ("zxcvasdf", m_context.variable("test2"));
}
    void loadCoverFromMetadata(QString trackLocation) {
        CoverInfo info;
        info.type = CoverInfo::METADATA;
        info.source = CoverInfo::GUESSED;
        info.coverLocation = QString();
        info.trackLocation = trackLocation;

        CoverArtCache::FutureResult res;
        res = CoverArtCache::loadCover(info, NULL, 0, false);
        EXPECT_QSTRING_EQ(QString(), res.cover.coverLocation);
        EXPECT_EQ(info.hash, res.cover.hash);

        SecurityTokenPointer securityToken =
                Sandbox::openSecurityToken(QDir(trackLocation), true);
        QImage img = SoundSourceProxy::importTemporaryCoverImage(
                trackLocation, securityToken);
        EXPECT_FALSE(img.isNull());
        EXPECT_EQ(img, res.cover.image);
    }
Exemple #11
0
TEST_F(CoverArtUtilTest, searchImage) {
    // creating a temp track directory
    QString trackdir(QDir::tempPath() % "/TrackDir");
    ASSERT_FALSE(QDir().exists(trackdir)); // it must start empty
    ASSERT_TRUE(QDir().mkpath(trackdir));

    TrackPointer pTrack(Track::newTemporary(kTrackLocationTest));
    SoundSourceProxy(pTrack).loadTrackMetadata();
    QLinkedList<QFileInfo> covers;
    CoverArt res;
    // looking for cover in an empty directory
    res = CoverArtUtils::selectCoverArtForTrack(pTrack.data(), covers);
    CoverArt expected;
    expected.info.source = CoverInfo::GUESSED;
    EXPECT_EQ(expected, res);

    // Looking for a track with embedded cover.
    pTrack = TrackPointer(Track::newTemporary(kTrackLocationTest));
    SoundSourceProxy(pTrack).loadTrackMetadataAndCoverArt();
    expected = CoverArt();
    expected.image = pTrack->getCoverArt().image;
    expected.info.type = CoverInfo::METADATA;
    expected.info.source = CoverInfo::GUESSED;
    expected.info.coverLocation = QString();
    expected.info.hash = CoverArtUtils::calculateHash(expected.image);
    EXPECT_EQ(expected, pTrack->getCoverArt());

    const char* format("jpg");
    const QString qFormat(format);

    // Since we already parsed this image from the matadata in
    // kTrackLocationTest, hang on to it since we use it as a template for
    // stuff below.
    const QImage img = expected.image;


    QString trackBaseName = "cover-test";
    QString trackAlbum = "album_name";

    // Search Strategy
    // 0. If we have just one file, we will get it.
    // 1. %track-file-base%.jpg in the track directory for %track-file-base%.mp3
    // 2. %album%.jpg
    // 3. cover.jpg
    // 4. front.jpg
    // 5. album.jpg
    // 6. folder.jpg
    // 7. if just one file exists take that otherwise none.

    // All the following expect the same image/hash to be selected.
    expected.image = img;
    expected.info.hash = CoverArtUtils::calculateHash(expected.image);

    // All the following expect FILE and GUESSED.
    expected.info.type = CoverInfo::FILE;
    expected.info.source = CoverInfo::GUESSED;

    // 0. saving just one cover in our temp track dir
    QString cLoc_foo = QString(trackdir % "/" % "foo." % qFormat);
    EXPECT_TRUE(img.save(cLoc_foo, format));

    // looking for cover in an directory with one image will select that one.
    expected.image = QImage(cLoc_foo);
    expected.info.coverLocation = "foo.jpg";
    expected.info.hash = CoverArtUtils::calculateHash(expected.image);
    covers << QFileInfo(cLoc_foo);
    res = CoverArtUtils::selectCoverArtForTrack(trackBaseName, trackAlbum,
                                                covers);
    EXPECT_EQ(expected, res);
    QFile::remove(cLoc_foo);

    QStringList extraCovers;
    // adding some extra images (bigger) just to populate the track dir.
    QString cLoc_big1 = QString(trackdir % "/" % "big1." % qFormat);
    EXPECT_TRUE(img.scaled(1000,1000).save(cLoc_big1, format));
    extraCovers << cLoc_big1;
    QString cLoc_big2 = QString(trackdir % "/" % "big2." % qFormat);
    EXPECT_TRUE(img.scaled(900,900).save(cLoc_big2, format));
    extraCovers << cLoc_big2;
    QString cLoc_big3 = QString(trackdir % "/" % "big3." % qFormat);
    EXPECT_TRUE(img.scaled(800,800).save(cLoc_big3, format));
    extraCovers << cLoc_big3;

    // saving more covers using the preferred names in the right order
    QLinkedList<QFileInfo> prefCovers;
    // 1. track_filename.jpg
    QString cLoc_filename = QString(trackdir % "/cover-test." % qFormat);
    EXPECT_TRUE(img.scaled(500,500).save(cLoc_filename, format));
    prefCovers << QFileInfo(cLoc_filename);
    // 2. album_name.jpg
    QString cLoc_albumName = QString(trackdir % "/album_name." % qFormat);
    EXPECT_TRUE(img.scaled(500,500).save(cLoc_albumName, format));
    prefCovers << QFileInfo(cLoc_albumName);
    // 3. cover.jpg
    QString cLoc_cover = QString(trackdir % "/" % "cover." % qFormat);
    EXPECT_TRUE(img.scaled(400,400).save(cLoc_cover, format));
    prefCovers << QFileInfo(cLoc_cover);
    // 4. front.jpg
    QString cLoc_front = QString(trackdir % "/" % "front." % qFormat);
    EXPECT_TRUE(img.scaled(300,300).save(cLoc_front, format));
    prefCovers << QFileInfo(cLoc_front);
    // 5. album.jpg
    QString cLoc_album = QString(trackdir % "/" % "album." % qFormat);
    EXPECT_TRUE(img.scaled(100,100).save(cLoc_album, format));
    prefCovers << QFileInfo(cLoc_album);
    // 6. folder.jpg
    QString cLoc_folder = QString(trackdir % "/" % "folder." % qFormat);
    EXPECT_TRUE(img.scaled(100,100).save(cLoc_folder, format));
    prefCovers << QFileInfo(cLoc_folder);
    // 8. other1.jpg
    QString cLoc_other1 = QString(trackdir % "/" % "other1." % qFormat);
    EXPECT_TRUE(img.scaled(10,10).save(cLoc_other1, format));
    prefCovers << QFileInfo(cLoc_other1);
    // 7. other2.jpg
    QString cLoc_other2 = QString(trackdir % "/" % "other2." % qFormat);
    EXPECT_TRUE(img.scaled(10,10).save(cLoc_other2, format));
    prefCovers << QFileInfo(cLoc_other2);

    // we must find covers in the right order
    EXPECT_EQ(8, prefCovers.size());

    // Remove the covers one by one from the front, checking that each one is
    // selected as we remove the previously-most-preferable cover.
    while (!prefCovers.isEmpty()) {
        QFileInfo cover = prefCovers.first();

        // We expect no cover selected for other1 since there are 2 covers,
        // neither of which match our preferred cover names. other2 will be
        // selected once we get to it since it is the only cover available.
        if (cover.baseName() == "other1") {
            expected.image = QImage();
            expected.info.type = CoverInfo::NONE;
            expected.info.coverLocation = QString();
            expected.info.hash = 0;
        } else {
            expected.image = QImage(cover.filePath());
            expected.info.type = CoverInfo::FILE;
            expected.info.coverLocation = cover.fileName();
            expected.info.hash = CoverArtUtils::calculateHash(expected.image);
        }
        res = CoverArtUtils::selectCoverArtForTrack(trackBaseName, trackAlbum,
                                                    prefCovers);
        EXPECT_QSTRING_EQ(expected.info.coverLocation, res.info.coverLocation);
        EXPECT_QSTRING_EQ(expected.info.hash, res.info.hash);
        EXPECT_EQ(expected, res);

        QFile::remove(cover.filePath());
        prefCovers.pop_front();
    }

    //
    // Additional tests
    //

    // what is chosen when cover.jpg and cover.JPG exists?
    // (it must always prefer the lighter cover)
    QString cLoc_coverJPG = trackdir % "/" % "cover." % "JPG";
    EXPECT_TRUE(img.scaled(200,200).save(cLoc_coverJPG, "JPG"));
    prefCovers.append(QFileInfo(cLoc_coverJPG));
    QString cLoc_coverjpg = trackdir % "/" % "cover." % "jpg";
    EXPECT_TRUE(img.scaled(400,400).save(cLoc_coverjpg, "jpg"));
    prefCovers.append(QFileInfo(cLoc_coverjpg));
    extraCovers << cLoc_coverJPG << cLoc_coverjpg;

    res = CoverArtUtils::selectCoverArtForTrack(trackBaseName, trackAlbum,
                                                prefCovers);
    expected.image = QImage(cLoc_coverJPG);
    expected.info.hash = CoverArtUtils::calculateHash(expected.image);
    expected.info.coverLocation = "cover.JPG";
    EXPECT_EQ(expected, res);

    // As we are looking for %album%.jpg and %base_track.jpg%,
    // we need to check if everything works with UTF8 chars.
    trackBaseName = QString::fromUtf8("track_ðÑöæäî");
    trackAlbum = QString::fromUtf8("öæäîðÑ_album");

    prefCovers.clear();

    // 2. album_name.jpg
    cLoc_albumName = QString(trackdir % "/" % trackAlbum % "." % qFormat);
    EXPECT_TRUE(img.save(cLoc_albumName, format));
    prefCovers.append(QFileInfo(cLoc_albumName));
    res = CoverArtUtils::selectCoverArtForTrack(trackBaseName, trackAlbum,
                                                prefCovers);
    expected.image = QImage(cLoc_albumName);
    expected.info.hash = CoverArtUtils::calculateHash(expected.image);
    expected.info.coverLocation = trackAlbum % ".jpg";
    EXPECT_EQ(expected, res);

    // 1. track_filename.jpg
    cLoc_filename = QString(trackdir % "/" % trackBaseName % "." % qFormat);
    EXPECT_TRUE(img.save(cLoc_filename, format));
    prefCovers.append(QFileInfo(cLoc_filename));
    res = CoverArtUtils::selectCoverArtForTrack(trackBaseName, trackAlbum,
                                                prefCovers);
    expected.image = QImage(cLoc_filename);
    expected.info.hash = CoverArtUtils::calculateHash(expected.image);
    expected.info.coverLocation = trackBaseName % ".jpg";
    EXPECT_EQ(expected, res);

    QFile::remove(cLoc_filename);
    QFile::remove(cLoc_albumName);

    // cleaning temp dir
    foreach (QString loc, extraCovers) {
        QFile::remove(loc);
    }
Exemple #12
0
TEST_F(SkinContextTest, TestVariable) {
    // Basic check that variable lookup works.
    m_context.setVariable("test", "asdf");
    EXPECT_QSTRING_EQ("asdf", m_context.variable("test"));
}