<commit_before>/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of meegotouch-controlpanelapplets.
**
** If you have questions regarding the use of this file, please contact
** Nokia at <EMAIL>.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/
#include "ut_aboutbusinesslogic.h"
#include "aboutbusinesslogic.h"

#include <stdint.h>
#include <inttypes.h>
#include <QMap>
#include <QDebug>
#include <QString>
#include <QVariant>
#include <QByteArray>

#include <QSystemInfo>
#include <QSystemDeviceInfo>
#include <QSystemNetworkInfo>
#include <QNetworkInterface>

#include <MApplication>

#define DEBUG
#include "../../src/debug.h"

/******************************************************************************
 * Stubbing the QNetworkInfo
 */
QString qnetworkinterface_hwaddr;

QString
QNetworkInterface::hardwareAddress () const
{
    return qnetworkinterface_hwaddr;
}

bool
QNetworkInterface::isValid () const
{
    return ! qnetworkinterface_hwaddr.isNull ();
}

/******************************************************************************
 * Stubbing the QSystemDeviceInfo::imei () and QSystemInfo::version ()
 */
QString systemdeviceinfo_imei_retval;
QString systeminfo_firmware_retval;

QTM_BEGIN_NAMESPACE

QString
QSystemDeviceInfo::imei()
{
    return systemdeviceinfo_imei_retval;
}

QString
QSystemInfo::version (
    QSystemInfo::Version type,
    const QString &parameter)
{
    Q_UNUSED (type);
    Q_UNUSED (parameter);
    return systeminfo_firmware_retval;
}

QSystemNetworkInfo::QSystemNetworkInfo (QObject *parent)
{
    Q_UNUSED (parent);
}

QSystemNetworkInfo::~QSystemNetworkInfo ()
{
}

QNetworkInterface qnetif_for_testing;

QNetworkInterface
QSystemNetworkInfo::interfaceForMode (QSystemNetworkInfo::NetworkMode mode)
{
    Q_UNUSED (mode);
    return qnetif_for_testing;
}

QTM_END_NAMESPACE

/******************************************************************************
 * Stubbing the dbus interface.
 */
static QString lastCalledMethod;

bool
QDBusAbstractInterface::callWithCallback (
        const QString           &method,
        const QList<QVariant>   &args,
        QObject                 *receiver,
        const char              *returnMethod,
        const char              *errorMethod)
{
    Q_UNUSED (args);
    Q_UNUSED (receiver);
    Q_UNUSED (errorMethod);
    Q_UNUSED (returnMethod);

    SYS_DEBUG ("*** method       = %s", SYS_STR(method));
    SYS_DEBUG ("*** returnMethod = %s", returnMethod);

    lastCalledMethod = method;
    return true;
}

/******************************************************************************
 * Ut_AboutBusinessLogic implementation.
 */
void
Ut_AboutBusinessLogic::init()
{
    m_Api = new AboutBusinessLogic;
}

void
Ut_AboutBusinessLogic::cleanup()
{
    delete m_Api;
    m_Api = 0;
}


static int argc = 1;
static char *app_name = (char*) "./ut_aboutbusinesslogic";

void
Ut_AboutBusinessLogic::initTestCase()
{
    m_App = new MApplication (argc, &app_name);
}

void
Ut_AboutBusinessLogic::cleanupTestCase()
{
    m_App->deleteLater ();
}

void
Ut_AboutBusinessLogic::testImei()
{
    systemdeviceinfo_imei_retval = "AA-BBBBBB-CCCCCC-D";

    QCOMPARE (m_Api->IMEI (), systemdeviceinfo_imei_retval);
}

void
Ut_AboutBusinessLogic::testOsName ()
{
    QString name;

    name = m_Api->osName();
    QCOMPARE (name, QString ("qtn_prod_sw_version"));
}

void
Ut_AboutBusinessLogic::testOsVersion ()
{
    QString name;

    systeminfo_firmware_retval = "HARDWARE_PROGRAM_VERSION13";
    name = m_Api->osVersion();

    QCOMPARE (name, QString ("VERSION13"));

    // check the LSB release file version
    systeminfo_firmware_retval = "";
    QVERIFY (name != m_Api->osVersion ());
}

