<commit_before>/***************************************************************************
**
** Copyright (C) 2010, 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of libmeegotouch.
**
** 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 <MLocale>
#include <mwindow_p.h>
#include "ut_mapplication.h"

#include <MApplication>
#include <MApplicationWindow>
#include <MApplicationService>
#include <MComponentData>

#ifdef Q_WS_X11
#include <QX11Info>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#endif //Q_WS_X11

#include <mtheme.h>
#include <mwindow_stub.h>
//#include <mfeedbackplayer_stub.h>
//#include <mfeedbackplayerprivate_stub.h>
#include <mfeedback_stub.h>

//todo: mapplication.cpp - these functions should not be called this way: window->d_ptr->sendDelayedExitDisplayEvent();
//when we fix that we can get rid off these 3 stubs
void MWindowPrivate::sendDelayedExitDisplayEvent()
{
}
void MWindowPrivate::setX11PrestartProperty(bool)
{
}
void MWindowPrivate::resolveOrientationRules()
{
}

const char* MWindowPrivate::LogicallyClosedPropertyName = "_m_logicallyClosed";

class MyApplication: public MApplication
{
public:
    MyApplication(int &argc, char **argv);
    MyApplication(int &argc, char **argv, MApplicationService *service);
    virtual void releasePrestart();
    virtual void restorePrestart();
};


MyApplication::MyApplication(int &argc, char **argv)
    : MApplication(argc, argv)
{
}

MyApplication::MyApplication(int &argc, char **argv, MApplicationService *service)
    : MApplication(argc, argv, service)
{
}

bool Ut_MApplication::m_releasePrestart = false;
void MyApplication::releasePrestart()
{
    Ut_MApplication::m_releasePrestart = true;
}

bool Ut_MApplication::m_restorePrestart = false;
void MyApplication::restorePrestart()
{
    Ut_MApplication::m_restorePrestart = true;
}

void Ut_MApplication::init()
{
    app = NULL;
    m_prestartReleased = false;
    m_prestartRestored = false;
    m_releasePrestart = false;
    m_restorePrestart = false;

    registeredService.clear();
}

void Ut_MApplication::cleanup()
{
}

void Ut_MApplication::mApplicationConstructor_data()
{
    QTest::addColumn<int>("count");
    QTest::addColumn<QString>("params");
    QTest::newRow("hw") << 2 <<  QString("-show-br -show-fps");
    QTest::newRow("hw-fullscreen") << 3 <<  QString("-show-br -show-fps -fullscreen");
    QTest::newRow("sw") << 2 <<  QString("-software -show-br");
    QTest::newRow("sw-fullscreen") << 3 <<  QString("-software -show-br -fullscreen");
}

MApplication *Ut_MApplication::buildApp(int count, const QString &params, MApplicationService *service)
{
    return buildApp(count, params, QString(), service);
}

MApplication *Ut_MApplication::buildApp(int count, const QString &params, const QString &appId, MApplicationService *service)
{
    MApplication *retVal = 0;

    QChar sep(' ');
    static char *argv[MAX_PARAMS] = {'\0'};
    static int x = 0;
    x = 0; //we have to always reset it

    QStringList list = params.split(sep);
    QStringListIterator it(list);
    while (it.hasNext() && x < MAX_PARAMS)  {
        argv[x++] = strdup(it.next().toLocal8Bit().constData());
    }
    Q_ASSERT(count == x);

    // try to call the constructor with the correct signature
    if (service) {
        if (appId.isEmpty()) {
            retVal = new MApplication(x, argv, service);
        } else {
            retVal = new MApplication(x, argv, appId, service);
        }
    } else {
        if (appId.isEmpty()) {
            retVal = new MApplication(x, argv);
        } else {
            retVal = new MApplication(x, argv, appId);
        }
    }

    return retVal;
}

MApplication *Ut_MApplication::buildPrestartApp(int count, const QString &params, MApplicationService *service)
{
    MApplication *retVal = 0;

    QChar sep(' ');
    static char *argv[MAX_PARAMS] = {'\0'};;
    static int x = 0;
    x = 0; //we have to always reset it

    QStringList list = params.split(sep);
    QStringListIterator it(list);
    while (it.hasNext() && x < MAX_PARAMS)  {
        argv[x++] = strdup(it.next().toLocal8Bit().constData());
    }
    Q_ASSERT(count == x);

    // try to call the constructor with the correct signature
    if (service) {
        retVal = new MyApplication(x, argv, service);
    } else {
        retVal = new MyApplication(x, argv);
    }

    return retVal;
}

QDir Ut_MApplication::generateThemeDirectory()
{
    QDir themeDir(THEMEDIR);
    return themeDir;<commit_msg>Changes: Improve Ut_MApplication test.<commit_after>/***************************************************************************
**
** Copyright (C) 2010, 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of libmeegotouch.
**
** 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 <MLocale>
#include <mwindow_p.h>
#include "ut_mapplication.h"

#include <MApplication>
#include <MApplicationWindow>
#include <MApplicationService>
#include <MComponentData>

#ifdef Q_WS_X11
#include <QX11Info>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#endif //Q_WS_X11

#include <mtheme.h>
#include <mwindow_stub.h>
//#include <mfeedbackplayer_stub.h>
//#include <mfeedbackplayerprivate_stub.h>
#include <mfeedback_stub.h>

//todo: mapplication.cpp - these functions should not be called this way: window->d_ptr->sendDelayedExitDisplayEvent();
//when we fix that we can get rid off these 3 stubs
void MWindowPrivate::sendDelayedExitDisplayEvent()
{
}
void MWindowPrivate::setX11PrestartProperty(bool)
{
}
void MWindowPrivate::resolveOrientationRules()
{
}

const char* MWindowPrivate::LogicallyClosedPropertyName = "_m_logicallyClosed";

class MyApplication: public MApplication
{
public:
    MyApplication(int &argc, char **argv);
    MyApplication(int &argc, char **argv, MApplicationService *service);
    virtual void releasePrestart();
    virtual void restorePrestart();
};


MyApplication::MyApplication(int &argc, char **argv)
    : MApplication(argc, argv)
{
}

MyApplication::MyApplication(int &argc, char **argv, MApplicationService *service)
    : MApplication(argc, argv, service)
{
}

bool Ut_MApplication::m_releasePrestart = false;
void MyApplication::releasePrestart()
{
    Ut_MApplication::m_releasePrestart = true;
}

bool Ut_MApplication::m_restorePrestart = false;
void MyApplication::restorePrestart()
{
    Ut_MApplication::m_restorePrestart = true;
}

void Ut_MApplication::init()
{
    app = NULL;
    m_prestartReleased = false;
    m_prestartRestored = false;
    m_releasePrestart = false;
    m_restorePrestart = false;

    registeredService.clear();
}

void Ut_MApplication::cleanup()
{
}

void Ut_MApplication::mApplicationConstructor_data()
{
    QTest::addColumn<int>("count");
    QTest::addColumn<QString>("params");
    QTest::newRow("hw") << 3 <<  QString("appName -show-br -show-fps");
    QTest::newRow("hw-fullscreen") << 4 <<  QString("appName -show-br -show-fps -fullscreen");
    QTest::newRow("sw") << 3 <<  QString("appName -software -show-br");
    QTest::newRow("sw-fullscreen") << 4 <<  QString("appName -software -show-br -fullscreen");
}

MApplication *Ut_MApplication::buildApp(int count, const QString &params, MApplicationService *service)
{
    return buildApp(count, params, QString(), service);
}

MApplication *Ut_MApplication::buildApp(int count, const QString &params, const QString &appId, MApplicationService *service)
{
    MApplication *retVal = 0;

    QChar sep(' ');
    static char *argv[MAX_PARAMS] = {'\0'};
    static int x = 0;
    x = 0; //we have to always reset it

    QStringList list = params.split(sep);
    QStringListIterator it(list);
    while (it.hasNext() && x < MAX_PARAMS)  {
        argv[x++] = strdup(it.next().toLocal8Bit().constData());
    }
    Q_ASSERT(count == x);

    // try to call the constructor with the correct signature
    if (service) {
        if (appId.isEmpty()) {
            retVal = new MApplication(x, argv, service);
        } else {
            retVal = new MApplication(x, argv, appId, service);
        }
    } else {
        if (appId.isEmpty()) {
            retVal = new MApplication(x, argv);
        } else {
            retVal = new MApplication(x, argv, appId);
        }
    }

    return retVal;
}

MApplication *Ut_MApplication::buildPrestartApp(int count, const QString &params, MApplicationService *service)
{
    MApplication *retVal = 0;

    QChar sep(' ');
    static char *argv[MAX_PARAMS] = {'\0'};
    static int x = 0;
    x = 0; //we have to always reset it

    QStringList list = params.split(sep);
    QStringListIterator it(list);
    while (it.hasNext() && x < MAX_PARAMS)  {
        argv[x++] = strdup(it.next().toLocal8Bit().constData());
    }
    Q_ASSERT(count == x);

    // try to call the constructor with the correct signature
    if (service) {
        retVal = new MyApplication(x, argv, service);
    } else {
        retVal = new MyApplication(x, argv);
    }

    return retVal;
}

QDir Ut_MApplication::generateThemeDirectory()
{
    QDir themeDir(THEMEDIR);
    return themeDir;
{'fraction_non_alphanumeric': 0.15687250996015936, 'fraction_numerical': 0.007768924302788844, 'mean_word_length': 4.1255742725880555, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 45, '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': '4880426', 'n_tokens_mistral': 3217, 'n_tokens_neox': 3131, 'n_words': 820}