ATF_TC_BODY(error_new, tc)
{
    atf_error_t err;
    int data;

    err = atf_error_new("test_error", NULL, 0, NULL);
    ATF_REQUIRE(atf_error_is(err, "test_error"));
    ATF_REQUIRE(!atf_error_is(err, "unknown_error"));
    ATF_REQUIRE(atf_error_data(err) == NULL);
    atf_error_free(err);

    data = 5;
    err = atf_error_new("test_data_error", &data, sizeof(data), NULL);
    ATF_REQUIRE(atf_error_is(err, "test_data_error"));
    ATF_REQUIRE(!atf_error_is(err, "unknown_error"));
    ATF_REQUIRE(atf_error_data(err) != NULL);
    ATF_REQUIRE_EQ(*((const int *)atf_error_data(err)), 5);
    atf_error_free(err);
}
ATF_TC_BODY(format, tc)
{
    atf_error_t err;
    char buf[1024];

    printf("Testing default formatting function\n");
    err = atf_error_new("test_error", NULL, 0, NULL);
    atf_error_format(err, buf, sizeof(buf));
    printf("Error string is: %s\n", buf);
    ATF_REQUIRE(strcmp(buf, "Error 'test_error'") == 0);
    atf_error_free(err);

    printf("Testing custom formatting function\n");
    err = atf_error_new("test_error", NULL, 0, test_format);
    atf_error_format(err, buf, sizeof(buf));
    printf("Error string is: %s\n", buf);
    ATF_REQUIRE(strcmp(buf, "Test formatting function") == 0);
    atf_error_free(err);
}
ATF_TC_BODY(is_error, tc)
{
    atf_error_t err;

    err = atf_no_error();
    ATF_REQUIRE(!atf_is_error(err));

    err = atf_error_new("test_error", NULL, 0, NULL);
    ATF_REQUIRE(atf_is_error(err));
    atf_error_free(err);
}
ATF_TC_BODY(error_new_wo_memory, tc)
{
    atf_error_t err;
    void *invalid;

    invalid = (void *)1;

    err = atf_error_new("test_error", invalid, SIZE_MAX, NULL);
    ATF_REQUIRE(atf_error_is(err, "no_memory"));
    ATF_REQUIRE(atf_error_data(err) == NULL);
    atf_error_free(err);
}
Esempio n. 5
0
static
atf_error_t
test_error(const char* msg)
{
    atf_error_t err;
    test_error_data_t data;

    data.m_msg = msg;

    err = atf_error_new("test", &data, sizeof(data), test_format);

    return err;
}
Esempio n. 6
0
static
atf_error_t
unknown_type_error(const char *path, int type)
{
    atf_error_t err;
    unknown_type_error_data_t data;

    data.m_path = path;
    data.m_type = type;

    err = atf_error_new("unknown_type", &data, sizeof(data),
                        unknown_type_format);

    return err;
}
Esempio n. 7
0
atf_error_t
atf_libc_error(int syserrno, const char *fmt, ...)
{
    atf_error_t err;
    atf_libc_error_data_t data;
    va_list ap;

    data.m_errno = syserrno;
    va_start(ap, fmt);
    vsnprintf(data.m_what, sizeof(data.m_what), fmt, ap);
    va_end(ap);

    err = atf_error_new("libc", &data, sizeof(data), libc_format);

    return err;
}
Esempio n. 8
0
static
atf_error_t
invalid_umask_error(const atf_fs_path_t *path, const int type,
                    const mode_t failing_mask)
{
    atf_error_t err;
    invalid_umask_error_data_t data;

    data.m_type = type;

    strncpy(data.m_path, atf_fs_path_cstring(path), sizeof(data.m_path));
    data.m_path[sizeof(data.m_path) - 1] = '\0';

    data.m_umask = failing_mask;

    err = atf_error_new("invalid_umask", &data, sizeof(data),
                        invalid_umask_format);

    return err;
}