Пример #1
0
static void
test_lys_parse_fd(void **state)
{
    (void) state; /* unused */
    const struct lys_module *module;
    char *yang_folder = TESTS_DIR"/api/files";
    char *yin_file = TESTS_DIR"/api/files/a.yin";
    char *yang_file = TESTS_DIR"/api/files/b.yang";
    int fd = -1;

    ctx = ly_ctx_new(yang_folder, 0);

    fd = open(yin_file, O_RDONLY);
    if (fd == -1) {
        fail();
    }

    module = lys_parse_fd(ctx, fd, LYS_IN_YIN);
    if (!module) {
        fail();
    }

    close(fd);
    assert_string_equal("a", module->name);

    fd = open(yang_file, O_RDONLY);
    if (fd == -1) {
        fail();
    }

    module = lys_parse_fd(ctx, fd, LYS_IN_YANG);
    if (!module) {
        fail();
    }

    close(fd);
    assert_string_equal("b", module->name);

    module = lys_parse_mem(ctx, lys_module_a, LYS_IN_YIN);
    if (module) {
        fail();
    }

    ly_ctx_destroy(ctx, NULL);
    ctx = NULL;
}
Пример #2
0
static int
setup_write(void **state)
{
    (void) state; /* unused */
    int fd;
    struct wr *w;

    w = malloc(sizeof *w);
    w->session = calloc(1, sizeof *w->session);
    w->session->ctx = ly_ctx_new(TESTS_DIR"../schemas");
    w->session->ti_lock = malloc(sizeof *w->session->ti_lock);
    pthread_mutex_init(w->session->ti_lock, NULL);

    /* ietf-netconf */
    fd = open(TESTS_DIR"../schemas/ietf-netconf.yin", O_RDONLY);
    if (fd == -1) {
        free(w);
        return -1;
    }

    lys_parse_fd(w->session->ctx, fd, LYS_IN_YIN);
    close(fd);

    w->session->status = NC_STATUS_RUNNING;
    w->session->version = NC_VERSION_10;
    w->session->msgid = 999;
    w->session->ti_type = NC_TI_FD;
    w->session->ti.fd.in = STDIN_FILENO;
    w->session->ti.fd.out = STDOUT_FILENO;

    /* get rpc to write */
    w->rpc = nc_rpc_lock(NC_DATASTORE_RUNNING);
    assert_non_null(w->rpc);

    w->session->ti.fd.in = -1;

    *state = w;

    return 0;
}