void
Ut_AboutBusinessLogic::testBluetooth ()
{
    QSignalSpy spy (
        m_Api,
        SIGNAL (requestFinished (AboutBusinessLogic::requestType, QVariant)));

    QMap <QString, QVariant> properties;
    properties["Address"] = QString ("fake-bluetooth-address");

    /*
     * Let's initiate the Bluetooth query that will call the
     * QDBusAbstractInterface::callWithCallback() that is stubbed.
     */
    m_Api->initiateBluetoothQueries ();
    QCOMPARE (lastCalledMethod, QString ("DefaultAdapter"));

    /*
     * Let's answer the previous step by calling the DBus callback manually.<commit_msg>changes: bugfix<commit_after>/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of meegotouch-controlpanelapplets.
**
** If you have questions regarding the use of this file, please contact
** Nokia at <EMAIL>.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/
#include "ut_aboutbusinesslogic.h"
#include "aboutbusinesslogic.h"

#include <stdint.h>
#include <inttypes.h>
#include <QMap>
#include <QDebug>
#include <QString>
#include <QVariant>
#include <QByteArray>

#include <QSystemInfo>
#include <QSystemDeviceInfo>
#include <QSystemNetworkInfo>
#include <QNetworkInterface>

#include <MApplication>

#define DEBUG
#include "../../src/debug.h"

/******************************************************************************
 * Stubbing the QNetworkInfo
 */
QString qnetworkinterface_hwaddr;

QString
QNetworkInterface::hardwareAddress () const
{
    return qnetworkinterface_hwaddr;
}

bool
QNetworkInterface::isValid () const
{
    return ! qnetworkinterface_hwaddr.isNull ();
}

/******************************************************************************
 * Stubbing the QSystemDeviceInfo::imei () and QSystemInfo::version ()
 */
QString systemdeviceinfo_imei_retval;
QString systeminfo_firmware_retval;

QTM_BEGIN_NAMESPACE

QString
QSystemDeviceInfo::imei()
{
    return systemdeviceinfo_imei_retval;
}

QString
QSystemInfo::version (
    QSystemInfo::Version type,
    const QString &parameter)
{
    Q_UNUSED (type);
    Q_UNUSED (parameter);
    return systeminfo_firmware_retval;
}

QSystemNetworkInfo::QSystemNetworkInfo (QObject *parent)
{
    Q_UNUSED (parent);
}

QSystemNetworkInfo::~QSystemNetworkInfo ()
{
}

QNetworkInterface qnetif_for_testing;

QNetworkInterface
QSystemNetworkInfo::interfaceForMode (QSystemNetworkInfo::NetworkMode mode)
{
    Q_UNUSED (mode);
    return qnetif_for_testing;
}

QTM_END_NAMESPACE

/******************************************************************************
 * Stubbing the dbus interface.
 */
static QString lastCalledMethod;

bool
QDBusAbstractInterface::callWithCallback (
        const QString           &method,
        const QList<QVariant>   &args,
        QObject                 *receiver,
        const char              *returnMethod,
        const char              *errorMethod)
{
    Q_UNUSED (args);
    Q_UNUSED (receiver);
    Q_UNUSED (errorMethod);
    Q_UNUSED (returnMethod);

    SYS_DEBUG ("*** method       = %s", SYS_STR(method));
    SYS_DEBUG ("*** returnMethod = %s", returnMethod);

    lastCalledMethod = method;
    return true;
}

/******************************************************************************
 * Ut_AboutBusinessLogic implementation.
 */
void
Ut_AboutBusinessLogic::init()
{
    m_Api = new AboutBusinessLogic;
}

void
Ut_AboutBusinessLogic::cleanup()
{
    delete m_Api;
    m_Api = 0;
}


static int argc = 1;
static char *app_name = (char*) "./ut_aboutbusinesslogic";

void
Ut_AboutBusinessLogic::initTestCase()
{
    m_App = new MApplication (argc, &app_name);
}

void
Ut_AboutBusinessLogic::cleanupTestCase()
{
    m_App->deleteLater ();
}

void
Ut_AboutBusinessLogic::testImei()
{
    systemdeviceinfo_imei_retval = "AA-BBBBBB-CCCCCC-D";

    QCOMPARE (m_Api->IMEI (), systemdeviceinfo_imei_retval);
}

void
Ut_AboutBusinessLogic::testOsName ()
{
    QString name;

    name = m_Api->osName();
    QCOMPARE (name, QString ("qtn_prod_sw_version"));
}

void
Ut_AboutBusinessLogic::testOsVersion ()
{
    QString name;

    systeminfo_firmware_retval = "HARDWARE_PROGRAM_VERSION13";
    name = m_Api->osVersion();

    QVERIFY (name.contains (QString ("VERSION13")));

    // check the LSB release file version
    systeminfo_firmware_retval = "";
    QVERIFY (name != m_Api->osVersion ());
}

void
Ut_AboutBusinessLogic::testBluetooth ()
{
    QSignalSpy spy (
        m_Api,
        SIGNAL (requestFinished (AboutBusinessLogic::requestType, QVariant)));

    QMap <QString, QVariant> properties;
    properties["Address"] = QString ("fake-bluetooth-address");

    /*
     * Let's initiate the Bluetooth query that will call the
     * QDBusAbstractInterface::callWithCallback() that is stubbed.
     */
    m_Api->initiateBluetoothQueries ();
    QCOMPARE (lastCalledMethod, QString ("DefaultAdapter"));

    /*
     * Let's answer the previous step by calling the DBus callback manually.
{'fraction_non_alphanumeric': 0.19541905257678294, 'fraction_numerical': 0.0024986985944820406, 'mean_word_length': 4.6941315945465325, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3951017', 'n_tokens_mistral': 2898, 'n_tokens_neox': 2776, 'n_words': 662}