<commit_before>/*
 * Copyright (C) Red Hat, Inc. 2019
 *
 * 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, see
 * <http://www.gnu.org/licenses/>.
 */

#include <config.h>

#include "testutils.h"
#include "storage_conf.h"
#include "storage_capabilities.h"


#define VIR_FROM_THIS VIR_FROM_NONE


struct test_virStoragePoolCapsFormatData {
    const char *filename;
    virCapsPtr driverCaps;
};

static void
test_virCapabilitiesAddFullStoragePool(virCapsPtr caps)
{
    size_t i;

    for (i = 0; i < VIR_STORAGE_POOL_LAST; i++)
        virCapabilitiesAddStoragePool(caps, i);
}


static void
test_virCapabilitiesAddFSStoragePool(virCapsPtr caps)
{
    virCapabilitiesAddStoragePool(caps, VIR_STORAGE_POOL_FS);
}


static int
test_virStoragePoolCapsFormat(const void *opaque)
{
    struct test_virStoragePoolCapsFormatData *data =
        (struct test_virStoragePoolCapsFormatData *) opaque;
    virCapsPtr driverCaps = data->driverCaps;
    virStoragePoolCapsPtr poolCaps = NULL;
    int ret = -1;
    VIR_AUTOFREE(char *) path = NULL;
    VIR_AUTOFREE(char *) poolCapsFromFile = NULL;
    VIR_AUTOFREE(char *) poolCapsXML = NULL;


    if (!(poolCaps = virStoragePoolCapsNew(driverCaps)))
        goto cleanup;

    if (virAsprintf(&path, "%s/storagepoolcapsschemadata/poolcaps-%s.xml",
                    abs_srcdir, data->filename) < 0)
        goto cleanup;

    if (virFileReadAll(path, 8192, &poolCapsFromFile) < 0)
        goto cleanup;

    if (!(poolCapsXML = virStoragePoolCapsFormat(poolCaps)))
        goto cleanup;

    if (STRNEQ(poolCapsFromFile, poolCapsXML)) {
        virTestDifference(stderr, poolCapsFromFile, poolCapsXML);
        goto cleanup;
    }<commit_msg>tests: use virTestCompareToFile in storagepoolcapstest<commit_after>/*
 * Copyright (C) Red Hat, Inc. 2019
 *
 * 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, see
 * <http://www.gnu.org/licenses/>.
 */

#include <config.h>

#include "testutils.h"
#include "storage_conf.h"
#include "storage_capabilities.h"


#define VIR_FROM_THIS VIR_FROM_NONE


struct test_virStoragePoolCapsFormatData {
    const char *filename;
    virCapsPtr driverCaps;
};

static void
test_virCapabilitiesAddFullStoragePool(virCapsPtr caps)
{
    size_t i;

    for (i = 0; i < VIR_STORAGE_POOL_LAST; i++)
        virCapabilitiesAddStoragePool(caps, i);
}


static void
test_virCapabilitiesAddFSStoragePool(virCapsPtr caps)
{
    virCapabilitiesAddStoragePool(caps, VIR_STORAGE_POOL_FS);
}


static int
test_virStoragePoolCapsFormat(const void *opaque)
{
    struct test_virStoragePoolCapsFormatData *data =
        (struct test_virStoragePoolCapsFormatData *) opaque;
    virCapsPtr driverCaps = data->driverCaps;
    virStoragePoolCapsPtr poolCaps = NULL;
    int ret = -1;
    VIR_AUTOFREE(char *) path = NULL;
    VIR_AUTOFREE(char *) poolCapsXML = NULL;


    if (!(poolCaps = virStoragePoolCapsNew(driverCaps)))
        goto cleanup;

    if (virAsprintf(&path, "%s/storagepoolcapsschemadata/poolcaps-%s.xml",
                    abs_srcdir, data->filename) < 0)
        goto cleanup;

    if (!(poolCapsXML = virStoragePoolCapsFormat(poolCaps)))
        goto cleanup;

    if (virTestCompareToFile(poolCapsXML, path) < 0)
        goto cleanup;
{'fraction_non_alphanumeric': 0.08342857142857144, 'fraction_numerical': 0.005485714285714286, 'mean_word_length': 3.8730512249443207, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '93861', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1347, 'n_words': 410}