mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-22 23:35:39 +00:00
Added property types: pointer, string, number, float
This commit is contained in:
@@ -11,12 +11,28 @@
|
||||
/**
|
||||
* Test basic functionality
|
||||
*/
|
||||
static void SDLCALL count_properties(void *userdata, SDL_PropertiesID props, const char *name)
|
||||
{
|
||||
int *count = (int *)userdata;
|
||||
++(*count);
|
||||
}
|
||||
static void SDLCALL count_foo_properties(void *userdata, SDL_PropertiesID props, const char *name)
|
||||
{
|
||||
int *count = (int *)userdata;
|
||||
if (SDL_strcmp(name, "foo") == 0) {
|
||||
++(*count);
|
||||
}
|
||||
}
|
||||
static int properties_testBasic(void *arg)
|
||||
{
|
||||
SDL_PropertiesID props;
|
||||
char key[2], expected_value[2];
|
||||
SDL_PropertyType type;
|
||||
void *value;
|
||||
int i, result;
|
||||
const char *value_string;
|
||||
Sint64 value_number;
|
||||
float value_float;
|
||||
int i, result, count;
|
||||
|
||||
props = SDL_CreateProperties();
|
||||
SDLTest_AssertPass("Call to SDL_CreateProperties()");
|
||||
@@ -30,24 +46,130 @@ static int properties_testBasic(void *arg)
|
||||
SDLTest_AssertPass("Call to SDL_SetProperty()");
|
||||
SDLTest_AssertCheck(result == 0,
|
||||
"Verify property value was set, got: %d", result);
|
||||
value = SDL_GetProperty(props, key);
|
||||
value = SDL_GetProperty(props, key, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetProperty()");
|
||||
SDLTest_AssertCheck(value && SDL_strcmp((const char *)value, expected_value) == 0,
|
||||
"Verify property value was set, got %s, expected %s", value ? (const char *)value : "NULL", expected_value);
|
||||
}
|
||||
|
||||
count = 0;
|
||||
SDL_EnumerateProperties(props, count_properties, &count);
|
||||
SDLTest_AssertCheck(count == 10,
|
||||
"Verify property count, expected 10, got: %d", count);
|
||||
|
||||
for (i = 0; i < 10; ++i) {
|
||||
SDL_snprintf(key, SDL_arraysize(key), "%c", 'a' + i);
|
||||
result = SDL_SetProperty(props, key, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_SetProperty(NULL)");
|
||||
SDLTest_AssertCheck(result == 0,
|
||||
"Verify property value was set, got: %d", result);
|
||||
value = SDL_GetProperty(props, key);
|
||||
value = SDL_GetProperty(props, key, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetProperty()");
|
||||
SDLTest_AssertCheck(value == NULL,
|
||||
"Verify property value was set, got %s, expected NULL", (const char *)value);
|
||||
}
|
||||
|
||||
count = 0;
|
||||
SDL_EnumerateProperties(props, count_properties, &count);
|
||||
SDLTest_AssertCheck(count == 0,
|
||||
"Verify property count, expected 0, got: %d", count);
|
||||
|
||||
/* Check default values */
|
||||
value = SDL_GetProperty(props, "foo", (void *)0xabcd);
|
||||
SDLTest_AssertCheck(value == (void *)0xabcd,
|
||||
"Verify property, expected 0xabcd, got: %p", value);
|
||||
value_string = SDL_GetStringProperty(props, "foo", "abcd");
|
||||
SDLTest_AssertCheck(value_string && SDL_strcmp(value_string, "abcd") == 0,
|
||||
"Verify string property, expected \"abcd\", got: %s", value_string);
|
||||
value_number = SDL_GetNumberProperty(props, "foo", 1234);
|
||||
SDLTest_AssertCheck(value_number == 1234,
|
||||
"Verify number property, expected 1234, got: %" SDL_PRIu64 "", value_number);
|
||||
value_float = SDL_GetFloatProperty(props, "foo", 1234.0f);
|
||||
SDLTest_AssertCheck(value_float == 1234.0f,
|
||||
"Verify float property, expected 1234, got: %f", value_float);
|
||||
|
||||
/* Check data value */
|
||||
SDLTest_AssertPass("Call to SDL_SetProperty(\"foo\", 0x01)");
|
||||
SDL_SetProperty(props, "foo", (void *)0x01);
|
||||
type = SDL_GetPropertyType(props, "foo");
|
||||
SDLTest_AssertCheck(type == SDL_PROPERTY_TYPE_POINTER,
|
||||
"Verify property type, expected %d, got: %d", SDL_PROPERTY_TYPE_POINTER, type);
|
||||
value = SDL_GetProperty(props, "foo", NULL);
|
||||
SDLTest_AssertCheck(value == (void *)0x01,
|
||||
"Verify property, expected 0x01, got: %p", value);
|
||||
value_string = SDL_GetStringProperty(props, "foo", NULL);
|
||||
SDLTest_AssertCheck(value_string == NULL,
|
||||
"Verify string property, expected NULL, got: %s", value_string);
|
||||
value_number = SDL_GetNumberProperty(props, "foo", 0);
|
||||
SDLTest_AssertCheck(value_number == 0,
|
||||
"Verify number property, expected 0, got: %" SDL_PRIu64 "", value_number);
|
||||
value_float = SDL_GetFloatProperty(props, "foo", 0.0f);
|
||||
SDLTest_AssertCheck(value_float == 0.0f,
|
||||
"Verify float property, expected 0, got: %f", value_float);
|
||||
|
||||
/* Check string value */
|
||||
SDLTest_AssertPass("Call to SDL_SetStringProperty(\"foo\", \"bar\")");
|
||||
SDL_SetStringProperty(props, "foo", "bar");
|
||||
type = SDL_GetPropertyType(props, "foo");
|
||||
SDLTest_AssertCheck(type == SDL_PROPERTY_TYPE_STRING,
|
||||
"Verify property type, expected %d, got: %d", SDL_PROPERTY_TYPE_STRING, type);
|
||||
value = SDL_GetProperty(props, "foo", NULL);
|
||||
SDLTest_AssertCheck(value == NULL,
|
||||
"Verify property, expected NULL, got: %p", value);
|
||||
value_string = SDL_GetStringProperty(props, "foo", NULL);
|
||||
SDLTest_AssertCheck(value_string != NULL && SDL_strcmp(value_string, "bar") == 0,
|
||||
"Verify string property, expected \"bar\", got: %s", value_string);
|
||||
value_number = SDL_GetNumberProperty(props, "foo", 0);
|
||||
SDLTest_AssertCheck(value_number == 0,
|
||||
"Verify number property, expected 0, got: %" SDL_PRIu64 "", value_number);
|
||||
value_float = SDL_GetFloatProperty(props, "foo", 0.0f);
|
||||
SDLTest_AssertCheck(value_float == 0.0f,
|
||||
"Verify float property, expected 0, got: %f", value_float);
|
||||
|
||||
/* Check number value */
|
||||
SDLTest_AssertPass("Call to SDL_SetNumberProperty(\"foo\", 1)");
|
||||
SDL_SetNumberProperty(props, "foo", 1);
|
||||
type = SDL_GetPropertyType(props, "foo");
|
||||
SDLTest_AssertCheck(type == SDL_PROPERTY_TYPE_NUMBER,
|
||||
"Verify property type, expected %d, got: %d", SDL_PROPERTY_TYPE_NUMBER, type);
|
||||
value = SDL_GetProperty(props, "foo", NULL);
|
||||
SDLTest_AssertCheck(value == NULL,
|
||||
"Verify property, expected NULL, got: %p", value);
|
||||
value_string = SDL_GetStringProperty(props, "foo", NULL);
|
||||
SDLTest_AssertCheck(value_string == NULL,
|
||||
"Verify string property, expected NULL, got: %s", value_string);
|
||||
value_number = SDL_GetNumberProperty(props, "foo", 0);
|
||||
SDLTest_AssertCheck(value_number == 1,
|
||||
"Verify number property, expected 1, got: %" SDL_PRIu64 "", value_number);
|
||||
value_float = SDL_GetFloatProperty(props, "foo", 0.0f);
|
||||
SDLTest_AssertCheck(value_float == 0.0f,
|
||||
"Verify float property, expected 0, got: %f", value_float);
|
||||
|
||||
/* Check float value */
|
||||
SDLTest_AssertPass("Call to SDL_SetNumberProperty(\"foo\", 1)");
|
||||
SDL_SetFloatProperty(props, "foo", 1.0f);
|
||||
type = SDL_GetPropertyType(props, "foo");
|
||||
SDLTest_AssertCheck(type == SDL_PROPERTY_TYPE_FLOAT,
|
||||
"Verify property type, expected %d, got: %d", SDL_PROPERTY_TYPE_FLOAT, type);
|
||||
value = SDL_GetProperty(props, "foo", NULL);
|
||||
SDLTest_AssertCheck(value == NULL,
|
||||
"Verify property, expected NULL, got: %p", value);
|
||||
value_string = SDL_GetStringProperty(props, "foo", NULL);
|
||||
SDLTest_AssertCheck(value_string == NULL,
|
||||
"Verify string property, expected NULL, got: %s", value_string);
|
||||
value_number = SDL_GetNumberProperty(props, "foo", 0);
|
||||
SDLTest_AssertCheck(value_number == 0,
|
||||
"Verify number property, expected 0, got: %" SDL_PRIu64 "", value_number);
|
||||
value_float = SDL_GetFloatProperty(props, "foo", 0.0f);
|
||||
SDLTest_AssertCheck(value_float == 1.0f,
|
||||
"Verify string property, expected 1, got: %f", value_float);
|
||||
|
||||
/* Make sure we have exactly one property named foo */
|
||||
count = 0;
|
||||
SDL_EnumerateProperties(props, count_foo_properties, &count);
|
||||
SDLTest_AssertCheck(count == 1,
|
||||
"Verify foo property count, expected 1, got: %d", count);
|
||||
|
||||
SDL_DestroyProperties(props);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
@@ -130,7 +252,7 @@ static int properties_testLocking(void *arg)
|
||||
{
|
||||
SDL_Delay(10);
|
||||
SDL_LockProperties(data.props);
|
||||
value = SDL_GetProperty(data.props, "a");
|
||||
value = SDL_GetProperty(data.props, "a", NULL);
|
||||
SDL_UnlockProperties(data.props);
|
||||
|
||||
if (!value || SDL_strcmp((const char *)value, "thread_loop") == 0) {
|
||||
@@ -144,7 +266,7 @@ static int properties_testLocking(void *arg)
|
||||
SDL_LockProperties(data.props);
|
||||
SDL_SetProperty(data.props, "a", "main");
|
||||
SDL_Delay(100);
|
||||
value = SDL_GetProperty(data.props, "a");
|
||||
value = SDL_GetProperty(data.props, "a", NULL);
|
||||
SDLTest_AssertCheck(value && SDL_strcmp((const char *)value, "main") == 0,
|
||||
"After 100ms sleep, property is %s, expected 'main'", value ? (const char *)value : "NULL");
|
||||
SDL_UnlockProperties(data.props);
|
||||
@@ -152,7 +274,7 @@ static int properties_testLocking(void *arg)
|
||||
data.done = SDL_TRUE;
|
||||
SDL_WaitThread(thread, NULL);
|
||||
|
||||
value = SDL_GetProperty(data.props, "a");
|
||||
value = SDL_GetProperty(data.props, "a", NULL);
|
||||
SDLTest_AssertCheck(value && SDL_strcmp((const char *)value, "thread_done") == 0,
|
||||
"After thread complete, property is %s, expected 'thread_done'", value ? (const char *)value : "NULL");
|
||||
}
|
||||
|
||||
@@ -1492,7 +1492,7 @@ static int video_getSetWindowData(void *arg)
|
||||
}
|
||||
|
||||
/* Get non-existent data */
|
||||
result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), name);
|
||||
result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), name, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
|
||||
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
|
||||
SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
|
||||
@@ -1505,8 +1505,7 @@ static int video_getSetWindowData(void *arg)
|
||||
|
||||
/* Get data (twice) */
|
||||
for (iteration = 1; iteration <= 2; iteration++) {
|
||||
result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window),
|
||||
name);
|
||||
result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), name, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [iteration %d]", name, iteration);
|
||||
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
|
||||
SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
|
||||
@@ -1521,7 +1520,7 @@ static int video_getSetWindowData(void *arg)
|
||||
}
|
||||
|
||||
/* Get data again */
|
||||
result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), name);
|
||||
result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), name, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again]", name);
|
||||
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
|
||||
SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
|
||||
@@ -1541,7 +1540,7 @@ static int video_getSetWindowData(void *arg)
|
||||
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
|
||||
|
||||
/* Get new data */
|
||||
result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), name);
|
||||
result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), name, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
|
||||
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
|
||||
SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
|
||||
@@ -1561,13 +1560,13 @@ static int video_getSetWindowData(void *arg)
|
||||
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
|
||||
|
||||
/* Get non-existent data */
|
||||
result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), name);
|
||||
result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), name, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
|
||||
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
|
||||
SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
|
||||
|
||||
/* Get non-existent data new name */
|
||||
result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), name2);
|
||||
result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), name2, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name2);
|
||||
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
|
||||
SDLTest_AssertCheck(SDL_strcmp(referenceName2, name2) == 0, "Validate that name2 was not changed, expected: %s, got: %s", referenceName2, name2);
|
||||
@@ -1579,7 +1578,7 @@ static int video_getSetWindowData(void *arg)
|
||||
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
|
||||
|
||||
/* Get data (again) */
|
||||
result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), name);
|
||||
result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), name, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again, after clear]", name);
|
||||
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
|
||||
SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
|
||||
@@ -1605,13 +1604,13 @@ static int video_getSetWindowData(void *arg)
|
||||
checkInvalidParameterError();
|
||||
|
||||
/* Get data with NULL name */
|
||||
result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), NULL);
|
||||
result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), NULL, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowData(name=NULL)");
|
||||
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
|
||||
checkInvalidParameterError();
|
||||
|
||||
/* Get data with empty name */
|
||||
result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), "");
|
||||
result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), "", NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowData(name='')");
|
||||
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
|
||||
checkInvalidParameterError();
|
||||
|
||||
@@ -145,7 +145,7 @@ static SDL_bool CreateWindowAndRenderer(Uint32 window_flags, const char *driver)
|
||||
#endif
|
||||
|
||||
#ifdef __WIN32__
|
||||
d3d11_device = (ID3D11Device *)SDL_GetProperty(SDL_GetRendererProperties(renderer), "SDL.renderer.d3d11.device");
|
||||
d3d11_device = (ID3D11Device *)SDL_GetProperty(SDL_GetRendererProperties(renderer), "SDL.renderer.d3d11.device", NULL);
|
||||
if (d3d11_device) {
|
||||
ID3D11Device_AddRef(d3d11_device);
|
||||
ID3D11Device_GetImmediateContext(d3d11_device, &d3d11_context);
|
||||
@@ -457,7 +457,7 @@ static SDL_bool GetTextureForMemoryFrame(AVFrame *frame, SDL_Texture **texture)
|
||||
case SDL_PIXELFORMAT_UNKNOWN:
|
||||
{
|
||||
SDL_PropertiesID props = SDL_GetTextureProperties(*texture);
|
||||
struct SwsContextContainer *sws_container = (struct SwsContextContainer *)SDL_GetProperty(props, SWS_CONTEXT_CONTAINER_PROPERTY);
|
||||
struct SwsContextContainer *sws_container = (struct SwsContextContainer *)SDL_GetProperty(props, SWS_CONTEXT_CONTAINER_PROPERTY, NULL);
|
||||
if (!sws_container) {
|
||||
sws_container = (struct SwsContextContainer *)SDL_calloc(1, sizeof(*sws_container));
|
||||
if (!sws_container) {
|
||||
@@ -625,7 +625,7 @@ static SDL_bool GetTextureForD3D11Frame(AVFrame *frame, SDL_Texture **texture)
|
||||
}
|
||||
}
|
||||
|
||||
ID3D11Resource *dx11_resource = SDL_GetProperty(SDL_GetTextureProperties(*texture), "SDL.texture.d3d11.texture");
|
||||
ID3D11Resource *dx11_resource = SDL_GetProperty(SDL_GetTextureProperties(*texture), "SDL.texture.d3d11.texture", NULL);
|
||||
if (!dx11_resource) {
|
||||
SDL_SetError("Couldn't get texture ID3D11Resource interface");
|
||||
return SDL_FALSE;
|
||||
|
||||
Reference in New Issue
Block a user