Пример #1
0
atf_error_t
atf_text_split(const char *str, const char *delim, atf_list_t *words)
{
    atf_error_t err;
    const char *end;
    const char *iter;

    err = atf_list_init(words);
    if (atf_is_error(err))
        goto err;

    end = str + strlen(str);
    INV(*end == '\0');
    iter = str;
    while (iter < end) {
        const char *ptr;

        INV(iter != NULL);
        ptr = strstr(iter, delim);
        if (ptr == NULL)
            ptr = end;

        INV(ptr >= iter);
        if (ptr > iter) {
            atf_dynstr_t word;

            err = atf_dynstr_init_raw(&word, iter, ptr - iter);
            if (atf_is_error(err))
                goto err_list;

            err = atf_list_append(words, atf_dynstr_fini_disown(&word), true);
            if (atf_is_error(err))
                goto err_list;
        }

        iter = ptr + strlen(delim);
    }

    INV(!atf_is_error(err));
    return err;

err_list:
    atf_list_fini(words);
err:
    return err;
}
Пример #2
0
ATF_TC_BODY (exec_list, tc)
{
    atf_fs_path_t process_helpers;

    atf_list_t argv;

    atf_process_status_t status;

    RE (atf_list_init (&argv));

    get_process_helpers_path (tc, true, &process_helpers);
    atf_list_append (&argv, strdup (atf_fs_path_cstring (&process_helpers)), true);
    atf_list_append (&argv, strdup ("echo"), true);
    atf_list_append (&argv, strdup ("test-message"), true);
    {
        atf_fs_path_t outpath;

        atf_process_stream_t outsb;

        RE (atf_fs_path_init_fmt (&outpath, "stdout"));
        RE (atf_process_stream_init_redirect_path (&outsb, &outpath));
        RE (atf_process_exec_list (&status, &process_helpers, &argv, &outsb, NULL));
        atf_process_stream_fini (&outsb);
        atf_fs_path_fini (&outpath);
    }
    atf_list_fini (&argv);

    ATF_CHECK (atf_process_status_exited (&status));
    ATF_CHECK_EQ (atf_process_status_exitstatus (&status), EXIT_SUCCESS);

    {
        int fd = open ("stdout", O_RDONLY);

        ATF_CHECK (fd != -1);
        check_line (fd, "test-message");
        close (fd);
    }

    atf_process_status_fini (&status);
    atf_fs_path_fini (&process_helpers);
}