Added SDL properties API

Fixes https://github.com/libsdl-org/SDL/issues/7799
This commit is contained in:
Sam Lantinga 2023-10-10 12:38:22 -07:00
parent 2bca4671a6
commit 973c8b3273
21 changed files with 746 additions and 37 deletions

View File

@ -473,6 +473,7 @@
<ClInclude Include="..\..\src\SDL_internal.h" />
<ClInclude Include="..\..\src\SDL_list.h" />
<ClInclude Include="..\..\src\SDL_log_c.h" />
<ClInclude Include="..\..\src\SDL_properties_c.h" />
<ClInclude Include="..\..\src\sensor\dummy\SDL_dummysensor.h" />
<ClInclude Include="..\..\src\sensor\SDL_sensor_c.h" />
<ClInclude Include="..\..\src\sensor\SDL_syssensor.h" />
@ -541,9 +542,6 @@
<ClInclude Include="..\..\src\video\yuv2rgb\yuv_rgb.h" />
<ClInclude Include="..\..\src\video\yuv2rgb\yuv_rgb_sse_func.h" />
<ClInclude Include="..\..\src\video\yuv2rgb\yuv_rgb_std_func.h" />
<ClCompile Include="..\..\src\SDL_hashtable.c" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\atomic\SDL_atomic.c" />
<ClCompile Include="..\..\src\atomic\SDL_spinlock.c" />
<ClCompile Include="..\..\src\audio\directsound\SDL_directsound.c" />
@ -714,8 +712,10 @@
<ClCompile Include="..\..\src\SDL_assert.c" />
<ClCompile Include="..\..\src\SDL_list.c" />
<ClCompile Include="..\..\src\SDL_error.c" />
<ClCompile Include="..\..\src\SDL_hashtable.c" />
<ClCompile Include="..\..\src\SDL_hints.c" />
<ClCompile Include="..\..\src\SDL_log.c" />
<ClCompile Include="..\..\src\SDL_properties.c" />
<ClCompile Include="..\..\src\SDL_utils.c" />
<ClCompile Include="..\..\src\sensor\dummy\SDL_dummysensor.c" />
<ClCompile Include="..\..\src\sensor\SDL_sensor.c" />

View File

@ -306,6 +306,9 @@
<ClInclude Include="..\..\include\SDL3\SDL_power.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL3\SDL_properties.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL3\SDL_quit.h">
<Filter>API Headers</Filter>
</ClInclude>
@ -823,6 +826,7 @@
<ClInclude Include="..\..\src\SDL_hints_c.h" />
<ClInclude Include="..\..\src\SDL_internal.h" />
<ClInclude Include="..\..\src\SDL_log_c.h" />
<ClInclude Include="..\..\src\SDL_properties_c.h" />
<ClInclude Include="..\..\src\render\direct3d12\SDL_shaders_d3d12.h">
<Filter>render\direct3d12</Filter>
</ClInclude>
@ -849,6 +853,7 @@
<ClCompile Include="..\..\src\SDL_hashtable.c" />
<ClCompile Include="..\..\src\SDL_hints.c" />
<ClCompile Include="..\..\src\SDL_list.c" />
<ClCompile Include="..\..\src\SDL_properties.c" />
<ClCompile Include="..\..\src\SDL_utils.c" />
<ClCompile Include="..\..\src\audio\SDL_audio.c">
<Filter>audio</Filter>

View File

@ -71,6 +71,7 @@
<ClInclude Include="..\include\SDL3\SDL_platform.h" />
<ClInclude Include="..\include\SDL3\SDL_platform_defines.h" />
<ClInclude Include="..\include\SDL3\SDL_power.h" />
<ClInclude Include="..\include\SDL3\SDL_properties.h" />
<ClInclude Include="..\include\SDL3\SDL_quit.h" />
<ClInclude Include="..\include\SDL3\SDL_rect.h" />
<ClInclude Include="..\include\SDL3\SDL_render.h" />
@ -156,6 +157,7 @@
<ClInclude Include="..\src\SDL_internal.h" />
<ClInclude Include="..\src\SDL_list.h" />
<ClInclude Include="..\src\SDL_log_c.h" />
<ClInclude Include="..\src\SDL_properties_c.h" />
<ClInclude Include="..\src\sensor\dummy\SDL_dummysensor.h" />
<ClInclude Include="..\src\sensor\SDL_sensor_c.h" />
<ClInclude Include="..\src\sensor\SDL_syssensor.h" />
@ -398,6 +400,7 @@
<ClCompile Include="..\src\SDL_guid.c" />
<ClCompile Include="..\src\SDL_hints.c" />
<ClCompile Include="..\src\SDL_log.c" />
<ClCompile Include="..\src\SDL_properties.c" />
<ClCompile Include="..\src\SDL_utils.c" />
<ClCompile Include="..\src\sensor\dummy\SDL_dummysensor.c" />
<ClCompile Include="..\src\sensor\SDL_sensor.c" />

View File

@ -324,7 +324,9 @@
<ClInclude Include="..\src\SDL_fatal.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\src\SDL_hashtable.h" />
<ClInclude Include="..\src\SDL_hashtable.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\src\SDL_hints_c.h">
<Filter>Source Files</Filter>
</ClInclude>
@ -334,6 +336,9 @@
<ClInclude Include="..\src\SDL_log_c.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\src\SDL_properties_c.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\src\locale\SDL_syslocale.h">
<Filter>Source Files</Filter>
</ClInclude>
@ -640,13 +645,24 @@
<ClCompile Include="..\src\SDL_guid.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\SDL_hashtable.c" />
<ClCompile Include="..\src\SDL_hashtable.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\SDL_hints.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\SDL_list.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\SDL_log.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\SDL_utils.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\SDL_properties.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\locale\SDL_locale.c">
<Filter>Source Files</Filter>
</ClCompile>
@ -797,12 +813,6 @@
<ClCompile Include="..\src\video\winrt\SDL_winrtgamebar.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\SDL_list.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\SDL_utils.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\haptic\windows\SDL_dinputhaptic.c">
<Filter>Source Files</Filter>
</ClCompile>

