示例#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 u_string_t value of a variable
 *
 * Return an u_string_t containing the name string of variable \p v.
 *
 * \param v   variable object
 *
 * \return the value string of \p v (may be \c NULL)
 */
u_string_t *var_get_value_s(var_t *v)
{
    dbg_return_if (v == NULL, NULL);

    if(v->svalue == NULL)
        dbg_err_if(u_string_create(v->data, v->size, &v->svalue));
    
    return v->svalue;
err:
    return NULL;
}
示例#3
0
文件: string.c 项目: fdotli/libu
static int test_emptiness (u_test_case_t *tc)
{
    char *tmp;
    u_string_t *s = NULL;

    u_test_err_if (u_string_create(NULL, 0, &s));

    /* Detach free's the parent string object whie the detached
     * buffer is left untouched. */
    u_test_err_ifm ((tmp = u_string_detach_cstr(s)) != NULL,
            "an empty string should detach to a NULL pointer");

    return U_TEST_SUCCESS;
err:
    return U_TEST_FAILURE;
}
示例#4
0
static u_string_t *__sample_str(u_hmap_o_t *obj)
{
    enum { MAX_OBJ_STR = 256 };
    char buf[MAX_OBJ_STR];
    u_string_t *s = NULL;

    int key = *((int *) obj->key);
    char *val = (char *) obj->val;

    dbg_err_if (u_snprintf(buf, MAX_OBJ_STR, "[%d:%s]", key, val));
    dbg_err_if (u_string_create(buf, strlen(buf)+1, &s));

    return s;

err:
    return NULL;
}
示例#5
0
文件: var.c 项目: DanielTillett/klone
int var_bin_create(const char *name, const unsigned char *data, size_t size, 
        var_t **pv)
{
    var_t *v = NULL;

    dbg_return_if (name == NULL, ~0);
    dbg_return_if (data == NULL, ~0);
    dbg_return_if (pv == NULL, ~0);

    v = u_zalloc(sizeof(var_t));
    dbg_err_if(v == NULL);

    dbg_err_if(u_string_create(name, strlen(name), &v->sname));

    dbg_err_if(var_set_bin_value(v, data, size));

    *pv = v;

    return 0;
err:
    if(v)
        var_free(v);
    return ~0;
}