void Mime_initModule() { HashMap_init(&module.s2t_map); HashMap_init(&module.t2s_map); Mime p; for(uint32_t i = 0; i < MIME_NUM; ++i) { p = mime_arr + i; HashMap_put(&module.s2t_map, p->suffix, (void*)p->type); HashMap_put(&module.t2s_map, p->type, (void*)p->suffix); } }
void HasMap_test() { HashMap* m = HashMap_init(); bstring b1 = bfromcstr("1"); bstring b2 = bfromcstr("2"); bstring b3 = bfromcstr("3"); bstring b4 = bfromcstr("4"); bstring b5 = bfromcstr("5"); bstring b6 = bfromcstr("6"); bstring b7 = bfromcstr("7"); HashMap_put(m, b1, 1); HashMap_put(m, b2, 2); HashMap_put(m, b3, 3); HashMap_put(m, b4, 4); HashMap_put(m, b5, 5); HashMap_put(m, b6, 6); printf("=== HashMap exists ===\n"); printf("%d: %s\n", 1, HashMap_exists(m, b1) ? "true" : "false"); printf("%d: %s\n", 2, HashMap_exists(m, b2) ? "true" : "false"); printf("%d: %s\n", 3, HashMap_exists(m, b3) ? "true" : "false"); printf("%d: %s\n", 4, HashMap_exists(m, b4) ? "true" : "false"); printf("%d: %s\n", 5, HashMap_exists(m, b5) ? "true" : "false"); printf("%d: %s\n", 6, HashMap_exists(m, b6) ? "true" : "false"); printf("%d: %s\n", 7, HashMap_exists(m, b7) ? "true" : "false"); printf("\n=== Remove 6 ===\n"); int val = HashMap_remove(m, b6); printf("%d == %d\n", val, 6); printf("%d: %s\n", 6, HashMap_exists(m, b6) ? "true" : "false"); printf("\n=== Get 4 ===\n"); val = HashMap_get(m, b4); printf("%d == %d\n", val, 4); printf("%d: %s\n", 4, HashMap_exists(m, b4) ? "true" : "false"); HashMap_destroy(m); }
static int test_setup(void** state) { HashMap map = (HashMap)malloc(sizeof(HashMap_t)); HashMap_init(map); *state = map; return 0; }