Exemplo n.º 1
0
void AddCommandTest::testAddItem()
{
    QTemporaryFile tempFile;
    tempFile.setAutoRemove(false);
    tempFile.open();
    tempFile.write("Hello World!");

    const char *args[6] = {
        "akonadiclient",
        "add",
        "/res3",
        tempFile.fileName().toLocal8Bit().data(),
        "--base",
        QDir::tempPath().toLocal8Bit().data()
    };

    tempFile.close();
    KCmdLineArgs *parsedArgs = getParsedArgs(6, args);

    AddCommand *command = new AddCommand(this);

    int ret = command->init(parsedArgs);
    QCOMPARE(ret, 0);

    ret = runCommand(command);
    QCOMPARE(ret, 0);
}
Exemplo n.º 2
0
void AddCommandTest::testAddItem()
{
    QDir dir(mTempDir->name());
    dir.cd("foo");
    QDir::setCurrent(dir.absolutePath());

    CollectionResolveJob *resolveJob = new CollectionResolveJob("/res3", this);
    QVERIFY(resolveJob->hasUsableInput());
    AKVERIFYEXEC(resolveJob);

    QVERIFY(resolveJob->collection().isValid());

    Collection col;
    col.setName("test");
    col.setParentCollection(resolveJob->collection());

    CollectionCreateJob *createJob = new CollectionCreateJob(col, this);
    AKVERIFYEXEC(createJob);

    col = createJob->collection();
    QVERIFY(col.isValid());

    const int numArgs = 5;
    QVector<QByteArray> args;
    args.reserve(numArgs);
    args << "akonadiclient" << "add" << "/res3/test" << "../test.txt" << "bar";

    const char *testArgs[numArgs];
    for (int i = 0; i < numArgs; i++) {
        testArgs[i] = args.at(i).data();
    }

    KCmdLineArgs *parsedArgs = getParsedArgs(numArgs, testArgs);

    AddCommand *command = new AddCommand(this);

    int ret = command->init(parsedArgs);
    QCOMPARE(ret, 0);

    ret = runCommand(command);
    QCOMPARE(ret, 0);

    ItemFetchJob *itemFetchJob1 = new ItemFetchJob(col, this);
    itemFetchJob1->fetchScope().fetchAllAttributes(false);
    itemFetchJob1->fetchScope().fetchFullPayload(true);

    AKVERIFYEXEC(itemFetchJob1);

    QCOMPARE(itemFetchJob1->items().count(), 1);
    QCOMPARE(itemFetchJob1->items().at(0).payloadData(), QByteArray("Testing"));

    CollectionFetchJob *fetchJob1 = new CollectionFetchJob(col, CollectionFetchJob::FirstLevel, this);
    AKVERIFYEXEC(fetchJob1);

    QCOMPARE(fetchJob1->collections().count(), 1);

    col = fetchJob1->collections().at(0);
    QCOMPARE(col.name(), QString("bar"));

    ItemFetchJob *itemFetchJob2 = new ItemFetchJob(col, this);
    itemFetchJob2->fetchScope().fetchAllAttributes(false);
    itemFetchJob2->fetchScope().fetchFullPayload(true);

    AKVERIFYEXEC(itemFetchJob2);
    QCOMPARE(itemFetchJob2->items().count(), 1);
    QCOMPARE(itemFetchJob2->items().at(0).payloadData(), QByteArray("Bar Item"));
}