bool mf_unit_add_test(t_unit *v_this, const char *context, const char *name, void (*test)(t_unit_test *)) { t_list_cell *cell; t_unit_test *t; cell = D_LIST(begin)(&v_this->v_context); while (cell != NULL) { if (uf_strcmp(context, ((t_unit_context*)cell->v_data)->v_name) == 0) break ; cell = cell->v_next; } if (cell == NULL) return (M_ERROR(false, "Could not find %s context", context)); t = uf_unit_alloc_test(name, test); if (t == NULL) return (false); if (D_LIST(push_back)(&((t_unit_context*)cell->v_data)->v_test, t) == false) { uf_free_s((void **)&t); return (false); } return (true); }
void D_UNIT_FUNCT(ret_val) { F_UNIT_ASSERT(uf_is_upper('A') == true); F_UNIT_ASSERT(uf_is_upper('a') == false); F_UNIT_ASSERT(uf_is_lower('A') == false); F_UNIT_ASSERT(uf_is_lower('a') == true); F_UNIT_ASSERT(uf_is_alpha('a') == true); F_UNIT_ASSERT(uf_is_alpha('9') == false); F_UNIT_ASSERT(uf_is_printable(0) == false); F_UNIT_ASSERT(uf_is_printable('a') == true); F_UNIT_ASSERT(uf_is_digit('a') == false); F_UNIT_ASSERT(uf_is_digit('9') == true); F_UNIT_ASSERT(uf_is_space(' ') == true); F_UNIT_ASSERT(uf_is_space('9') == false); F_UNIT_ASSERT(uf_str_len("") == 0); F_UNIT_ASSERT(uf_str_len("foo") == 3); F_UNIT_ASSERT(uf_strcmp("foo", "foo") == 0); F_UNIT_ASSERT(uf_strcmp("foo", "fDo") != 0); F_UNIT_ASSERT(uf_strncmp("foo", "foo", 2) == 0); F_UNIT_ASSERT(uf_strncmp("foo", "fDo", 2) != 0); }
void f_htable_delete(t_htable *v_this, const char *key) { t_list *list; t_list_cell *cell; list = F_ARRAY_AT(&v_this->v_array, D_HTABLE(generate_key)(v_this->v_prime, key), t_list *); cell = D_LIST(begin)(list); while (cell != NULL) { if (uf_strcmp(key, ((t_htable_cell*)cell->v_data)->v_key) == 0) { D_LIST(delete)(list, cell); break ; } cell = cell->v_next; }
void *f_htable_get(t_htable *v_this, const char *str) { t_list *list; void *ret; t_list_cell *cell; ret = NULL; list = D_ARRAY(at)(&v_this->v_array, D_HTABLE(generate_key)(v_this, str), t_list *); cell = D_LIST(begin)(list); while (cell != NULL && ret == NULL) { if (uf_strcmp(str, ((t_htable_cell*)cell->v_data)->v_key) == 0) ret = ((t_htable_cell*)cell->v_data)->v_data; cell = cell->v_next; } return (ret); }
static bool uf_getopt_check_option(t_getopt *v_this, const char *check) { size_t i; i = 0; while (v_this->v_option[i] != NULL) { if (uf_strcmp(v_this->v_option[i], check) == 0) { v_this->v_current_argv = v_this->v_option[i]; v_this->v_current_argc = v_this->v_current_argc + 1; if (v_this->v_current_argc < v_this->v_argc) v_this->v_next_argv = v_this->v_argv[v_this->v_current_argc]; else v_this->v_next_argv = NULL; return (true); } i = i + 1; } return (false); }
static bool uf_fmt_av(t_getopt *v_this, t_string *string, bool value, const char *add) { size_t i; i = 0; if (value == true) { while (v_this->v_posibility[i] != NULL) { if (uf_strcmp(v_this->v_posibility[i], add) == 0) { if (D_STRING(add_str)(string, add) == false || D_STRING(add_char)(string, ' ') == false) return (false); } i = i + 1; } } return (true); }
void *f_htable_erase(t_htable *v_this, const char *key) { t_list *list; void *ret; t_list_cell *cell; ret = NULL; list = F_ARRAY_AT(&v_this->v_array, D_HTABLE(generate_key)(v_this->v_prime, key), t_list *); cell = D_LIST(begin)(list); while (cell != NULL && ret == NULL) { if (uf_strcmp(key, ((t_htable_cell*)cell->v_data)->v_key) == 0) { D_LIST(erase)(list, cell, &ret); ret = ((t_htable_cell*)ret)->v_data; } cell = cell->v_next; } return (ret); }
bool f_getopt_check(const t_getopt *v_this, const char *option) { return (uf_strcmp(v_this->v_current_argv, option) == 0); }
void D_UNIT_FUNCT(string2) { F_UNIT_ASSERT(uf_strcmp("Hello", "42") == 0); }