示例#1
0
文件: string.c 项目: childhood/libu
static int test_u_str (u_test_case_t *tc)
{
    u_string_t *s = NULL;

    u_test_err_if (u_string_create("0", 1, &s));

    u_test_err_if (strcmp(u_string_c(s), "0"));

    u_test_err_if (u_string_sprintf(s, "%s", "1"));
    u_test_err_if (strcmp(u_string_c(s), "1"));

    u_test_err_if (u_string_aprintf(s, "%s", "23"));
    u_test_err_if (strcmp(u_string_c(s), "123"));

    u_test_err_if (u_string_cat(s, "45"));
    u_test_err_if (strcmp(u_string_c(s), "12345"));

    u_test_err_if (u_string_ncat(s, "6777", 2));
    u_test_err_if (strcmp(u_string_c(s), "1234567"));

    u_test_err_if (u_string_sprintf(s, "%s", "reset"));
    u_test_err_if (strcmp(u_string_c(s), "reset"));

    u_string_free(s);

    return U_TEST_SUCCESS;
err:
    return U_TEST_FAILURE;
}
示例#2
0
文件: var.c 项目: DanielTillett/klone
/**
 * \ingroup vars
 * \brief   Get the name of a variable
 *
 * Return a \c char* containing the name of variable \p v.
 *
 * \param v  variable object
 *
 * \return the name string of the given \p v (may be \c NULL)
 */
const char *var_get_name(var_t *v)
{
    dbg_return_if (v == NULL, NULL);

    return u_string_c(v->sname);
}