View File

@ -283,6 +283,7 @@
<ClInclude Include="..\..\include\SDL3\SDL_platform.h" />
<ClInclude Include="..\..\include\SDL3\SDL_platform_defines.h" />
<ClInclude Include="..\..\include\SDL3\SDL_power.h" />
<ClInclude Include="..\..\include\SDL3\SDL_properties.h" />
<ClInclude Include="..\..\include\SDL3\SDL_quit.h" />
<ClInclude Include="..\..\include\SDL3\SDL_rect.h" />
<ClInclude Include="..\..\include\SDL3\SDL_render.h" />
@ -400,6 +401,7 @@
<ClInclude Include="..\..\src\SDL_internal.h" />
<ClInclude Include="..\..\src\SDL_list.h" />
<ClInclude Include="..\..\src\SDL_log_c.h" />
<ClInclude Include="..\..\src\SDL_properties_c.h" />
<ClInclude Include="..\..\src\sensor\dummy\SDL_dummysensor.h" />
<ClInclude Include="..\..\src\sensor\SDL_sensor_c.h" />
<ClInclude Include="..\..\src\sensor\SDL_syssensor.h" />
@ -467,9 +469,6 @@
<ClInclude Include="..\..\src\video\yuv2rgb\yuv_rgb.h" />
<ClInclude Include="..\..\src\video\yuv2rgb\yuv_rgb_sse_func.h" />
<ClInclude Include="..\..\src\video\yuv2rgb\yuv_rgb_std_func.h" />
<ClCompile Include="..\..\src\SDL_hashtable.c" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\atomic\SDL_atomic.c" />
<ClCompile Include="..\..\src\atomic\SDL_spinlock.c" />
<ClCompile Include="..\..\src\audio\directsound\SDL_directsound.c" />
@ -590,10 +589,12 @@
<ClCompile Include="..\..\src\render\software\SDL_triangle.c" />
<ClCompile Include="..\..\src\SDL.c" />
<ClCompile Include="..\..\src\SDL_assert.c" />
<ClCompile Include="..\..\src\SDL_list.c" />
<ClCompile Include="..\..\src\SDL_error.c" />
<ClCompile Include="..\..\src\SDL_hashtable.c" />
<ClCompile Include="..\..\src\SDL_hints.c" />
<ClCompile Include="..\..\src\SDL_list.c" />
<ClCompile Include="..\..\src\SDL_log.c" />
<ClCompile Include="..\..\src\SDL_properties.c" />
<ClCompile Include="..\..\src\SDL_utils.c" />
<ClCompile Include="..\..\src\sensor\dummy\SDL_dummysensor.c" />
<ClCompile Include="..\..\src\sensor\SDL_sensor.c" />

View File

@ -300,6 +300,9 @@
<ClInclude Include="..\..\include\SDL3\SDL_power.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL3\SDL_properties.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL3\SDL_quit.h">
<Filter>API Headers</Filter>
</ClInclude>
@ -814,6 +817,7 @@
<ClInclude Include="..\..\src\SDL_hints_c.h" />
<ClInclude Include="..\..\src\SDL_internal.h" />
<ClInclude Include="..\..\src\SDL_log_c.h" />
<ClInclude Include="..\..\src\SDL_properties_c.h" />
<ClInclude Include="..\..\src\render\direct3d12\SDL_shaders_d3d12.h">
<Filter>render\direct3d12</Filter>
</ClInclude>
@ -828,6 +832,7 @@
<ClCompile Include="..\..\src\SDL_hashtable.c" />
<ClCompile Include="..\..\src\SDL_hints.c" />
<ClCompile Include="..\..\src\SDL_list.c" />
<ClCompile Include="..\..\src\SDL_properties.c" />
<ClCompile Include="..\..\src\SDL_utils.c" />
<ClCompile Include="..\..\src\audio\SDL_audio.c">
<Filter>audio</Filter>

View File

@ -211,6 +211,7 @@
<ClCompile Include="..\..\..\test\testautomation_mouse.c" />
<ClCompile Include="..\..\..\test\testautomation_pixels.c" />
<ClCompile Include="..\..\..\test\testautomation_platform.c" />
<ClCompile Include="..\..\..\test\testautomation_properties.c" />
<ClCompile Include="..\..\..\test\testautomation_rect.c" />
<ClCompile Include="..\..\..\test\testautomation_render.c" />
<ClCompile Include="..\..\..\test\testautomation_rwops.c" />

View File

