void test_compress_histo (void) { histo_t *histo = new_histo(); test_assert_critical(histo != NULL); for (size_t i = 0 ; i < 4096 ; i += 2) { test_assert(histo_push(&histo, i) == 0); } tab_t *tab; tab = compress_histo(histo); test_assert_critical(tab != NULL); test_assert(tab->size == 2048); for (size_t i = 0 ; i < tab->size ; i++) { test_assert(tab->val[i] == 2*i); test_assert(tab->num[i] == 1); } free(tab); redirect_stderr(); set_alloc_failure_rate_to(1.0); tab = compress_histo(histo); reset_alloc(); unredirect_stderr(); test_assert(tab == NULL); test_assert(strcmp(caught_in_stderr(), "") != 0); free(histo); return; }
static void mkclrmap( /* make our color map */ int nc ) { register int i; if ((samplefac ? neu_init(xmax*ymax) : new_histo(xmax*ymax)) == -1) goto memerr; for (i = 0; i < ymax; i++) { getrow(i); if (samplefac) neu_colrs(scanln, xmax); else cnt_colrs(scanln, xmax); } if (samplefac) neu_clrtab(nc); else new_clrtab(nc); for (i = 0; i < nc; i++) { rmap[i] = clrtab[i][RED]; gmap[i] = clrtab[i][GRN]; bmap[i] = clrtab[i][BLU]; } if (dither && (pixscan = (uby8 *)malloc(xmax)) == NULL) goto memerr; return; memerr: fprintf(stderr, "%s: out of memory\n", progname); exit(1); }
void test_histo_push (void) { histo_t *histo; histo = new_histo(); test_assert_critical(histo != NULL); for (size_t i = 0 ; i < (1 << 16) ; i++) { test_assert(histo_push(&histo, i) == 0); } test_assert(histo->size == (1 << 16)); for (size_t i = 0 ; i < (1 << 16) ; i++) { test_assert(histo->num[i] == 1); } free(histo); histo = new_histo(); test_assert_critical(histo != NULL); for (size_t i = (1 << 16) ; i > 0 ; i--) { test_assert(histo_push(&histo, i-1) == 0); } test_assert(histo->size == 2*((1 << 16)-1)); for (size_t i = 0 ; i < (1 << 16) ; i++) { test_assert(histo->num[i] == 1); } free(histo); histo = new_histo(); test_assert_critical(histo != NULL); redirect_stderr(); set_alloc_failure_rate_to(1.0); test_assert(histo_push(&histo, HISTO_INIT_SIZE) == 1); reset_alloc(); unredirect_stderr(); test_assert(strcmp(caught_in_stderr(), "") != 0); free(histo); return; }
void test_new_histo (void) { histo_t *histo; histo = new_histo(); test_assert_critical(histo != NULL); for (size_t i = 0 ; i < HISTO_INIT_SIZE ; i++) { test_assert(histo->num[i] == 0); } free(histo); redirect_stderr(); set_alloc_failure_rate_to(1.0); histo = new_histo(); reset_alloc(); unredirect_stderr(); test_assert(histo == NULL); test_assert(strcmp(caught_in_stderr(), "") != 0); return; }