<commit_before>/*************************************************************************** 
** 
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 
** All rights reserved. 
** Contact: Nokia Corporation (<EMAIL>) 
** 
** This file is part of Testability Driver Qt Agent
** 
** 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 <QDebug>
#include <QDateTime>

#include <taslogger.h>
#include <tascoreutils.h>

#include "tastraverserloader.h"
#include "tassignalspy.h"

// constructor
TasSignalSpy::TasSignalSpy(QObject * object, const char * signal, TasObjectContainer& objectContainer, bool traverseSender)
    :mObjectContainer(objectContainer)
{    
    QObject::connect(object, signal, this, SLOT(signalHasOccured()));
    mSignalSpy = new QSignalSpy(object, signal);
	mSignalName = QString(signal).replace(QString::number(QSIGNAL_CODE), QString(""));
    setTarget(object);
    mTraverseSender = traverseSender;
    if(mTraverseSender){
        TasTraverserLoader loader;
        mTraversers = loader.loadTraversers();
    }
}

// destructor
TasSignalSpy::~TasSignalSpy()
{
    delete mSignalSpy;    
    mTraversers.clear();
}

void TasSignalSpy::setTarget(QObject* target)
{
    mTarget = target;
    mSenderClassName = QString(mTarget->metaObject()->className());
    mSenderId = TasCoreUtils::objectId(mTarget);
}

/*!
  Slot for capturing signals that the signal spy gets.
 */
void TasSignalSpy::signalHasOccured()
{
    TasLogger::logger()->debug("TasSignalSpy::signalHasOccured signal:" + mSignalName + " sender:" + mSenderClassName);
    // retrieve current time
	QDateTime timeStamp = QDateTime::currentDateTime();

    TasObject& signalData = mObjectContainer.addNewObject(timeStamp.toString(DATE_FORMAT), mSignalName, "QtSignal");

    signalData.addAttribute( "signalName", mSignalName);
    signalData.addAttribute( "senderObjectType", mSenderClassName);
    signalData.addAttribute( "senderObjectId", mSenderId);					
    signalData.addAttribute( "timeStamp", timeStamp.toString(DATE_FORMAT) );
    
    //take arguments if any
    if(!mSignalSpy->isEmpty()){
        QList<QVariant> arguments = mSignalSpy->takeFirst();
        for(int i = 0 ; i < arguments.size(); i++){
            QVariant argument = arguments.at( i );
            TasObject& item_object_arguments = signalData.addNewObject( QString::number(i), "", "QtSignalArgument" );
            item_object_arguments.addAttribute( "type", argument.typeName());
            item_object_arguments.addAttribute( "value", argument.toString());
        } 
    }

    if(mTraverseSender){
        TasObject& targetObj = signalData.addObject();
        QHashIterator<QString, TasTraverseInterface*> i(mTraversers);
        while (i.hasNext()) {
            i.next();
            i.value()->traverseObject(&targetObj, mTarget);
        }
    }
}

<commit_msg>Fixing bug 204237 on signal fixture<commit_after>/*************************************************************************** 
** 
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 
** All rights reserved. 
** Contact: Nokia Corporation (<EMAIL>) 
** 
** This file is part of Testability Driver Qt Agent
** 
** 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 <QDebug>
#include <QDateTime>

#include <taslogger.h>
#include <tascoreutils.h>

#include "tastraverserloader.h"
#include "tassignalspy.h"

// constructor
TasSignalSpy::TasSignalSpy(QObject * object, const char * signal, TasObjectContainer& objectContainer, bool traverseSender)
    :mObjectContainer(objectContainer)
{    
    mSignalSpy = new QSignalSpy(object, signal);
    QObject::connect(object, signal, this, SLOT(signalHasOccured()));

	mSignalName = QString(signal).replace(QString::number(QSIGNAL_CODE), QString(""));
    setTarget(object);
    mTraverseSender = traverseSender;
    if(mTraverseSender){
        TasTraverserLoader loader;
        mTraversers = loader.loadTraversers();
    }
}

// destructor
TasSignalSpy::~TasSignalSpy()
{
    delete mSignalSpy;    
    mTraversers.clear();
}

void TasSignalSpy::setTarget(QObject* target)
{
    mTarget = target;
    mSenderClassName = QString(mTarget->metaObject()->className());
    mSenderId = TasCoreUtils::objectId(mTarget);
}

/*!
  Slot for capturing signals that the signal spy gets.
 */
void TasSignalSpy::signalHasOccured()
{
    TasLogger::logger()->debug("TasSignalSpy::signalHasOccured signal:" + mSignalName + " sender:" + mSenderClassName);
    // retrieve current time
	QDateTime timeStamp = QDateTime::currentDateTime();

    TasObject& signalData = mObjectContainer.addNewObject(timeStamp.toString(DATE_FORMAT), mSignalName, "QtSignal");

    signalData.addAttribute( "signalName", mSignalName);
    signalData.addAttribute( "senderObjectType", mSenderClassName);
    signalData.addAttribute( "senderObjectId", mSenderId);					
    signalData.addAttribute( "timeStamp", timeStamp.toString(DATE_FORMAT) );
    
    //take arguments if any
    if(!mSignalSpy->isEmpty()){
        QList<QVariant> arguments = mSignalSpy->takeFirst();
        for(int i = 0 ; i < arguments.size(); i++){
            QVariant argument = arguments.at( i );
            TasObject& item_object_arguments = signalData.addNewObject( QString::number(i), "", "QtSignalArgument" );
            item_object_arguments.addAttribute( "type", argument.typeName());
            item_object_arguments.addAttribute( "value", argument.toString());
        } 
    }

    if(mTraverseSender){
        TasObject& targetObj = signalData.addObject();
        QHashIterator<QString, TasTraverseInterface*> i(mTraversers);
        while (i.hasNext()) {
            i.next();
            i.value()->traverseObject(&targetObj, mTarget);
        }
    }
}


{'fraction_non_alphanumeric': 0.1622773633734206, 'fraction_numerical': 0.0030446034404018876, 'mean_word_length': 4.185477505919495, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 31, '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': '6873999', 'n_tokens_mistral': 1958, 'n_tokens_neox': 1866, 'n_words': 445}