<commit_before>#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>

#include "torture.h"

#include "csync_private.h"
#include "vio/csync_vio.h"

#define CSYNC_TEST_DIR "/tmp/csync/"
#define CSYNC_TEST_DIRS "/tmp/csync/this/is/a/mkdirs/test"
#define CSYNC_TEST_FILE "/tmp/csync/file.txt"

static void setup(void **state)
{
    CSYNC *csync;
    int rc;

    rc = system("rm -rf /tmp/csync/");
    assert_int_equal(rc, 0);

    rc = csync_create(&csync, "/tmp/csync1", "/tmp/csync2");
    assert_int_equal(rc, 0);

    csync->replica = LOCAL_REPLICA;

    *state = csync;
}

static void setup_dir(void **state) {
    int rc;
    mbchar_t *dir = c_utf8_to_locale(CSYNC_TEST_DIR);

    setup(state);

    rc = _tmkdir(dir, 0755);
    c_free_locale_string(dir);
    assert_int_equal(rc, 0);
}

static void setup_file(void **state) {
    int rc;

    setup_dir(state);

    rc = system("echo \"This is a test\" > /tmp/csync/file.txt");
    assert_int_equal(rc, 0);
}

static void teardown(void **state) {
    CSYNC *csync = *state;
    int rc;

    rc = csync_destroy(csync);
    assert_int_equal(rc, 0);

    rc = system("rm -rf /tmp/csync/");
    assert_int_equal(rc, 0);

    *state = NULL;
}

static void check_csync_vio_load(void **state)
{
    CSYNC *csync = *state;
    int rc;

    rc = csync_vio_init(csync, "smb", NULL);
    assert_int_equal(rc, 0);

    csync_vio_shutdown(csync);
}

static void check_csync_vio_load_wrong_proto(void **state)
{
    CSYNC *csync = *state;
    int rc;

    rc = csync_vio_init(csync, "wrong", NULL);
    assert_int_equal(rc, -1);

    csync_vio_shutdown(csync);
}

static void check_csync_vio_load_bad_plugin(void **state)<commit_msg>tests: Load the sftp module for vio testing.<commit_after>#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>

#include "torture.h"

#include "csync_private.h"
#include "vio/csync_vio.h"

#define CSYNC_TEST_DIR "/tmp/csync/"
#define CSYNC_TEST_DIRS "/tmp/csync/this/is/a/mkdirs/test"
#define CSYNC_TEST_FILE "/tmp/csync/file.txt"

static void setup(void **state)
{
    CSYNC *csync;
    int rc;

    rc = system("rm -rf /tmp/csync/");
    assert_int_equal(rc, 0);

    rc = csync_create(&csync, "/tmp/csync1", "/tmp/csync2");
    assert_int_equal(rc, 0);

    csync->replica = LOCAL_REPLICA;

    *state = csync;
}

static void setup_dir(void **state) {
    int rc;
    mbchar_t *dir = c_utf8_to_locale(CSYNC_TEST_DIR);

    setup(state);

    rc = _tmkdir(dir, 0755);
    c_free_locale_string(dir);
    assert_int_equal(rc, 0);
}

static void setup_file(void **state) {
    int rc;

    setup_dir(state);

    rc = system("echo \"This is a test\" > /tmp/csync/file.txt");
    assert_int_equal(rc, 0);
}

static void teardown(void **state) {
    CSYNC *csync = *state;
    int rc;

    rc = csync_destroy(csync);
    assert_int_equal(rc, 0);

    rc = system("rm -rf /tmp/csync/");
    assert_int_equal(rc, 0);

    *state = NULL;
}

static void check_csync_vio_load(void **state)
{
    CSYNC *csync = *state;
    int rc;

    rc = csync_vio_init(csync, "sftp", NULL);
    assert_int_equal(rc, 0);

    csync_vio_shutdown(csync);
}

static void check_csync_vio_load_wrong_proto(void **state)
{
    CSYNC *csync = *state;
    int rc;

    rc = csync_vio_init(csync, "wrong", NULL);
    assert_int_equal(rc, -1);

    csync_vio_shutdown(csync);
}

static void check_csync_vio_load_bad_plugin(void **state)
{'fraction_non_alphanumeric': 0.15017064846416384, 'fraction_numerical': 0.008532423208191127, 'mean_word_length': 3.5973856209150328, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, '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': '5081010', 'n_tokens_mistral': 1509, 'n_tokens_neox': 1461, 'n_words': 286}