@ -33,6 +33,7 @@
/* End PBXAggregateTarget section */
/* Begin PBXBuildFile section */
000040E76FDC6AE48CBF0000 /* SDL_hashtable.c in Sources */ = {isa = PBXBuildFile; fileRef = 000078E1881E857EBB6C0000 /* SDL_hashtable.c */; };
007317A40858DECD00B2BC32 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0073179D0858DECD00B2BC32 /* Cocoa.framework */; platformFilters = (macos, ); };
007317A60858DECD00B2BC32 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0073179F0858DECD00B2BC32 /* IOKit.framework */; platformFilters = (ios, maccatalyst, macos, ); };
00CFA89D106B4BA100758660 /* ForceFeedback.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00CFA89C106B4BA100758660 /* ForceFeedback.framework */; platformFilters = (macos, ); };
@ -405,6 +406,8 @@
F3B38CDB296E2E52005DA6D3 /* SDL_oldnames.h in Headers */ = {isa = PBXBuildFile; fileRef = F3B38CCD296E2E52005DA6D3 /* SDL_oldnames.h */; settings = {ATTRIBUTES = (Public, ); }; };
F3B38CDF296E2E52005DA6D3 /* SDL_intrin.h in Headers */ = {isa = PBXBuildFile; fileRef = F3B38CCE296E2E52005DA6D3 /* SDL_intrin.h */; settings = {ATTRIBUTES = (Public, ); }; };
F3D60A8328C16A1900788A3A /* SDL_hidapi_wii.c in Sources */ = {isa = PBXBuildFile; fileRef = F3D60A8228C16A1800788A3A /* SDL_hidapi_wii.c */; };
F3E5A6EB2AD5E0E600293D83 /* SDL_properties.c in Sources */ = {isa = PBXBuildFile; fileRef = F3E5A6EA2AD5E0E600293D83 /* SDL_properties.c */; };
F3E5A6ED2AD5E10800293D83 /* SDL_properties.h in Headers */ = {isa = PBXBuildFile; fileRef = F3E5A6EC2AD5E10800293D83 /* SDL_properties.h */; settings = {ATTRIBUTES = (Public, ); }; };
F3F07D5A269640160074468B /* SDL_hidapi_luna.c in Sources */ = {isa = PBXBuildFile; fileRef = F3F07D59269640160074468B /* SDL_hidapi_luna.c */; };
F3F7D8ED2933074E00816151 /* SDL_audio.h in Headers */ = {isa = PBXBuildFile; fileRef = F3F7D8AA2933074900816151 /* SDL_audio.h */; settings = {ATTRIBUTES = (Public, ); }; };
F3F7D8F12933074E00816151 /* SDL_platform.h in Headers */ = {isa = PBXBuildFile; fileRef = F3F7D8AB2933074900816151 /* SDL_platform.h */; settings = {ATTRIBUTES = (Public, ); }; };
@ -469,8 +472,6 @@
F3F7D9E12933074E00816151 /* SDL_begin_code.h in Headers */ = {isa = PBXBuildFile; fileRef = F3F7D8E72933074E00816151 /* SDL_begin_code.h */; settings = {ATTRIBUTES = (Public, ); }; };
F3F7D9E52933074E00816151 /* SDL_system.h in Headers */ = {isa = PBXBuildFile; fileRef = F3F7D8E82933074E00816151 /* SDL_system.h */; settings = {ATTRIBUTES = (Public, ); }; };
FA73671D19A540EF004122E4 /* CoreVideo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA73671C19A540EF004122E4 /* CoreVideo.framework */; platformFilters = (ios, maccatalyst, macos, tvos, watchos, ); };
000040E76FDC6AE48CBF0000 /* SDL_hashtable.c in Sources */ = {isa = PBXBuildFile; fileRef = 000078E1881E857EBB6C0000 /* SDL_hashtable.c */; };
0000CE8F0EF0E7EF781D0000 /* SDL_hashtable.h in Headers */ = {isa = PBXBuildFile; fileRef = 0000B6ADCD88CAD6610F0000 /* SDL_hashtable.h */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -497,6 +498,8 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
000078E1881E857EBB6C0000 /* SDL_hashtable.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hashtable.c; sourceTree = "<group>"; };
0000B6ADCD88CAD6610F0000 /* SDL_hashtable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_hashtable.h; sourceTree = "<group>"; };
0073179D0858DECD00B2BC32 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
0073179F0858DECD00B2BC32 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
007317C10858E15000B2BC32 /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = System/Library/Frameworks/Carbon.framework; sourceTree = SDKROOT; };
@ -897,6 +900,8 @@
F3B38CCD296E2E52005DA6D3 /* SDL_oldnames.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_oldnames.h; path = SDL3/SDL_oldnames.h; sourceTree = "<group>"; };
F3B38CCE296E2E52005DA6D3 /* SDL_intrin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_intrin.h; path = SDL3/SDL_intrin.h; sourceTree = "<group>"; };
F3D60A8228C16A1800788A3A /* SDL_hidapi_wii.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_wii.c; sourceTree = "<group>"; };
F3E5A6EA2AD5E0E600293D83 /* SDL_properties.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_properties.c; sourceTree = "<group>"; };
F3E5A6EC2AD5E10800293D83 /* SDL_properties.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_properties.h; path = SDL3/SDL_properties.h; sourceTree = "<group>"; };
F3F07D59269640160074468B /* SDL_hidapi_luna.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_luna.c; sourceTree = "<group>"; };
F3F7D8AA2933074900816151 /* SDL_audio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_audio.h; path = SDL3/SDL_audio.h; sourceTree = "<group>"; };
F3F7D8AB2933074900816151 /* SDL_platform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_platform.h; path = SDL3/SDL_platform.h; sourceTree = "<group>"; };
@ -964,8 +969,6 @@
F59C710600D5CB5801000001 /* SDL.info */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = SDL.info; sourceTree = "<group>"; };
F5A2EF3900C6A39A01000001 /* BUGS.txt */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; name = BUGS.txt; path = ../../BUGS.txt; sourceTree = SOURCE_ROOT; };
FA73671C19A540EF004122E4 /* CoreVideo.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreVideo.framework; path = System/Library/Frameworks/CoreVideo.framework; sourceTree = SDKROOT; };
000078E1881E857EBB6C0000 /* SDL_hashtable.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SDL_hashtable.c; path = SDL_hashtable.c; sourceTree = "<group>"; };
0000B6ADCD88CAD6610F0000 /* SDL_hashtable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_hashtable.h; path = SDL_hashtable.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -994,7 +997,6 @@
0153844A006D81B07F000001 /* Public Headers */ = {
isa = PBXGroup;
children = (
F3F7D8CF2933074C00816151 /* SDL.h */,
F3F7D8E02933074D00816151 /* SDL_assert.h */,
F3F7D8B92933074A00816151 /* SDL_atomic.h */,
F3F7D8AA2933074900816151 /* SDL_audio.h */,
@ -1023,26 +1025,27 @@
F3F7D8D92933074C00816151 /* SDL_loadso.h */,
F3F7D8C42933074B00816151 /* SDL_locale.h */,
F3F7D8B72933074A00816151 /* SDL_log.h */,
F3F7D8B02933074900816151 /* SDL_main.h */,
F3B38CCA296E2E52005DA6D3 /* SDL_main_impl.h */,
F3F7D8B02933074900816151 /* SDL_main.h */,
F3F7D8B62933074A00816151 /* SDL_messagebox.h */,
F3F7D8D22933074C00816151 /* SDL_metal.h */,
F3F7D8D52933074C00816151 /* SDL_misc.h */,
F3F7D8DA2933074D00816151 /* SDL_mouse.h */,
F3F7D8E62933074E00816151 /* SDL_mutex.h */,
F3B38CCD296E2E52005DA6D3 /* SDL_oldnames.h */,
F3F7D8E12933074D00816151 /* SDL_opengl.h */,
F3F7D8C02933074A00816151 /* SDL_opengl_glext.h */,
F3F7D8E12933074D00816151 /* SDL_opengl.h */,
F3F7D8C62933074B00816151 /* SDL_opengles.h */,
F3F7D8C72933074B00816151 /* SDL_opengles2.h */,
F3F7D8AE2933074900816151 /* SDL_opengles2_gl2.h */,
F3F7D8BD2933074A00816151 /* SDL_opengles2_gl2ext.h */,
F3F7D8C92933074B00816151 /* SDL_opengles2_gl2platform.h */,
F3F7D8B12933074900816151 /* SDL_opengles2_khrplatform.h */,
F3F7D8C72933074B00816151 /* SDL_opengles2.h */,
F3F7D8B52933074A00816151 /* SDL_pixels.h */,
F3F7D8AB2933074900816151 /* SDL_platform.h */,
F3B38CCB296E2E52005DA6D3 /* SDL_platform_defines.h */,
F3F7D8AB2933074900816151 /* SDL_platform.h */,
F3F7D8DB2933074D00816151 /* SDL_power.h */,
F3E5A6EC2AD5E10800293D83 /* SDL_properties.h */,
F3F7D8DF2933074D00816151 /* SDL_quit.h */,
F3F7D8E22933074D00816151 /* SDL_rect.h */,
F3F7D8DE2933074D00816151 /* SDL_render.h */,
@ -1061,6 +1064,7 @@
F3F7D8E42933074D00816151 /* SDL_version.h */,
F3F7D8C52933074B00816151 /* SDL_video.h */,
F3F7D8D42933074C00816151 /* SDL_vulkan.h */,
F3F7D8CF2933074C00816151 /* SDL.h */,
);
name = "Public Headers";
path = ../../include;
@ -1123,6 +1127,8 @@
A7D8A57523E2513D00DCD162 /* SDL_error_c.h */,
A7D8A8BF23E2513F00DCD162 /* SDL_error.c */,
F382071C284F362F004DD584 /* SDL_guid.c */,
000078E1881E857EBB6C0000 /* SDL_hashtable.c */,
0000B6ADCD88CAD6610F0000 /* SDL_hashtable.h */,
A7D8A8D123E2514000DCD162 /* SDL_hints_c.h */,
A7D8A5AB23E2513D00DCD162 /* SDL_hints.c */,
A7D8A58323E2513D00DCD162 /* SDL_internal.h */,
@ -1130,11 +1136,10 @@
A1BB8B6227F6CF330057CFA8 /* SDL_list.h */,
F386F6E42884663E001840AA /* SDL_log_c.h */,
A7D8A5DD23E2513D00DCD162 /* SDL_log.c */,
F3E5A6EA2AD5E0E600293D83 /* SDL_properties.c */,
F386F6E52884663E001840AA /* SDL_utils_c.h */,
F386F6E62884663E001840AA /* SDL_utils.c */,
A7D8A57123E2513D00DCD162 /* SDL.c */,
000078E1881E857EBB6C0000 /* SDL_hashtable.c */,
0000B6ADCD88CAD6610F0000 /* SDL_hashtable.h */,
);
name = "Library Source";
path = ../../src;
@ -2156,6 +2161,7 @@
F3B38CDB296E2E52005DA6D3 /* SDL_oldnames.h in Headers */,
F3F7D9C92933074E00816151 /* SDL_opengl.h in Headers */,
F3F7D9452933074E00816151 /* SDL_opengl_glext.h in Headers */,
F3E5A6ED2AD5E10800293D83 /* SDL_properties.h in Headers */,
F3F7D95D2933074E00816151 /* SDL_opengles.h in Headers */,
F3F7D9612933074E00816151 /* SDL_opengles2.h in Headers */,
F3F7D8FD2933074E00816151 /* SDL_opengles2_gl2.h in Headers */,
@ -2502,6 +2508,7 @@
A7D8BBD723E2574800DCD162 /* SDL_uikitevents.m in Sources */,
A7D8B5F323E2514300DCD162 /* SDL_syspower.c in Sources */,
A7D8B95023E2514400DCD162 /* SDL_iconv.c in Sources */,
F3E5A6EB2AD5E0E600293D83 /* SDL_properties.c in Sources */,
A7D8BA9D23E2514400DCD162 /* s_fabs.c in Sources */,
F395C1B12569C6A000942BFF /* SDL_mfijoystick.m in Sources */,
A7D8B99223E2514400DCD162 /* SDL_shaders_metal.metal in Sources */,

