<commit_before>/******************************************************************************
 * This file is part of the Gluon Development Platform
 * Copyright (c) 2010 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "modeltest.h"

#include <QtGui/QtGui>

Q_DECLARE_METATYPE( QModelIndex )

/*!
    Connect to all of the models signals.  Whenever anything happens recheck everything.
*/
ModelTest::ModelTest( QAbstractItemModel* _model, QObject* parent ) : QObject( parent ), model( _model ), fetchingMore( false )
{
    Q_ASSERT( model );

    connect( model, SIGNAL( columnsAboutToBeInserted( const QModelIndex&, int, int ) ),
             this, SLOT( runAllTests() ) );
    connect( model, SIGNAL( columnsAboutToBeRemoved( const QModelIndex&, int, int ) ),
             this, SLOT( runAllTests() ) );
    connect( model, SIGNAL( columnsInserted( const QModelIndex&, int, int ) ),
             this, SLOT( runAllTests() ) );
    connect( model, SIGNAL( columnsRemoved( const QModelIndex&, int, int ) ),
             this, SLOT( runAllTests() ) );
    connect( model, SIGNAL( dataChanged( const QModelIndex&, const QModelIndex& ) ),
             this, SLOT( runAllTests() ) );
    connect( model, SIGNAL( headerDataChanged( Qt::Orientation, int, int ) ),
             this, SLOT( runAllTests() ) );
    connect( model, SIGNAL( layoutAboutToBeChanged() ), this, SLOT( runAllTests() ) );
    connect( model, SIGNAL( layoutChanged() ), this, SLOT( runAllTests() ) );
    connect( model, SIGNAL( modelReset() ), this, SLOT( runAllTests() ) );
    connect( model, SIGNAL( rowsAboutToBeInserted( const QModelIndex&, int, int ) ),
             this, SLOT( runAllTests() ) );
    connect( model, SIGNAL( rowsAboutToBeRemoved( const QModelIndex&, int, int ) ),
             this, SLOT( runAllTests() ) );
    connect( model, SIGNAL( rowsInserted( const QModelIndex&, int, int ) ),
             this, SLOT( runAllTests() ) );
    connect( model, SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ),
             this, SLOT( runAllTests() ) );

    // Special checks for inserting/removing
    connect( model, SIGNAL( layoutAboutToBeChanged() ),
             this, SLOT( layoutAboutToBeChanged() ) );
    connect( model, SIGNAL( layoutChanged() ),
             this, SLOT( layoutChanged() ) );

    connect( model, SIGNAL( rowsAboutToBeInserted( const QModelIndex&, int, int ) ),
             this, SLOT( rowsAboutToBeInserted( const QModelIndex&, int, int ) ) );
    connect( model, SIGNAL( rowsAboutToBeRemoved( const QModelIndex&, int, int ) ),
             this, SLOT( rowsAboutToBeRemoved( const QModelIndex&, int, int ) ) );
    connect( model, SIGNAL( rowsInserted( const QModelIndex&, int, int ) ),
             this, SLOT( rowsInserted( const QModelIndex&, int, int ) ) );
    connect( model, SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ),
             this, SLOT( rowsRemoved( const QModelIndex&, int, int ) ) );

    runAllTests();
}

void ModelTest::runAllTests()
{
    if( fetchingMore )
        return;
    nonDestructiveBasicTest();
    rowCount();
    columnCount();
    hasIndex();
    index();
    parent();
    data();
}

