
Most SDL functions used to indicate success or failure using an int return code. These functions have been changed to return SDL_bool. Here is a coccinelle patch to change code that previously compared the return value to 0 and changes it to a boolean test: @ bool_return_type @ identifier func =~ "^(SDL_AddEventWatch|SDL_AddHintCallback|SDL_AddSurfaceAlternateImage|SDL_AddVulkanRenderSemaphores|SDL_BindAudioStream|SDL_BindAudioStreams|SDL_BlitSurface|SDL_BlitSurface9Grid|SDL_BlitSurfaceScaled|SDL_BlitSurfaceTiled|SDL_BlitSurfaceTiledWithScale|SDL_BlitSurfaceUnchecked|SDL_BlitSurfaceUncheckedScaled|SDL_CaptureMouse|SDL_ClearAudioStream|SDL_ClearClipboardData|SDL_ClearComposition|SDL_ClearError|SDL_ClearProperty|SDL_ClearSurface|SDL_CloseIO|SDL_CloseStorage|SDL_ConvertAudioSamples|SDL_ConvertEventToRenderCoordinates|SDL_ConvertPixels|SDL_ConvertPixelsAndColorspace|SDL_CopyFile|SDL_CopyProperties|SDL_CopyStorageFile|SDL_CreateDirectory|SDL_CreateStorageDirectory|SDL_CreateWindowAndRenderer|SDL_DateTimeToTime|SDL_DestroyWindowSurface|SDL_DetachVirtualJoystick|SDL_DisableScreenSaver|SDL_EnableScreenSaver|SDL_EnumerateDirectory|SDL_EnumerateProperties|SDL_EnumerateStorageDirectory|SDL_FillSurfaceRect|SDL_FillSurfaceRects|SDL_FlashWindow|SDL_FlipSurface|SDL_FlushAudioStream|SDL_FlushRenderer|SDL_GL_DestroyContext|SDL_GL_GetAttribute|SDL_GL_GetSwapInterval|SDL_GL_LoadLibrary|SDL_GL_MakeCurrent|SDL_GL_SetAttribute|SDL_GL_SetSwapInterval|SDL_GL_SwapWindow|SDL_GetAudioDeviceFormat|SDL_GetAudioStreamFormat|SDL_GetCameraFormat|SDL_GetClosestFullscreenDisplayMode|SDL_GetCurrentRenderOutputSize|SDL_GetCurrentTime|SDL_GetDXGIOutputInfo|SDL_GetDateTimeLocalePreferences|SDL_GetDisplayBounds|SDL_GetDisplayUsableBounds|SDL_GetGDKDefaultUser|SDL_GetGDKTaskQueue|SDL_GetGamepadSensorData|SDL_GetGamepadTouchpadFinger|SDL_GetHapticEffectStatus|SDL_GetJoystickBall|SDL_GetMasksForPixelFormat|SDL_GetPathInfo|SDL_GetRectUnion|SDL_GetRectUnionFloat|SDL_GetRenderClipRect|SDL_GetRenderColorScale|SDL_GetRenderDrawBlendMode|SDL_GetRenderDrawColor|SDL_GetRenderDrawColorFloat|SDL_GetRenderLogicalPresentation|SDL_GetRenderLogicalPresentationRect|SDL_GetRenderOutputSize|SDL_GetRenderSafeArea|SDL_GetRenderScale|SDL_GetRenderVSync|SDL_GetRenderViewport|SDL_GetSensorData|SDL_GetStorageFileSize|SDL_GetStoragePathInfo|SDL_GetSurfaceAlphaMod|SDL_GetSurfaceBlendMode|SDL_GetSurfaceClipRect|SDL_GetSurfaceColorKey|SDL_GetSurfaceColorMod|SDL_GetTextInputArea|SDL_GetTextureAlphaMod|SDL_GetTextureAlphaModFloat|SDL_GetTextureBlendMode|SDL_GetTextureColorMod|SDL_GetTextureColorModFloat|SDL_GetTextureScaleMode|SDL_GetTextureSize|SDL_GetWindowAspectRatio|SDL_GetWindowBordersSize|SDL_GetWindowMaximumSize|SDL_GetWindowMinimumSize|SDL_GetWindowPosition|SDL_GetWindowRelativeMouseMode|SDL_GetWindowSafeArea|SDL_GetWindowSize|SDL_GetWindowSizeInPixels|SDL_GetWindowSurfaceVSync|SDL_HideCursor|SDL_HideWindow|SDL_Init|SDL_InitHapticRumble|SDL_InitSubSystem|SDL_LoadWAV|SDL_LoadWAV_IO|SDL_LockAudioStream|SDL_LockProperties|SDL_LockSurface|SDL_LockTexture|SDL_LockTextureToSurface|SDL_MaximizeWindow|SDL_MinimizeWindow|SDL_MixAudio|SDL_OpenURL|SDL_OutOfMemory|SDL_PauseAudioDevice|SDL_PauseAudioStreamDevice|SDL_PauseHaptic|SDL_PlayHapticRumble|SDL_PremultiplyAlpha|SDL_PremultiplySurfaceAlpha|SDL_PushEvent|SDL_PutAudioStreamData|SDL_RaiseWindow|SDL_ReadStorageFile|SDL_ReadSurfacePixel|SDL_ReadSurfacePixelFloat|SDL_RegisterApp|SDL_ReloadGamepadMappings|SDL_RemovePath|SDL_RemoveStoragePath|SDL_RemoveTimer|SDL_RenamePath|SDL_RenameStoragePath|SDL_RenderClear|SDL_RenderCoordinatesFromWindow|SDL_RenderCoordinatesToWindow|SDL_RenderFillRect|SDL_RenderFillRects|SDL_RenderGeometry|SDL_RenderGeometryRaw|SDL_RenderLine|SDL_RenderLines|SDL_RenderPoint|SDL_RenderPoints|SDL_RenderPresent|SDL_RenderRect|SDL_RenderRects|SDL_RenderTexture|SDL_RenderTexture9Grid|SDL_RenderTextureRotated|SDL_RenderTextureTiled|SDL_RequestAndroidPermission|SDL_RestoreWindow|SDL_ResumeAudioDevice|SDL_ResumeAudioStreamDevice|SDL_ResumeHaptic|SDL_RumbleGamepad|SDL_RumbleGamepadTriggers|SDL_RumbleJoystick|SDL_RumbleJoystickTriggers|SDL_RunHapticEffect|SDL_SaveBMP|SDL_SaveBMP_IO|SDL_SendAndroidMessage|SDL_SendGamepadEffect|SDL_SendJoystickEffect|SDL_SendJoystickVirtualSensorData|SDL_SetAppMetadata|SDL_SetAppMetadataProperty|SDL_SetAudioDeviceGain|SDL_SetAudioPostmixCallback|SDL_SetAudioStreamFormat|SDL_SetAudioStreamFrequencyRatio|SDL_SetAudioStreamGain|SDL_SetAudioStreamGetCallback|SDL_SetAudioStreamInputChannelMap|SDL_SetAudioStreamOutputChannelMap|SDL_SetAudioStreamPutCallback|SDL_SetBooleanProperty|SDL_SetClipboardData|SDL_SetClipboardText|SDL_SetCursor|SDL_SetFloatProperty|SDL_SetGamepadLED|SDL_SetGamepadMapping|SDL_SetGamepadPlayerIndex|SDL_SetGamepadSensorEnabled|SDL_SetHapticAutocenter|SDL_SetHapticGain|SDL_SetJoystickLED|SDL_SetJoystickPlayerIndex|SDL_SetJoystickVirtualAxis|SDL_SetJoystickVirtualBall|SDL_SetJoystickVirtualButton|SDL_SetJoystickVirtualHat|SDL_SetJoystickVirtualTouchpad|SDL_SetLinuxThreadPriority|SDL_SetLinuxThreadPriorityAndPolicy|SDL_SetLogPriorityPrefix|SDL_SetMemoryFunctions|SDL_SetNumberProperty|SDL_SetPaletteColors|SDL_SetPointerProperty|SDL_SetPointerPropertyWithCleanup|SDL_SetPrimarySelectionText|SDL_SetRenderClipRect|SDL_SetRenderColorScale|SDL_SetRenderDrawBlendMode|SDL_SetRenderDrawColor|SDL_SetRenderDrawColorFloat|SDL_SetRenderLogicalPresentation|SDL_SetRenderScale|SDL_SetRenderTarget|SDL_SetRenderVSync|SDL_SetRenderViewport|SDL_SetScancodeName|SDL_SetStringProperty|SDL_SetSurfaceAlphaMod|SDL_SetSurfaceBlendMode|SDL_SetSurfaceColorKey|SDL_SetSurfaceColorMod|SDL_SetSurfaceColorspace|SDL_SetSurfacePalette|SDL_SetSurfaceRLE|SDL_SetTLS|SDL_SetTextInputArea|SDL_SetTextureAlphaMod|SDL_SetTextureAlphaModFloat|SDL_SetTextureBlendMode|SDL_SetTextureColorMod|SDL_SetTextureColorModFloat|SDL_SetTextureScaleMode|SDL_SetThreadPriority|SDL_SetWindowAlwaysOnTop|SDL_SetWindowAspectRatio|SDL_SetWindowBordered|SDL_SetWindowFocusable|SDL_SetWindowFullscreen|SDL_SetWindowFullscreenMode|SDL_SetWindowHitTest|SDL_SetWindowIcon|SDL_SetWindowKeyboardGrab|SDL_SetWindowMaximumSize|SDL_SetWindowMinimumSize|SDL_SetWindowModalFor|SDL_SetWindowMouseGrab|SDL_SetWindowMouseRect|SDL_SetWindowOpacity|SDL_SetWindowPosition|SDL_SetWindowRelativeMouseMode|SDL_SetWindowResizable|SDL_SetWindowShape|SDL_SetWindowSize|SDL_SetWindowSurfaceVSync|SDL_SetWindowTitle|SDL_SetiOSAnimationCallback|SDL_ShowAndroidToast|SDL_ShowCursor|SDL_ShowMessageBox|SDL_ShowSimpleMessageBox|SDL_ShowWindow|SDL_ShowWindowSystemMenu|SDL_StartTextInput|SDL_StartTextInputWithProperties|SDL_StopHapticEffect|SDL_StopHapticEffects|SDL_StopHapticRumble|SDL_StopTextInput|SDL_SyncWindow|SDL_TimeToDateTime|SDL_TryLockMutex|SDL_TryLockRWLockForReading|SDL_TryLockRWLockForWriting|SDL_TryWaitSemaphore|SDL_UnlockAudioStream|SDL_UpdateHapticEffect|SDL_UpdateNVTexture|SDL_UpdateTexture|SDL_UpdateWindowSurface|SDL_UpdateWindowSurfaceRects|SDL_UpdateYUVTexture|SDL_Vulkan_CreateSurface|SDL_Vulkan_LoadLibrary|SDL_WaitConditionTimeout|SDL_WaitSemaphoreTimeout|SDL_WarpMouseGlobal|SDL_WriteStorageFile|SDL_WriteSurfacePixel|SDL_WriteSurfacePixelFloat)$"; @@ ( func( ... ) - == 0 | - func( + !func( ... ) - < 0 | - func( + !func( ... ) - != 0 | - func( + !func( ... ) - == -1 )
589 lines
22 KiB
C
589 lines
22 KiB
C
/**
|
|
* New/updated tests: aschiffler at ferzkopp dot net
|
|
*/
|
|
#include <SDL3/SDL.h>
|
|
#include <SDL3/SDL_test.h>
|
|
#include "testautomation_suites.h"
|
|
|
|
/* ================= Test Case Implementation ================== */
|
|
|
|
static int clipboard_update_count;
|
|
|
|
static SDL_bool ClipboardEventWatch(void *userdata, SDL_Event *event)
|
|
{
|
|
if (event->type == SDL_EVENT_CLIPBOARD_UPDATE) {
|
|
++clipboard_update_count;
|
|
}
|
|
return SDL_TRUE;
|
|
}
|
|
|
|
enum
|
|
{
|
|
TEST_MIME_TYPE_TEXT,
|
|
TEST_MIME_TYPE_CUSTOM_TEXT,
|
|
TEST_MIME_TYPE_DATA,
|
|
NUM_TEST_MIME_TYPES
|
|
};
|
|
static const char *test_mime_types[] = {
|
|
"text/plain;charset=utf-8",
|
|
"test/text",
|
|
"test/data"
|
|
};
|
|
SDL_COMPILE_TIME_ASSERT(test_mime_types, SDL_arraysize(test_mime_types) == NUM_TEST_MIME_TYPES);
|
|
|
|
typedef struct
|
|
{
|
|
const void *data;
|
|
size_t data_size;
|
|
} TestClipboardData;
|
|
|
|
static int clipboard_callback_count;
|
|
|
|
static const void *ClipboardDataCallback(void *userdata, const char *mime_type, size_t *length)
|
|
{
|
|
TestClipboardData *test_data = (TestClipboardData *)userdata;
|
|
|
|
++clipboard_callback_count;
|
|
|
|
if (SDL_strcmp(mime_type, test_mime_types[TEST_MIME_TYPE_TEXT]) == 0) {
|
|
/* We're returning the string "TEST", with no termination */
|
|
static const char *test_text = "XXX TEST XXX";
|
|
*length = 4;
|
|
return test_text + 4;
|
|
}
|
|
if (SDL_strcmp(mime_type, test_mime_types[TEST_MIME_TYPE_CUSTOM_TEXT]) == 0) {
|
|
/* We're returning the string "CUSTOM", with no termination */
|
|
static const char *custom_text = "XXX CUSTOM XXX";
|
|
*length = 6;
|
|
return custom_text + 4;
|
|
}
|
|
if (SDL_strcmp(mime_type, test_mime_types[TEST_MIME_TYPE_DATA]) == 0) {
|
|
*length = test_data->data_size;
|
|
return test_data->data;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
static int clipboard_cleanup_count;
|
|
|
|
static void ClipboardCleanupCallback(void *userdata)
|
|
{
|
|
++clipboard_cleanup_count;
|
|
}
|
|
|
|
/* Test case functions */
|
|
|
|
/**
|
|
* End-to-end test of SDL_xyzClipboardData functions
|
|
* \sa SDL_HasClipboardData
|
|
* \sa SDL_GetClipboardData
|
|
* \sa SDL_SetClipboardData
|
|
*/
|
|
static int clipboard_testClipboardDataFunctions(void *arg)
|
|
{
|
|
int result = -1;
|
|
SDL_bool boolResult;
|
|
int last_clipboard_update_count;
|
|
int last_clipboard_callback_count;
|
|
int last_clipboard_cleanup_count;
|
|
void *data;
|
|
size_t size;
|
|
char *text;
|
|
const char *expected_text;
|
|
|
|
TestClipboardData test_data1 = {
|
|
&test_data1,
|
|
sizeof(test_data1)
|
|
};
|
|
TestClipboardData test_data2 = {
|
|
&last_clipboard_callback_count,
|
|
sizeof(last_clipboard_callback_count)
|
|
};
|
|
|
|
SDL_AddEventWatch(ClipboardEventWatch, NULL);
|
|
|
|
/* Test clearing clipboard data */
|
|
result = SDL_ClearClipboardData();
|
|
SDLTest_AssertCheck(
|
|
result == SDL_TRUE,
|
|
"Validate SDL_ClearClipboardData result, expected SDL_TRUE, got %i",
|
|
result);
|
|
|
|
/* Test clearing clipboard data when it's already clear */
|
|
last_clipboard_update_count = clipboard_update_count;
|
|
result = SDL_ClearClipboardData();
|
|
SDLTest_AssertCheck(
|
|
result == SDL_TRUE,
|
|
"Validate SDL_ClearClipboardData result, expected SDL_TRUE, got %i",
|
|
result);
|
|
SDLTest_AssertCheck(
|
|
clipboard_update_count == last_clipboard_update_count,
|
|
"Verify clipboard update unchanged, got %d",
|
|
clipboard_update_count - last_clipboard_update_count);
|
|
|
|
/* Validate error handling */
|
|
last_clipboard_update_count = clipboard_update_count;
|
|
result = SDL_SetClipboardData(NULL, NULL, NULL, test_mime_types, SDL_arraysize(test_mime_types));
|
|
SDLTest_AssertCheck(
|
|
result == SDL_FALSE,
|
|
"Validate SDL_SetClipboardData(invalid) result, expected SDL_FALSE, got %i",
|
|
result);
|
|
SDLTest_AssertCheck(
|
|
clipboard_update_count == last_clipboard_update_count,
|
|
"Verify clipboard update count unchanged, got %d",
|
|
clipboard_update_count - last_clipboard_update_count);
|
|
|
|
last_clipboard_update_count = clipboard_update_count;
|
|
result = SDL_SetClipboardData(ClipboardDataCallback, ClipboardCleanupCallback, NULL, NULL, 0);
|
|
SDLTest_AssertCheck(
|
|
result == SDL_FALSE,
|
|
"Validate SDL_SetClipboardData(invalid) result, expected SDL_FALSE, got %i",
|
|
result);
|
|
SDLTest_AssertCheck(
|
|
clipboard_update_count == last_clipboard_update_count,
|
|
"Verify clipboard update count unchanged, got %d",
|
|
clipboard_update_count - last_clipboard_update_count);
|
|
|
|
/* Test setting and getting clipboard data */
|
|
last_clipboard_update_count = clipboard_update_count;
|
|
last_clipboard_callback_count = clipboard_callback_count;
|
|
last_clipboard_cleanup_count = clipboard_cleanup_count;
|
|
result = SDL_SetClipboardData(ClipboardDataCallback, ClipboardCleanupCallback, &test_data1, test_mime_types, SDL_arraysize(test_mime_types));
|
|
SDLTest_AssertCheck(
|
|
result == SDL_TRUE,
|
|
"Validate SDL_SetClipboardData(test_data1) result, expected SDL_TRUE, got %i",
|
|
result);
|
|
SDLTest_AssertCheck(
|
|
clipboard_update_count == last_clipboard_update_count + 1,
|
|
"Verify clipboard update count incremented by 1, got %d",
|
|
clipboard_update_count - last_clipboard_update_count);
|
|
SDLTest_AssertCheck(
|
|
clipboard_cleanup_count == last_clipboard_cleanup_count,
|
|
"Verify clipboard cleanup count unchanged, got %d",
|
|
clipboard_cleanup_count - last_clipboard_cleanup_count);
|
|
|
|
expected_text = "TEST";
|
|
text = SDL_GetClipboardText();
|
|
SDLTest_AssertCheck(
|
|
text && SDL_strcmp(text, expected_text) == 0,
|
|
"Verify clipboard text, expected \"%s\", got \"%s\"",
|
|
expected_text, text);
|
|
SDL_free(text);
|
|
|
|
boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_TEXT]);
|
|
SDLTest_AssertCheck(
|
|
boolResult,
|
|
"Verify has test text data, expected SDL_TRUE, got SDL_FALSE");
|
|
text = SDL_GetClipboardData(test_mime_types[TEST_MIME_TYPE_TEXT], &size);
|
|
SDLTest_AssertCheck(
|
|
text != NULL,
|
|
"Verify has test text data, expected valid result, got NULL");
|
|
if (text) {
|
|
SDLTest_AssertCheck(
|
|
text[size] == '\0',
|
|
"Verify test text data, expected null termination, got %c",
|
|
text[size]);
|
|
SDLTest_AssertCheck(
|
|
SDL_strcmp(text, expected_text) == 0,
|
|
"Verify test text data, expected \"%s\", got \"%s\"",
|
|
expected_text, text);
|
|
}
|
|
SDLTest_AssertCheck(
|
|
size == SDL_strlen(expected_text),
|
|
"Verify test text size, expected %d, got %d",
|
|
(int)SDL_strlen(expected_text), (int)size);
|
|
SDL_free(text);
|
|
|
|
expected_text = "CUSTOM";
|
|
boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_CUSTOM_TEXT]);
|
|
SDLTest_AssertCheck(
|
|
boolResult,
|
|
"Verify has test text data, expected SDL_TRUE, got SDL_FALSE");
|
|
text = SDL_GetClipboardData(test_mime_types[TEST_MIME_TYPE_CUSTOM_TEXT], &size);
|
|
SDLTest_AssertCheck(
|
|
text != NULL,
|
|
"Verify has test text data, expected valid result, got NULL");
|
|
if (text) {
|
|
SDLTest_AssertCheck(
|
|
text[size] == '\0',
|
|
"Verify test text data, expected null termination, got %c",
|
|
text[size]);
|
|
SDLTest_AssertCheck(
|
|
SDL_strcmp(text, expected_text) == 0,
|
|
"Verify test text data, expected \"%s\", got \"%s\"",
|
|
expected_text, text);
|
|
}
|
|
SDLTest_AssertCheck(
|
|
size == SDL_strlen(expected_text),
|
|
"Verify test text size, expected %d, got %d",
|
|
(int)SDL_strlen(expected_text), (int)size);
|
|
SDL_free(text);
|
|
|
|
boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_DATA]);
|
|
SDLTest_AssertCheck(
|
|
boolResult,
|
|
"Verify has test text data, expected SDL_TRUE, got SDL_FALSE");
|
|
data = SDL_GetClipboardData(test_mime_types[TEST_MIME_TYPE_DATA], &size);
|
|
SDLTest_AssertCheck(
|
|
data && SDL_memcmp(data, test_data1.data, test_data1.data_size) == 0,
|
|
"Verify test data");
|
|
SDLTest_AssertCheck(
|
|
size == test_data1.data_size,
|
|
"Verify test data size, expected %d, got %d",
|
|
(int)test_data1.data_size, (int)size);
|
|
SDL_free(data);
|
|
|
|
boolResult = SDL_HasClipboardData("test/invalid");
|
|
SDLTest_AssertCheck(
|
|
!boolResult,
|
|
"Verify has test text data, expected SDL_FALSE, got SDL_TRUE");
|
|
data = SDL_GetClipboardData("test/invalid", &size);
|
|
SDLTest_AssertCheck(
|
|
data == NULL,
|
|
"Verify invalid data, expected NULL, got %p",
|
|
data);
|
|
SDLTest_AssertCheck(
|
|
size == 0,
|
|
"Verify invalid data size, expected 0, got %d",
|
|
(int)size);
|
|
SDL_free(data);
|
|
|
|
#if 0 /* There's no guarantee how or when the callback is called */
|
|
SDLTest_AssertCheck(
|
|
(clipboard_callback_count == last_clipboard_callback_count + 3) ||
|
|
(clipboard_callback_count == last_clipboard_callback_count + 4),
|
|
"Verify clipboard callback count incremented by 3 or 4, got %d",
|
|
clipboard_callback_count - last_clipboard_callback_count);
|
|
#endif
|
|
|
|
/* Test setting and getting clipboard data again */
|
|
last_clipboard_update_count = clipboard_update_count;
|
|
last_clipboard_callback_count = clipboard_callback_count;
|
|
last_clipboard_cleanup_count = clipboard_cleanup_count;
|
|
result = SDL_SetClipboardData(ClipboardDataCallback, ClipboardCleanupCallback, &test_data2, test_mime_types, SDL_arraysize(test_mime_types));
|
|
SDLTest_AssertCheck(
|
|
result == SDL_TRUE,
|
|
"Validate SDL_SetClipboardData(test_data2) result, expected SDL_TRUE, got %i",
|
|
result);
|
|
SDLTest_AssertCheck(
|
|
clipboard_update_count == last_clipboard_update_count + 1,
|
|
"Verify clipboard update count incremented by 1, got %d",
|
|
clipboard_update_count - last_clipboard_update_count);
|
|
SDLTest_AssertCheck(
|
|
clipboard_cleanup_count == last_clipboard_cleanup_count + 1,
|
|
"Verify clipboard cleanup count incremented by 1, got %d",
|
|
clipboard_cleanup_count - last_clipboard_cleanup_count);
|
|
|
|
expected_text = "TEST";
|
|
text = SDL_GetClipboardText();
|
|
SDLTest_AssertCheck(
|
|
text && SDL_strcmp(text, expected_text) == 0,
|
|
"Verify clipboard text, expected \"%s\", got \"%s\"",
|
|
expected_text, text);
|
|
SDL_free(text);
|
|
|
|
boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_TEXT]);
|
|
SDLTest_AssertCheck(
|
|
boolResult,
|
|
"Verify has test text data, expected SDL_TRUE, got SDL_FALSE");
|
|
text = SDL_GetClipboardData(test_mime_types[TEST_MIME_TYPE_TEXT], &size);
|
|
SDLTest_AssertCheck(
|
|
text != NULL,
|
|
"Verify has test text data, expected valid result, got NULL");
|
|
if (text) {
|
|
SDLTest_AssertCheck(
|
|
text[size] == '\0',
|
|
"Verify test text data, expected null termination, got %c",
|
|
text[size]);
|
|
SDLTest_AssertCheck(
|
|
SDL_strcmp(text, expected_text) == 0,
|
|
"Verify test text data, expected \"%s\", got \"%s\"",
|
|
expected_text, text);
|
|
}
|
|
SDLTest_AssertCheck(
|
|
size == SDL_strlen(expected_text),
|
|
"Verify test text size, expected %d, got %d",
|
|
(int)SDL_strlen(expected_text), (int)size);
|
|
SDL_free(text);
|
|
|
|
expected_text = "CUSTOM";
|
|
boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_CUSTOM_TEXT]);
|
|
SDLTest_AssertCheck(
|
|
boolResult,
|
|
"Verify has test text data, expected SDL_TRUE, got SDL_FALSE");
|
|
text = SDL_GetClipboardData(test_mime_types[TEST_MIME_TYPE_CUSTOM_TEXT], &size);
|
|
SDLTest_AssertCheck(
|
|
text != NULL,
|
|
"Verify has test text data, expected valid result, got NULL");
|
|
if (text) {
|
|
SDLTest_AssertCheck(
|
|
text[size] == '\0',
|
|
"Verify test text data, expected null termination, got %c",
|
|
text[size]);
|
|
SDLTest_AssertCheck(
|
|
SDL_strcmp(text, expected_text) == 0,
|
|
"Verify test text data, expected \"%s\", got \"%s\"",
|
|
expected_text, text);
|
|
}
|
|
SDLTest_AssertCheck(
|
|
size == SDL_strlen(expected_text),
|
|
"Verify test text size, expected %d, got %d",
|
|
(int)SDL_strlen(expected_text), (int)size);
|
|
SDL_free(text);
|
|
|
|
data = SDL_GetClipboardData(test_mime_types[TEST_MIME_TYPE_DATA], &size);
|
|
SDLTest_AssertCheck(
|
|
data && SDL_memcmp(data, test_data2.data, test_data2.data_size) == 0,
|
|
"Verify test data");
|
|
SDLTest_AssertCheck(
|
|
size == test_data2.data_size,
|
|
"Verify test data size, expected %d, got %d",
|
|
(int)test_data2.data_size, (int)size);
|
|
SDL_free(data);
|
|
|
|
data = SDL_GetClipboardData("test/invalid", &size);
|
|
SDLTest_AssertCheck(
|
|
data == NULL,
|
|
"Verify invalid data, expected NULL, got %p",
|
|
data);
|
|
SDLTest_AssertCheck(
|
|
size == 0,
|
|
"Verify invalid data size, expected 0, got %d",
|
|
(int)size);
|
|
SDL_free(data);
|
|
|
|
#if 0 /* There's no guarantee how or when the callback is called */
|
|
SDLTest_AssertCheck(
|
|
(clipboard_callback_count == last_clipboard_callback_count + 3) ||
|
|
(clipboard_callback_count == last_clipboard_callback_count + 4),
|
|
"Verify clipboard callback count incremented by 3 or 4, got %d",
|
|
clipboard_callback_count - last_clipboard_callback_count);
|
|
#endif
|
|
|
|
/* Test clearing clipboard data when has data */
|
|
last_clipboard_update_count = clipboard_update_count;
|
|
last_clipboard_cleanup_count = clipboard_cleanup_count;
|
|
result = SDL_ClearClipboardData();
|
|
SDLTest_AssertCheck(
|
|
result == SDL_TRUE,
|
|
"Validate SDL_ClearClipboardData result, expected SDL_TRUE, got %i",
|
|
result);
|
|
SDLTest_AssertCheck(
|
|
clipboard_update_count == last_clipboard_update_count + 1,
|
|
"Verify clipboard update count incremented by 1, got %d",
|
|
clipboard_update_count - last_clipboard_update_count);
|
|
SDLTest_AssertCheck(
|
|
clipboard_cleanup_count == last_clipboard_cleanup_count + 1,
|
|
"Verify clipboard cleanup count incremented by 1, got %d",
|
|
clipboard_cleanup_count - last_clipboard_cleanup_count);
|
|
boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_TEXT]);
|
|
SDLTest_AssertCheck(
|
|
!boolResult,
|
|
"Verify has test text data, expected SDL_FALSE, got SDL_TRUE");
|
|
boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_DATA]);
|
|
SDLTest_AssertCheck(
|
|
!boolResult,
|
|
"Verify has test text data, expected SDL_FALSE, got SDL_TRUE");
|
|
boolResult = SDL_HasClipboardData("test/invalid");
|
|
SDLTest_AssertCheck(
|
|
!boolResult,
|
|
"Verify has test text data, expected SDL_FALSE, got SDL_TRUE");
|
|
|
|
SDL_DelEventWatch(ClipboardEventWatch, NULL);
|
|
|
|
return TEST_COMPLETED;
|
|
}
|
|
|
|
/**
|
|
* End-to-end test of SDL_xyzClipboardText functions
|
|
* \sa SDL_HasClipboardText
|
|
* \sa SDL_GetClipboardText
|
|
* \sa SDL_SetClipboardText
|
|
*/
|
|
static int clipboard_testClipboardTextFunctions(void *arg)
|
|
{
|
|
char *textRef = SDLTest_RandomAsciiString();
|
|
char *text = SDL_strdup(textRef);
|
|
SDL_bool boolResult;
|
|
int intResult;
|
|
char *charResult;
|
|
int last_clipboard_update_count;
|
|
|
|
SDL_AddEventWatch(ClipboardEventWatch, NULL);
|
|
|
|
/* Empty clipboard text */
|
|
last_clipboard_update_count = clipboard_update_count;
|
|
intResult = SDL_SetClipboardText(NULL);
|
|
SDLTest_AssertCheck(
|
|
intResult == SDL_TRUE,
|
|
"Verify result from SDL_SetClipboardText(NULL), expected SDL_TRUE, got %i",
|
|
intResult);
|
|
charResult = SDL_GetClipboardText();
|
|
SDLTest_AssertCheck(
|
|
charResult && SDL_strcmp(charResult, "") == 0,
|
|
"Verify SDL_GetClipboardText returned \"\", got %s",
|
|
charResult);
|
|
SDL_free(charResult);
|
|
boolResult = SDL_HasClipboardText();
|
|
SDLTest_AssertCheck(
|
|
boolResult == SDL_FALSE,
|
|
"Verify SDL_HasClipboardText returned SDL_FALSE, got %s",
|
|
(boolResult) ? "SDL_TRUE" : "SDL_FALSE");
|
|
SDLTest_AssertCheck(
|
|
clipboard_update_count == last_clipboard_update_count,
|
|
"Verify clipboard update unchanged, got %d",
|
|
clipboard_update_count - last_clipboard_update_count);
|
|
|
|
|
|
/* Set clipboard text */
|
|
last_clipboard_update_count = clipboard_update_count;
|
|
intResult = SDL_SetClipboardText(text);
|
|
SDLTest_AssertCheck(
|
|
intResult == SDL_TRUE,
|
|
"Verify result from SDL_SetClipboardText(%s), expected SDL_TRUE, got %i", text,
|
|
intResult);
|
|
SDLTest_AssertCheck(
|
|
SDL_strcmp(textRef, text) == 0,
|
|
"Verify SDL_SetClipboardText did not modify input string, expected '%s', got '%s'",
|
|
textRef, text);
|
|
boolResult = SDL_HasClipboardText();
|
|
SDLTest_AssertCheck(
|
|
boolResult == SDL_TRUE,
|
|
"Verify SDL_HasClipboardText returned SDL_TRUE, got %s",
|
|
(boolResult) ? "SDL_TRUE" : "SDL_FALSE");
|
|
charResult = SDL_GetClipboardText();
|
|
SDLTest_AssertCheck(
|
|
charResult && SDL_strcmp(textRef, charResult) == 0,
|
|
"Verify SDL_GetClipboardText returned correct string, expected '%s', got '%s'",
|
|
textRef, charResult);
|
|
SDL_free(charResult);
|
|
SDLTest_AssertCheck(
|
|
clipboard_update_count == last_clipboard_update_count + 1,
|
|
"Verify clipboard update count incremented by 1, got %d",
|
|
clipboard_update_count - last_clipboard_update_count);
|
|
|
|
/* Reset clipboard text */
|
|
intResult = SDL_SetClipboardText(NULL);
|
|
SDLTest_AssertCheck(
|
|
intResult == SDL_TRUE,
|
|
"Verify result from SDL_SetClipboardText(NULL), expected SDL_TRUE, got %i",
|
|
intResult);
|
|
|
|
/* Cleanup */
|
|
SDL_free(textRef);
|
|
SDL_free(text);
|
|
|
|
SDL_DelEventWatch(ClipboardEventWatch, NULL);
|
|
|
|
return TEST_COMPLETED;
|
|
}
|
|
|
|
/**
|
|
* End-to-end test of SDL_xyzPrimarySelectionText functions
|
|
* \sa SDL_HasPrimarySelectionText
|
|
* \sa SDL_GetPrimarySelectionText
|
|
* \sa SDL_SetPrimarySelectionText
|
|
*/
|
|
static int clipboard_testPrimarySelectionTextFunctions(void *arg)
|
|
{
|
|
char *textRef = SDLTest_RandomAsciiString();
|
|
char *text = SDL_strdup(textRef);
|
|
SDL_bool boolResult;
|
|
int intResult;
|
|
char *charResult;
|
|
int last_clipboard_update_count;
|
|
|
|
SDL_AddEventWatch(ClipboardEventWatch, NULL);
|
|
|
|
/* Empty primary selection */
|
|
last_clipboard_update_count = clipboard_update_count;
|
|
intResult = SDL_SetPrimarySelectionText(NULL);
|
|
SDLTest_AssertCheck(
|
|
intResult == SDL_TRUE,
|
|
"Verify result from SDL_SetPrimarySelectionText(NULL), expected SDL_TRUE, got %i",
|
|
intResult);
|
|
charResult = SDL_GetPrimarySelectionText();
|
|
SDLTest_AssertCheck(
|
|
charResult && SDL_strcmp(charResult, "") == 0,
|
|
"Verify SDL_GetPrimarySelectionText returned \"\", got %s",
|
|
charResult);
|
|
SDL_free(charResult);
|
|
boolResult = SDL_HasPrimarySelectionText();
|
|
SDLTest_AssertCheck(
|
|
boolResult == SDL_FALSE,
|
|
"Verify SDL_HasPrimarySelectionText returned SDL_FALSE, got %s",
|
|
(boolResult) ? "SDL_TRUE" : "SDL_FALSE");
|
|
SDLTest_AssertCheck(
|
|
clipboard_update_count == last_clipboard_update_count + 1,
|
|
"Verify clipboard update count incremented by 1, got %d",
|
|
clipboard_update_count - last_clipboard_update_count);
|
|
|
|
/* Set primary selection */
|
|
last_clipboard_update_count = clipboard_update_count;
|
|
intResult = SDL_SetPrimarySelectionText(text);
|
|
SDLTest_AssertCheck(
|
|
intResult == SDL_TRUE,
|
|
"Verify result from SDL_SetPrimarySelectionText(%s), expected SDL_TRUE, got %i", text,
|
|
intResult);
|
|
SDLTest_AssertCheck(
|
|
SDL_strcmp(textRef, text) == 0,
|
|
"Verify SDL_SetPrimarySelectionText did not modify input string, expected '%s', got '%s'",
|
|
textRef, text);
|
|
boolResult = SDL_HasPrimarySelectionText();
|
|
SDLTest_AssertCheck(
|
|
boolResult == SDL_TRUE,
|
|
"Verify SDL_HasPrimarySelectionText returned SDL_TRUE, got %s",
|
|
(boolResult) ? "SDL_TRUE" : "SDL_FALSE");
|
|
charResult = SDL_GetPrimarySelectionText();
|
|
SDLTest_AssertCheck(
|
|
charResult && SDL_strcmp(textRef, charResult) == 0,
|
|
"Verify SDL_GetPrimarySelectionText returned correct string, expected '%s', got '%s'",
|
|
textRef, charResult);
|
|
SDL_free(charResult);
|
|
SDLTest_AssertCheck(
|
|
clipboard_update_count == last_clipboard_update_count + 1,
|
|
"Verify clipboard update count incremented by 1, got %d",
|
|
clipboard_update_count - last_clipboard_update_count);
|
|
|
|
/* Reset primary selection */
|
|
intResult = SDL_SetPrimarySelectionText(NULL);
|
|
SDLTest_AssertCheck(
|
|
intResult == SDL_TRUE,
|
|
"Verify result from SDL_SetPrimarySelectionText(NULL), expected SDL_TRUE, got %i",
|
|
intResult);
|
|
|
|
/* Cleanup */
|
|
SDL_free(textRef);
|
|
SDL_free(text);
|
|
|
|
SDL_DelEventWatch(ClipboardEventWatch, NULL);
|
|
|
|
return TEST_COMPLETED;
|
|
}
|
|
|
|
/* ================= Test References ================== */
|
|
|
|
static const SDLTest_TestCaseReference clipboardTest1 = {
|
|
(SDLTest_TestCaseFp)clipboard_testClipboardDataFunctions, "clipboard_testClipboardDataFunctions", "End-to-end test of SDL_xyzClipboardData functions", TEST_ENABLED
|
|
};
|
|
|
|
static const SDLTest_TestCaseReference clipboardTest2 = {
|
|
(SDLTest_TestCaseFp)clipboard_testClipboardTextFunctions, "clipboard_testClipboardTextFunctions", "End-to-end test of SDL_xyzClipboardText functions", TEST_ENABLED
|
|
};
|
|
|
|
static const SDLTest_TestCaseReference clipboardTest3 = {
|
|
(SDLTest_TestCaseFp)clipboard_testPrimarySelectionTextFunctions, "clipboard_testPrimarySelectionTextFunctions", "End-to-end test of SDL_xyzPrimarySelectionText functions", TEST_ENABLED
|
|
};
|
|
|
|
/* Sequence of Clipboard test cases */
|
|
static const SDLTest_TestCaseReference *clipboardTests[] = {
|
|
&clipboardTest1, &clipboardTest2, &clipboardTest3, NULL
|
|
};
|
|
|
|
/* Clipboard test suite (global) */
|
|
SDLTest_TestSuiteReference clipboardTestSuite = {
|
|
"Clipboard",
|
|
NULL,
|
|
clipboardTests,
|
|
NULL
|
|
};
|