<commit_before>/*
 * Copyright (C) 2010-2013 <NAME>
 * Contact: https://github.com/jlaine/qdjango
 *
 * This file is part of the QDjango Library.
 *
 * 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.
 */

#include <QtTest>

#include "QDjangoHttpRequest.h"
#include "QDjangoHttpRequest_p.h"

/** Test QDjangoHttpServer class.
 */
class tst_QDjangoHttpRequest : public QObject
{
    Q_OBJECT

private slots:
    void testGet();
    void testPost();
};

void tst_QDjangoHttpRequest::testGet()
{
    QDjangoHttpRequest request;
    request.d->meta.insert("QUERY_STRING", "foo=bar");
    QCOMPARE(request.get(QLatin1String("foo")), QLatin1String("bar"));
}

void tst_QDjangoHttpRequest::testPost()
{
    QDjangoHttpRequest request;
    request.d->buffer = QByteArray("foo=bar");
    QCOMPARE(request.post(QLatin1String("foo")), QLatin1String("bar"));
}

QTEST_MAIN(tst_QDjangoHttpRequest)
#include "tst_qdjangohttprequest.moc"<commit_msg>improve tests for QDjangoHttpRequest plus handling<commit_after>/*
 * Copyright (C) 2010-2013 <NAME>
 * Contact: https://github.com/jlaine/qdjango
 *
 * This file is part of the QDjango Library.
 *
 * 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.
 */

#include <QtTest>

#include "QDjangoHttpRequest.h"
#include "QDjangoHttpRequest_p.h"

/** Test QDjangoHttpServer class.
 */
class tst_QDjangoHttpRequest : public QObject
{
    Q_OBJECT

private slots:
    void testGet();
    void testPost();
};

void tst_QDjangoHttpRequest::testGet()
{
    QDjangoHttpRequest request;

    // plain
    request.d->meta.insert("QUERY_STRING", "foo=bar&baz=qux");
    QCOMPARE(request.get(QLatin1String("foo")), QLatin1String("bar"));
    QCOMPARE(request.get(QLatin1String("baz")), QLatin1String("qux"));

    // space encoded as plus
    request.d->meta.insert("QUERY_STRING", "foo=bar+more&baz=qux");
    QCOMPARE(request.get(QLatin1String("foo")), QLatin1String("bar more"));
    QCOMPARE(request.get(QLatin1String("baz")), QLatin1String("qux"));

    // plus encoded as %2B
    request.d->meta.insert("QUERY_STRING", "foo=bar%2Bmore&baz=qux");
    QCOMPARE(request.get(QLatin1String("foo")), QLatin1String("bar+more"));
    QCOMPARE(request.get(QLatin1String("baz")), QLatin1String("qux"));
}

void tst_QDjangoHttpRequest::testPost()
{
    QDjangoHttpRequest request;

    // plain
    request.d->buffer = QByteArray("foo=bar&baz=qux");
    QCOMPARE(request.post(QLatin1String("foo")), QLatin1String("bar"));
    QCOMPARE(request.post(QLatin1String("baz")), QLatin1String("qux"));

    // space encoded as plus
    request.d->buffer = QByteArray("foo=bar+more&baz=qux");
    QCOMPARE(request.post(QLatin1String("foo")), QLatin1String("bar more"));
    QCOMPARE(request.post(QLatin1String("baz")), QLatin1String("qux"));

    // plus encoded as %2B
    request.d->buffer = QByteArray("foo=bar%2Bmore&baz=qux");
    QCOMPARE(request.post(QLatin1String("foo")), QLatin1String("bar+more"));
    QCOMPARE(request.post(QLatin1String("baz")), QLatin1String("qux"));
}

QTEST_MAIN(tst_QDjangoHttpRequest)
#include "tst_qdjangohttprequest.moc"
{'fraction_non_alphanumeric': 0.13082706766917293, 'fraction_numerical': 0.013032581453634085, 'mean_word_length': 4.938988095238095, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 2, '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': '4737200', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1285, 'n_words': 322}