From e9b710249fe9cd3d13838dc413bf89961e249a70 Mon Sep 17 00:00:00 2001 From: pancake Date: Sun, 6 Nov 2022 19:48:53 +0100 Subject: [PATCH] Rename RVector.len to RVector.length for consistency ##api --- binr/r2r/r2r.c | 26 +++++----- binr/r2r/run.c | 6 +-- libr/anal/op.c | 2 +- libr/anal/var.c | 6 +-- libr/bin/format/mach0/mach0.c | 2 +- libr/bin/format/wasm/wasm.c | 2 +- libr/bin/p/bin_wasm.c | 4 +- libr/cons/dietline.c | 4 +- libr/cons/line.c | 2 +- libr/core/canal.c | 8 +-- libr/core/cbin.c | 2 +- libr/core/cmd_anal.c | 4 +- libr/core/disasm.c | 4 +- libr/core/rtr.c | 2 +- libr/include/r_vector.h | 8 +-- libr/util/skyline.c | 6 +-- libr/util/vector.c | 4 +- test/unit/meson.build | 1 - test/unit/test_anal_meta.c | 40 +++++++-------- test/unit/test_anal_var.c | 46 ++++++++--------- test/unit/test_intervaltree.c | 2 +- test/unit/test_r2r.c | 2 +- test/unit/test_skyline.c | 97 ----------------------------------- 23 files changed, 91 insertions(+), 189 deletions(-) delete mode 100644 test/unit/test_skyline.c diff --git a/binr/r2r/r2r.c b/binr/r2r/r2r.c index df4bd53b43..5c1ea2a37e 100644 --- a/binr/r2r/r2r.c +++ b/binr/r2r/r2r.c @@ -430,7 +430,7 @@ int main(int argc, char **argv) { } R_FREE (cwd); - uint32_t loaded_tests = r_pvector_len (&state.db->tests); + uint32_t loaded_tests = r_pvector_length (&state.db->tests); printf ("Loaded %u tests.\n", loaded_tests); if (nothing) { goto coast; @@ -440,7 +440,7 @@ int main(int argc, char **argv) { if (!jq_available) { eprintf ("Skipping json tests because jq is not available.\n"); size_t i; - for (i = 0; i < r_pvector_len (&state.db->tests);) { + for (i = 0; i < r_pvector_length (&state.db->tests);) { R2RTest *test = r_pvector_at (&state.db->tests, i); if (test->type == R2R_TEST_TYPE_JSON) { r2r_test_free (test); @@ -451,7 +451,7 @@ int main(int argc, char **argv) { } } - r_pvector_insert_range (&state.queue, 0, state.db->tests.v.a, r_pvector_len (&state.db->tests)); + r_pvector_insert_range (&state.queue, 0, state.db->tests.v.a, r_pvector_length (&state.db->tests)); if (log_mode) { // Log mode prints the state after every completed file. @@ -490,15 +490,15 @@ int main(int argc, char **argv) { ut64 prev_completed = UT64_MAX; ut64 prev_paths_completed = 0; while (true) { - ut64 completed = (ut64)r_pvector_len (&state.results); + ut64 completed = (ut64)r_pvector_length (&state.results); if (log_mode) { print_log (&state, prev_completed, prev_paths_completed); } else if (completed != prev_completed) { print_state (&state, prev_completed); } prev_completed = completed; - prev_paths_completed = (ut64)r_pvector_len (&state.completed_paths); - if (completed == r_pvector_len (&state.db->tests)) { + prev_paths_completed = (ut64)r_pvector_length (&state.completed_paths); + if (completed == r_pvector_length (&state.db->tests)) { break; } r_th_cond_wait (state.cond, state.lock); @@ -811,7 +811,7 @@ static void print_result_diff(R2RRunConfig *config, R2RTestResultInfo *result) { static void print_new_results(R2RState *state, ut64 prev_completed) { // Detailed test result (with diff if necessary) - ut64 completed = (ut64)r_pvector_len (&state->results); + ut64 completed = (ut64)r_pvector_length (&state->results); ut64 i; for (i = prev_completed; i < completed; i++) { R2RTestResultInfo *result = r_pvector_at (&state->results, (size_t)i); @@ -864,8 +864,8 @@ static void print_state(R2RState *state, ut64 prev_completed) { // [x/x] OK 42 BR 0 ... printf (R_CONS_CLEAR_LINE); - ut64 a = (ut64)r_pvector_len (&state->results); - ut64 b = (ut64)r_pvector_len (&state->db->tests); + ut64 a = (ut64)r_pvector_length (&state->results); + ut64 b = (ut64)r_pvector_length (&state->db->tests); int w = printf ("[%"PFMT64u"/%"PFMT64u"]", a, b); while (w >= 0 && w < 20) { printf (" "); @@ -881,8 +881,8 @@ static void print_state(R2RState *state, ut64 prev_completed) { static void print_log(R2RState *state, ut64 prev_completed, ut64 prev_paths_completed) { print_new_results (state, prev_completed); - ut64 paths_completed = r_pvector_len (&state->completed_paths); - int a = r_pvector_len (&state->queue); + ut64 paths_completed = r_pvector_length (&state->completed_paths); + int a = r_pvector_length (&state->queue); for (; prev_paths_completed < paths_completed; prev_paths_completed++) { printf ("[%d/%d] %50s ", (int)paths_completed, @@ -916,9 +916,9 @@ static void interact(R2RState *state) { printf ("#####################\n"); if (use_fancy_stuff) { printf (" %"PFMT64u" failed test(s)"R_UTF8_POLICE_CARS_REVOLVING_LIGHT"\n", - (ut64)r_pvector_len (&failed_results)); + (ut64)r_pvector_length (&failed_results)); } else { - printf (" %"PFMT64u" failed test(s)\n", (ut64)r_pvector_len (&failed_results)); + printf (" %"PFMT64u" failed test(s)\n", (ut64)r_pvector_length (&failed_results)); } r_pvector_foreach (&failed_results, it) { diff --git a/binr/r2r/run.c b/binr/r2r/run.c index e4655fac60..8da56c98d6 100644 --- a/binr/r2r/run.c +++ b/binr/r2r/run.c @@ -924,7 +924,7 @@ static R2RProcessOutput *run_r2_test(R2RRunConfig *config, ut64 timeout_ms, cons #else size_t env_size = load_plugins ? 0 : 1; #endif - R2RProcessOutput *out = runner (config->r2_cmd, args.v.a, r_pvector_len (&args), envvars, envvals, env_size, timeout_ms, user); + R2RProcessOutput *out = runner (config->r2_cmd, args.v.a, r_pvector_length (&args), envvars, envvals, env_size, timeout_ms, user); r_pvector_clear (&args); #if __WINDOWS__ free (wcmds); @@ -1088,7 +1088,7 @@ R_API R2RAsmTestOutput *r2r_run_asm_test(R2RRunConfig *config, R2RAsmTest *test) r_strbuf_init (&cmd_buf); if (test->mode & R2R_ASM_TEST_MODE_ASSEMBLE) { r_pvector_push (&args, test->disasm); - R2RSubprocess *proc = r2r_subprocess_start (config->rasm2_cmd, args.v.a, r_pvector_len (&args), NULL, NULL, 0); + R2RSubprocess *proc = r2r_subprocess_start (config->rasm2_cmd, args.v.a, r_pvector_length (&args), NULL, NULL, 0); if (!r2r_subprocess_wait (proc, config->timeout_ms)) { r2r_subprocess_kill (proc); out->as_timeout = true; @@ -1126,7 +1126,7 @@ rip: } r_pvector_push (&args, "-d"); r_pvector_push (&args, hex); - R2RSubprocess *proc = r2r_subprocess_start (config->rasm2_cmd, args.v.a, r_pvector_len (&args), NULL, NULL, 0); + R2RSubprocess *proc = r2r_subprocess_start (config->rasm2_cmd, args.v.a, r_pvector_length (&args), NULL, NULL, 0); if (!r2r_subprocess_wait (proc, config->timeout_ms)) { r2r_subprocess_kill (proc); out->disas_timeout = true; diff --git a/libr/anal/op.c b/libr/anal/op.c index 0efd7aaa9a..49f10dc1b5 100644 --- a/libr/anal/op.c +++ b/libr/anal/op.c @@ -722,7 +722,7 @@ R_API int r_anal_op_reg_delta(RAnal *anal, ut64 addr, const char *name) { if (r_anal_op (anal, &op, addr, buf, sizeof (buf), R_ARCH_OP_MASK_ALL) > 0) { dst = r_vector_at (&op.dsts, 0); if (dst && dst->reg && dst->reg->name && (!name || !strcmp (dst->reg->name, name))) { - if (r_vector_len (&op.srcs) > 0) { + if (r_vector_length (&op.srcs) > 0) { r_anal_op_fini (&op); return ((RAnalValue*)r_vector_at (&op.srcs, 0))->delta; } diff --git a/libr/anal/var.c b/libr/anal/var.c index 3b076e6bf5..fc53f313c8 100644 --- a/libr/anal/var.c +++ b/libr/anal/var.c @@ -232,7 +232,7 @@ R_API void r_anal_var_delete(RAnalVar *var) { r_return_if_fail (var); RAnalFunction *fcn = var->fcn; size_t i; - for (i = 0; i < r_pvector_len (&fcn->vars); i++) { + for (i = 0; i < r_pvector_length (&fcn->vars); i++) { RAnalVar *v = r_pvector_at (&fcn->vars, i); if (v == var) { r_pvector_remove_at (&fcn->vars, i); @@ -245,7 +245,7 @@ R_API void r_anal_var_delete(RAnalVar *var) { R_API void r_anal_function_delete_vars_by_kind(RAnalFunction *fcn, RAnalVarKind kind) { r_return_if_fail (fcn); size_t i; - for (i = 0; i < r_pvector_len (&fcn->vars);) { + for (i = 0; i < r_pvector_length (&fcn->vars);) { RAnalVar *var = r_pvector_at (&fcn->vars, i); if (var->kind == kind) { r_pvector_remove_at (&fcn->vars, i); @@ -804,7 +804,7 @@ R_API int r_anal_var_count(RAnal *a, RAnalFunction *fcn, int kind, int type) { R_API int r_anal_var_count_all(RAnalFunction *fcn) { r_return_val_if_fail (fcn, 0); - return r_pvector_len (&fcn->vars); + return r_pvector_length (&fcn->vars); } R_API int r_anal_var_count_args(RAnalFunction *fcn) { diff --git a/libr/bin/format/mach0/mach0.c b/libr/bin/format/mach0/mach0.c index a1f52ed7fc..b0bb9dce9a 100644 --- a/libr/bin/format/mach0/mach0.c +++ b/libr/bin/format/mach0/mach0.c @@ -3543,7 +3543,7 @@ RSkipList *MACH0_(get_relocs)(struct MACH0_(obj_t) *bin) { case BIND_SUBOPCODE_THREADED_APPLY: if (threaded_binds) { int cur_seg_idx = (seg_idx != -1)? seg_idx: 0; - size_t n_threaded_binds = r_pvector_len (threaded_binds); + size_t n_threaded_binds = r_pvector_length (threaded_binds); while (addr < segment_end_addr) { ut8 tmp[8]; ut64 paddr = addr - bin->segs[cur_seg_idx].vmaddr + bin->segs[cur_seg_idx].fileoff; diff --git a/libr/bin/format/wasm/wasm.c b/libr/bin/format/wasm/wasm.c index 89d77487a2..22edcb7b50 100644 --- a/libr/bin/format/wasm/wasm.c +++ b/libr/bin/format/wasm/wasm.c @@ -919,7 +919,7 @@ static bool parse_import_sec(RBinWasmObj *bin) { ut32 seen = 0; for (i = 0; i < R_ARRAY_SIZE (bin->g_imports_arr); i++) { r_pvector_shrink (bin->g_imports_arr[i]); - seen += r_pvector_len (bin->g_imports_arr[i]); + seen += r_pvector_length (bin->g_imports_arr[i]); } return seen == count? true: false; } diff --git a/libr/bin/p/bin_wasm.c b/libr/bin/p/bin_wasm.c index 346069a4ef..188f558154 100644 --- a/libr/bin/p/bin_wasm.c +++ b/libr/bin/p/bin_wasm.c @@ -12,7 +12,7 @@ static inline void *vector_at(RPVector *vec, ut64 n) { // If the file is corrupted, the section may not have as many entries as it should - if (n < r_pvector_len (vec)) { + if (n < r_pvector_length (vec)) { return r_pvector_at (vec, n); } return NULL; @@ -144,7 +144,7 @@ alloc_err: static inline ut32 first_ord_not_import(RBinWasmObj *bin, ut32 kind) { RPVector *imps = r_bin_wasm_get_imports_kind (bin, kind); - return imps? r_pvector_len (imps): 0; + return imps? r_pvector_length (imps): 0; } static const char *import_typename(ut32 kind) { diff --git a/libr/cons/dietline.c b/libr/cons/dietline.c index 511526fe03..bf152deb5b 100644 --- a/libr/cons/dietline.c +++ b/libr/cons/dietline.c @@ -728,7 +728,7 @@ static void selection_widget_select(void) { } static void selection_widget_update(void) { - int argc = r_pvector_len (&I.completion.args); + int argc = r_pvector_length (&I.completion.args); const char **argv = (const char **)r_pvector_data (&I.completion.args); if (argc == 0 || (argc == 1 && I.buffer.length >= strlen (argv[0]))) { selection_widget_erase (); @@ -766,7 +766,7 @@ R_API void r_line_autocomplete(void) { if (I.completion.run) { I.completion.opt = false; I.completion.run (&I.completion, &I.buffer, I.prompt_type, I.completion.run_user); - argc = r_pvector_len (&I.completion.args); + argc = r_pvector_length (&I.completion.args); argv = (const char **)r_pvector_data (&I.completion.args); opt = I.completion.opt; } diff --git a/libr/cons/line.c b/libr/cons/line.c index 837091f1cf..7203f7a1b8 100644 --- a/libr/cons/line.c +++ b/libr/cons/line.c @@ -71,7 +71,7 @@ R_API void r_line_completion_push(RLineCompletion *completion, const char *str) if (completion->quit) { return; } - if (r_pvector_len (&completion->args) < completion->args_limit) { + if (r_pvector_length (&completion->args) < completion->args_limit) { char *s = strdup (str); if (s) { r_pvector_push (&completion->args, (void *)s); diff --git a/libr/core/canal.c b/libr/core/canal.c index efd44f77f8..865a83e96e 100644 --- a/libr/core/canal.c +++ b/libr/core/canal.c @@ -3454,11 +3454,11 @@ typedef struct { static bool anal_block_on_exit(RAnalBlock *bb, BlockRecurseCtx *ctx) { int *cur_regset = r_pvector_pop (&ctx->reg_set); - if (r_pvector_len (&ctx->reg_set) == 0) { + if (r_pvector_length (&ctx->reg_set) == 0) { free (cur_regset); return false; } - int *prev_regset = r_pvector_at (&ctx->reg_set, r_pvector_len (&ctx->reg_set) - 1); + int *prev_regset = r_pvector_at (&ctx->reg_set, r_pvector_length (&ctx->reg_set) - 1); size_t i; for (i = 0; i < REG_SET_SIZE; i++) { if (!prev_regset[i] && cur_regset[i] == 1) { @@ -3499,11 +3499,11 @@ static bool anal_block_cb(RAnalBlock *bb, BlockRecurseCtx *ctx) { free (buf); return false; } - if (r_pvector_len (&ctx->reg_set) == 0) { + if (r_pvector_length (&ctx->reg_set) == 0) { free (buf); return false; } - int *parent_reg_set = r_pvector_at (&ctx->reg_set, r_pvector_len (&ctx->reg_set) - 1); + int *parent_reg_set = r_pvector_at (&ctx->reg_set, r_pvector_length (&ctx->reg_set) - 1); int *reg_set = R_NEWS (int, REG_SET_SIZE); memcpy (reg_set, parent_reg_set, REG_SET_SIZE * sizeof (int)); r_pvector_push (&ctx->reg_set, reg_set); diff --git a/libr/core/cbin.c b/libr/core/cbin.c index 65985523c6..1b996958ec 100644 --- a/libr/core/cbin.c +++ b/libr/core/cbin.c @@ -1791,7 +1791,7 @@ static int bin_relocs(RCore *r, PJ *pj, int mode, int va) { return false; } if (bin_cache) { - if (r_pvector_len (&r->io->cache) == 0) { + if (r_pvector_length (&r->io->cache) == 0) { r_config_set_b (r->config, "io.cache", false); } else { r_config_set_b (r->config, "io.cache.read", true); diff --git a/libr/core/cmd_anal.c b/libr/core/cmd_anal.c index b949237dc1..ab875ab772 100644 --- a/libr/core/cmd_anal.c +++ b/libr/core/cmd_anal.c @@ -2345,7 +2345,7 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int free (opname); } - if (r_vector_len (&op.srcs) > 0) { + if (r_vector_length (&op.srcs) > 0) { pj_ka (pj, "srcs"); RAnalValue *val; r_vector_foreach (&op.srcs, val) { @@ -2354,7 +2354,7 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int pj_end (pj); } - if (r_vector_len (&op.dsts) > 0) { + if (r_vector_length (&op.dsts) > 0) { pj_ka (pj, "dsts"); RAnalValue *val; r_vector_foreach (&op.dsts, val) { diff --git a/libr/core/disasm.c b/libr/core/disasm.c index 9468523d94..6299b28a24 100644 --- a/libr/core/disasm.c +++ b/libr/core/disasm.c @@ -7233,8 +7233,8 @@ R_API int r_core_disasm_pde(RCore *core, int nb_opcodes, int mode) { } free (buf); r_reg_arena_pop (reg); - int len = r_pvector_len (&ocache); - if (r_pvector_len (&core->io->cache) > len) { + int len = r_pvector_length (&ocache); + if (r_pvector_length (&core->io->cache) > len) { // TODO: Implement push/pop for IO.cache while (len > 0) { (void)r_pvector_pop_front (&core->io->cache); diff --git a/libr/core/rtr.c b/libr/core/rtr.c index 616c9978d6..cc5fef112e 100644 --- a/libr/core/rtr.c +++ b/libr/core/rtr.c @@ -1150,7 +1150,7 @@ static void rtr_cmds_client_close(uv_tcp_t *client, bool remove) { rtr_cmds_context *context = loop->data; if (remove) { size_t i; - for (i = 0; i < r_pvector_len (&context->clients); i++) { + for (i = 0; i < r_pvector_length (&context->clients); i++) { if (r_pvector_at (&context->clients, i) == client) { r_pvector_remove_at (&context->clients, i); break; diff --git a/libr/include/r_vector.h b/libr/include/r_vector.h index 531b27803c..6d9341a882 100644 --- a/libr/include/r_vector.h +++ b/libr/include/r_vector.h @@ -77,7 +77,7 @@ static inline bool r_vector_empty(const RVector *vec) { R_API void r_vector_clear(RVector *vec); // returns the length of the vector -static inline size_t r_vector_len(const RVector *vec) { +static inline size_t r_vector_length(const RVector *vec) { r_return_val_if_fail (vec, 0); return vec->len; } @@ -205,8 +205,8 @@ R_API void r_pvector_clear(RPVector *vec); // free the vector and call vec->v.free on every element. R_API void r_pvector_free(RPVector *vec); -// TODO: rename to r_pvector_length () for consistency -static inline size_t r_pvector_len(const RPVector *vec) { +// TODO: rename to r_pvector_lengthgth () for consistency +static inline size_t r_pvector_length(const RPVector *vec) { r_return_val_if_fail (vec, 0); return vec->v.len; } @@ -222,7 +222,7 @@ static inline void r_pvector_set(RPVector *vec, size_t index, void *e) { } static inline bool r_pvector_empty(RPVector *vec) { - return r_pvector_len (vec) == 0; + return r_pvector_length (vec) == 0; } // returns a pointer to the offset inside the array where the element of the index lies. diff --git a/libr/util/skyline.c b/libr/util/skyline.c index 5c5458252a..d680335f3f 100644 --- a/libr/util/skyline.c +++ b/libr/util/skyline.c @@ -17,7 +17,7 @@ R_API bool r_skyline_add(RSkyline *skyline, RInterval itv, void *user) { // `slot` is the index of the first RSkylineItem with part->itv.addr >= new_part.itv.addr size_t slot; r_vector_lower_bound (skyline_vec, new_part.itv.addr, slot, CMP_BEGIN_GTE_PART); - const bool is_last = slot == r_vector_len (skyline_vec); + const bool is_last = slot == r_vector_length (skyline_vec); bool is_inside_prev_part = false; if (slot) { RSkylineItem *prev_part = r_vector_index_ptr (skyline_vec, slot - 1); @@ -39,7 +39,7 @@ R_API bool r_skyline_add(RSkyline *skyline, RInterval itv, void *user) { while (part && r_itv_include (new_part.itv, part->itv)) { // Remove `part` that fits in `new_part` r_vector_remove_at (skyline_vec, slot, NULL); - part = slot < r_vector_len (skyline_vec) ? r_vector_index_ptr (skyline_vec, slot) : NULL; + part = slot < r_vector_length (skyline_vec) ? r_vector_index_ptr (skyline_vec, slot) : NULL; } if (part && r_itv_overlap (new_part.itv, part->itv)) { // Chop start of last `part` that intersects `new_part` @@ -55,7 +55,7 @@ R_API bool r_skyline_add(RSkyline *skyline, RInterval itv, void *user) { R_API const RSkylineItem *r_skyline_get_item_intersect(RSkyline *skyline, ut64 addr, ut64 len) { r_return_val_if_fail (skyline, NULL); RVector *skyline_vec = &skyline->v; - size_t i, l = r_vector_len (skyline_vec); + size_t i, l = r_vector_length (skyline_vec); r_vector_lower_bound (skyline_vec, addr, i, CMP_END_GTE_PART); if (i == l) { return false; diff --git a/libr/util/vector.c b/libr/util/vector.c index 09e02f7f73..41837266ff 100644 --- a/libr/util/vector.c +++ b/libr/util/vector.c @@ -311,7 +311,7 @@ R_API void r_pvector_remove_data(RPVector *vec, void *x) { R_API void *r_pvector_pop(RPVector *vec) { r_return_val_if_fail (vec, NULL); - if (r_pvector_len (vec) < 1) { + if (r_pvector_length (vec) < 1) { return NULL; } void *r = r_pvector_at (vec, vec->v.len - 1); @@ -321,7 +321,7 @@ R_API void *r_pvector_pop(RPVector *vec) { R_API void *r_pvector_pop_front(RPVector *vec) { r_return_val_if_fail (vec, NULL); - if (r_pvector_len (vec) < 1) { + if (r_pvector_length (vec) < 1) { return NULL; } void *r = r_pvector_at (vec, 0); diff --git a/test/unit/meson.build b/test/unit/meson.build index 2e3cee4722..98bf806ad8 100644 --- a/test/unit/meson.build +++ b/test/unit/meson.build @@ -51,7 +51,6 @@ if get_option('enable_tests') 'reg', 'sign', 'skiplist', - 'skyline', 'spaces', 'sparse', 'stack', diff --git a/test/unit/test_anal_meta.c b/test/unit/test_anal_meta.c index c0894d9ce6..79e68f4358 100644 --- a/test/unit/test_anal_meta.c +++ b/test/unit/test_anal_meta.c @@ -218,7 +218,7 @@ bool test_meta_get_all_at() { r_meta_set_with_subtype (anal, R_META_TYPE_STRING, R_STRING_ENC_UTF8, 0x200, 0x30, "true confessions"); RPVector *items = r_meta_get_all_at (anal, 0x100); - mu_assert_eq (r_pvector_len (items), 2, "all count"); + mu_assert_eq (r_pvector_length (items), 2, "all count"); void **it; bool found[2] = {0}; r_pvector_foreach (items, it) { @@ -239,11 +239,11 @@ bool test_meta_get_all_at() { r_pvector_free (items); items = r_meta_get_all_at (anal, 0xff); - mu_assert_eq (r_pvector_len (items), 0, "all count"); + mu_assert_eq (r_pvector_length (items), 0, "all count"); r_pvector_free (items); items = r_meta_get_all_at (anal, 0x101); - mu_assert_eq (r_pvector_len (items), 0, "all count"); + mu_assert_eq (r_pvector_length (items), 0, "all count"); r_pvector_free (items); r_anal_free (anal); @@ -258,7 +258,7 @@ bool test_meta_get_all_in() { r_meta_set_with_subtype (anal, R_META_TYPE_STRING, R_STRING_ENC_UTF8, 0x200, 0x30, "true confessions"); RPVector *items = r_meta_get_all_in (anal, 0x100, R_META_TYPE_ANY); - mu_assert_eq (r_pvector_len (items), 2, "all count"); + mu_assert_eq (r_pvector_length (items), 2, "all count"); void **it; bool found[2] = {0}; r_pvector_foreach (items, it) { @@ -279,33 +279,33 @@ bool test_meta_get_all_in() { r_pvector_free (items); items = r_meta_get_all_in (anal, 0x100, R_META_TYPE_COMMENT); - mu_assert_eq (r_pvector_len (items), 1, "all count"); + mu_assert_eq (r_pvector_length (items), 1, "all count"); RAnalMetaItem *item = ((RIntervalNode *)r_pvector_at (items, 0))->data; mu_assert_streq (item->str, "vera gemini", "contents"); r_pvector_free (items); items = r_meta_get_all_in (anal, 0x100, R_META_TYPE_DATA); - mu_assert_eq (r_pvector_len (items), 1, "all count"); + mu_assert_eq (r_pvector_length (items), 1, "all count"); item = ((RIntervalNode *)r_pvector_at (items, 0))->data; mu_assert_eq (item->type, R_META_TYPE_DATA, "contents"); r_pvector_free (items); items = r_meta_get_all_in (anal, 0xff, R_META_TYPE_ANY); - mu_assert_eq (r_pvector_len (items), 0, "all count"); + mu_assert_eq (r_pvector_length (items), 0, "all count"); r_pvector_free (items); items = r_meta_get_all_in (anal, 0x101, R_META_TYPE_COMMENT); - mu_assert_eq (r_pvector_len (items), 0, "all count"); + mu_assert_eq (r_pvector_length (items), 0, "all count"); r_pvector_free (items); items = r_meta_get_all_in (anal, 0x103, R_META_TYPE_DATA); - mu_assert_eq (r_pvector_len (items), 1, "all count"); + mu_assert_eq (r_pvector_length (items), 1, "all count"); item = ((RIntervalNode *)r_pvector_at (items, 0))->data; mu_assert_eq (item->type, R_META_TYPE_DATA, "contents"); r_pvector_free (items); items = r_meta_get_all_in (anal, 0x104, R_META_TYPE_DATA); - mu_assert_eq (r_pvector_len (items), 0, "all count"); + mu_assert_eq (r_pvector_length (items), 0, "all count"); r_pvector_free (items); r_anal_free (anal); @@ -320,7 +320,7 @@ bool test_meta_get_all_intersect() { r_meta_set_with_subtype (anal, R_META_TYPE_STRING, R_STRING_ENC_UTF8, 0x200, 0x30, "true confessions"); RPVector *items = r_meta_get_all_intersect (anal, 0x100, 1, R_META_TYPE_ANY); - mu_assert_eq (r_pvector_len (items), 2, "all count"); + mu_assert_eq (r_pvector_length (items), 2, "all count"); void **it; bool found[2] = {0}; r_pvector_foreach (items, it) { @@ -341,35 +341,35 @@ bool test_meta_get_all_intersect() { r_pvector_free (items); items = r_meta_get_all_intersect (anal, 0x100, 1, R_META_TYPE_DATA); - mu_assert_eq (r_pvector_len (items), 1, "all count"); + mu_assert_eq (r_pvector_length (items), 1, "all count"); RAnalMetaItem *item = ((RIntervalNode *)r_pvector_at (items, 0))->data; mu_assert_eq (item->type, R_META_TYPE_DATA, "contents"); r_pvector_free (items); items = r_meta_get_all_intersect (anal, 0x100, 0x300, R_META_TYPE_DATA); - mu_assert_eq (r_pvector_len (items), 1, "all count"); + mu_assert_eq (r_pvector_length (items), 1, "all count"); item = ((RIntervalNode *)r_pvector_at (items, 0))->data; mu_assert_eq (item->type, R_META_TYPE_DATA, "contents"); r_pvector_free (items); items = r_meta_get_all_intersect (anal, 0x0, 0x300, R_META_TYPE_DATA); - mu_assert_eq (r_pvector_len (items), 1, "all count"); + mu_assert_eq (r_pvector_length (items), 1, "all count"); item = ((RIntervalNode *)r_pvector_at (items, 0))->data; mu_assert_eq (item->type, R_META_TYPE_DATA, "contents"); r_pvector_free (items); items = r_meta_get_all_intersect (anal, 0x0, 0x100, R_META_TYPE_DATA); - mu_assert_eq (r_pvector_len (items), 0, "all count"); + mu_assert_eq (r_pvector_length (items), 0, "all count"); r_pvector_free (items); items = r_meta_get_all_intersect (anal, 0x103, 0x300, R_META_TYPE_DATA); - mu_assert_eq (r_pvector_len (items), 1, "all count"); + mu_assert_eq (r_pvector_length (items), 1, "all count"); item = ((RIntervalNode *)r_pvector_at (items, 0))->data; mu_assert_eq (item->type, R_META_TYPE_DATA, "contents"); r_pvector_free (items); items = r_meta_get_all_intersect (anal, 0x104, 0x300, R_META_TYPE_DATA); - mu_assert_eq (r_pvector_len (items), 0, "all count"); + mu_assert_eq (r_pvector_length (items), 0, "all count"); r_pvector_free (items); r_anal_free (anal); @@ -551,17 +551,17 @@ bool test_meta_spaces() { mu_assert_null (node, "masked by space"); RPVector *nodes = r_meta_get_all_at (anal, 0x100); - mu_assert_eq (r_pvector_len (nodes), 1, "all count"); + mu_assert_eq (r_pvector_length (nodes), 1, "all count"); mu_assert_ptreq (((RIntervalNode *)r_pvector_at (nodes, 0))->data, reaper_item, "all masked"); r_pvector_free (nodes); nodes = r_meta_get_all_in (anal, 0x100, R_META_TYPE_ANY); - mu_assert_eq (r_pvector_len (nodes), 1, "all count"); + mu_assert_eq (r_pvector_length (nodes), 1, "all count"); mu_assert_ptreq (((RIntervalNode *)r_pvector_at (nodes, 0))->data, reaper_item, "all masked"); r_pvector_free (nodes); nodes = r_meta_get_all_intersect (anal, 0x0, 0x500, R_META_TYPE_ANY); - mu_assert_eq (r_pvector_len (nodes), 1, "all count"); + mu_assert_eq (r_pvector_length (nodes), 1, "all count"); mu_assert_ptreq (((RIntervalNode *)r_pvector_at (nodes, 0))->data, reaper_item, "all masked"); r_pvector_free (nodes); diff --git a/test/unit/test_anal_var.c b/test/unit/test_anal_var.c index 04fda50c5e..e15ea53f83 100644 --- a/test/unit/test_anal_var.c +++ b/test/unit/test_anal_var.c @@ -104,16 +104,16 @@ bool test_r_anal_var() { mu_assert_eq (stackptr, ST64_MAX, "unset stackptr"); RPVector *used_vars = r_anal_function_get_vars_used_at (fcn, 0x123); - mu_assert ("no used vars", !used_vars || r_pvector_len (used_vars)); + mu_assert ("no used vars", !used_vars || r_pvector_length (used_vars)); used_vars = r_anal_function_get_vars_used_at (fcn, 0x130); - mu_assert_eq (r_pvector_len (used_vars), 1, "used vars count"); + mu_assert_eq (r_pvector_length (used_vars), 1, "used vars count"); mu_assert ("used vars", r_pvector_contains (used_vars, a)); stackptr = r_anal_function_get_var_stackptr_at (fcn, -8, 0x130); mu_assert_eq (stackptr, 13, "stackptr"); stackptr = r_anal_function_get_var_stackptr_at (fcn, 123123, 0x130); mu_assert_eq (stackptr, ST64_MAX, "stackptr"); used_vars = r_anal_function_get_vars_used_at (fcn, 0x120); - mu_assert_eq (r_pvector_len (used_vars), 2, "used vars count"); + mu_assert_eq (r_pvector_length (used_vars), 2, "used vars count"); mu_assert ("used vars", r_pvector_contains (used_vars, a)); mu_assert ("used vars", r_pvector_contains (used_vars, b)); stackptr = r_anal_function_get_var_stackptr_at (fcn, -0x10, 0x120); @@ -121,7 +121,7 @@ bool test_r_anal_var() { stackptr = r_anal_function_get_var_stackptr_at (fcn, -8, 0x120); mu_assert_eq (stackptr, 42, "stackptr"); used_vars = r_anal_function_get_vars_used_at (fcn, 0x10); - mu_assert_eq (r_pvector_len (used_vars), 1, "used vars count"); + mu_assert_eq (r_pvector_length (used_vars), 1, "used vars count"); mu_assert ("used vars", r_pvector_contains (used_vars, b)); stackptr = r_anal_function_get_var_stackptr_at (fcn, -0x10, 0x10); mu_assert_eq (stackptr, -100, "stackptr"); @@ -134,24 +134,24 @@ bool test_r_anal_var() { assert_sane (anal); used_vars = r_anal_function_get_vars_used_at (fcn, 0xffffffffffff0130UL); // addresses should stay the same - mu_assert ("no used vars", !used_vars || r_pvector_len (used_vars)); + mu_assert ("no used vars", !used_vars || r_pvector_length (used_vars)); r_anal_var_set_access (a, "rbp", 0xffffffffffff0130UL, R_ANAL_VAR_ACCESS_TYPE_READ, 42); used_vars = r_anal_function_get_vars_used_at (fcn, 0xffffffffffff0130UL); - mu_assert_eq (r_pvector_len (used_vars), 1, "used vars count"); + mu_assert_eq (r_pvector_length (used_vars), 1, "used vars count"); mu_assert ("used vars", r_pvector_contains (used_vars, a)); used_vars = r_anal_function_get_vars_used_at (fcn, 0x123); - mu_assert ("no used vars", !used_vars || r_pvector_len (used_vars)); + mu_assert ("no used vars", !used_vars || r_pvector_length (used_vars)); r_anal_var_set_access (a, "rbp" , 0x123, R_ANAL_VAR_ACCESS_TYPE_READ, 42); used_vars = r_anal_function_get_vars_used_at (fcn, 0x123); - mu_assert_eq (r_pvector_len (used_vars), 1, "used vars count"); + mu_assert_eq (r_pvector_length (used_vars), 1, "used vars count"); mu_assert ("used vars", r_pvector_contains (used_vars, a)); used_vars = r_anal_function_get_vars_used_at (fcn, 0xffffffffffff0130); - mu_assert_eq (r_pvector_len (used_vars), 1, "used vars count"); + mu_assert_eq (r_pvector_length (used_vars), 1, "used vars count"); mu_assert ("used vars", r_pvector_contains (used_vars, a)); used_vars = r_anal_function_get_vars_used_at (fcn, 0xffffffffffff0120); - mu_assert_eq (r_pvector_len (used_vars), 2, "used vars count"); + mu_assert_eq (r_pvector_length (used_vars), 2, "used vars count"); mu_assert ("used vars", r_pvector_contains (used_vars, a)); mu_assert ("used vars", r_pvector_contains (used_vars, b)); stackptr = r_anal_function_get_var_stackptr_at (fcn, -0x10, 0xffffffffffff0120); @@ -159,41 +159,41 @@ bool test_r_anal_var() { stackptr = r_anal_function_get_var_stackptr_at (fcn, -8, 0xffffffffffff0120); mu_assert_eq (stackptr, 42, "stackptr"); used_vars = r_anal_function_get_vars_used_at (fcn, 0xffffffffffff0010); - mu_assert_eq (r_pvector_len (used_vars), 1, "used vars count"); + mu_assert_eq (r_pvector_length (used_vars), 1, "used vars count"); mu_assert ("used vars", r_pvector_contains (used_vars, b)); r_anal_function_relocate (fcn, 0x8000000000000010); assert_sane (anal); used_vars = r_anal_function_get_vars_used_at (fcn, 0x8000000000000100); - mu_assert ("no used vars", !used_vars || r_pvector_len (used_vars)); + mu_assert ("no used vars", !used_vars || r_pvector_length (used_vars)); r_anal_var_set_access (a, "rbp", 0x8000000000000100, R_ANAL_VAR_ACCESS_TYPE_READ, 987321); used_vars = r_anal_function_get_vars_used_at (fcn, 0x8000000000000100); - mu_assert_eq (r_pvector_len (used_vars), 1, "used vars count"); + mu_assert_eq (r_pvector_length (used_vars), 1, "used vars count"); mu_assert ("used vars", r_pvector_contains (used_vars, a)); stackptr = r_anal_function_get_var_stackptr_at (fcn, -8, 0x8000000000000100); mu_assert_eq (stackptr, 987321, "stackptr"); used_vars = r_anal_function_get_vars_used_at (fcn, 0x7ffffffffffffe00); - mu_assert ("no used vars", !used_vars || r_pvector_len (used_vars)); + mu_assert ("no used vars", !used_vars || r_pvector_length (used_vars)); r_anal_var_set_access (a, "rbp", 0x7ffffffffffffe00, R_ANAL_VAR_ACCESS_TYPE_READ, 777); used_vars = r_anal_function_get_vars_used_at (fcn, 0x7ffffffffffffe00); - mu_assert_eq (r_pvector_len (used_vars), 1, "used vars count"); + mu_assert_eq (r_pvector_length (used_vars), 1, "used vars count"); mu_assert ("used vars", r_pvector_contains (used_vars, a)); stackptr = r_anal_function_get_var_stackptr_at (fcn, -8, 0x7ffffffffffffe00); mu_assert_eq (stackptr, 777, "stackptr"); used_vars = r_anal_function_get_vars_used_at (fcn, 0x8000000000000040UL); - mu_assert_eq (r_pvector_len (used_vars), 1, "used vars count"); + mu_assert_eq (r_pvector_length (used_vars), 1, "used vars count"); mu_assert ("used vars", r_pvector_contains (used_vars, a)); used_vars = r_anal_function_get_vars_used_at (fcn, 0x8000000000010033); - mu_assert_eq (r_pvector_len (used_vars), 1, "used vars count"); + mu_assert_eq (r_pvector_length (used_vars), 1, "used vars count"); mu_assert ("used vars", r_pvector_contains (used_vars, a)); used_vars = r_anal_function_get_vars_used_at (fcn, 0x8000000000000040); - mu_assert_eq (r_pvector_len (used_vars), 1, "used vars count"); + mu_assert_eq (r_pvector_length (used_vars), 1, "used vars count"); mu_assert ("used vars", r_pvector_contains (used_vars, a)); used_vars = r_anal_function_get_vars_used_at (fcn, 0x8000000000000030); - mu_assert_eq (r_pvector_len (used_vars), 2, "used vars count"); + mu_assert_eq (r_pvector_length (used_vars), 2, "used vars count"); mu_assert ("used vars", r_pvector_contains (used_vars, a)); mu_assert ("used vars", r_pvector_contains (used_vars, b)); stackptr = r_anal_function_get_var_stackptr_at (fcn, -0x10, 0x8000000000000030); @@ -207,13 +207,13 @@ bool test_r_anal_var() { assert_sane (anal); used_vars = r_anal_function_get_vars_used_at (fcn, 0xffffffffffff0130UL); - mu_assert ("used vars count", !used_vars || !r_pvector_len (used_vars)); + mu_assert ("used vars count", !used_vars || !r_pvector_length (used_vars)); used_vars = r_anal_function_get_vars_used_at (fcn, 0x123); - mu_assert ("used vars count", !used_vars || !r_pvector_len (used_vars)); + mu_assert ("used vars count", !used_vars || !r_pvector_length (used_vars)); used_vars = r_anal_function_get_vars_used_at (fcn, 0x130); - mu_assert ("used vars count", !used_vars || !r_pvector_len (used_vars)); + mu_assert ("used vars count", !used_vars || !r_pvector_length (used_vars)); used_vars = r_anal_function_get_vars_used_at (fcn, 0x8000000000000030); - mu_assert_eq (r_pvector_len (used_vars), 1, "used vars count"); + mu_assert_eq (r_pvector_length (used_vars), 1, "used vars count"); mu_assert ("used vars", r_pvector_contains (used_vars, b)); // serialization / RAnalVarProt diff --git a/test/unit/test_intervaltree.c b/test/unit/test_intervaltree.c index 2b22725748..f455f2077c 100644 --- a/test/unit/test_intervaltree.c +++ b/test/unit/test_intervaltree.c @@ -235,7 +235,7 @@ bool test_r_interval_tree_delete() { } while (!r_pvector_empty (&contained_entries)) { - TestEntry *entry = r_pvector_remove_at (&contained_entries, rand () % r_pvector_len (&contained_entries)); + TestEntry *entry = r_pvector_remove_at (&contained_entries, rand () % r_pvector_length (&contained_entries)); RIntervalNode *node = r_interval_tree_node_at_data (&tree, entry->start, entry); mu_assert_notnull (node, "node not null"); diff --git a/test/unit/test_r2r.c b/test/unit/test_r2r.c index e8baebdb5f..6058090176 100644 --- a/test/unit/test_r2r.c +++ b/test/unit/test_r2r.c @@ -13,7 +13,7 @@ bool test_r2r_database_load_cmd(void) { R2RTestDatabase *db = r2r_test_database_new (); database_load (db, FILENAME, 1); - mu_assert_eq (r_pvector_len (&db->tests), 4, "tests count"); + mu_assert_eq (r_pvector_length (&db->tests), 4, "tests count"); R2RTest *test = r_pvector_at (&db->tests, 0); mu_assert_eq (test->type, R2R_TEST_TYPE_CMD, "test type"); diff --git a/test/unit/test_skyline.c b/test/unit/test_skyline.c deleted file mode 100644 index 89cb83ba42..0000000000 --- a/test/unit/test_skyline.c +++ /dev/null @@ -1,97 +0,0 @@ -#include -#include -#include "minunit.h" - -bool test_r_skyline(void) { - RSkyline sky; - r_skyline_init (&sky); - r_skyline_add (&sky, (RInterval){ 0, 1 }, (void *)1); - mu_assert_true (r_skyline_contains (&sky, 0), "Skyline should contain 0"); - mu_assert_false (r_skyline_contains (&sky, 1), "Skyline shouldn't contain 1"); - r_skyline_add (&sky, (RInterval){ 2, 4 }, (void *)2); - mu_assert_true (r_skyline_contains (&sky, 2), "Skyline should contain 2"); - mu_assert_eq ((size_t)r_skyline_get (&sky, 0), 1, "r_skyline_get should get first map"); - mu_assert_eq ((size_t)r_skyline_get (&sky, 2), 2, "r_skyline_get should get second map"); - mu_assert_eq ((size_t)r_skyline_get_intersect (&sky, 1, 2), 2, "r_skyline_get_intersect should get second map"); - r_skyline_add (&sky, (RInterval){ 0, 3 }, (void *)3); - mu_assert_true (r_skyline_contains (&sky, 0) && r_skyline_contains (&sky, 3), - "Skyline should still contain 0 to 3 after overlap"); - mu_assert_eq ((size_t)r_skyline_get (&sky, 0), 3, "r_skyline_get should get third map"); - r_skyline_fini (&sky); - mu_end; -} - -bool test_r_skyline_overlaps(void) { - RSkyline sky; - r_skyline_init (&sky); - - r_skyline_add (&sky, (RInterval){ 10, 10 }, (void *)1); - const RSkylineItem *item = r_skyline_get_item (&sky, 10); - mu_assert_eq ((size_t)item->user, 1, "r_skyline_get should get 1st map"); - - r_skyline_add (&sky, (RInterval){ 9, 2 }, (void *)2); - item = r_skyline_get_item (&sky, 10); - mu_assert_eq ((size_t)item->user, 2, "r_skyline_get should get 2nd map"); - - r_skyline_add (&sky, (RInterval){ 19, 2 }, (void *)3); - item = r_skyline_get_item (&sky, 19); - mu_assert_eq ((size_t)item->user, 3, "r_skyline_get should get 3rd map"); - - r_skyline_add (&sky, (RInterval){ 14, 3 }, (void *)4); - item = r_skyline_get_item (&sky, 14); - mu_assert_eq ((size_t)item->user, 4, "r_skyline_get should get 4th map"); - - item = r_skyline_get_item (&sky, 12); - mu_assert_eq ((size_t)item->user, 1, "r_skyline_get should get 1st map head after it was overlapped"); - mu_assert_eq (r_itv_begin (item->itv), 11, "1st map head should start at 11"); - mu_assert_eq (r_itv_end (item->itv), 14, "1st map head should end at 14"); - - item = r_skyline_get_item (&sky, 17); - mu_assert_eq ((size_t)item->user, 1, "r_skyline_get should get 1st map tail after it was overlapped"); - mu_assert_eq (r_itv_begin (item->itv), 17, "1st map tail should start at 17"); - mu_assert_eq (r_itv_end (item->itv), 19, "1st map tail should end at 19"); - - r_skyline_add (&sky, (RInterval){ 0, 30 }, (void *)5); - mu_assert_eq (r_vector_len (&sky.v), 1, "5th map should cover entire skyline"); - item = r_skyline_get_item (&sky, 10); - mu_assert_eq ((size_t)item->user, 5, "r_skyline_get should get 5th map"); - mu_assert_eq (r_itv_size (item->itv), 30, "5th map should have size of 30"); - - r_skyline_add (&sky, (RInterval){ 0, 10 }, (void *)6); - r_skyline_add (&sky, (RInterval){ 10, 10 }, (void *)7); - r_skyline_add (&sky, (RInterval){ 20, 10 }, (void *)8); - r_skyline_add (&sky, (RInterval){ 30, 10 }, (void *)9); - mu_assert_eq (r_vector_len (&sky.v), 4, "maps 5 through 9 should be the only ones existing"); - - r_skyline_add (&sky, (RInterval){ 5, 30 }, (void *)10); - mu_assert_eq (r_vector_len (&sky.v), 3, "10th map should remove all maps it covered, leaving a head and a tail"); - - item = r_skyline_get_item (&sky, 35); - mu_assert_eq (r_itv_begin (item->itv), 35, "9th map should begin at 35 after 10th covered its beginning"); - - r_skyline_add (&sky, (RInterval){ 3, 5 }, (void *)11); - item = r_skyline_get_item (&sky, 0); - mu_assert_eq (r_itv_size (item->itv), 3, "6th map should have size of 3 after 11th covered its end"); - - item = r_skyline_get_item (&sky, 20); - mu_assert_eq (r_itv_begin (item->itv), 8, "10th map should begin at 8 after 11th covered its beginning"); - - r_skyline_add (&sky, (RInterval){ 3, 5 }, (void *)12); - item = r_skyline_get_item (&sky, 3); - bool cond = r_vector_len (&sky.v) == 4 && r_itv_begin (item->itv) == 3 - && r_itv_end (item->itv) == 8 && (size_t)item->user == 12; - mu_assert_true (cond, "12th map should completely cover 11th"); - - r_skyline_fini (&sky); - mu_end; -} - -static int all_tests(void) { - mu_run_test (test_r_skyline); - mu_run_test (test_r_skyline_overlaps); - return tests_passed != tests_run; -} - -int main(int argc, char **argv) { - return all_tests(); -}