<commit_before>#include <QtCore/QBuffer>
#include <QtCore/QCoreApplication>
#include <QtCore/QPointer>
#include <QtCore/QVariant>
#include <QtTest/QSignalSpy>
#include <QtTest/QTest>
#include "workertest.h"
#include "worker.h"

Q_DECLARE_METATYPE(Worker::Error)

WorkerTest::WorkerTest(void)
	: input(0), worker(0)
{
}

void WorkerTest::writeData(const QByteArray& data)
{
	QCOMPARE(int(this->input->write(data)), data.size());
	this->input->seek(this->input->size() - data.size());
	QCoreApplication::processEvents();
}

void WorkerTest::initTestCase(void)
{
	qRegisterMetaType<Worker::Error>("Worker::Error");
}

void WorkerTest::cleanupTestCase(void)
{
}

void WorkerTest::init(void)
{
	this->input = new QBuffer();
	QVERIFY(this->input->open(QIODevice::ReadWrite));

	this->worker = new Worker(this->input, this);
}

void WorkerTest::cleanup(void)
{
	delete this->worker;
	this->worker = 0;
	delete this->input;
	this->input = 0;
}

void WorkerTest::testGreeting(void)
{
	QCOMPARE(this->worker->m_peer.data(), this->input);
	QCOMPARE(this->worker->m_state, Worker::ConnectedState);
	QVERIFY(!this->worker->m_target);
	QVERIFY(!this->worker->m_connector);
	QVERIFY(this->worker->m_buf.isEmpty());
	QCOMPARE(this->worker->m_expected_length, -1);

	this->writeData("\x05");
	QVERIFY(!this->worker->m_target);
	QVERIFY(!this->worker->m_connector);
	QCOMPARE(this->worker->m_buf.size(), 1);
	QCOMPARE(this->worker->m_expected_length, -1);

	this->writeData("\x01");
	QVERIFY(!this->worker->m_target);<commit_msg>Fix for Qt 4.2<commit_after>#include <QtCore/QBuffer>
#include <QtCore/QCoreApplication>
#include <QtCore/QPointer>
#include <QtCore/QVariant>
#include <QtTest/QSignalSpy>
#include <QtTest/QTest>
#include "workertest.h"
#include "worker.h"

Q_DECLARE_METATYPE(Worker::Error)

WorkerTest::WorkerTest(void)
	: input(0), worker(0)
{
}

void WorkerTest::writeData(const QByteArray& data)
{
	QCOMPARE(int(this->input->write(data)), data.size());
	this->input->seek(this->input->size() - data.size());
	QCoreApplication::processEvents();
}

void WorkerTest::initTestCase(void)
{
	qRegisterMetaType<Worker::Error>("Worker::Error");
}

void WorkerTest::cleanupTestCase(void)
{
}

void WorkerTest::init(void)
{
	this->input = new QBuffer();
	QVERIFY(this->input->open(QIODevice::ReadWrite));

	this->worker = new Worker(this->input, this);
}

void WorkerTest::cleanup(void)
{
	delete this->worker;
	this->worker = 0;
	delete this->input;
	this->input = 0;
}

void WorkerTest::testGreeting(void)
{
#if QT_VERSION >= 0x40300
	QCOMPARE(this->worker->m_peer.data(), this->input);
#endif
	QCOMPARE(this->worker->m_state, Worker::ConnectedState);
	QVERIFY(!this->worker->m_target);
	QVERIFY(!this->worker->m_connector);
	QVERIFY(this->worker->m_buf.isEmpty());
	QCOMPARE(this->worker->m_expected_length, -1);

	this->writeData("\x05");
	QVERIFY(!this->worker->m_target);
	QVERIFY(!this->worker->m_connector);
	QCOMPARE(this->worker->m_buf.size(), 1);
	QCOMPARE(this->worker->m_expected_length, -1);

	this->writeData("\x01");
	QVERIFY(!this->worker->m_target);
{'fraction_non_alphanumeric': 0.19339005235602094, 'fraction_numerical': 0.00981675392670157, 'mean_word_length': 7.00261780104712, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 98, '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': '6931400', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1157, 'n_words': 154}