Ejemplo n.º 1
0
void JobTest::moveDirectoryToSamePartition()
{
    kdDebug() << k_funcinfo << endl;
    const QString src = homeTmpDir() + "dirFromHome";
    const QString dest = homeTmpDir() + "dirFromHome_moved";
    createTestDirectory(src);
    moveLocalDirectory(src, dest);
}
Ejemplo n.º 2
0
void JobTest::moveFileToSamePartition()
{
    kdDebug() << k_funcinfo << endl;
    const QString filePath = homeTmpDir() + "fileFromHome";
    const QString dest = homeTmpDir() + "fileFromHome_moved";
    createTestFile(filePath);
    moveLocalFile(filePath, dest);
}
Ejemplo n.º 3
0
void JobTest::copyDirectoryToExistingDirectory()
{
    kdDebug() << k_funcinfo << endl;
    // just the same as copyDirectoryToSamePartition, but it means that
    // this time dest exists.
    const QString src = homeTmpDir() + "dirFromHome";
    const QString dest = homeTmpDir() + "dirFromHome_copied";
    createTestDirectory(src);
    copyLocalDirectory(src, dest, AlreadyExists);
}
Ejemplo n.º 4
0
void JobTest::setup()
{
    // Start with a clean base dir
    cleanup();
    QDir dir; // TT: why not a static method?
    bool ok = dir.mkdir(homeTmpDir());
    if(!ok)
        kdFatal() << "Couldn't create " << homeTmpDir() << endl;
    ok = dir.mkdir(otherTmpDir());
    if(!ok)
        kdFatal() << "Couldn't create " << otherTmpDir() << endl;
    ok = dir.mkdir(realSystemPath());
    if(!ok)
        kdFatal() << "Couldn't create " << realSystemPath() << endl;
}
Ejemplo n.º 5
0
void JobTest::moveFileNoPermissions()
{
    kdDebug() << k_funcinfo << endl;
    const QString src = "/etc/passwd";
    const QString dest = homeTmpDir() + "passwd";
    assert(QFile::exists(src));
    assert(QFileInfo(src).isFile());
    KURL u;
    u.setPath(src);
    KURL d;
    d.setPath(dest);

    KIO::CopyJob *job = KIO::move(u, d, 0);
    job->setInteractive(false); // no skip dialog, thanks
    QMap< QString, QString > metaData;
    bool ok = KIO::NetAccess::synchronousRun(job, 0, 0, 0, &metaData);
    assert(!ok);
    assert(KIO::NetAccess::lastError() == KIO::ERR_ACCESS_DENIED);
    // OK this is fishy. Just like mv(1), KIO's behavior depends on whether
    // a direct rename(2) was used, or a full copy+del. In the first case
    // there is no destination file created, but in the second case the
    // destination file remains.
    // In fact we assume /home is a separate partition, in this test, so:
    assert(QFile::exists(dest));
    assert(QFile::exists(src));
}
Ejemplo n.º 6
0
void JobTest::moveSymlinkToOtherPartition()
{
    kdDebug() << k_funcinfo << endl;
    const QString filePath = homeTmpDir() + "testlink";
    const QString dest = otherTmpDir() + "testlink_moved";
    createTestSymlink(filePath);
    moveLocalSymlink(filePath, dest);
}
Ejemplo n.º 7
0
void JobTest::copyFileToOtherPartition()
{
    kdDebug() << k_funcinfo << endl;
    const QString filePath = homeTmpDir() + "fileFromHome";
    const QString dest = otherTmpDir() + "fileFromHome_copied";
    createTestFile(filePath);
    copyLocalFile(filePath, dest);
}
Ejemplo n.º 8
0
void JobTest::copyFileToSystem(bool resolve_local_urls)
{
    kdDebug() << k_funcinfo << resolve_local_urls << endl;
    extern KIO_EXPORT bool kio_resolve_local_urls;
    kio_resolve_local_urls = resolve_local_urls;

    const QString src = homeTmpDir() + "fileFromHome";
    createTestFile(src);
    KURL u;
    u.setPath(src);
    KURL d = systemTmpDir();
    d.addPath("fileFromHome_copied");

    kdDebug() << "copying " << u << " to " << d << endl;

    // copy the file with file_copy
    KIO::FileCopyJob *job = KIO::file_copy(u, d);
    connect(job, SIGNAL(mimetype(KIO::Job *, const QString &)), this, SLOT(slotMimetype(KIO::Job *, const QString &)));
    bool ok = KIO::NetAccess::synchronousRun(job, 0);
    assert(ok);

    QString dest = realSystemPath() + "fileFromHome_copied";

    assert(QFile::exists(dest));
    assert(QFile::exists(src)); // still there

    {
        // do NOT check that the timestamp is the same.
        // It can't work with file_copy when it uses the datapump,
        // unless we use setModificationTime in the app code.
    }

    // Check mimetype
    kdDebug() << m_mimetype << endl;
    // There's no mimemagic determination in kio_file in kde3. Fixing this for kde4...
    assert(m_mimetype == "application/octet-stream");
    // assert( m_mimetype == "text/plain" );

    // cleanup and retry with KIO::copy()
    QFile::remove(dest);
    ok = KIO::NetAccess::dircopy(u, d, 0);
    assert(ok);
    assert(QFile::exists(dest));
    assert(QFile::exists(src)); // still there
    {
        // check that the timestamp is the same (#79937)
        QFileInfo srcInfo(src);
        QFileInfo destInfo(dest);
        assert(srcInfo.lastModified() == destInfo.lastModified());
    }

    // restore normal behavior
    kio_resolve_local_urls = true;
}
Ejemplo n.º 9
0
void JobTest::copyDirectoryToOtherPartition()
{
    kdDebug() << k_funcinfo << endl;
    const QString src = homeTmpDir() + "dirFromHome";
    const QString dest = otherTmpDir() + "dirFromHome_copied";
    // src is already created by copyDirectoryToSamePartition()
    // so this is just in case someone calls this method only
    if(!QFile::exists(src))
        createTestDirectory(src);
    copyLocalDirectory(src, dest);
}
Ejemplo n.º 10
0
void JobTest::get()
{
    kdDebug() << k_funcinfo << endl;
    const QString filePath = homeTmpDir() + "fileFromHome";
    createTestFile(filePath);
    KURL u;
    u.setPath(filePath);
    m_result = -1;
    KIO::StoredTransferJob *job = KIO::storedGet(u);
    connect(job, SIGNAL(result(KIO::Job *)), this, SLOT(slotGetResult(KIO::Job *)));
    kapp->eventLoop()->enterLoop();
    assert(m_result == 0); // no error
    assert(m_data.size() == 11);
    assert(QCString(m_data) == "Hello world");
}
Ejemplo n.º 11
0
void JobTest::listRecursive()
{
    const QString src = homeTmpDir();
    KURL u;
    u.setPath(src);
    KIO::ListJob *job = KIO::listRecursive(u);
    connect(job, SIGNAL(entries(KIO::Job *, const KIO::UDSEntryList &)), SLOT(slotEntries(KIO::Job *, const KIO::UDSEntryList &)));
    bool ok = KIO::NetAccess::synchronousRun(job, 0);
    assert(ok);
    m_names.sort();
    check("listRecursive", m_names.join(","),
          ".,..,"
          "dirFromHome,dirFromHome/testfile,dirFromHome/testlink,dirFromHome_copied,"
          "dirFromHome_copied/dirFromHome,dirFromHome_copied/dirFromHome/testfile,dirFromHome_copied/dirFromHome/testlink,"
          "dirFromHome_copied/testfile,dirFromHome_copied/testlink,"
          "fileFromHome,fileFromHome_copied");
}
Ejemplo n.º 12
0
    void pasteFileToOtherPartition()
    {
        const QString filePath = homeTmpDir() + "fileFromHome";
        const QString dest = otherTmpDir() + "fileFromHome_copied";
        QFile::remove(dest);
        createTestFile( filePath );

        QMimeData* mimeData = new QMimeData;
        KUrl fileUrl(filePath);
        fileUrl.populateMimeData(mimeData);
        QApplication::clipboard()->setMimeData(mimeData);

        KIO::Job* job = KIO::pasteClipboard(otherTmpDir(), static_cast<QWidget*>(0));
        job->setUiDelegate(0);
        bool ok = KIO::NetAccess::synchronousRun(job, 0);
        QVERIFY( ok );

        QVERIFY( QFile::exists( dest ) );
        QVERIFY( QFile::exists( filePath ) ); // still there
    }
