activityfw/activityserviceplugin/tsrc/unittest_commandlineparser/src/unittest_commandlineparser.cpp
author Jaakko Haukipuro (Nokia-MS/Oulu) <Jaakko.Haukipuro@nokia.com>
Thu, 16 Sep 2010 12:11:40 +0100
changeset 117 c63ee96dbe5f
permissions -rw-r--r--
Missing activityfw and taskswitcher components - fix for Bug 3670

/*
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:
*
*/
#include "unittest_commandlineparser.h"

#include <QtTest/QtTest>
#include <QVariant>
#include <QString>
#include <QStringList>

#include "afactivities_global.h"
#include "afcommandlineparser.h"

void TestCommandLineParser::testActivityUriParsingAllOk()
{
    QStringList commandLine;
    commandLine << "Appname" << "-activity" << QString("appto://DEADBEEF?%1=TestActivity1").arg(Af::KActivityUriNameKey);

    QVariantHash activityParams = QVariantHash();
    QString name = QString();
    Af::ActivationReason reason = Af::ActivationReasonNormal;
    
    AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams);
    
    QCOMPARE(activityParams.count(), 1);
    QVERIFY(activityParams.contains(Af::KActivityUriNameKey));
    QCOMPARE(activityParams.value(Af::KActivityUriNameKey), QVariant("TestActivity1"));
    QCOMPARE(name, QString("TestActivity1"));
    QCOMPARE(reason, Af::ActivationReasonActivity);
}

void TestCommandLineParser::testActivityUriParsingEmptyActivityName()
{
    QStringList commandLine;
    commandLine << "Appname" << "-activity" << QString("appto://DEADBEEF?%1=&someKey=someValue").arg(Af::KActivityUriNameKey);
    
    QVariantHash activityParams = QVariantHash();
    QString name = QString();
    Af::ActivationReason reason = Af::ActivationReasonNormal;
    
    AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams);
    
    QCOMPARE(activityParams.count(), 0);
    QVERIFY(name.isEmpty());
    QCOMPARE(reason, Af::ActivationReasonNormal);
}

void TestCommandLineParser::testActivityUriParsingNoActivityName()
{
    QStringList commandLine;
    commandLine << "Appname" << "-activity" << "appto://DEADBEEF?someKey=someValue";

    QVariantHash activityParams = QVariantHash();
    QString name = QString();
    Af::ActivationReason reason = Af::ActivationReasonNormal;
    
    AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams);
    
    QCOMPARE(activityParams.count(), 0);
    QVERIFY(name.isEmpty());
    QCOMPARE(reason, Af::ActivationReasonNormal);
}

void TestCommandLineParser::testActivityUriParsingNoArgumentAfterMarker()
{
    QStringList commandLine;
    commandLine << "Appname" << "-activity";

    QVariantHash activityParams = QVariantHash();
    QString name = QString();
    Af::ActivationReason reason = Af::ActivationReasonNormal;
    
    AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams);
    
    QCOMPARE(activityParams.count(), 0);
    QVERIFY(name.isEmpty());
    QCOMPARE(reason, Af::ActivationReasonNormal);
}

void TestCommandLineParser::testActivityUriParsingNoMarker()
{
    QStringList commandLine;
    commandLine << "Appname";

    QVariantHash activityParams = QVariantHash();
    QString name = QString();
    Af::ActivationReason reason = Af::ActivationReasonNormal;
    
    AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams);
    
    QCOMPARE(activityParams.count(), 0);
    QVERIFY(name.isEmpty());
    QCOMPARE(reason, Af::ActivationReasonNormal);
}

void TestCommandLineParser::testActivityUriParsingNoUriAfterMarker()
{
    QStringList commandLine;
    commandLine << "Appname"<< "-activity" << "adsasdasd";

    QVariantHash activityParams = QVariantHash();
    QString name = QString();
    Af::ActivationReason reason = Af::ActivationReasonNormal;
    
    AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams);
    
    QCOMPARE(activityParams.count(), 0);
    QVERIFY(name.isEmpty());
    QCOMPARE(reason, Af::ActivationReasonNormal);
}

void TestCommandLineParser::testNormalStartParsingEmpty()
{
    QStringList commandLine;
    commandLine << "Appname";

    QVariantHash activityParams = QVariantHash();
    QString name = QString();
    Af::ActivationReason reason = Af::ActivationReasonNormal;
    
    AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams);
    
    QCOMPARE(activityParams.count(), 0);
    QVERIFY(name.isEmpty());
    QCOMPARE(reason, Af::ActivationReasonNormal);
}

void TestCommandLineParser::testNormalStartParsingSomeParameters()
{
    QStringList commandLine;
    commandLine << "Appname" << "test1" << "test2";

    QVariantHash activityParams = QVariantHash();
    QString name = QString();
    Af::ActivationReason reason = Af::ActivationReasonNormal;
    
    AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams);
    
    QCOMPARE(activityParams.count(), 0);
    QVERIFY(name.isEmpty());
    QCOMPARE(reason, Af::ActivationReasonNormal);
}

void TestCommandLineParser::testNormalStartParsingOneParameter()
{
    QStringList commandLine;
    commandLine << "Appname" << "test1%&^test2";

    QVariantHash activityParams = QVariantHash();
    QString name = QString();
    Af::ActivationReason reason = Af::ActivationReasonNormal;
    
    AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams);
    
    QCOMPARE(activityParams.count(), 0);
    QVERIFY(name.isEmpty());
    QCOMPARE(reason, Af::ActivationReasonNormal);
}

void TestCommandLineParser::testServiceParsing()
{
    QStringList commandLine;
    commandLine << "Appname " << "service=yes" << "intf=IntName" << "oper=Operation";

    QVariantHash activityParams = QVariantHash();
    QString name = QString();
    Af::ActivationReason reason = Af::ActivationReasonNormal;
    
    AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams);
    
    QCOMPARE(activityParams.count(), 2);
    QCOMPARE(activityParams.value("oper"), QVariant("Operation"));
    QCOMPARE(name, QString("IntName"));
    QCOMPARE(reason, Af::ActivationReasonService);
}

void TestCommandLineParser::testServiceParsingEmbedded()
{
    QStringList commandLine;
    commandLine << "Appname " << "embedded=yes" << "service=yes" << "intf=IntName" << "oper=Operation";

    QVariantHash activityParams = QVariantHash();
    QString name = QString();
    Af::ActivationReason reason = Af::ActivationReasonNormal;
    
    AfCommandLineParser::parseCommandLine(commandLine, reason, name, activityParams);
    
    QCOMPARE(activityParams.count(), 3);
    QCOMPARE(activityParams.value("oper"), QVariant("Operation"));
    QCOMPARE(activityParams.value("embedded"), QVariant(true));
    QCOMPARE(name, QString("IntName"));
    QCOMPARE(reason, Af::ActivationReasonService);
}