mirror of
https://github.com/radareorg/radare2.git
synced 2025-03-04 04:17:25 +00:00
Add tests for r_id_storage (#17548)
This commit is contained in:
parent
f01711583a
commit
e54103eef9
@ -55,7 +55,8 @@ if get_option('enable_tests')
|
||||
'util',
|
||||
'vector',
|
||||
'big',
|
||||
'idpool'
|
||||
'idpool',
|
||||
'idstorage'
|
||||
]
|
||||
|
||||
foreach test : tests
|
||||
|
@ -61,6 +61,17 @@ static bool test_r_id_pool_id_end_of_pool(void) {
|
||||
mu_end;
|
||||
}
|
||||
|
||||
static bool test_r_id_pool_initial_pattern(void) {
|
||||
RIDPool *pool = r_id_pool_new (3, 42);
|
||||
ut32 grabbed[3];
|
||||
r_id_pool_grab_id (pool, &grabbed[0]);
|
||||
r_id_pool_grab_id (pool, &grabbed[1]);
|
||||
r_id_pool_grab_id (pool, &grabbed[2]);
|
||||
r_id_pool_free (pool);
|
||||
mu_assert (grabbed[0] < grabbed[1] && grabbed[1] < grabbed[2], "initial_pattern");
|
||||
mu_end;
|
||||
}
|
||||
|
||||
static int all_tests(void) {
|
||||
mu_run_test (test_r_id_pool_broken_parameters);
|
||||
mu_run_test (test_r_id_pool_start_id);
|
||||
@ -68,6 +79,7 @@ static int all_tests(void) {
|
||||
mu_run_test (test_r_id_pool_id_reuse1);
|
||||
mu_run_test (test_r_id_pool_id_unique);
|
||||
mu_run_test (test_r_id_pool_id_end_of_pool);
|
||||
mu_run_test (test_r_id_pool_initial_pattern);
|
||||
return tests_passed != tests_run;
|
||||
}
|
||||
|
||||
|
86
test/unit/test_idstorage.c
Normal file
86
test/unit/test_idstorage.c
Normal file
@ -0,0 +1,86 @@
|
||||
#include <r_util.h>
|
||||
#include "minunit.h"
|
||||
|
||||
bool test_r_id_storage_add0(void) {
|
||||
char const *str = "lol";
|
||||
RIDStorage *ids = r_id_storage_new (5, 23);
|
||||
ut32 id;
|
||||
bool success = r_id_storage_add (ids, str, &id);
|
||||
void *ptr = r_id_storage_get (ids, id);
|
||||
r_id_storage_free (ids);
|
||||
mu_assert (success && (ptr == str), "id_storage_add 0");
|
||||
mu_end;
|
||||
}
|
||||
|
||||
bool test_r_id_storage_add1(void) {
|
||||
char const *str = "lol";
|
||||
RIDStorage *ids = r_id_storage_new (0, 4);
|
||||
ut32 id;
|
||||
r_id_storage_add (ids, str, &id);
|
||||
r_id_storage_add (ids, str, &id);
|
||||
r_id_storage_add (ids, str, &id);
|
||||
r_id_storage_add (ids, str, &id);
|
||||
bool success = r_id_storage_add (ids, str, &id);
|
||||
r_id_storage_free (ids);
|
||||
mu_assert (!success, "id_storage_add 1");
|
||||
mu_end;
|
||||
}
|
||||
|
||||
bool test_r_id_storage_set(void) {
|
||||
char const *str = "lol";
|
||||
RIDStorage *ids = r_id_storage_new (5, 23);
|
||||
r_id_storage_set (ids, str, 1);
|
||||
void *ptr = r_id_storage_get (ids, 1);
|
||||
r_id_storage_free (ids);
|
||||
mu_assert_ptreq (ptr, str, "id_storage_set");
|
||||
mu_end;
|
||||
}
|
||||
|
||||
bool test_r_id_storage_delete(void) {
|
||||
RIDStorage *ids = r_id_storage_new (5, 23);
|
||||
ut32 id;
|
||||
r_id_storage_add (ids, "lol", &id);
|
||||
r_id_storage_delete (ids, id);
|
||||
void *ptr = r_id_storage_get (ids, id);
|
||||
r_id_storage_free (ids);
|
||||
mu_assert_ptreq (ptr, NULL, "id_storage_delete");
|
||||
mu_end;
|
||||
}
|
||||
|
||||
bool test_r_id_storage_take0(void) {
|
||||
char const *str = "lol";
|
||||
RIDStorage *ids = r_id_storage_new (5, 23);
|
||||
ut32 id;
|
||||
r_id_storage_add (ids, str, &id);
|
||||
void *ptr = r_id_storage_take (ids, id);
|
||||
r_id_storage_free (ids);
|
||||
mu_assert_ptreq (ptr, str, "id_storage_take 0");
|
||||
mu_end;
|
||||
}
|
||||
|
||||
bool test_r_id_storage_take1(void) {
|
||||
char const *str = "lol";
|
||||
RIDStorage *ids = r_id_storage_new (5, 23);
|
||||
ut32 id;
|
||||
r_id_storage_add (ids, str, &id);
|
||||
r_id_storage_take (ids, id);
|
||||
void *ptr = r_id_storage_get (ids, id);
|
||||
r_id_storage_free (ids);
|
||||
mu_assert_ptreq (ptr, NULL, "id_storage_take 1");
|
||||
mu_end;
|
||||
}
|
||||
|
||||
|
||||
int all_tests() {
|
||||
mu_run_test (test_r_id_storage_add0);
|
||||
mu_run_test (test_r_id_storage_add1);
|
||||
mu_run_test (test_r_id_storage_set);
|
||||
mu_run_test (test_r_id_storage_delete);
|
||||
mu_run_test (test_r_id_storage_take0);
|
||||
mu_run_test (test_r_id_storage_take1);
|
||||
return tests_passed != tests_run;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
return all_tests ();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user