static void test_check_slices_after_adding_all(void) { static const char *gladiators[] = { "Spartacus", "C r i x u s", "Priscus and Verus", "Tetraites", "Spiculus", "Marcus Attilius", "Carpophorus", "Flamma", "Commodus", "Mevia", "Hoplomachus", "Laquearius", "Lorarius", "Paegniarius", "Sagittarius", "Pegasasu no Seiya", "Thraex", "Gladiatrix", "Crupellarii", "Cestus", "Arbelas", "Retiarius", "Samnite", "Venator", "Dimachaerus", "Bustuarius", "This is a loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong name for a gladiator" }; struct sol_arena *arena; struct sol_str_slice results[sol_util_array_size(gladiators)]; unsigned int i; arena = sol_arena_new(); ASSERT(arena); for (i = 0; i < sol_util_array_size(gladiators); i++) ASSERT_INT_EQ(sol_arena_slice_dup_str(arena, &results[i], gladiators[i]), 0); for (i = 0; i < sol_util_array_size(gladiators); i++) ASSERT(sol_str_slice_eq(results[i], sol_str_slice_from_str(gladiators[i]))); sol_arena_del(arena); }
SOL_API bool sol_http_param_add_copy(struct sol_http_params *params, struct sol_http_param_value value) { struct sol_http_param_value *ptr; int r; SOL_NULL_CHECK(params, false); SOL_HTTP_PARAMS_CHECK_API_VERSION(params, false); if (!params->arena) { params->arena = sol_arena_new(); SOL_NULL_CHECK(params->arena, false); } if (value.type == SOL_HTTP_PARAM_QUERY_PARAM || value.type == SOL_HTTP_PARAM_COOKIE || value.type == SOL_HTTP_PARAM_POST_FIELD || value.type == SOL_HTTP_PARAM_HEADER) { if (value.value.key_value.key.len) { r = sol_arena_slice_dup(params->arena, &value.value.key_value.key, value.value.key_value.key); SOL_INT_CHECK(r, < 0, false); } if (value.value.key_value.value.len) { r = sol_arena_slice_dup(params->arena, &value.value.key_value.value, value.value.key_value.value); SOL_INT_CHECK(r, < 0, false); }
static bool startup(void *data) { bool finished = true; int result = EXIT_FAILURE; struct sol_ptr_vector *memory_maps; str_arena = sol_arena_new(); if (!str_arena) { fprintf(stderr, "Cannot create str arena\n"); goto end; } if (args.execute_type) { the_runner = runner_new_from_type(args.name, args.options); } else { the_runner = runner_new_from_file(args.name, args.options, &args.fbp_search_paths); } if (!the_runner) goto end; if (args.check_only) { printf("'%s' - Syntax OK\n", args.name); result = EXIT_SUCCESS; goto end; } if (args.provide_sim_nodes) { int err; err = runner_attach_simulation(the_runner); if (err < 0) { fprintf(stderr, "Cannot attach simulation nodes\n"); goto end; } } if (sol_conffile_resolve_memmap(&memory_maps)) { SOL_ERR("Couldn't resolve memory mappings on config file"); goto end; } if (memory_maps) load_memory_maps(memory_maps); if (runner_run(the_runner) < 0) { fprintf(stderr, "Failed to run\n"); goto end; } finished = false; end: if (finished) sol_quit_with_code(result); return false; }
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); }
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); }
SOL_API bool sol_http_param_add_copy(struct sol_http_params *params, struct sol_http_param_value value) { struct sol_http_param_value *ptr; int r; SOL_NULL_CHECK(params, -EINVAL); #ifndef SOL_NO_API_VERSION if (params->api_version != SOL_HTTP_PARAM_API_VERSION) { SOL_ERR("API version mistmatch; expected %u, got %u", SOL_HTTP_PARAM_API_VERSION, params->api_version); return false; } #endif if (!params->arena) { params->arena = sol_arena_new(); SOL_NULL_CHECK(params->arena, false); } if (value.type == SOL_HTTP_PARAM_QUERY_PARAM || value.type == SOL_HTTP_PARAM_COOKIE || value.type == SOL_HTTP_PARAM_POST_FIELD || value.type == SOL_HTTP_PARAM_HEADER) { if (value.value.key_value.key.len) { r = sol_arena_slice_dup(params->arena, &value.value.key_value.key, value.value.key_value.key); SOL_INT_CHECK(r, < 0, false); } if (value.value.key_value.value.len) { r = sol_arena_slice_dup(params->arena, &value.value.key_value.value, value.value.key_value.value); SOL_INT_CHECK(r, < 0, false); }