コード例 #1
0
Ensure(load_save_matches, loads_matches_from_disk_properly)
{
  vector **primatches = allocate(N_PRI_HALOS, sizeof(vector*));
  vector **secmatches = allocate(N_SEC_HALOS, sizeof(vector*));

  load_matches(MATCHES_FILE_ADDR, primatches, secmatches);

  int i, j;
  match *dummy_match = allocate(1, sizeof(*dummy_match));
  for(i = 0; i < N_PRI_HALOS; i++)
    for(j = 0; j < i; j++){
      dummy_match = vector_get(primatches[i], j);
      assert_that(dummy_match->matchid, is_equal_to(MATCHID));
      assert_that_double(dummy_match->goodness, is_equal_to_double(GOODNESS));
    }

  for(i = 0; i < N_PRI_HALOS; i++)
    free(primatches[i]);

  for(i = 0; i < N_SEC_HALOS; i++)
    free(secmatches[i]);

  free(primatches);
  free(secmatches);
}
コード例 #2
0
ファイル: tabexp.c プロジェクト: shawakaze/cmus
char *tabexp_expand(const char *src, void (*load_matches)(const char *src), int direction)
{
	static int idx = -1;
	char *expanded;

	if (tabexp.tails == NULL) {
		load_matches(src);
		if (tabexp.tails == NULL) {
			BUG_ON(tabexp.head != NULL);
			return NULL;
		}
		BUG_ON(tabexp.head == NULL);
		idx = -1;
	}
	idx += direction;

	if (idx >= tabexp.count)
		idx = 0;
	else if (idx < 0)
		idx = tabexp.count - 1;

	expanded = xstrjoin(tabexp.head, tabexp.tails[idx]);
	if (tabexp.count == 1)
		tabexp_reset();
	return expanded;
}
コード例 #3
0
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;
}
コード例 #4
0
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;
}