test/testtimer.c
changeset 1895 c121d94672cb
parent 1769 290b5baf2fca
child 5514 6bd701987ba9
     1.1 --- a/test/testtimer.c	Thu Jul 06 18:01:37 2006 +0000
     1.2 +++ b/test/testtimer.c	Mon Jul 10 21:04:37 2006 +0000
     1.3 @@ -12,76 +12,79 @@
     1.4  
     1.5  static int ticks = 0;
     1.6  
     1.7 -static Uint32 SDLCALL ticktock(Uint32 interval)
     1.8 +static Uint32 SDLCALL
     1.9 +ticktock(Uint32 interval)
    1.10  {
    1.11 -	++ticks;
    1.12 -	return(interval);
    1.13 +    ++ticks;
    1.14 +    return (interval);
    1.15  }
    1.16  
    1.17 -static Uint32 SDLCALL callback(Uint32 interval, void *param)
    1.18 +static Uint32 SDLCALL
    1.19 +callback(Uint32 interval, void *param)
    1.20  {
    1.21 -  printf("Timer %d : param = %d\n", interval, (int)(uintptr_t)param);
    1.22 -  return interval;
    1.23 +    printf("Timer %d : param = %d\n", interval, (int) (uintptr_t) param);
    1.24 +    return interval;
    1.25  }
    1.26  
    1.27 -int main(int argc, char *argv[])
    1.28 +int
    1.29 +main(int argc, char *argv[])
    1.30  {
    1.31 -	int desired;
    1.32 -	SDL_TimerID t1, t2, t3;
    1.33 +    int desired;
    1.34 +    SDL_TimerID t1, t2, t3;
    1.35  
    1.36 -	if ( SDL_Init(SDL_INIT_TIMER) < 0 ) {
    1.37 -		fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    1.38 -		return(1);
    1.39 -	}
    1.40 +    if (SDL_Init(SDL_INIT_TIMER) < 0) {
    1.41 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    1.42 +        return (1);
    1.43 +    }
    1.44  
    1.45 -	/* Start the timer */
    1.46 -	desired = 0;
    1.47 -	if ( argv[1] ) {
    1.48 -		desired = atoi(argv[1]);
    1.49 -	}
    1.50 -	if ( desired == 0 ) {
    1.51 -		desired = DEFAULT_RESOLUTION;
    1.52 -	}
    1.53 -	SDL_SetTimer(desired, ticktock);
    1.54 +    /* Start the timer */
    1.55 +    desired = 0;
    1.56 +    if (argv[1]) {
    1.57 +        desired = atoi(argv[1]);
    1.58 +    }
    1.59 +    if (desired == 0) {
    1.60 +        desired = DEFAULT_RESOLUTION;
    1.61 +    }
    1.62 +    SDL_SetTimer(desired, ticktock);
    1.63  
    1.64 -	/* Wait 10 seconds */
    1.65 -	printf("Waiting 10 seconds\n");
    1.66 -	SDL_Delay(10*1000);
    1.67 +    /* Wait 10 seconds */
    1.68 +    printf("Waiting 10 seconds\n");
    1.69 +    SDL_Delay(10 * 1000);
    1.70  
    1.71 -	/* Stop the timer */
    1.72 -	SDL_SetTimer(0, NULL);
    1.73 +    /* Stop the timer */
    1.74 +    SDL_SetTimer(0, NULL);
    1.75  
    1.76 -	/* Print the results */
    1.77 -	if ( ticks ) {
    1.78 -		fprintf(stderr,
    1.79 -		"Timer resolution: desired = %d ms, actual = %f ms\n",
    1.80 -					desired, (double)(10*1000)/ticks);
    1.81 -	}
    1.82 -	
    1.83 -	/* Test multiple timers */
    1.84 -	printf("Testing multiple timers...\n");
    1.85 -	t1 = SDL_AddTimer(100, callback, (void*)1);
    1.86 -	if(!t1)
    1.87 -	  fprintf(stderr,"Could not create timer 1: %s\n", SDL_GetError());
    1.88 -	t2 = SDL_AddTimer(50, callback, (void*)2);
    1.89 -	if(!t2)
    1.90 -	  fprintf(stderr,"Could not create timer 2: %s\n", SDL_GetError());
    1.91 -	t3 = SDL_AddTimer(233, callback, (void*)3);
    1.92 -	if(!t3)
    1.93 -	  fprintf(stderr,"Could not create timer 3: %s\n", SDL_GetError());
    1.94 -	
    1.95 -	/* Wait 10 seconds */
    1.96 -	printf("Waiting 10 seconds\n");
    1.97 -	SDL_Delay(10*1000);
    1.98 +    /* Print the results */
    1.99 +    if (ticks) {
   1.100 +        fprintf(stderr,
   1.101 +                "Timer resolution: desired = %d ms, actual = %f ms\n",
   1.102 +                desired, (double) (10 * 1000) / ticks);
   1.103 +    }
   1.104  
   1.105 -	printf("Removing timer 1 and waiting 5 more seconds\n");
   1.106 -	SDL_RemoveTimer(t1);
   1.107 +    /* Test multiple timers */
   1.108 +    printf("Testing multiple timers...\n");
   1.109 +    t1 = SDL_AddTimer(100, callback, (void *) 1);
   1.110 +    if (!t1)
   1.111 +        fprintf(stderr, "Could not create timer 1: %s\n", SDL_GetError());
   1.112 +    t2 = SDL_AddTimer(50, callback, (void *) 2);
   1.113 +    if (!t2)
   1.114 +        fprintf(stderr, "Could not create timer 2: %s\n", SDL_GetError());
   1.115 +    t3 = SDL_AddTimer(233, callback, (void *) 3);
   1.116 +    if (!t3)
   1.117 +        fprintf(stderr, "Could not create timer 3: %s\n", SDL_GetError());
   1.118  
   1.119 -	SDL_Delay(5*1000);
   1.120 +    /* Wait 10 seconds */
   1.121 +    printf("Waiting 10 seconds\n");
   1.122 +    SDL_Delay(10 * 1000);
   1.123  
   1.124 -	SDL_RemoveTimer(t2);
   1.125 -	SDL_RemoveTimer(t3);
   1.126 +    printf("Removing timer 1 and waiting 5 more seconds\n");
   1.127 +    SDL_RemoveTimer(t1);
   1.128  
   1.129 -	SDL_Quit();
   1.130 -	return(0);
   1.131 +    SDL_Delay(5 * 1000);
   1.132 +
   1.133 +    SDL_RemoveTimer(t2);
   1.134 +    SDL_RemoveTimer(t3);
   1.135 +
   1.136 +    SDL_Quit();
   1.137 +    return (0);
   1.138  }