~mandel/ubuntu-download-manager/string-id

« back to all changes in this revision

Viewing changes to ubuntu-download-manager-tests/test_download.cpp

  • Committer: Tarmac
  • Author(s): Manuel de la Pena
  • Date: 2013-10-09 21:49:05 UTC
  • mfrom: (147.1.3 remove-after-process)
  • Revision ID: tarmac-20131009214905-8pa395zxfi3rt6vo
Remove the file after the successful execution of the post-download command line. Fixes: https://bugs.launchpad.net/bugs/1233209.

Approved by PS Jenkins bot, Diego Sarmentero.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1550
1550
}
1551
1551
 
1552
1552
void
 
1553
TestDownload::testFileRemoveAfterSuccessfulProcess() {
 
1554
    // assert that the file is indeed removed
 
1555
    QVariantMap metadata;
 
1556
    QStringList command;
 
1557
    command << "grep" << "$file" << "-Rn";
 
1558
    metadata["post-download-command"] = command;
 
1559
 
 
1560
    _processFactory->record();
 
1561
    _reqFactory->record();
 
1562
    SingleDownload* download = new SingleDownload(_id, _path, _isConfined,
 
1563
        _rootPath, _url, metadata, _headers,
 
1564
        QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
1565
        QSharedPointer<RequestFactory>(_reqFactory),
 
1566
        QSharedPointer<ProcessFactory>(_processFactory));
 
1567
 
 
1568
    // write something in the expected file
 
1569
    QString fileName = download->filePath();
 
1570
    QFile* file = new QFile(fileName);
 
1571
    file->open(QIODevice::ReadWrite | QFile::Append);
 
1572
    file->write("my data goes here");
 
1573
    file->close();
 
1574
 
 
1575
    download->start();  // change state
 
1576
    download->startDownload();
 
1577
 
 
1578
    // we need to set the data before we pause!!!
 
1579
    QList<MethodData> calledMethods = _reqFactory->calledMethods();
 
1580
    QCOMPARE(1, calledMethods.count());
 
1581
    FakeNetworkReply* reply = reinterpret_cast<FakeNetworkReply*>(
 
1582
        calledMethods[0].params().outParams()[0]);
 
1583
 
 
1584
    // makes the process to be executed
 
1585
    reply->emitFinished();
 
1586
 
 
1587
    calledMethods = _processFactory->calledMethods();
 
1588
    QCOMPARE(1, calledMethods.count());
 
1589
    FakeProcess* process = reinterpret_cast<FakeProcess*>(
 
1590
        calledMethods[0].params().outParams()[0]);
 
1591
 
 
1592
    // emit the finished signal with a result > 0 and ensure error is emitted
 
1593
    process->emitFinished(0, QProcess::NormalExit);
 
1594
    // asser that the file does not longer exist in the system
 
1595
    QVERIFY(!QFile::exists(fileName));
 
1596
}
 
1597
 
 
1598
void
1553
1599
TestDownload::testSetRawHeaderAcceptEncoding_data() {
1554
1600
    QTest::addColumn<QMap<QString, QString> >("headers");
1555
1601