<commit_before>#include <config.h>

#include "testutils.h"

#ifdef WITH_LXC

# include "lxc/lxc_native.h"
# include "lxc/lxc_conf.h"
# include "testutilslxc.h"

# define VIR_FROM_THIS VIR_FROM_NONE

static virCapsPtr caps;
static virDomainXMLOptionPtr xmlopt;

static int
blankProblemElements(char *data)
{
    if (virtTestClearLineRegex("<uuid>([[:alnum:]]|-)+</uuid>", data) < 0)
        return -1;
    return 0;
}

static int
testCompareXMLToConfigFiles(const char *xml,
                            const char *configfile,
                            bool expectError)
{
    int ret = -1;
    char *config = NULL;
    char *expectxml = NULL;
    char *actualxml = NULL;
    virDomainDefPtr vmdef = NULL;

    if (virtTestLoadFile(configfile, &config) < 0)
        goto fail;

    vmdef = lxcParseConfigString(config, caps, xmlopt);
    if ((vmdef && expectError) || (!vmdef && !expectError))
        goto fail;

    if (vmdef) {
        if (!(actualxml = virDomainDefFormat(vmdef, caps, 0)))
            goto fail;

        if (virtTestLoadFile(xml, &expectxml) < 0)
            goto fail;

        if (blankProblemElements(expectxml) < 0 ||
            blankProblemElements(actualxml) < 0)
            goto fail;

        if (STRNEQ(expectxml, actualxml)) {
            virtTestDifferenceFull(stderr, expectxml, xml, actualxml, NULL);
            goto fail;
        }
    }

    ret = 0;

 fail:
    VIR_FREE(expectxml);
    VIR_FREE(actualxml);
    VIR_FREE(config);
    virDomainDefFree(vmdef);
    return ret;
}

struct testInfo {
    const char *name;
    bool expectError;
};

static int
testCompareXMLToConfigHelper(const void *data)
{
    int result = -1;<commit_msg>tests: lxcconf2xml: Drop XML blanking<commit_after>#include <config.h>

#include "testutils.h"

#ifdef WITH_LXC

# include "lxc/lxc_native.h"
# include "lxc/lxc_conf.h"
# include "testutilslxc.h"

# define VIR_FROM_THIS VIR_FROM_NONE

static virCapsPtr caps;
static virDomainXMLOptionPtr xmlopt;

static int testSanitizeDef(virDomainDefPtr vmdef)
{
    /* Remove UUID randomness */
    if (virUUIDParse("c7a5fdbd-edaf-9455-926a-d65c16db1809", vmdef->uuid) < 0)
        return -1;
    return 0;
}

static int
testCompareXMLToConfigFiles(const char *xmlfile,
                            const char *configfile,
                            bool expectError)
{
    int ret = -1;
    char *config = NULL;
    char *actualxml = NULL;
    virDomainDefPtr vmdef = NULL;

    if (virtTestLoadFile(configfile, &config) < 0)
        goto fail;

    vmdef = lxcParseConfigString(config, caps, xmlopt);
    if ((vmdef && expectError) || (!vmdef && !expectError))
        goto fail;

    if (vmdef) {
        if (testSanitizeDef(vmdef) < 0)
            goto fail;

        if (!(actualxml = virDomainDefFormat(vmdef, caps, 0)))
            goto fail;

        if (virtTestCompareToFile(actualxml, xmlfile) < 0)
            goto fail;
    }

    ret = 0;

 fail:
    VIR_FREE(actualxml);
    VIR_FREE(config);
    virDomainDefFree(vmdef);
    return ret;
}

struct testInfo {
    const char *name;
    bool expectError;
};

static int
testCompareXMLToConfigHelper(const void *data)
{
    int result = -1;
{'fraction_non_alphanumeric': 0.1098831701926113, 'fraction_numerical': 0.012314493211240922, 'mean_word_length': 2.6205714285714286, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 26}, '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': '4405204', 'n_tokens_mistral': 1104, 'n_tokens_neox': 1060, 'n_words': 252}