/*!
    nonDestructiveBasicTest tries to call a number of the basic functions (not all)
    to make sure the model doesn't outright segfault, testing the functions that makes sense.
*/
void ModelTest::nonDestructiveBasicTest()
{
    Q_ASSERT( model->buddy( QModelIndex() ) == QModelIndex() );
    model->canFetchMore( QModelIndex() );
    Q_ASSERT( model->columnCount( QModelIndex() ) >= 0 );
    Q_ASSERT( model->data( QModelIndex() ) == QVariant() );
    fetchingMore = true;
    model->fetchMore( QModelIndex() );<commit_msg>Remove the many unneccesary 'this' usage in the connect method.<commit_after>/******************************************************************************
 * This file is part of the Gluon Development Platform
 * Copyright (c) 2010 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "modeltest.h"

#include <QtGui/QtGui>

Q_DECLARE_METATYPE( QModelIndex )

/*!
    Connect to all of the models signals.  Whenever anything happens recheck everything.
*/
ModelTest::ModelTest( QAbstractItemModel* _model, QObject* parent ) : QObject( parent ), model( _model ), fetchingMore( false )
{
    Q_ASSERT( model );

    connect( model, SIGNAL( columnsAboutToBeInserted( const QModelIndex&, int, int ) ),
             SLOT( runAllTests() ) );
    connect( model, SIGNAL( columnsAboutToBeRemoved( const QModelIndex&, int, int ) ),
             SLOT( runAllTests() ) );
    connect( model, SIGNAL( columnsInserted( const QModelIndex&, int, int ) ),
             SLOT( runAllTests() ) );
    connect( model, SIGNAL( columnsRemoved( const QModelIndex&, int, int ) ),
             SLOT( runAllTests() ) );
    connect( model, SIGNAL( dataChanged( const QModelIndex&, const QModelIndex& ) ),
             SLOT( runAllTests() ) );
    connect( model, SIGNAL( headerDataChanged( Qt::Orientation, int, int ) ),
             SLOT( runAllTests() ) );
    connect( model, SIGNAL( layoutAboutToBeChanged() ), SLOT( runAllTests() ) );
    connect( model, SIGNAL( layoutChanged() ), SLOT( runAllTests() ) );
    connect( model, SIGNAL( modelReset() ), SLOT( runAllTests() ) );
    connect( model, SIGNAL( rowsAboutToBeInserted( const QModelIndex&, int, int ) ),
             SLOT( runAllTests() ) );
    connect( model, SIGNAL( rowsAboutToBeRemoved( const QModelIndex&, int, int ) ),
             SLOT( runAllTests() ) );
    connect( model, SIGNAL( rowsInserted( const QModelIndex&, int, int ) ),
             SLOT( runAllTests() ) );
    connect( model, SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ),
             SLOT( runAllTests() ) );

    // Special checks for inserting/removing
    connect( model, SIGNAL( layoutAboutToBeChanged() ),
             SLOT( layoutAboutToBeChanged() ) );
    connect( model, SIGNAL( layoutChanged() ),
             SLOT( layoutChanged() ) );

    connect( model, SIGNAL( rowsAboutToBeInserted( const QModelIndex&, int, int ) ),
             SLOT( rowsAboutToBeInserted( const QModelIndex&, int, int ) ) );
    connect( model, SIGNAL( rowsAboutToBeRemoved( const QModelIndex&, int, int ) ),
             SLOT( rowsAboutToBeRemoved( const QModelIndex&, int, int ) ) );
    connect( model, SIGNAL( rowsInserted( const QModelIndex&, int, int ) ),
             SLOT( rowsInserted( const QModelIndex&, int, int ) ) );
    connect( model, SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ),
             SLOT( rowsRemoved( const QModelIndex&, int, int ) ) );

    runAllTests();
}

void ModelTest::runAllTests()
{
    if( fetchingMore )
        return;
    nonDestructiveBasicTest();
    rowCount();
    columnCount();
    hasIndex();
    index();
    parent();
    data();
}

/*!
    nonDestructiveBasicTest tries to call a number of the basic functions (not all)
    to make sure the model doesn't outright segfault, testing the functions that makes sense.
*/
void ModelTest::nonDestructiveBasicTest()
{
    Q_ASSERT( model->buddy( QModelIndex() ) == QModelIndex() );
    model->canFetchMore( QModelIndex() );
    Q_ASSERT( model->columnCount( QModelIndex() ) >= 0 );
    Q_ASSERT( model->data( QModelIndex() ) == QVariant() );
    fetchingMore = true;
    model->fetchMore( QModelIndex() );
{'fraction_non_alphanumeric': 0.13373024959926724, 'fraction_numerical': 0.00412182276162125, 'mean_word_length': 3.4794871794871796, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4310379', 'n_tokens_mistral': 2594, 'n_tokens_neox': 2499, 'n_words': 848}