test/testtimer.c
changeset 7639 9406b7dd2f2d
parent 7517 965d57022c01
child 8149 681eb46b8ac4
     1.1 --- a/test/testtimer.c	Mon Aug 12 22:00:21 2013 -0700
     1.2 +++ b/test/testtimer.c	Wed Aug 14 23:30:10 2013 -0700
     1.3 @@ -33,7 +33,7 @@
     1.4  static Uint32 SDLCALL
     1.5  callback(Uint32 interval, void *param)
     1.6  {
     1.7 -    printf("Timer %d : param = %d\n", interval, (int) (uintptr_t) param);
     1.8 +    SDL_Log("Timer %d : param = %d\n", interval, (int) (uintptr_t) param);
     1.9      return interval;
    1.10  }
    1.11  
    1.12 @@ -45,8 +45,11 @@
    1.13      Uint32 start32, now32;
    1.14      Uint64 start, now;
    1.15  
    1.16 +	/* Enable standard application logging */
    1.17 +    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
    1.18 +
    1.19      if (SDL_Init(SDL_INIT_TIMER) < 0) {
    1.20 -        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    1.21 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
    1.22          return (1);
    1.23      }
    1.24  
    1.25 @@ -61,7 +64,7 @@
    1.26      t1 = SDL_AddTimer(desired, ticktock, NULL);
    1.27  
    1.28      /* Wait 10 seconds */
    1.29 -    printf("Waiting 10 seconds\n");
    1.30 +    SDL_Log("Waiting 10 seconds\n");
    1.31      SDL_Delay(10 * 1000);
    1.32  
    1.33      /* Stop the timer */
    1.34 @@ -69,28 +72,27 @@
    1.35  
    1.36      /* Print the results */
    1.37      if (ticks) {
    1.38 -        fprintf(stderr,
    1.39 -                "Timer resolution: desired = %d ms, actual = %f ms\n",
    1.40 +        SDL_Log("Timer resolution: desired = %d ms, actual = %f ms\n",
    1.41                  desired, (double) (10 * 1000) / ticks);
    1.42      }
    1.43  
    1.44      /* Test multiple timers */
    1.45 -    printf("Testing multiple timers...\n");
    1.46 +    SDL_Log("Testing multiple timers...\n");
    1.47      t1 = SDL_AddTimer(100, callback, (void *) 1);
    1.48      if (!t1)
    1.49 -        fprintf(stderr, "Could not create timer 1: %s\n", SDL_GetError());
    1.50 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 1: %s\n", SDL_GetError());
    1.51      t2 = SDL_AddTimer(50, callback, (void *) 2);
    1.52      if (!t2)
    1.53 -        fprintf(stderr, "Could not create timer 2: %s\n", SDL_GetError());
    1.54 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 2: %s\n", SDL_GetError());
    1.55      t3 = SDL_AddTimer(233, callback, (void *) 3);
    1.56      if (!t3)
    1.57 -        fprintf(stderr, "Could not create timer 3: %s\n", SDL_GetError());
    1.58 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 3: %s\n", SDL_GetError());
    1.59  
    1.60      /* Wait 10 seconds */
    1.61 -    printf("Waiting 10 seconds\n");
    1.62 +    SDL_Log("Waiting 10 seconds\n");
    1.63      SDL_Delay(10 * 1000);
    1.64  
    1.65 -    printf("Removing timer 1 and waiting 5 more seconds\n");
    1.66 +    SDL_Log("Removing timer 1 and waiting 5 more seconds\n");
    1.67      SDL_RemoveTimer(t1);
    1.68  
    1.69      SDL_Delay(5 * 1000);
    1.70 @@ -103,15 +105,15 @@
    1.71          ticktock(0, NULL);
    1.72      }
    1.73      now = SDL_GetPerformanceCounter();
    1.74 -    printf("1 million iterations of ticktock took %f ms\n", (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
    1.75 +    SDL_Log("1 million iterations of ticktock took %f ms\n", (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
    1.76  
    1.77 -    printf("Performance counter frequency: %llu\n", (unsigned long long) SDL_GetPerformanceFrequency());
    1.78 +    SDL_Log("Performance counter frequency: %llu\n", (unsigned long long) SDL_GetPerformanceFrequency());
    1.79      start32 = SDL_GetTicks();
    1.80      start = SDL_GetPerformanceCounter();
    1.81      SDL_Delay(1000);
    1.82      now = SDL_GetPerformanceCounter();
    1.83      now32 = SDL_GetTicks();
    1.84 -    printf("Delay 1 second = %d ms in ticks, %f ms according to performance counter\n", (now32-start32), (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
    1.85 +    SDL_Log("Delay 1 second = %d ms in ticks, %f ms according to performance counter\n", (now32-start32), (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
    1.86  
    1.87      SDL_Quit();
    1.88      return (0);