static void handle_info_msg(struct msg_match_info *input_msg) { gint tatami; gint position; struct name_data *j; tatami = input_msg->tatami - 1; position = input_msg->position; if (tatami < 0 || tatami >= NUM_TATAMIS) return; if (position < 0 || position >= NUM_LINES) return; match_list[tatami][position].category = input_msg->category; match_list[tatami][position].number = input_msg->number; match_list[tatami][position].blue = input_msg->blue; match_list[tatami][position].white = input_msg->white; match_list[tatami][position].flags = input_msg->flags; match_list[tatami][position].rest_end = input_msg->rest_time + time(NULL); /*** g_print("match info %d:%d b=%d w=%d\n", match_list[tatami][position].category, match_list[tatami][position].number, match_list[tatami][position].blue, match_list[tatami][position].white); ***/ j = avl_get_data(match_list[tatami][position].category); if (j == NULL) { ask_for_data(match_list[tatami][position].category); } j = avl_get_data(match_list[tatami][position].blue); if (j == NULL) { ask_for_data(match_list[tatami][position].blue); } if (position > 0) { j = avl_get_data(match_list[tatami][position].white); if (j == NULL) { ask_for_data(match_list[tatami][position].white); } } write_matches(); //refresh_window(); if (show_tatami[tatami] == FALSE && number_of_conf_tatamis() == 0 && match_list[tatami][position].blue && match_list[tatami][position].white) show_tatami[tatami] = TRUE; }
Ensure(load_save_matches, saves_matches_to_disk_properly) { vector **primatches = allocate(N_PRI_HALOS, sizeof(vector*)); vector **secmatches = allocate(N_SEC_HALOS, sizeof(vector*)); int i, j; match dummy_match = {.matchid = MATCHID, .goodness = GOODNESS}; for(i = 0; i < N_PRI_HALOS; i++){ primatches[i] = new_vector(i, sizeof(match)); for(j = 0; j < i; j++) vector_push(primatches[i], &dummy_match); } for(i = 0; i < N_SEC_HALOS; i++){ secmatches[i] = new_vector(i, sizeof(match)); for(j = 0; j < i; j++) vector_push(secmatches[i], &dummy_match); } write_matches(MATCHES_FILE_ADDR, primatches, secmatches, N_PRI_HALOS, N_SEC_HALOS); vector **primatches_r = allocate(N_PRI_HALOS, sizeof(vector*)); vector **secmatches_r = allocate(N_SEC_HALOS, sizeof(vector*)); load_matches(MATCHES_FILE_ADDR, primatches_r, secmatches_r); match *thematch = allocate(1, sizeof(*thematch)); for(i = 0; i < N_PRI_HALOS; i++) for(j = 0; j < i; j++){ thematch = vector_get(primatches_r[i], j); assert_that(thematch->matchid, is_equal_to(MATCHID)); } free(primatches); free(secmatches); free(primatches_r); free(secmatches_r); return; }
Ensure(load_save_matches, can_handle_null_in_pri_or_secmatches) { vector **primatches = allocate(N_PRI_HALOS, sizeof(vector*)); vector **secmatches = allocate(N_SEC_HALOS, sizeof(vector*)); int i, j; match dummy_match = {.matchid = MATCHID, .goodness = GOODNESS}; for(i = 0; i < N_PRI_HALOS; i++){ if(i % 2 == 0){ primatches[i] = NULL; continue; } else{ primatches[i] = new_vector(i, sizeof(match)); for(j = 0; j < i; j++) vector_push(primatches[i], &dummy_match); } } for(i = 0; i < N_SEC_HALOS; i++){ if(i % 2 == 0){ secmatches[i] = new_vector(i, sizeof(match)); for(j = 0; j < i; j++) vector_push(secmatches[i], &dummy_match); } else{ secmatches[i] = NULL; continue; } } write_matches(MATCHES_FILE_ADDR, primatches, secmatches, N_PRI_HALOS, N_SEC_HALOS); match *thematch = allocate(1, sizeof(*thematch)); vector **primatches_r = allocate(N_PRI_HALOS, sizeof(vector*)); vector **secmatches_r = allocate(N_SEC_HALOS, sizeof(vector*)); load_matches(MATCHES_FILE_ADDR, primatches_r, secmatches_r); for(i = 0; i < N_PRI_HALOS; i++) if(i % 2 == 0) assert_that(primatches_r[i]->logLength, is_equal_to(0)); else{ for(j = 0; j < i; j++){ thematch = vector_get(primatches_r[i], j); assert_that(thematch->matchid, is_equal_to(MATCHID)); } } for(i = 0; i < N_SEC_HALOS; i++) if(i % 2 == 0){ for(j = 0; j < i; j++){ thematch = vector_get(secmatches_r[i], j); assert_that(thematch->matchid, is_equal_to(MATCHID)); } } else assert_that(secmatches_r[i]->logLength, is_equal_to(0)); free(primatches); free(secmatches); free(primatches_r); free(secmatches_r); return; }