View File

@ -61,6 +61,7 @@
#include <SDL3/SDL_pixels.h>
#include <SDL3/SDL_platform.h>
#include <SDL3/SDL_power.h>
#include <SDL3/SDL_properties.h>
#include <SDL3/SDL_quit.h>
#include <SDL3/SDL_rect.h>
#include <SDL3/SDL_render.h>

View File

@ -0,0 +1,133 @@
/*
Simple DiretMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/**
* \file SDL_properties.h
*
* \brief Header file for SDL properties.
*/
#ifndef SDL_properties_h_
#define SDL_properties_h_
#include <SDL3/SDL_begin_code.h>
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/**
* SDL properties ID
*/
typedef Uint32 SDL_PropertiesID;
/**
* Create a set of properties
*
* \returns an ID for a new set of properties, or 0 on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_DestroyProperties
*/
extern DECLSPEC SDL_PropertiesID SDLCALL SDL_CreateProperties(void);
/**
* Lock a set of properties
*
* Obtain a multi-threaded lock for these properties. Other threads will wait while trying to lock these properties until they are unlocked. Properties must be unlocked before they are destroyed.
*
* The lock is automatically taken when setting individual properties, this function is only needed when you want to set several properties atomically or want to guarantee that properties being queried aren't freed in another thread.
*
* \param props the properties to lock
*
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_UnlockProperties
*/
extern DECLSPEC int SDLCALL SDL_LockProperties(SDL_PropertiesID props);
/**
* Unlock a set of properties
*
* \param props the properties to unlock
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_LockProperties
*/
extern DECLSPEC void SDLCALL SDL_UnlockProperties(SDL_PropertiesID props);
/**
* Set a property on a set of properties
*
* \param props the properties to modify
* \param name the name of the property to modify
* \param value the new value of the property, or NULL to delete the property
* \param cleanup the function to call when this property is deleted, or NULL if no cleanup is necessary
* \param userdata a pointer that is passed to the cleanup function
*
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetProperty
*/
extern DECLSPEC int SDLCALL SDL_SetProperty(SDL_PropertiesID props, const char *name, void *value, void (SDLCALL *cleanup)(void *userdata, void *value), void *userdata);
/**
* Get a property on a set of properties
*
* \param props the properties to query
* \param name the name of the property to query
*
* \returns the value of the property, or NULL if it is not set.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_SetProperty
*/
extern DECLSPEC void *SDLCALL SDL_GetProperty(SDL_PropertiesID props, const char *name);
/**
* Destroy a set of properties
*
* All properties are deleted and their cleanup functions will be called, if any. The set of properties must be unlocked when it is destroyed.
*
* \param props the properties to destroy
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_CreateProperties
*/
extern DECLSPEC void SDLCALL SDL_DestroyProperties(SDL_PropertiesID props);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#include <SDL3/SDL_close_code.h>
#endif /* SDL_properties_h_ */

