searchui/stateproviders/searchstateprovider/tsrc/t_searchstateprovider/src/t_searchstateprovider.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 02 Sep 2010 20:27:46 +0300
changeset 20 68cdadcf169e
parent 17 7d8c8d8f5eab
child 21 708468d5143e
permissions -rw-r--r--
Revision: 201033 Kit: 201035

/*
 * 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:  Main test class for searchstateprovider library.
 *
 */

#include "t_searchstateprovider.h"
//#include "searchruntimeprovider.h"
#include "searchstateprovider.h"
#include "searchuiloader.h"
#include <qmetatype.h>
#include <qstate.h>
#include <hblistwidget.h>
#include <hbsearchpanel.h>
#include <hbinstance.h>
#include <hbmainwindow.h>
#include <hbview.h>
#include <hbgraphicsscene.h>

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//

SearchStateProviderTest::SearchStateProviderTest()
    {

    }

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
SearchStateProviderTest::~SearchStateProviderTest()
    {
    delete mMainWindow;
    }

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
void SearchStateProviderTest::init()
    {

    // delete mMainWindow;
    }

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
void SearchStateProviderTest::initTestCase()
    {
    mMainWindow = mainWindow();
    }

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
void SearchStateProviderTest::cleanupTestCase()
    {

    }

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
void SearchStateProviderTest::testCreateAndDestructSearchStateProvider()
    {
    SearchStateProvider provider;

    /*   QVERIFY(provider.mWizardMenuStateToken.mLibrary == "searchstateprovider.dll");
     QVERIFY(provider.mWizardMenuStateToken.mUri == "search.nokia.com/state/wizardprogressivestate");

     QVERIFY(provider.mWizardActivatedStateToken.mLibrary == "searchstateprovider.dll");
     QVERIFY(provider.mWizardActivatedStateToken.mUri == "search.nokia.com/state/wizardsettingstate");

     QVERIFY(provider.mInitStateToken.mLibrary == "searchstateprovider.dll");
     QVERIFY(provider.mInitStateToken.mUri == "search.nokia.com/state/initstate");
     */}

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
void SearchStateProviderTest::testStates()
    {
    /*  SearchStateProvider provider;
    
     QCOMPARE(states.count(), 3);

     */}

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
void SearchStateProviderTest::testCreateProgressiveState()
    {

    QVERIFY(verifyStateCreation("search.nokia.com/state/wizardprogressivestate"));
    // delete wind;
    }
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
void SearchStateProviderTest::testCreateSettingsState()
    {
    //HbMainWindow* wind = mainWindow();   
    QVERIFY(verifyStateCreation("search.nokia.com/state/wizardsettingstate"));
    // delete wind;
    }
void SearchStateProviderTest::testcreatenanddelete()
    {    
    SearchUiLoader* uiloader = SearchUiLoader::instance();    
    QVERIFY(uiloader->View());
    QVERIFY(uiloader->ListWidget());
    QVERIFY(uiloader->SearchPanel());
    uiloader->deleteLater();
    }
void SearchStateProviderTest::testslotsendtobackground()
    {
    SearchUiLoader* uiloader = SearchUiLoader::instance();
    uiloader->slotsendtobackground();
    QCOMPARE(uiloader->mListWidget->count(),0);
    QCOMPARE(uiloader->mSearchPanel->criteria(),QString());
    uiloader->deleteLater();
    }
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
void SearchStateProviderTest::testCreateinitState()
    {
    //HbMainWindow* wind = mainWindow();   
    QVERIFY(verifyStateCreation("search.nokia.com/state/initstate"));
    //  delete wind;
    }

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
bool SearchStateProviderTest::verifyStateCreation(const QString& uri)
    {
    SearchStateProvider provider;
    QState* state = provider.createState(uri);
    bool result = (state != NULL);
    if (state)
        {
        delete state;
        }
    return result;
    }

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
HbMainWindow* SearchStateProviderTest::mainWindow()
    {
    int count = HbInstance::instance()->allMainWindows().count();

    for (int i = count - 1; i > -1; i--)
        {
        delete HbInstance::instance()->allMainWindows().at(i);
        }
    return new HbMainWindow;
    }

#ifdef Q_OS_SYMBIAN

//QTEST_MAIN corrected since crashes if TRAP not in correct place.
//Will be corrected in later (estimate 4.6.0) Qt release for Symbian.
int main(int argc, char *argv[])
    {
    QCoreApplication app(argc, argv);
#ifdef __WINSCW__
    char *new_argv[3];
    QString str = "C:\\data\\" + QFileInfo(
            QCoreApplication::applicationFilePath()).baseName() + ".log";
    QByteArray bytes = str.toAscii();
    char arg1[] = "-o";
    new_argv[0] = argv[0];
    new_argv[1] = arg1;
    new_argv[2] = bytes.data();
    SearchStateProviderTest tc;
    return QTest::qExec(&tc, 3, new_argv);
#else
    SearchStateProviderTest tc;
    return QTest::qExec(&tc, argc, argv);
#endif
    }
#else //Q_OS_SYMBIAN
QTEST_MAIN(SearchStateProviderTest)
#endif //Q_OS_SYMBIAN