Tests: Use the main callback code macros

This commit is contained in:
L zard authored and Sam Lantinga committed 2024-05-27 09:22:07 -07:00
1 parent 7d81e9d46c
commit 06aa02453a
7 files changed
+68 -64

No files matched your search

+17 -17
View File
@@ -37,7 +37,7 @@ int SDL_AppInit(void **appstate, int argc, char **argv)
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, 0);
if (!state) {
return 1;
return SDL_MAIN_CALLBACK_EXIT_SUCCESS;
}
/* Enable standard application logging */
@@ -57,7 +57,7 @@ int SDL_AppInit(void **appstate, int argc, char **argv)
if (consumed <= 0) {
static const char *options[] = { "[device_name]", NULL };
SDLTest_CommonLogUsage(state, argv[0], options);
return -1;
return SDL_MAIN_CALLBACK_EXIT_FAILURE;
}
i += consumed;
@@ -66,12 +66,12 @@ int SDL_AppInit(void **appstate, int argc, char **argv)
/* Load the SDL library */
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
return SDL_MAIN_CALLBACK_EXIT_SUCCESS;
}
if (SDL_CreateWindowAndRenderer("testaudiocapture", 320, 240, 0, &window, &renderer) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create SDL window and renderer: %s\n", SDL_GetError());
return 1;
return SDL_MAIN_CALLBACK_EXIT_SUCCESS;
}
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
@@ -104,17 +104,17 @@ int SDL_AppInit(void **appstate, int argc, char **argv)
device = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, NULL);
if (!device) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for playback: %s!\n", SDL_GetError());
return -1;
return SDL_MAIN_CALLBACK_EXIT_FAILURE;
}
SDL_PauseAudioDevice(device);
SDL_GetAudioDeviceFormat(device, &outspec, NULL);
stream_out = SDL_CreateAudioStream(&outspec, &outspec);
if (!stream_out) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create an audio stream for playback: %s!\n", SDL_GetError());
return -1;
return SDL_MAIN_CALLBACK_EXIT_FAILURE;
} else if (SDL_BindAudioStream(device, stream_out) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't bind an audio stream for playback: %s!\n", SDL_GetError());
return -1;
return SDL_MAIN_CALLBACK_EXIT_FAILURE;
}
SDL_Log("Opening capture device %s%s%s...\n",
@@ -125,33 +125,33 @@ int SDL_AppInit(void **appstate, int argc, char **argv)
device = SDL_OpenAudioDevice(want_device, NULL);
if (!device) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for capture: %s!\n", SDL_GetError());
return -1;
return SDL_MAIN_CALLBACK_EXIT_FAILURE;
}
SDL_PauseAudioDevice(device);
SDL_GetAudioDeviceFormat(device, &inspec, NULL);
stream_in = SDL_CreateAudioStream(&inspec, &inspec);
if (!stream_in) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create an audio stream for capture: %s!\n", SDL_GetError());
return -1;
return SDL_MAIN_CALLBACK_EXIT_FAILURE;
} else if (SDL_BindAudioStream(device, stream_in) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't bind an audio stream for capture: %s!\n", SDL_GetError());
return -1;
return SDL_MAIN_CALLBACK_EXIT_FAILURE;
}
SDL_SetAudioStreamFormat(stream_in, NULL, &outspec); /* make sure we output at the playback format. */
SDL_Log("Ready! Hold down mouse or finger to record!\n");
return 0;
return SDL_MAIN_CALLBACK_CONTINUE;
}
int SDL_AppEvent(void *appstate, const SDL_Event *event)
{
if (event->type == SDL_EVENT_QUIT) {
return 1; /* terminate as success. */
return SDL_MAIN_CALLBACK_EXIT_SUCCESS;
} else if (event->type == SDL_EVENT_KEY_DOWN) {
if (event->key.keysym.sym == SDLK_ESCAPE) {
return 1; /* terminate as success. */
return SDL_MAIN_CALLBACK_EXIT_SUCCESS;
}
} else if (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN) {
if (event->button.button == 1) {
@@ -166,7 +166,7 @@ int SDL_AppEvent(void *appstate, const SDL_Event *event)
SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream_out));
}
}
return 0; /* keep going. */
return SDL_MAIN_CALLBACK_CONTINUE;
}
int SDL_AppIterate(void *appstate)
@@ -185,14 +185,14 @@ int SDL_AppIterate(void *appstate)
const int br = SDL_GetAudioStreamData(stream_in, buf, sizeof(buf));
if (br < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to read from input audio stream: %s\n", SDL_GetError());
return -1; /* quit the app, report failure. */
return SDL_MAIN_CALLBACK_EXIT_FAILURE;
} else if (SDL_PutAudioStreamData(stream_out, buf, br) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to write to output audio stream: %s\n", SDL_GetError());
return -1; /* quit the app, report failure. */
return SDL_MAIN_CALLBACK_EXIT_FAILURE;
}
}
return 0; /* keep app going. */
return SDL_MAIN_CALLBACK_CONTINUE;
}
void SDL_AppQuit(void *appstate)