Exemplo n.º 1
0
static void
test_null(void)
{
    struct sol_arena *arena;
    struct sol_str_slice dst;

    arena = sol_arena_new();
    ASSERT(arena);

    ASSERT(sol_arena_slice_dup_str(arena, &dst, NULL));
    ASSERT(sol_arena_slice_dup_str_n(arena, &dst, NULL, 0));
    ASSERT(sol_arena_slice_dup(arena, &dst, SOL_STR_SLICE_STR(NULL, 0)));
    ASSERT(!sol_arena_strdup(arena, NULL));
    ASSERT(!sol_arena_strndup(arena, NULL, 0));

    sol_arena_del(arena);
}
Exemplo n.º 2
0
static void
test_simple(void)
{
    static const char *gladiators[] = {
        "Spartacus",
        "C r i x u s",
        "Priscus and Verus"
    };

    struct sol_arena *arena;
    struct sol_str_slice dst;
    char *dst_str;
    unsigned int i;

    arena = sol_arena_new();
    ASSERT(arena);

    for (i = 0; i < sol_util_array_size(gladiators); i++) {
        struct sol_str_slice gladiator_slice = sol_str_slice_from_str(gladiators[i]);

        ASSERT_INT_EQ(sol_arena_slice_dup_str(arena, &dst, gladiators[i]), 0);
        ASSERT(sol_str_slice_eq(dst, gladiator_slice));

        ASSERT_INT_EQ(sol_arena_slice_dup_str_n(arena, &dst, gladiators[i], strlen(gladiators[i])), 0);
        ASSERT(sol_str_slice_eq(dst, gladiator_slice));

        ASSERT_INT_EQ(sol_arena_slice_dup(arena, &dst, sol_str_slice_from_str(gladiators[i])), 0);
        ASSERT(sol_str_slice_eq(dst, gladiator_slice));

        dst_str = sol_arena_strdup(arena, gladiators[i]);
        ASSERT(dst_str);
        ASSERT(streq(gladiators[i], dst_str));

        dst_str = sol_arena_strndup(arena, gladiators[i], strlen(gladiators[i]));
        ASSERT(dst_str);
        ASSERT(streq(gladiators[i], dst_str));
    }

    sol_arena_del(arena);
}
Exemplo n.º 3
0
SOL_API char *
sol_arena_strdup_slice(struct sol_arena *arena, const struct sol_str_slice slice)
{
    return sol_arena_strndup(arena, slice.data, slice.len);
}
Exemplo n.º 4
0
SOL_API char *
sol_arena_strdup(struct sol_arena *arena, const char *str)
{
    SOL_NULL_CHECK(str, NULL);
    return sol_arena_strndup(arena, str, strlen(str));
}