View File

@ -38,6 +38,7 @@
#include "SDL_assert_c.h"
#include "SDL_log_c.h"
#include "SDL_properties_c.h"
#include "audio/SDL_audio_c.h"
#include "video/SDL_video_c.h"
#include "events/SDL_events_c.h"
@ -167,6 +168,7 @@ int SDL_InitSubSystem(Uint32 flags)
}
SDL_InitLog();
SDL_InitProperties();
/* Clear the error message */
SDL_ClearError();
@ -499,6 +501,7 @@ void SDL_Quit(void)
SDL_DBus_Quit();
#endif
SDL_QuitProperties();
SDL_QuitLog();
/* Now that every subsystem has been quit, we reset the subsystem refcount

View File

@ -18,7 +18,6 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
#include "SDL_hashtable.h"
@ -209,6 +208,21 @@ SDL_bool SDL_IterateHashTableKeys(const SDL_HashTable *table, const void **_key,
return SDL_TRUE;
}
SDL_bool SDL_HashTableEmpty(SDL_HashTable *table)
{
if (table != NULL) {
Uint32 i;
for (i = 0; i < table->table_len; i++) {
SDL_HashItem *item = table->table[i];
if (item != NULL) {
return SDL_FALSE;
}
}
}
return SDL_TRUE;
}
void SDL_DestroyHashTable(SDL_HashTable *table)
{
if (table != NULL) {
@ -240,10 +254,10 @@ static SDL_INLINE Uint32 hash_string_djbxor(const char *str, size_t len)
return hash;
}
Uint32 SDL_HashString(const void *sym, void *data)
Uint32 SDL_HashString(const void *key, void *data)
{
const char *str = (const char*) sym;
return hash_string_djbxor(str, SDL_strlen((const char *) str));
const char *str = (const char *)key;
return hash_string_djbxor(str, SDL_strlen(str));
}
SDL_bool SDL_KeyMatchString(const void *a, const void *b, void *data)
@ -253,7 +267,21 @@ SDL_bool SDL_KeyMatchString(const void *a, const void *b, void *data)
} else if (!a || !b) {
return SDL_FALSE; /* one pointer is NULL (and first test shows they aren't the same pointer), must not match. */
}
return (SDL_strcmp((const char *) a, (const char *) b) == 0) ? SDL_TRUE : SDL_FALSE; /* Check against actual string contents. */
return (SDL_strcmp((const char *)a, (const char *)b) == 0) ? SDL_TRUE : SDL_FALSE; /* Check against actual string contents. */
}
/* vi: set ts=4 sw=4 expandtab: */
/* We assume we can fit the ID in the key directly */
SDL_COMPILE_TIME_ASSERT(SDL_HashID_KeySize, sizeof(Uint32) <= sizeof(const void *));
Uint32 SDL_HashID(const void *key, void *unused)
{
return (Uint32)(uintptr_t)key;
}
SDL_bool SDL_KeyMatchID(const void *a, const void *b, void *unused)
{
if (a == b) {
return SDL_TRUE;
}
return SDL_FALSE;
}

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -40,14 +40,15 @@ void SDL_DestroyHashTable(SDL_HashTable *table);
SDL_bool SDL_InsertIntoHashTable(SDL_HashTable *table, const void *key, const void *value);
SDL_bool SDL_RemoveFromHashTable(SDL_HashTable *table, const void *key);
SDL_bool SDL_FindInHashTable(const SDL_HashTable *table, const void *key, const void **_value);
SDL_bool SDL_HashTableEmpty(SDL_HashTable *table);
SDL_bool SDL_IterateHashTable(const SDL_HashTable *table, const void *key, const void **_value, void **iter);
SDL_bool SDL_IterateHashTableKeys(const SDL_HashTable *table, const void **_key, void **iter);
Uint32 SDL_HashString(const void *sym, void *unused);
Uint32 SDL_HashString(const void *key, void *unused);
SDL_bool SDL_KeyMatchString(const void *a, const void *b, void *unused);
Uint32 SDL_HashID(const void *key, void *unused);
SDL_bool SDL_KeyMatchID(const void *a, const void *b, void *unused);
#endif /* SDL_hashtable_h_ */
/* vi: set ts=4 sw=4 expandtab: */

