1 #include "stdio.h"
2 #include "stdlib.h"
3 #include "sys/time.h"
4
5 #include "../src/meh.h"
6 #include "../src/scale.h"
7
8 #define TESTRUNS 20
9 #define STARTTEST(name) int test_##name(){ testname = #name; testsrun++; do
10 #define ENDTEST while(0); testspassed++; return 0;}
11 #define STARTTIME struct timeval tvs[2];int _i, _j; for(_i = 0; _i < 2; gettimeofday(&tvs[_i], NULL), _i++){for(_j = 0; _j < (_i ? TESTRUNS : 3); _j++)
12 #define ENDTIME }long int mselapsed = (tvs[1].tv_sec - tvs[0].tv_sec) * 1000000L + (tvs[1].tv_usec - tvs[0].tv_usec); printf("%s: average time: %li.%.3li ms\n", testname, mselapsed/1000/TESTRUNS, (mselapsed/TESTRUNS)%1000);
13 #define assert(x) if(!(x)){fprintf(stderr, "test \"%s\" failed\n assert(%s) was false\n at %s:%i\n\n", testname, #x, __FILE__ ,__LINE__);return -1;}
14
15 char *testname = NULL;
16 int testsrun = 0, testspassed = 0;
17
18 typedef int (*test_t)();
19
STARTTEST(scale)20 STARTTEST(scale){
21 struct image img;
22 img.bufwidth = 1280*2;
23 img.bufheight = 1024*2;
24 img.buf = malloc(img.bufwidth*img.bufheight*4);
25 char *to = malloc(1280*1024*4);
26 STARTTIME{
27 scale(&img, 1280, 1024, 1280, to);
28 }ENDTIME
29 free(to);
30 free(img.buf);
31 }ENDTEST
32
STARTTEST(nearestscale)33 STARTTEST(nearestscale){
34 struct image img;
35 img.bufwidth = 1280*2;
36 img.bufheight = 1024*2;
37 img.buf = malloc(img.bufwidth*img.bufheight*4);
38 char *to = malloc(1280*1024*4);
39 STARTTIME{
40 nearestscale(&img, 1280, 1024, 1280, to);
41 }ENDTIME
42 free(to);
43 free(img.buf);
44 }ENDTEST
45
46 test_t tests[] = {
47 test_scale,
48 test_nearestscale,
49 NULL
50 };
51
summary()52 void summary(){
53 printf("%i tests run: %i passed %i failed\n", testsrun, testspassed, testsrun - testspassed);
54 }
55
main()56 int main(){
57 test_t *test = tests;
58 for(; *test; test++)
59 (*test)();
60 summary();
61 return 0;
62 }
63
64