Ejemplo n.º 13
0
void JobTest::moveDirectoryNoPermissions()
{
    kdDebug() << k_funcinfo << endl;
    const QString src = "/etc/init.d";
    const QString dest = homeTmpDir() + "init.d";
    assert(QFile::exists(src));
    assert(QFileInfo(src).isDir());
    KURL u;
    u.setPath(src);
    KURL d;
    d.setPath(dest);

    KIO::CopyJob *job = KIO::move(u, d, 0);
    job->setInteractive(false); // no skip dialog, thanks
    QMap< QString, QString > metaData;
    bool ok = KIO::NetAccess::synchronousRun(job, 0, 0, 0, &metaData);
    assert(!ok);
    assert(KIO::NetAccess::lastError() == KIO::ERR_ACCESS_DENIED);
    assert(QFile::exists(dest)); // see moveFileNoPermissions
    assert(QFile::exists(src));
}
Ejemplo n.º 14
0
 void cleanupTestCase()
 {
     delDir( homeTmpDir() );
     delDir( otherTmpDir() );
 }
Ejemplo n.º 15
0
void JobTest::cleanup()
{
    KIO::NetAccess::del(homeTmpDir(), 0);
    KIO::NetAccess::del(otherTmpDir(), 0);
    KIO::NetAccess::del(systemTmpDir(), 0);
}