278
src/SDL_properties.c Normal file
View File

@ -0,0 +1,278 @@
/*
Simple DiretMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
#include "SDL_hashtable.h"
#include "SDL_properties_c.h"
typedef struct
{
void *value;
void (SDLCALL *cleanup)(void *userdata, void *value);
void *userdata;
} SDL_Property;
typedef struct
{
SDL_HashTable *props;
SDL_Mutex *lock;
} SDL_Properties;
static SDL_HashTable *SDL_properties;
static SDL_RWLock *SDL_properties_lock;
static SDL_PropertiesID SDL_last_properties_id;
static void SDL_FreeProperty(const void *key, const void *value, void *data)
{
SDL_Property *property = (SDL_Property *)value;
if (property->cleanup) {
property->cleanup(property->userdata, property->value);
}
SDL_free((void *)key);
SDL_free((void *)value);
}
static void SDL_FreeProperties(const void *key, const void *value, void *data)
{
SDL_Properties *properties = (SDL_Properties *)value;
if (properties) {
if (properties->props) {
SDL_DestroyHashTable(properties->props);
properties->props = NULL;
}
if (properties->lock) {
SDL_DestroyMutex(properties->lock);
properties->lock = NULL;
}
SDL_free(properties);
}
}
int SDL_InitProperties(void)
{
if (!SDL_properties_lock) {
SDL_properties_lock = SDL_CreateRWLock();
if (!SDL_properties_lock) {
return -1;
}
}
if (!SDL_properties) {
SDL_properties = SDL_CreateHashTable(NULL, 16, SDL_HashID, SDL_KeyMatchID, SDL_FreeProperties, SDL_FALSE);
if (!SDL_properties) {
return -1;
}
}
return 0;
}
void SDL_QuitProperties(void)
{
if (SDL_properties) {
SDL_DestroyHashTable(SDL_properties);
SDL_properties = NULL;
}
if (SDL_properties_lock) {
SDL_DestroyRWLock(SDL_properties_lock);
SDL_properties_lock = NULL;
}
}
SDL_PropertiesID SDL_CreateProperties(void)
{
SDL_PropertiesID props;
SDL_Properties *properties = NULL;
SDL_bool inserted = SDL_FALSE;
if (!SDL_properties && SDL_InitProperties() < 0) {
return 0;
}
properties = SDL_malloc(sizeof(*properties));
if (!properties) {
goto error;
}
properties->props = SDL_CreateHashTable(NULL, 4, SDL_HashString, SDL_KeyMatchString, SDL_FreeProperty, SDL_FALSE);
if (!properties->props) {
goto error;
}
properties->lock = SDL_CreateMutex();
if (!properties->lock) {
goto error;
}
if (SDL_InitProperties() < 0) {
goto error;
}
if (SDL_LockRWLockForWriting(SDL_properties_lock) == 0) {
props = ++SDL_last_properties_id;
if (SDL_InsertIntoHashTable(SDL_properties, (const void *)(uintptr_t)props, properties)) {
inserted = SDL_TRUE;
}
SDL_UnlockRWLock(SDL_properties_lock);
}
if (inserted) {
/* All done! */
return props;
}
error:
SDL_FreeProperties(NULL, properties, NULL);
return 0;
}
int SDL_LockProperties(SDL_PropertiesID props)
{
SDL_Properties *properties = NULL;
if (!props) {
return SDL_InvalidParamError("props");
}
if (SDL_LockRWLockForReading(SDL_properties_lock) == 0) {
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
SDL_UnlockRWLock(SDL_properties_lock);
}
if (!properties) {
SDL_InvalidParamError("props");
return -1;
}
return SDL_LockMutex(properties->lock);
}
void SDL_UnlockProperties(SDL_PropertiesID props)
{
SDL_Properties *properties = NULL;
if (!props) {
return;
}
if (SDL_LockRWLockForReading(SDL_properties_lock) == 0) {
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
SDL_UnlockRWLock(SDL_properties_lock);
}
if (!properties) {
return;
}
SDL_UnlockMutex(properties->lock);
}
int SDL_SetProperty(SDL_PropertiesID props, const char *name, void *value, void (SDLCALL *cleanup)(void *userdata, void *value), void *userdata)
{
SDL_Properties *properties = NULL;
SDL_Property *property = NULL;
int result = 0;
if (!props) {
return SDL_InvalidParamError("props");
}
if (!name || !*name) {
return SDL_InvalidParamError("name");
}
if (SDL_LockRWLockForReading(SDL_properties_lock) == 0) {
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
SDL_UnlockRWLock(SDL_properties_lock);
}
if (!properties) {
return SDL_InvalidParamError("props");
}
if (value) {
property = (SDL_Property *)SDL_malloc(sizeof(*property));
if (!property) {
return SDL_OutOfMemory();
}
property->value = value;
property->cleanup = cleanup;
property->userdata = userdata;
}
SDL_LockMutex(properties->lock);
{
SDL_RemoveFromHashTable(properties->props, name);
if (property) {
char *key = SDL_strdup(name);
if (!SDL_InsertIntoHashTable(properties->props, key, property)) {
SDL_FreeProperty(key, property, NULL);
result = -1;
}
}
}
SDL_UnlockMutex(properties->lock);
return result;
}
void *SDL_GetProperty(SDL_PropertiesID props, const char *name)
{
SDL_Properties *properties = NULL;
void *value = NULL;
if (!props) {
SDL_InvalidParamError("props");
return NULL;
}
if (!name || !*name) {
SDL_InvalidParamError("name");
return NULL;
}
if (SDL_LockRWLockForReading(SDL_properties_lock) == 0) {
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
SDL_UnlockRWLock(SDL_properties_lock);
}
if (!properties) {
SDL_InvalidParamError("props");
return NULL;
}
/* Note that taking the lock here only guarantees that we won't read the
* hashtable while it's being modified. The value itself can easily be
* freed from another thread after it is returned here.
*/
SDL_LockMutex(properties->lock);
{
SDL_Property *property = NULL;
if (SDL_FindInHashTable(properties->props, name, (const void **)&property)) {
value = property->value;
} else {
SDL_SetError("Couldn't find property named %s", name);
}
}
SDL_UnlockMutex(properties->lock);
return value;
}
void SDL_DestroyProperties(SDL_PropertiesID props)
{
if (!props) {
return;
}
if (SDL_LockRWLockForWriting(SDL_properties_lock) == 0) {
SDL_RemoveFromHashTable(SDL_properties, (const void *)(uintptr_t)props);
SDL_UnlockRWLock(SDL_properties_lock);
}
}

