-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
437 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
namespace Bindgen; | ||
|
||
public class Test | ||
{ | ||
public static string Generate() | ||
{ | ||
return $$""" | ||
// For more information see the blog post: https://aakinshin.net/posts/blittable/ | ||
// Original code derived from: https://github.com/AndreyAkinshin/BlittableStructs/blob/master/BlittableStructs/BlittableHelper.cs | ||
|
||
/* | ||
The MIT License | ||
|
||
Copyright (c) 2015 Andrey Akinshin | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.Serialization; | ||
|
||
namespace Bindgen.Test; | ||
|
||
public static class BlittableHelper | ||
{ | ||
public static bool IsBlittable<T>() | ||
{ | ||
return IsBlittableCache<T>.VALUE; | ||
} | ||
|
||
public static bool IsBlittable(this Type type) | ||
{ | ||
if (type == typeof(decimal)) | ||
{ | ||
return false; | ||
} | ||
if (type.IsArray) | ||
{ | ||
var elementType = type.GetElementType(); | ||
return elementType != null && elementType.IsValueType && IsBlittable(elementType); | ||
} | ||
try | ||
{ | ||
var instance = FormatterServices.GetUninitializedObject(type); | ||
GCHandle.Alloc(instance, GCHandleType.Pinned).Free(); | ||
return true; | ||
} | ||
catch | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
private static class IsBlittableCache<T> | ||
{ | ||
public static readonly bool VALUE = IsBlittable(typeof(T)); | ||
} | ||
} | ||
"""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using Xunit; | ||
using Bindgen.Test; | ||
|
||
namespace RaylibNET.Test; | ||
|
||
public class RayguiTest | ||
{ | ||
private unsafe void CheckType<T>() where T : unmanaged | ||
{ | ||
Assert.True(BlittableHelper.IsBlittable<T>()); | ||
} | ||
|
||
[Fact] | ||
public void CheckTypes() | ||
{ | ||
CheckType<ConfigFlags>(); | ||
CheckType<TraceLogLevel>(); | ||
CheckType<KeyboardKey>(); | ||
CheckType<MouseButton>(); | ||
CheckType<MouseCursor>(); | ||
CheckType<GamepadButton>(); | ||
CheckType<GamepadAxis>(); | ||
CheckType<MaterialMapIndex>(); | ||
CheckType<ShaderLocationIndex>(); | ||
CheckType<ShaderUniformDataType>(); | ||
CheckType<ShaderAttributeDataType>(); | ||
CheckType<PixelFormat>(); | ||
CheckType<TextureFilter>(); | ||
CheckType<TextureWrap>(); | ||
CheckType<CubemapLayout>(); | ||
CheckType<FontType>(); | ||
CheckType<BlendMode>(); | ||
CheckType<Gesture>(); | ||
CheckType<CameraMode>(); | ||
CheckType<CameraProjection>(); | ||
CheckType<NPatchLayout>(); | ||
CheckType<GuiState>(); | ||
CheckType<GuiTextAlignment>(); | ||
CheckType<GuiTextAlignmentVertical>(); | ||
CheckType<GuiTextWrapMode>(); | ||
CheckType<GuiControl>(); | ||
CheckType<GuiControlProperty>(); | ||
CheckType<GuiDefaultProperty>(); | ||
CheckType<GuiToggleProperty>(); | ||
CheckType<GuiSliderProperty>(); | ||
CheckType<GuiProgressBarProperty>(); | ||
CheckType<GuiScrollBarProperty>(); | ||
CheckType<GuiCheckBoxProperty>(); | ||
CheckType<GuiComboBoxProperty>(); | ||
CheckType<GuiDropdownBoxProperty>(); | ||
CheckType<GuiTextBoxProperty>(); | ||
CheckType<GuiSpinnerProperty>(); | ||
CheckType<GuiListViewProperty>(); | ||
CheckType<GuiColorPickerProperty>(); | ||
CheckType<GuiIconName>(); | ||
CheckType<Color>(); | ||
CheckType<Image>(); | ||
CheckType<Texture>(); | ||
CheckType<RenderTexture>(); | ||
CheckType<NPatchInfo>(); | ||
CheckType<GlyphInfo>(); | ||
CheckType<Font>(); | ||
CheckType<Camera3D>(); | ||
CheckType<Camera2D>(); | ||
CheckType<Mesh>(); | ||
CheckType<Shader>(); | ||
CheckType<MaterialMap>(); | ||
CheckType<Material>(); | ||
CheckType<Transform>(); | ||
CheckType<BoneInfo>(); | ||
CheckType<Model>(); | ||
CheckType<ModelAnimation>(); | ||
CheckType<Ray>(); | ||
CheckType<RayCollision>(); | ||
CheckType<BoundingBox>(); | ||
CheckType<Wave>(); | ||
CheckType<rAudioBuffer>(); | ||
CheckType<rAudioProcessor>(); | ||
CheckType<AudioStream>(); | ||
CheckType<Sound>(); | ||
CheckType<Music>(); | ||
CheckType<VrDeviceInfo>(); | ||
CheckType<VrStereoConfig>(); | ||
CheckType<FilePathList>(); | ||
CheckType<AutomationEvent>(); | ||
CheckType<AutomationEventList>(); | ||
CheckType<GuiStyleProp>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0"/> | ||
<PackageReference Include="coverlet.collector" Version="1.2.0"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Raylib.NET\Raylib.NET.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using Xunit; | ||
using Bindgen.Test; | ||
|
||
namespace RaylibNET.Test; | ||
|
||
public class RaylibTest | ||
{ | ||
private unsafe void CheckType<T>() where T : unmanaged | ||
{ | ||
Assert.True(BlittableHelper.IsBlittable<T>()); | ||
} | ||
|
||
[Fact] | ||
public void CheckTypes() | ||
{ | ||
CheckType<ConfigFlags>(); | ||
CheckType<TraceLogLevel>(); | ||
CheckType<KeyboardKey>(); | ||
CheckType<MouseButton>(); | ||
CheckType<MouseCursor>(); | ||
CheckType<GamepadButton>(); | ||
CheckType<GamepadAxis>(); | ||
CheckType<MaterialMapIndex>(); | ||
CheckType<ShaderLocationIndex>(); | ||
CheckType<ShaderUniformDataType>(); | ||
CheckType<ShaderAttributeDataType>(); | ||
CheckType<PixelFormat>(); | ||
CheckType<TextureFilter>(); | ||
CheckType<TextureWrap>(); | ||
CheckType<CubemapLayout>(); | ||
CheckType<FontType>(); | ||
CheckType<BlendMode>(); | ||
CheckType<Gesture>(); | ||
CheckType<CameraMode>(); | ||
CheckType<CameraProjection>(); | ||
CheckType<NPatchLayout>(); | ||
CheckType<Color>(); | ||
CheckType<Image>(); | ||
CheckType<Texture>(); | ||
CheckType<RenderTexture>(); | ||
CheckType<NPatchInfo>(); | ||
CheckType<GlyphInfo>(); | ||
CheckType<Font>(); | ||
CheckType<Camera3D>(); | ||
CheckType<Camera2D>(); | ||
CheckType<Mesh>(); | ||
CheckType<Shader>(); | ||
CheckType<MaterialMap>(); | ||
CheckType<Material>(); | ||
CheckType<Transform>(); | ||
CheckType<BoneInfo>(); | ||
CheckType<Model>(); | ||
CheckType<ModelAnimation>(); | ||
CheckType<Ray>(); | ||
CheckType<RayCollision>(); | ||
CheckType<BoundingBox>(); | ||
CheckType<Wave>(); | ||
CheckType<rAudioBuffer>(); | ||
CheckType<rAudioProcessor>(); | ||
CheckType<AudioStream>(); | ||
CheckType<Sound>(); | ||
CheckType<Music>(); | ||
CheckType<VrDeviceInfo>(); | ||
CheckType<VrStereoConfig>(); | ||
CheckType<FilePathList>(); | ||
CheckType<AutomationEvent>(); | ||
CheckType<AutomationEventList>(); | ||
} | ||
} |
Oops, something went wrong.