<commit_before>/*
 * Copyright (C) 2008-2021 The QXmpp developers
 *
 * Authors:
 *  <NAME>
 *  <NAME>
 *
 * Source:
 *  https://github.com/qxmpp-project/qxmpp
 *
 * This file is a part of QXmpp 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 "QXmppPasswordChecker.h"

#include <QDomDocument>
#include <QtTest>

template<class T>
static void parsePacket(T &packet, const QByteArray &xml)
{
    //qDebug() << "parsing" << xml;
    QDomDocument doc;
    QCOMPARE(doc.setContent(xml, true), true);
    QDomElement element = doc.documentElement();
    packet.parse(element);
}

template<class T><commit_msg>tests: util: Add xmlToDom() helper<commit_after>/*
 * Copyright (C) 2008-2021 The QXmpp developers
 *
 * Authors:
 *  <NAME>
 *  <NAME>
 *  <NAME>
 *
 * Source:
 *  https://github.com/qxmpp-project/qxmpp
 *
 * This file is a part of QXmpp 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 "QXmppPasswordChecker.h"

#include <QDomDocument>
#include <QtTest>

// QVERIFY2 with empty return value (return {};)
#define QVERIFY_RV(statement, description)                                       \
    if (!QTest::qVerify(statement, #statement, description, __FILE__, __LINE__)) \
        return {};

QDomElement xmlToDom(const QByteArray &xml)
{
    QDomDocument doc;
    QVERIFY_RV(doc.setContent(xml, true), "XML is not valid");
    return doc.documentElement();
}

template<class T>
static void parsePacket(T &packet, const QByteArray &xml)
{
    //qDebug() << "parsing" << xml;
    packet.parse(xmlToDom(xml));
}

template<class T>
{'fraction_non_alphanumeric': 0.10178217821782178, 'fraction_numerical': 0.008316831683168317, 'mean_word_length': 3.6179159049360146, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 16, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 11}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3042847', 'n_tokens_mistral': 772, 'n_tokens_neox': 759, 'n_words': 286}