23
src/SDL_properties_c.h Normal file
View File

@ -0,0 +1,23 @@
/*
Simple DiretMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
extern int SDL_InitProperties(void);
extern void SDL_QuitProperties(void);

View File

@ -908,6 +908,12 @@ SDL3_0.0.0 {
SDL_SetAudioPostmixCallback;
SDL_GetAudioStreamQueued;
SDL_GetTextureDXGIResource;
SDL_CreateProperties;
SDL_LockProperties;
SDL_UnlockProperties;
SDL_SetProperty;
SDL_GetProperty;
SDL_DestroyProperties;
# extra symbols go here (don't modify this line)
local: *;
};

View File

@ -933,3 +933,9 @@
#define SDL_SetAudioPostmixCallback SDL_SetAudioPostmixCallback_REAL
#define SDL_GetAudioStreamQueued SDL_GetAudioStreamQueued_REAL
#define SDL_GetTextureDXGIResource SDL_GetTextureDXGIResource_REAL
#define SDL_CreateProperties SDL_CreateProperties_REAL
#define SDL_LockProperties SDL_LockProperties_REAL
#define SDL_UnlockProperties SDL_UnlockProperties_REAL
#define SDL_SetProperty SDL_SetProperty_REAL
#define SDL_GetProperty SDL_GetProperty_REAL
#define SDL_DestroyProperties SDL_DestroyProperties_REAL

View File

@ -979,3 +979,9 @@ SDL_DYNAPI_PROC(int,SDL_SetAudioStreamFrequencyRatio,(SDL_AudioStream *a, float
SDL_DYNAPI_PROC(int,SDL_SetAudioPostmixCallback,(SDL_AudioDeviceID a, SDL_AudioPostmixCallback b, void *c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_GetAudioStreamQueued,(SDL_AudioStream *a),(a),return)
SDL_DYNAPI_PROC(IDXGIResource*,SDL_GetTextureDXGIResource,(SDL_Texture *a),(a),return)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_CreateProperties,(void),(),return)
SDL_DYNAPI_PROC(int,SDL_LockProperties,(SDL_PropertiesID a),(a),return)
SDL_DYNAPI_PROC(void,SDL_UnlockProperties,(SDL_PropertiesID a),(a),)
SDL_DYNAPI_PROC(int,SDL_SetProperty,(SDL_PropertiesID a, const char *b, void *c, void (SDLCALL *d)(void *userdata, void *value), void *e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(void*,SDL_GetProperty,(SDL_PropertiesID a, const char *b),(a,b),return)
SDL_DYNAPI_PROC(void,SDL_DestroyProperties,(SDL_PropertiesID a),(a),)

View File

@ -35,6 +35,7 @@ static SDLTest_TestSuiteReference *testSuites[] = {
&mouseTestSuite,
&pixelsTestSuite,
&platformTestSuite,
&propertiesTestSuite,
&rectTestSuite,
&renderTestSuite,
&rwopsTestSuite,

View File

@ -0,0 +1,190 @@
/**
* Properties test suite
*/
#include <SDL3/SDL.h>
#include <SDL3/SDL_test.h>
#include "testautomation_suites.h"
/* Test case functions */
/**
* \brief Test basic functionality
*/
static int properties_testBasic(void *arg)
{
SDL_PropertiesID props;
char key[2], expected_value[2];
void *value;
int i, result;
props = SDL_CreateProperties();
SDLTest_AssertPass("Call to SDL_CreateProperties()");
SDLTest_AssertCheck(props != 0,
"Verify props were created, got: %" SDL_PRIu32 "", props);
for (i = 0; i < 10; ++i) {
SDL_snprintf(key, SDL_arraysize(key), "%c", 'a' + i);
SDL_snprintf(expected_value, SDL_arraysize(expected_value), "%c", 'a' + i);
result = SDL_SetProperty(props, key, expected_value, NULL, NULL);
SDLTest_AssertPass("Call to SDL_SetProperty()");
SDLTest_AssertCheck(result == 0,
"Verify property value was set, got: %d", result);
value = SDL_GetProperty(props, key);
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);
}
for (i = 0; i < 10; ++i) {
SDL_snprintf(key, SDL_arraysize(key), "%c", 'a' + i);
result = SDL_SetProperty(props, key, NULL, NULL, 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);
SDLTest_AssertPass("Call to SDL_GetProperty()");
SDLTest_AssertCheck(value == NULL,
"Verify property value was set, got %s, expected NULL", (const char *)value);
}
SDL_DestroyProperties(props);
return TEST_COMPLETED;
}
/**
* \brief Test cleanup functionality
*/
static void SDLCALL cleanup(void *userdata, void *value)
{
int *count = (int *)userdata;
++(*count);
}
static int properties_testCleanup(void *arg)
{
SDL_PropertiesID props;
char key[2], expected_value[2];
int i, count;
props = SDL_CreateProperties();
SDLTest_AssertPass("Call to SDL_SetProperty(cleanup)");
count = 0;
SDL_SetProperty(props, "a", "0", cleanup, &count);
SDL_SetProperty(props, "a", NULL, cleanup, &count);
SDLTest_AssertCheck(count == 1,
"Verify cleanup for deleting property, got %d, expected 1", count);
SDLTest_AssertPass("Call to SDL_DestroyProperties()");
count = 0;
for (i = 0; i < 10; ++i) {
SDL_snprintf(key, SDL_arraysize(key), "%c", 'a' + i);
SDL_snprintf(expected_value, SDL_arraysize(expected_value), "%c", 'a' + i);
SDL_SetProperty(props, key, expected_value, cleanup, &count);
}
SDL_DestroyProperties(props);
SDLTest_AssertCheck(count == 10,
"Verify cleanup for destroying properties, got %d, expected 10", count);
return TEST_COMPLETED;
}
/**
* \brief Test locking functionality
*/
struct properties_thread_data
{
SDL_bool done;
SDL_PropertiesID props;
};
static int properties_thread(void *arg)
{
struct properties_thread_data *data = (struct properties_thread_data *)arg;
while (!data->done) {
SDL_LockProperties(data->props);
SDL_SetProperty(data->props, "a", "thread_loop", NULL, NULL);
SDL_UnlockProperties(data->props);
}
SDL_LockProperties(data->props);
SDL_SetProperty(data->props, "a", "thread_done", NULL, NULL);
SDL_UnlockProperties(data->props);
return 0;
}
static int properties_testLocking(void *arg)
{
struct properties_thread_data data;
SDL_Thread *thread;
void *value;
SDLTest_AssertPass("Testing property locking");
data.done = SDL_FALSE;
data.props = SDL_CreateProperties();
SDLTest_AssertPass("Setting property to 'init'");
SDL_SetProperty(data.props, "a", "init", NULL, NULL);
thread = SDL_CreateThread(properties_thread, "properties_thread", &data);
if (thread) {
SDLTest_AssertPass("Waiting for property to change to 'thread_loop'");
for ( ; ; )
{
SDL_Delay(10);
SDL_LockProperties(data.props);
value = SDL_GetProperty(data.props, "a");
SDL_UnlockProperties(data.props);
if (!value || SDL_strcmp((const char *)value, "thread_loop") == 0) {
break;
}
}
SDLTest_AssertCheck(value && SDL_strcmp((const char *)value, "thread_loop") == 0,
"After thread loop, property is %s, expected 'thread_loop'", value ? (const char *)value : "NULL");
SDLTest_AssertPass("Setting property to 'main'");
SDL_LockProperties(data.props);
SDL_SetProperty(data.props, "a", "main", NULL, NULL);
SDL_Delay(100);
value = SDL_GetProperty(data.props, "a");
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);
data.done = SDL_TRUE;
SDL_WaitThread(thread, NULL);
value = SDL_GetProperty(data.props, "a");
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");
}
SDL_DestroyProperties(data.props);
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Properties test cases */
static const SDLTest_TestCaseReference propertiesTest1 = {
(SDLTest_TestCaseFp)properties_testBasic, "properties_testBasic", "Test basic property functionality", TEST_ENABLED
};
static const SDLTest_TestCaseReference propertiesTest2 = {
(SDLTest_TestCaseFp)properties_testCleanup, "properties_testCleanup", "Test property cleanup functionality", TEST_ENABLED
};
static const SDLTest_TestCaseReference propertiesTest3 = {
(SDLTest_TestCaseFp)properties_testLocking, "properties_testLocking", "Test property locking functionality", TEST_ENABLED
};
/* Sequence of Properties test cases */
static const SDLTest_TestCaseReference *propertiesTests[] = {
&propertiesTest1, &propertiesTest2, &propertiesTest3, NULL
};
/* Properties test suite (global) */
SDLTest_TestSuiteReference propertiesTestSuite = {
"Properties",
NULL,
propertiesTests,
NULL
};

View File

@ -22,6 +22,7 @@ extern SDLTest_TestSuiteReference mathTestSuite;
extern SDLTest_TestSuiteReference mouseTestSuite;
extern SDLTest_TestSuiteReference pixelsTestSuite;
extern SDLTest_TestSuiteReference platformTestSuite;
extern SDLTest_TestSuiteReference propertiesTestSuite;
extern SDLTest_TestSuiteReference rectTestSuite;
extern SDLTest_TestSuiteReference renderTestSuite;
extern SDLTest_TestSuiteReference rwopsTestSuite;