From e3c35322646a2aa164d2e7e416c71e49109af259 Mon Sep 17 00:00:00 2001 From: rory-cd Date: Mon, 24 Nov 2025 21:46:44 +1100 Subject: [PATCH 01/12] feat: bundle Windows and MacOS SplashKit libs into NuGet package Allows C# users to utilise SplashKit without the installer, by including the SplashKit native libraries within the NuGet package. --- tools/scripts/nuget-pkg/SplashKitSDK.csproj | 39 +++++++++++++++++++ tools/scripts/nuget-pkg/download-libraries.sh | 30 +------------- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/tools/scripts/nuget-pkg/SplashKitSDK.csproj b/tools/scripts/nuget-pkg/SplashKitSDK.csproj index 70cb9b2d..3e971ab4 100644 --- a/tools/scripts/nuget-pkg/SplashKitSDK.csproj +++ b/tools/scripts/nuget-pkg/SplashKitSDK.csproj @@ -1,7 +1,9 @@ + net6.0;net7.0;net8.0;net9.0 + AnyCPU SplashKitSDK enable enable @@ -21,9 +23,46 @@ GPL-3.0-or-later + + + portable + + + + + portable + + + + + + + true + runtimes/win-x64/native + PreserveNewest + true + %(FileName)%(Extension) + + + + + true + runtimes/osx-x64/native + PreserveNewest + true + %(FileName)%(Extension) + + + + true + runtimes/osx-arm64/native + PreserveNewest + true + %(FileName)%(Extension) + diff --git a/tools/scripts/nuget-pkg/download-libraries.sh b/tools/scripts/nuget-pkg/download-libraries.sh index bdc54922..b518b1ec 100755 --- a/tools/scripts/nuget-pkg/download-libraries.sh +++ b/tools/scripts/nuget-pkg/download-libraries.sh @@ -26,32 +26,4 @@ do # Remove the temporary directory rm -rf "${temp_dir}" -done - -# TODO: Add the following comment lines to SplashKitSDK.csproj (with further testing) -# AnyCPU - -# -# portable -# - -# -# portable -# - -# -# -# true -# lib\$(TargetFramework) -# PreserveNewest -# true -# %(FileName)%(Extension) -# -# -# true -# lib\$(TargetFramework) -# PreserveNewest -# true -# %(FileName)%(Extension) -# -# +done \ No newline at end of file From 1a5ac554ced2baf2a2f5e90c5d8e4651c7dd953f Mon Sep 17 00:00:00 2001 From: rory-cd Date: Sun, 7 Dec 2025 17:25:26 +1100 Subject: [PATCH 02/12] feat(tests): add C# solution for running nuget test programs This solution mimicks the existing SplashKit tests, using a launcher program (Main) to run focused test programs. Tests placed in the solution will be used to check functionality of the SplashKit NuGet package. --- tools/scripts/test/Directory.Build.props | 8 ++ tools/scripts/test/Directory.Packages.props | 5 ++ .../HelloWorld.csproj} | 25 +++--- .../scripts/test/{ => HelloWorld}/Program.cs | 5 +- tools/scripts/test/Main/Main.csproj | 13 ++++ tools/scripts/test/Main/Program.cs | 78 +++++++++++++++++++ tools/scripts/test/NuGet.config | 3 +- tools/scripts/test/NuGetTests.sln | 14 ++++ 8 files changed, 134 insertions(+), 17 deletions(-) create mode 100644 tools/scripts/test/Directory.Build.props create mode 100644 tools/scripts/test/Directory.Packages.props rename tools/scripts/test/{test.csproj => HelloWorld/HelloWorld.csproj} (55%) rename tools/scripts/test/{ => HelloWorld}/Program.cs (94%) create mode 100644 tools/scripts/test/Main/Main.csproj create mode 100644 tools/scripts/test/Main/Program.cs create mode 100644 tools/scripts/test/NuGetTests.sln diff --git a/tools/scripts/test/Directory.Build.props b/tools/scripts/test/Directory.Build.props new file mode 100644 index 00000000..25582c75 --- /dev/null +++ b/tools/scripts/test/Directory.Build.props @@ -0,0 +1,8 @@ + + + + net6.0;net7.0;net8.0;net9.0 + + NETSDK1138;NU1604 + + diff --git a/tools/scripts/test/Directory.Packages.props b/tools/scripts/test/Directory.Packages.props new file mode 100644 index 00000000..2ba83dc1 --- /dev/null +++ b/tools/scripts/test/Directory.Packages.props @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/tools/scripts/test/test.csproj b/tools/scripts/test/HelloWorld/HelloWorld.csproj similarity index 55% rename from tools/scripts/test/test.csproj rename to tools/scripts/test/HelloWorld/HelloWorld.csproj index e8105523..2f9d9b48 100644 --- a/tools/scripts/test/test.csproj +++ b/tools/scripts/test/HelloWorld/HelloWorld.csproj @@ -1,14 +1,13 @@ - - - - Exe - net7.0 - enable - enable - - + + + + Exe + enable + enable + + - - - - + + + + diff --git a/tools/scripts/test/Program.cs b/tools/scripts/test/HelloWorld/Program.cs similarity index 94% rename from tools/scripts/test/Program.cs rename to tools/scripts/test/HelloWorld/Program.cs index 33cbd7ac..ba3d672b 100644 --- a/tools/scripts/test/Program.cs +++ b/tools/scripts/test/HelloWorld/Program.cs @@ -1,3 +1,2 @@ -using static SplashKitSDK.SplashKit; - -WriteLine("Hello, World!"); +using static SplashKitSDK.SplashKit; +WriteLine("Hello, World!"); diff --git a/tools/scripts/test/Main/Main.csproj b/tools/scripts/test/Main/Main.csproj new file mode 100644 index 00000000..119c37e3 --- /dev/null +++ b/tools/scripts/test/Main/Main.csproj @@ -0,0 +1,13 @@ + + + + Exe + enable + enable + + + + + + + diff --git a/tools/scripts/test/Main/Program.cs b/tools/scripts/test/Main/Program.cs new file mode 100644 index 00000000..871bd0ed --- /dev/null +++ b/tools/scripts/test/Main/Program.cs @@ -0,0 +1,78 @@ +using System.Diagnostics; +using SplashKitSDK; + +int opt = 0; + +// Get the target framework for this program +string? targFramework = System.AppContext.TargetFrameworkName; // Output example: ".NETCoreApp,Version=v9.0" +string? targFrameworkVersion = targFramework?.Remove(0, 21); // Extracts version number (e.g. "9.0") + +// Get the specific runtime framework (e.g. ".NET 9.0.11") +string runtimeFramework = System + .Runtime + .InteropServices + .RuntimeInformation + .FrameworkDescription; + +// Get the SplashKit NuGet package version +string? nVersion = typeof(SplashKit)? + .Assembly? + .GetName()? + .Version? + .ToString(); + +// Get the project directory, to list all available projects +string solutionDir = Directory + .GetParent(Directory.GetCurrentDirectory())? + .ToString() ?? ""; + +do +{ + // Display test options + Console.WriteLine("-----------------------------------------------------"); + Console.WriteLine($" NuGet Dev Tests, using SplashKit NuGet {nVersion}"); + Console.WriteLine($" Targeting .NET {targFrameworkVersion} // Runtime {runtimeFramework}"); + Console.WriteLine("-----------------------------------------------------"); + Console.WriteLine(" -1: Quit"); + + // Search the solution directory for projects + var projectPaths = Directory.EnumerateFiles(solutionDir, "*.csproj", SearchOption.AllDirectories); + // Populate a list of all project names (except this one) + List projectNames = new(); + foreach (var project in projectPaths) + { + if (project.Contains("Main.csproj")) continue; + projectNames.Add(Path.GetFileNameWithoutExtension(project)); + } + + // Print project names + for (int i = 0; i < projectNames.Count; i++) + Console.WriteLine($" {i}: {projectNames[i]}"); + + Console.WriteLine("-----------------------------------------------------"); + Console.Write(" Select test to run: "); + + // Collect input + string? input = Console.ReadLine(); + bool inputIsValid = int.TryParse(input, out opt) && opt >= 0; + + // Run selected program + if (inputIsValid) + { + string selectedProject = projectNames[opt]; + var projectPath = Path.Combine(solutionDir, selectedProject, $"{selectedProject}.csproj"); + + // Set process options + var startInfo = new ProcessStartInfo + { + FileName = "dotnet", + Arguments = $"run --project {projectPath} -f net{targFrameworkVersion}" + }; + // Start process + System.Console.WriteLine($"\nRunning {selectedProject}...\n\n"); + Process.Start(startInfo)?.WaitForExit(); + Console.WriteLine("\n"); + } + +} while (opt != -1); +return 0; diff --git a/tools/scripts/test/NuGet.config b/tools/scripts/test/NuGet.config index 863038c7..a13060f5 100644 --- a/tools/scripts/test/NuGet.config +++ b/tools/scripts/test/NuGet.config @@ -1,6 +1,7 @@ - + + \ No newline at end of file diff --git a/tools/scripts/test/NuGetTests.sln b/tools/scripts/test/NuGetTests.sln new file mode 100644 index 00000000..bb32f590 --- /dev/null +++ b/tools/scripts/test/NuGetTests.sln @@ -0,0 +1,14 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal From 45d6144dc4227ff9ee33f9fe90f56683f27d3769 Mon Sep 17 00:00:00 2001 From: rory-cd Date: Sun, 7 Dec 2025 17:43:34 +1100 Subject: [PATCH 03/12] chore: ignore obj/ and Libraries/ in NuGet folders --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index cbf9a5b3..8498f5cc 100644 --- a/.gitignore +++ b/.gitignore @@ -99,7 +99,8 @@ logs/ out/skm out/lib/ tools/scripts/nuget-pkg/obj -tools/scripts/test/obj +tools/scripts/nuget-pkg/Libraries +tools/scripts/test/**/obj ### Debian packaging ### tools/scripts/debian/libsplashkit-dev* From e9ae8719467a35acb136a93b4a8b9a2cf010d677 Mon Sep 17 00:00:00 2001 From: rory-cd Date: Mon, 8 Dec 2025 22:55:27 +1100 Subject: [PATCH 04/12] fix: amend splashkit version targeting --- tools/scripts/test/Directory.Packages.props | 3 ++- tools/scripts/test/HelloWorld/HelloWorld.csproj | 4 ---- tools/scripts/test/Main/Main.csproj | 4 ---- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/tools/scripts/test/Directory.Packages.props b/tools/scripts/test/Directory.Packages.props index 2ba83dc1..23d25666 100644 --- a/tools/scripts/test/Directory.Packages.props +++ b/tools/scripts/test/Directory.Packages.props @@ -1,5 +1,6 @@ - + + \ No newline at end of file diff --git a/tools/scripts/test/HelloWorld/HelloWorld.csproj b/tools/scripts/test/HelloWorld/HelloWorld.csproj index 2f9d9b48..65779695 100644 --- a/tools/scripts/test/HelloWorld/HelloWorld.csproj +++ b/tools/scripts/test/HelloWorld/HelloWorld.csproj @@ -6,8 +6,4 @@ enable - - - - diff --git a/tools/scripts/test/Main/Main.csproj b/tools/scripts/test/Main/Main.csproj index 119c37e3..65779695 100644 --- a/tools/scripts/test/Main/Main.csproj +++ b/tools/scripts/test/Main/Main.csproj @@ -5,9 +5,5 @@ enable enable - - - - From b62205a93924ab2e3f17c7c075ee06f6a2b7a444 Mon Sep 17 00:00:00 2001 From: rory-cd Date: Thu, 11 Dec 2025 22:11:00 +1100 Subject: [PATCH 05/12] FIX: Update runner menu to improve UX --- tools/scripts/test/Main/Program.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/scripts/test/Main/Program.cs b/tools/scripts/test/Main/Program.cs index 871bd0ed..852fc0c7 100644 --- a/tools/scripts/test/Main/Program.cs +++ b/tools/scripts/test/Main/Program.cs @@ -33,6 +33,7 @@ Console.WriteLine($" NuGet Dev Tests, using SplashKit NuGet {nVersion}"); Console.WriteLine($" Targeting .NET {targFrameworkVersion} // Runtime {runtimeFramework}"); Console.WriteLine("-----------------------------------------------------"); + Console.WriteLine(" R: Reload tests"); Console.WriteLine(" -1: Quit"); // Search the solution directory for projects @@ -44,6 +45,7 @@ if (project.Contains("Main.csproj")) continue; projectNames.Add(Path.GetFileNameWithoutExtension(project)); } + projectNames.Sort(); // Print project names for (int i = 0; i < projectNames.Count; i++) @@ -54,7 +56,7 @@ // Collect input string? input = Console.ReadLine(); - bool inputIsValid = int.TryParse(input, out opt) && opt >= 0; + bool inputIsValid = int.TryParse(input, out opt) && opt >= 0 && opt < projectNames.Count; // Run selected program if (inputIsValid) @@ -75,4 +77,3 @@ } } while (opt != -1); -return 0; From e2c1fa0079475781845ebde07263a61eb8904191 Mon Sep 17 00:00:00 2001 From: rory-cd Date: Thu, 11 Dec 2025 22:14:14 +1100 Subject: [PATCH 06/12] NEW: Add reference to existing test resources Adds a global settings class with a field referencing the existing integration test resources. This allows for sharing of resources with existing tests, reducing repo bloat. --- tools/scripts/test/Directory.Build.props | 4 ++++ tools/scripts/test/GlobalSettings.cs | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 tools/scripts/test/GlobalSettings.cs diff --git a/tools/scripts/test/Directory.Build.props b/tools/scripts/test/Directory.Build.props index 25582c75..b5591fed 100644 --- a/tools/scripts/test/Directory.Build.props +++ b/tools/scripts/test/Directory.Build.props @@ -5,4 +5,8 @@ NETSDK1138;NU1604 + + + + diff --git a/tools/scripts/test/GlobalSettings.cs b/tools/scripts/test/GlobalSettings.cs new file mode 100644 index 00000000..a9cdb4ba --- /dev/null +++ b/tools/scripts/test/GlobalSettings.cs @@ -0,0 +1,7 @@ +public static class GlobalSettings +{ + // This path references resources used by the SplashKit Core integration test suite. + // By referencing the below field, NuGet test projects are able to share assets with the core tests. + // To utilise, put "SetResourcesPath(GlobalSettings.ResourcePath);" at the beginning of a test project + public static string ResourcePath = "../../../../coresdk/src/test/Resources"; +} \ No newline at end of file From 60ad55d3a36b8dc9762e05197bf43850dfefd1a2 Mon Sep 17 00:00:00 2001 From: rory-cd Date: Thu, 11 Dec 2025 22:21:38 +1100 Subject: [PATCH 07/12] NEW: Add translated tests to NuGet test collection Adds a selection of tests from the core integration tests to the NuGet test collection. Tests have been translated from C++ to C# with minimal other changes. --- tools/scripts/test/Audio/Audio.csproj | 9 + tools/scripts/test/Audio/Program.cs | 115 ++++++++++ tools/scripts/test/Graphics/Graphics.csproj | 9 + tools/scripts/test/Graphics/Program.cs | 201 ++++++++++++++++++ tools/scripts/test/Input/Input.csproj | 9 + tools/scripts/test/Input/Program.cs | 141 ++++++++++++ .../NetworkConversions.csproj | 9 + .../test/NetworkConversions/Program.cs | 137 ++++++++++++ tools/scripts/test/TcpNetworking/Program.cs | 172 +++++++++++++++ .../test/TcpNetworking/TcpNetworking.csproj | 9 + tools/scripts/test/UdpNetworking/Program.cs | 50 +++++ .../test/UdpNetworking/UdpNetworking.csproj | 9 + tools/scripts/test/Windows/Program.cs | 39 ++++ tools/scripts/test/Windows/Windows.csproj | 9 + 14 files changed, 918 insertions(+) create mode 100644 tools/scripts/test/Audio/Audio.csproj create mode 100644 tools/scripts/test/Audio/Program.cs create mode 100644 tools/scripts/test/Graphics/Graphics.csproj create mode 100644 tools/scripts/test/Graphics/Program.cs create mode 100644 tools/scripts/test/Input/Input.csproj create mode 100644 tools/scripts/test/Input/Program.cs create mode 100644 tools/scripts/test/NetworkConversions/NetworkConversions.csproj create mode 100644 tools/scripts/test/NetworkConversions/Program.cs create mode 100644 tools/scripts/test/TcpNetworking/Program.cs create mode 100644 tools/scripts/test/TcpNetworking/TcpNetworking.csproj create mode 100644 tools/scripts/test/UdpNetworking/Program.cs create mode 100644 tools/scripts/test/UdpNetworking/UdpNetworking.csproj create mode 100644 tools/scripts/test/Windows/Program.cs create mode 100644 tools/scripts/test/Windows/Windows.csproj diff --git a/tools/scripts/test/Audio/Audio.csproj b/tools/scripts/test/Audio/Audio.csproj new file mode 100644 index 00000000..65779695 --- /dev/null +++ b/tools/scripts/test/Audio/Audio.csproj @@ -0,0 +1,9 @@ + + + + Exe + enable + enable + + + diff --git a/tools/scripts/test/Audio/Program.cs b/tools/scripts/test/Audio/Program.cs new file mode 100644 index 00000000..0da9a3a1 --- /dev/null +++ b/tools/scripts/test/Audio/Program.cs @@ -0,0 +1,115 @@ +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +SetResourcesPath(GlobalSettings.ResourcePath); + +Console.WriteLine("Starting Audio Tests..."); + +Console.WriteLine($" Audio should be ready? {AudioReady()}"); + +Console.WriteLine(" Closing audio..."); +CloseAudio(); + +Console.WriteLine($" Audio should not be ready? {AudioReady()}"); + +Delay(500); + +Console.WriteLine(" Opening audio..."); +OpenAudio(); + +Console.WriteLine($" Is audio ready? {AudioReady()}"); + +Console.WriteLine($" Have not loaded a sound yet. Is a sound effect loaded? {HasSoundEffect("test")}"); + +SoundEffect s1 = LoadSoundEffect("test", "test.ogg"); + +Console.WriteLine($" Loaded sound effect. Is there a sound effect loaded? {HasSoundEffect("test")}"); +Console.WriteLine(" Playing loaded sound effect"); +PlaySoundEffect(s1, 1, 1.0f); + +Delay(2000); + +Console.WriteLine(" Downloading sound effect..."); +DownloadSoundEffect("text message 2", "http://soundbible.com/grab.php?id=2155&type=wav", 80); +Console.WriteLine(" Playing downloaded sound effect twice"); +PlaySoundEffect("text message 2", 2, 0.8); + +Delay(5000); + +Console.WriteLine(" Downloading music..."); +DownloadMusic("music", "http://cdn.pixabay.com/download/audio/2025/10/29/audio_dcca153626.mp3?filename=classical-royal-british-music-427631.mp3", 80); +Console.WriteLine(" Playing downloaded music for 5 seconds"); +PlayMusic("music"); + +Delay(5000); +StopMusic(); + +Console.WriteLine(" Playing named sound effect once at full volume"); +PlaySoundEffect(SoundEffectNamed("test"), 1, 1.0f); + +Delay(2000); + +Console.WriteLine(" Playing sound effect twice"); +PlaySoundEffect(SoundEffectNamed("test"), 2); + +Delay(5000); + +Console.WriteLine(" Playing sound effect"); +PlaySoundEffect(SoundEffectNamed("test"), 1); +Delay(1000); +Console.WriteLine(" Stopping sound effect"); +StopSoundEffect(SoundEffectNamed("test1")); + +SoundEffect s2 = LoadSoundEffect("dancing", "dancingFrog.wav"); +Console.WriteLine(" Fading out sound effect over 2 seconds"); +PlaySoundEffect(s2); +FadeSoundEffectOut(s2, 2000); +Delay(3000); +Console.WriteLine(" Fading out all sound effects over 5 seconds"); +PlaySoundEffect(s2); +FadeAllSoundEffectsOut(5000); + +Delay(6000); + +FreeSoundEffect(s1); + +LoadSoundEffect("test2", "error.wav"); +LoadSoundEffect("test3", "30248__streety__sword7.flac"); + +FreeAllSoundEffects(); + +LoadMusic("dance", "dancingFrog.wav"); + +Console.WriteLine(" Playing music..."); +PlayMusic(MusicNamed("dance"), 1, 1.0f); + +Delay(5000); + +Console.WriteLine(" Pausing music..."); +PauseMusic(); + +Delay(2000); + +Console.WriteLine(" Resuming music..."); +ResumeMusic(); + +Delay(5000); + +Console.WriteLine(" Stopping music..."); +StopMusic(); + +Delay(2000); +Console.WriteLine(" Fading in music over 2 secs..."); +FadeMusicIn("dance", 2000); +Delay(5000); +Console.WriteLine(" Fading out music over 5 secs..."); +FadeMusicOut(5000); +Delay(5000); + +Console.WriteLine(" Closing audio..."); +CloseAudio(); + +Console.WriteLine($" Is audio ready? {AudioReady()}"); + +Console.WriteLine("Audio Tests Ended"); +Delay(5000); diff --git a/tools/scripts/test/Graphics/Graphics.csproj b/tools/scripts/test/Graphics/Graphics.csproj new file mode 100644 index 00000000..65779695 --- /dev/null +++ b/tools/scripts/test/Graphics/Graphics.csproj @@ -0,0 +1,9 @@ + + + + Exe + enable + enable + + + diff --git a/tools/scripts/test/Graphics/Program.cs b/tools/scripts/test/Graphics/Program.cs new file mode 100644 index 00000000..5bae449a --- /dev/null +++ b/tools/scripts/test/Graphics/Program.cs @@ -0,0 +1,201 @@ +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +void TestDrawingOnNewWindow() +{ + Bitmap userImage; + + userImage = CreateBitmap ("user_image", 20, 20); + SaveBitmap(userImage, "0"); + ClearBitmap (userImage, Color.BrightGreen); + SaveBitmap(userImage, "1"); + FillRectangleOnBitmap (userImage, Color.Black, 0, 0, 10, 10); + SaveBitmap(userImage, "2"); + + Window myWindow = OpenWindow ("Black TL+BR", 200, 200); + ClearWindow (myWindow, Color.White); + FillRectangleOnBitmap (userImage, Color.Black, 10, 10, 10, 10); + SaveBitmap(userImage, "3"); + + DrawBitmapOnWindow (myWindow, userImage, 0, 0); + SaveBitmap(userImage, "4"); + RefreshWindow(myWindow); + + Bitmap userImage1; + + userImage1 = CreateBitmap ("user_image1", 20, 20); + ClearBitmap (userImage1, Color.Black); + FillRectangleOnBitmap (userImage1, Color.BrightGreen, 10, 0, 10, 10); + FillRectangleOnBitmap (userImage1, Color.BrightGreen, 0, 10, 10, 10); + + DrawBitmapOnWindow (myWindow, userImage1, 30, 0); + SaveBitmap(userImage, "4"); + + // Get pixel from bitmap + Color bitmapClr0 = GetPixel(userImage1, 0, 0); + Color bitmapClr1 = GetPixel(userImage1, 0, 10); + string bitmapClrStr0 = "Clr@0,0 " + ColorToString(bitmapClr0); + string bitmapClrStr1 = "Clr@0,10 " + ColorToString(bitmapClr1); + DrawTextOnWindow(myWindow, bitmapClrStr0, Color.Black, 0, 20); + DrawTextOnWindow(myWindow, bitmapClrStr1, Color.Black, 0, 30); + RefreshWindow(myWindow); + + Delay(5000); + + CloseWindow(myWindow); + FreeBitmap(userImage); +} + +void TestClipping(Window w1) +{ + ClearWindow(w1, Color.WhiteSmoke); + DrawText("White Smoke Bottom Right", Color.Black, 10, 280); + SetClip(w1, RectangleFrom(0, 0, 250, 250)); + FillRectangle(StringToColor("#ff0000ff"), 0, 0, 300, 300, OptionDrawTo(w1)); + DrawText("Testing Clipping", Color.Black, 10, 10); + DrawText("Red Top Left", Color.Black, 10, 20); + + PushClip(RectangleFrom(50, 50, 250, 250)); + FillRectangle(StringToColor("#00ff00ff"), 0, 0, 300, 300, OptionDrawTo(w1)); + + PushClip(RectangleFrom(145, 0, 10, 300)); + FillRectangle(Color.Gold, 0, 0, 300, 300, OptionDrawTo(w1)); + + PopClip(); + PushClip(RectangleFrom(0, 145, 300, 10)); + FillRectangle(Color.Gold, 0, 0, 300, 300, OptionDrawTo(w1)); + + ResetClip(); + + RefreshScreen(); + Delay(3000); + + Bitmap bmp = CreateBitmap("bmp", 100, 100); + SetClip(bmp, RectangleFrom(0, 0, 75, 75)); + FillRectangle(Color.Red, 0, 0, 100, 100, OptionDrawTo(bmp)); + PushClip(bmp, RectangleFrom(0, 0, 50, 50)); + FillRectangle(Color.Green, 0, 0, 100, 100, OptionDrawTo(bmp)); + + PushClip(bmp, RectangleFrom(20, 0, 10, 100)); + FillRectangle(Color.Gold, 0, 0, 100, 100, OptionDrawTo(bmp)); + PopClip(bmp); + + PushClip(bmp, RectangleFrom(0, 20, 100, 10)); + FillRectangle(Color.Gold, 0, 0, 100, 100, OptionDrawTo(bmp)); + PopClip(bmp); + + PushClip(bmp, RectangleFrom(0, 0, 25, 25)); + FillRectangle(Color.Blue, 0, 0, 100, 100, OptionDrawTo(bmp)); + ResetClip(bmp); + + ClearWindow(w1, Color.Silver); + DrawText("B > G > R from top left of bmp", Color.Black, 10, 10); + DrawBitmap(bmp, 100, 100); + SaveBitmap(bmp, "bmp"); + RefreshScreen(); + Delay(3000); +} + +SetResourcesPath(GlobalSettings.ResourcePath); + +Console.WriteLine("Checking the number of displays and their details"); +Console.WriteLine($"There are {NumberOfDisplays()} displays"); +Console.WriteLine("------------------------"); + +for (int i = 0; i < NumberOfDisplays(); i++) +{ + Display d = DisplayDetails((uint)i); + Console.WriteLine($"Display {i}"); + Console.WriteLine($" name: {DisplayName(d)}"); + Console.WriteLine($" @: {DisplayX(d)}, {DisplayY(d)}"); + Console.WriteLine($" s: {DisplayWidth(d)}x{DisplayHeight(d)}"); + Console.WriteLine("------------------------"); +} + +TestDrawingOnNewWindow(); + +Window w1 = OpenWindow("Testing Graphics", 300, 300); + +TestClipping(w1); + +// Open a second window next to the first for testing on_window functions +Point2D w1Pos = WindowPosition(w1); +Window w2 = OpenWindow("Testing Second Window", 300, 300); +MoveWindowTo(w2, (int)(w1Pos.X + 350), (int)w1Pos.Y); + +Color inClr = StringToColor("#ffeebbaa"); + +Color clr, clr2; + +while ( !(WindowCloseRequested(w1) || WindowCloseRequested(w2)) ) +{ + ProcessEvents(); + + // First window + for (int x = 0; x < WindowWidth(w1); x++) + { + for (int y = 0; y < WindowHeight(w1); y++) + { + clr = HSBColor(x / (WindowWidth(w1) * 1.0f), y / (WindowHeight(w1) * 1.0f), y / (WindowHeight(w1) * 1.0f)); + DrawPixel(clr, x, y); + } + } + + FillRectangle(inClr, 100, 100, 100, 100); + + clr = GetPixel(MousePosition()); + + string clrString = "Color " + ColorToString(clr); + string rString = "Red " + RedOf(clr).ToString(); + string gString = "Green " + GreenOf(clr).ToString(); + string bString = "Blue " + BlueOf(clr).ToString(); + string aString = "Alpha " + AlphaOf(clr).ToString(); + string hString = "Hue " + HueOf(clr).ToString(); + string sString = "Sat " + SaturationOf(clr).ToString(); + string briString = "Bri " + BrightnessOf(clr).ToString(); + + DrawText(clrString, Color.Black, 20, 180); + DrawText(rString, Color.Black, 20, 190); + DrawText(gString, Color.Black, 20, 200); + DrawText(bString, Color.Black, 20, 210); + DrawText(aString, Color.Black, 20, 220); + DrawText(hString, Color.Black, 20, 240); + DrawText(sString, Color.Black, 20, 250); + DrawText(briString, Color.Black, 20, 260); + + // Second window + for (int x = 0; x < WindowWidth(w2); x++) + { + for (int y = 0; y < WindowHeight(w2); y++) + { + clr2 = HSBColor(x / (WindowWidth(w2) * 1.0f), y / (WindowHeight(w2) * 1.0f), y / (WindowHeight(w2) * 1.0f)); + DrawPixelOnWindow(w2, clr2, x, y); + } + } + + FillRectangleOnWindow(w2, Color.Magenta, 100, 100, 100, 100); + + clr2 = GetPixel(w2, MousePosition()); + + string clrString2 = "Color " + ColorToString(clr2); + string rString2 = "Red " + RedOf(clr2).ToString(); + string gString2 = "Green " + GreenOf(clr2).ToString(); + string bString2 = "Blue " + BlueOf(clr2).ToString(); + string aString2 = "Alpha " + AlphaOf(clr2).ToString(); + string hString2 = "Hue " + HueOf(clr2).ToString(); + string sString2 = "Sat " + SaturationOf(clr2).ToString(); + string briString2 = "Bri " + BrightnessOf(clr2).ToString(); + + DrawTextOnWindow(w2, clrString2, Color.Black, 20, 180); + DrawTextOnWindow(w2, rString2, Color.Black, 20, 190); + DrawTextOnWindow(w2, gString2, Color.Black, 20, 200); + DrawTextOnWindow(w2, bString2, Color.Black, 20, 210); + DrawTextOnWindow(w2, aString2, Color.Black, 20, 220); + DrawTextOnWindow(w2, hString2, Color.Black, 20, 240); + DrawTextOnWindow(w2, sString2, Color.Black, 20, 250); + DrawTextOnWindow(w2, briString2, Color.Black, 20, 260); + + RefreshScreen(); +} + +CloseAllWindows(); diff --git a/tools/scripts/test/Input/Input.csproj b/tools/scripts/test/Input/Input.csproj new file mode 100644 index 00000000..65779695 --- /dev/null +++ b/tools/scripts/test/Input/Input.csproj @@ -0,0 +1,9 @@ + + + + Exe + enable + enable + + + diff --git a/tools/scripts/test/Input/Program.cs b/tools/scripts/test/Input/Program.cs new file mode 100644 index 00000000..41c6e080 --- /dev/null +++ b/tools/scripts/test/Input/Program.cs @@ -0,0 +1,141 @@ +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +string keyTyped = "", keyDown = "", keyUp = ""; + +void OnKeyTyped(int code) +{ + keyTyped = KeyName((KeyCode)code); +} + +void OnKeyDown(int code) +{ + keyDown = KeyName((KeyCode)code); +} + +void OnKeyUp(int code) +{ + keyUp = KeyName((KeyCode)code); +} + +SetResourcesPath(GlobalSettings.ResourcePath); + +RegisterCallbackOnKeyTyped(OnKeyTyped); +RegisterCallbackOnKeyDown(OnKeyDown); +RegisterCallbackOnKeyUp(OnKeyUp); + +Rectangle rect = new() +{ + X = 230.0f, + Y = 50.0f, + Width = 200.0f, + Height = 30.0f +}; + +Window w1 = OpenWindow("Test Input", 600, 600); +Window w2 = OpenWindow("Test Input Window 2", 600, 600); + +LoadFont("hara", "hara.ttf"); +LoadFont("kochi", "kochi-gothic-subst"); + +StartReadingText(rect); + +SetCurrentWindow(w2); + +StartReadingText(rect, "スプラッシュ・キット"); + +Color back = Color.Wheat; + +while (ReadingText(w1) || ReadingText(w2)) +{ + ProcessEvents(); + + if (QuitRequested() || WindowCloseRequested(w1) || WindowCloseRequested(w2)) break; + + SetCurrentWindow(w1); + + if (!TextEntryCancelled(w1)) + ClearScreen(Color.White); + else + ClearScreen(Color.Peru); + + DrawText("Enter english string: ", Color.Navy, "hara", 18, 30, 50); + DrawCollectedText(Color.Black, FontNamed("hara"), 18, OptionDefaults()); + + if (!ReadingText(w1)) + { + DrawText("Read: ", Color.Blue, "hara", 18, 30, 80); + DrawText(TextInput(w1), Color.Blue, "hara", 18, 30, 110); + } + + string location = "Mouse location: "; + location += MouseX().ToString() + ":" + MouseY().ToString(); + + string leftClicked = "Left click status: "; + leftClicked += MouseClicked(MouseButton.LeftButton).ToString() + " up: " + MouseUp(MouseButton.LeftButton).ToString() + " down: " + MouseDown(MouseButton.LeftButton).ToString(); + + string rightClicked = "Right click status: "; + rightClicked += MouseClicked(MouseButton.RightButton).ToString() + " up: " + MouseUp(MouseButton.RightButton).ToString() + " down: " + MouseDown(MouseButton.RightButton).ToString(); + + string anyKeyInput = "Any keys pressed: "; + if(AnyKeyPressed()) anyKeyInput += "yes"; + else anyKeyInput += "no"; + + string keyDetails = "T key is "; + if (KeyDown(KeyCode.TKey)) keyDetails += "down"; + if (KeyUp(KeyCode.TKey)) keyDetails += "up"; + if (KeyReleased(KeyCode.TKey)) keyDetails += " - released"; + if (KeyTyped(KeyCode.TKey)) keyDetails += " - typed"; + if (KeyTyped(KeyCode.FKey)) WindowToggleFullscreen(WindowWithFocus()); + if (KeyTyped(KeyCode.BKey)) WindowToggleBorder(WindowWithFocus()); + + DrawText(location, Color.Plum, "hara", 14, 18, 200); + DrawText(leftClicked, Color.Plum, "hara", 14, 18, 220); + DrawText(rightClicked, Color.Plum, "hara", 14, 18, 240); + DrawText(anyKeyInput, Color.Plum, "hara", 14, 18, 250); + DrawText(keyDetails, Color.Plum, "hara", 14, 18, 280); + DrawText(keyDown, Color.Plum, "hara", 14, 18, 300); + DrawText(keyUp, Color.Plum, "hara", 14, 18, 320); + DrawText(keyTyped, Color.Plum, "hara", 14, 18, 340); + + SetCurrentWindow(w2); + + if (KeyTyped(KeyCode.CKey)) + { + back = RandomRGBColor(255); + } + + ClearScreen(back); + DrawText("Enter Japanese string: ", Color.Navy, "hara", 18, 30, 50); + DrawCollectedText(Color.Black, FontNamed("kochi"), 18, OptionDefaults()); + + if (!ReadingText(w2)) + { + DrawText("Read: ", Color.Blue, "hara", 18, 30, 80); + DrawText(TextInput(w2), Color.Blue, "kochi", 18, 30, 110); + } + + // Get location of mouse in W2 + location = "Mouse location: "; + location += MouseX().ToString() + ":" + MouseY().ToString(); + + DrawText(location, Color.Plum, "hara", 14, 18, 200); + DrawText(leftClicked, Color.Plum, "hara", 14, 18, 220); + DrawText(rightClicked, Color.Plum, "hara", 14, 18, 240); + DrawText(anyKeyInput, Color.Plum, "hara", 14, 18, 250); + DrawText(keyDetails, Color.Plum, "hara", 14, 18, 280); + DrawText(keyDown, Color.Plum, "hara", 14, 18, 300); + DrawText(keyUp, Color.Plum, "hara", 14, 18, 320); + DrawText(keyTyped, Color.Plum, "hara", 14, 18, 340); + + RefreshScreen(); +} + +CloseWindow("Test Input"); +CloseWindow("Test Input Window 2"); + +DeregisterCallbackOnKeyTyped(OnKeyTyped); +DeregisterCallbackOnKeyDown(OnKeyDown); +DeregisterCallbackOnKeyUp(OnKeyUp); + +FreeAllFonts(); diff --git a/tools/scripts/test/NetworkConversions/NetworkConversions.csproj b/tools/scripts/test/NetworkConversions/NetworkConversions.csproj new file mode 100644 index 00000000..65779695 --- /dev/null +++ b/tools/scripts/test/NetworkConversions/NetworkConversions.csproj @@ -0,0 +1,9 @@ + + + + Exe + enable + enable + + + diff --git a/tools/scripts/test/NetworkConversions/Program.cs b/tools/scripts/test/NetworkConversions/Program.cs new file mode 100644 index 00000000..ce14196a --- /dev/null +++ b/tools/scripts/test/NetworkConversions/Program.cs @@ -0,0 +1,137 @@ +using static SplashKitSDK.SplashKit; +using System.Diagnostics; + +const string TestIp = "127.0.0.1"; +const string TestIpHex = "0x7F000001"; +const string TestMac = "00:00:00:00:00:00"; +const string TestMacHex = "0x000000000000"; + +void RunEncodingDecodingTests() +{ + // Incomplete ip address tests + Trace.Assert(Ipv4ToHex("127.0.0") == "0x7F000000"); + Trace.Assert(DecToIpv4(Ipv4ToDec("127.0.0")) == "127.0.0.0"); + Trace.Assert(DecToIpv4(Ipv4ToDec("127,0.0")) == "127.0.0.0"); + Trace.Assert(DecToIpv4(Ipv4ToDec("")) == "0.0.0.0"); + + uint tooSmallInt = 4000; + Trace.Assert(DecToIpv4(tooSmallInt) == "0.0.15.160"); + + // Complete ip address tests + Trace.Assert(DecToIpv4(Ipv4ToDec(TestIp)) == TestIp); + Trace.Assert(DecToHex(Ipv4ToDec(TestIp)) == TestIpHex); + Trace.Assert(Ipv4ToHex(TestIp) == TestIpHex); + Trace.Assert(HexStrToIpv4(TestIpHex) == TestIp); + Trace.Assert(MyIP() == "127.0.0.1"); + + Console.WriteLine("All encoding/decoding tests passed!\n"); +} + +void MacToHexTest() +{ + Trace.Assert(MacToHex("00:00:00:00:00:00") == "0x000000000000"); + Trace.Assert(MacToHex("FF:FF:FF:FF:FF:FF") == "0xFFFFFFFFFFFF"); + Trace.Assert(MacToHex("12:34:56:78:9A:BC") == "0x123456789ABC"); + Trace.Assert(MacToHex("AB:CD:EF:12:34:56") == "0xABCDEF123456"); + Trace.Assert(MacToHex(TestMac) == TestMacHex); + + string result = MacToHex("AB:CD:EF:12:34:56"); + Trace.Assert(result == "0xABCDEF123456"); + + // Additional positive tests + Trace.Assert(MacToHex("01:23:45:67:89:AB") == "0x0123456789AB"); + Trace.Assert(MacToHex("DE:AD:BE:EF:00:01") == "0xDEADBEEF0001"); + + // Negative tests + Trace.Assert(MacToHex("00:00:00:00:00:00") != "0xFFFFFFFFFFFF"); + Trace.Assert(MacToHex("FF:FF:FF:FF:FF:FF") != "0x000000000000"); + Trace.Assert(MacToHex("12:34:56:78:9A:BC") != "0xABCDEF123456"); + Trace.Assert(MacToHex("AB:CD:EF:12:34:56") != "0x123456789ABC"); + + // Additional negative tests + Trace.Assert(MacToHex("01:23:45:67:89:AB") != "0xDEADBEEF0001"); + Trace.Assert(MacToHex("DE:AD:BE:EF:00:01") != "0x0123456789AB"); + + // Tests for invalid types of MAC addresses + Console.WriteLine("Testing invalid MAC addresses (Expect ERROR):"); + Trace.Assert(MacToHex("01:23:45:67:89") != "0x0123456789ABC"); + Trace.Assert(MacToHex("01:23:45:AB") != "0x0123456789"); + Trace.Assert(MacToHex("01:23:45:67:89:AB:CD") != "0x0123456789AB"); + Trace.Assert(MacToHex("01:23:67:89:AB") != "0x0123456789ABCD"); + Trace.Assert(MacToHex("0000") == ""); + + Console.WriteLine($"All MAC to Hexadecimal tests passed!\nAB:CD:EF:12:34:56 in hex: {result}\n"); +} + +void HexToMacTest() +{ + Trace.Assert(HexToMac("0x000000000000") == "00:00:00:00:00:00"); + Trace.Assert(HexToMac("0xFFFFFFFFFFFF") == "FF:FF:FF:FF:FF:FF"); + Trace.Assert(HexToMac("0x123456789ABC") == "12:34:56:78:9A:BC"); + Trace.Assert(HexToMac("0xABCDEF123456") != "AB:CD:GF:12:34:56"); + Trace.Assert(HexToMac("0xABCDEF123456") == "AB:CD:EF:12:34:56"); + + string result = HexToMac(TestMacHex); + Trace.Assert(result == TestMac); + + // Additional positive tests + Trace.Assert(HexToMac("0x0123456789AB") == "01:23:45:67:89:AB"); + Trace.Assert(HexToMac("0xDEADBEEF0001") == "DE:AD:BE:EF:00:01"); + + // Negative tests + Trace.Assert(HexToMac("0x000000000000") != "FF:FF:FF:FF:FF:FF"); + Trace.Assert(HexToMac("0xFFFFFFFFFFFF") != "00:00:00:00:00:00"); + Trace.Assert(HexToMac("0x123456789ABC") != "AB:CD:EF:12:34:56"); + + // Additional negative tests + Trace.Assert(HexToMac("0x0123456789AB") != "DE:AD:BE:EF:00:01"); + Trace.Assert(HexToMac("0xDEADBEEF0001") != "01:23:45:67:89:AB"); + + // Tests for invalid types of hex values + Console.WriteLine("Testing invalid hex values (Expect ERROR):"); + Trace.Assert(HexToMac("0x123456789AB") != "01:23:45:67:89:AB"); + Trace.Assert(HexToMac("0x123456789ABCD") != "01:23:45:67:89:AB"); + Trace.Assert(HexToMac("000000000000") != "00:00:00:00:00:00"); + + Console.WriteLine($"All Hexadecimal to MAC tests passed!\n{TestMacHex} in MAC format: {result}"); + Console.WriteLine("-------------------------------------\n"); +} + +void IsValidMacTest() +{ + // Valid MAC addresses + Trace.Assert(IsValidMac("00:00:00:00:00:00")); + Trace.Assert(IsValidMac("FF:FF:FF:FF:FF:FF")); + Trace.Assert(IsValidMac("12:34:56:78:9A:BC")); + Trace.Assert(IsValidMac("AB:CD:EF:12:34:56")); + Trace.Assert(IsValidMac("01:23:45:67:89:AB")); + Trace.Assert(IsValidMac("DE:AD:BE:EF:00:01")); + + // Invalid MAC addresses - wrong length + Trace.Assert(!IsValidMac("00:00:00:00:00:0")); + Trace.Assert(!IsValidMac("FF:FF:FF:FF:FF:F")); + Trace.Assert(!IsValidMac("12:34:56:78:9A:B")); + Trace.Assert(!IsValidMac("AB:CD:EF:12:34:5")); + Trace.Assert(!IsValidMac("AB:CD:EF:12:34:567")); + Trace.Assert(!IsValidMac("AB:CD:EF:12:34")); + + // Invalid MAC addresses - invalid characters + Trace.Assert(!IsValidMac("GG:00:00:00:00:00")); + Trace.Assert(!IsValidMac("00:00:00:00:00:GG")); + Trace.Assert(!IsValidMac("ZZ:ZZ:ZZ:ZZ:ZZ:ZZ")); + Trace.Assert(!IsValidMac("12:34:56:78:9A:BG")); + + // Invalid MAC addresses - wrong format + Trace.Assert(!IsValidMac("00-00-00-00-00-00")); + Trace.Assert(!IsValidMac("0000.0000.0000")); + Trace.Assert(!IsValidMac("000000000000")); + Trace.Assert(!IsValidMac("00:00:00:00:00")); + Trace.Assert(!IsValidMac("00:00:00:00:00:00:00")); + + Console.WriteLine("All MAC address validation tests passed!\n"); +} + +RunEncodingDecodingTests(); +MacToHexTest(); +HexToMacTest(); +IsValidMacTest(); diff --git a/tools/scripts/test/TcpNetworking/Program.cs b/tools/scripts/test/TcpNetworking/Program.cs new file mode 100644 index 00000000..1ff53be4 --- /dev/null +++ b/tools/scripts/test/TcpNetworking/Program.cs @@ -0,0 +1,172 @@ +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +const int Server1Port = 5000; +const int Server2Port = Server1Port + 1; + +ServerSocket svr; +Connection lConA, lConB, lTmp; +Message msg; + +void PauseTest() +{ + Console.WriteLine("Press any key to continue"); + Console.ReadLine(); +} + +void CheckMessages() +{ + Console.WriteLine("Checking for messages"); + CheckNetworkActivity(); + + if (HasMessages()) + { + Console.WriteLine("Reading messages received for client"); + while (HasMessages(lConA)) + { + msg = ReadMessage(lConA); + Console.WriteLine($" -> {MessageData(msg)} from {MessageHost(msg)}:{MessagePort(msg)}"); + CloseMessage(msg); + } + + Console.WriteLine("Reading messages received for ToSvr client"); + while (HasMessages("ToSvr")) + { + msg = ReadMessage("ToSvr"); + Console.WriteLine($" -> {MessageData(msg)} from {MessageHost(msg)}:{MessagePort(msg)}"); + CloseMessage(msg); + } + + for (int i = 0; i < ConnectionCount(svr); ++i) + { + lTmp = RetrieveConnection(svr, i); + if (HasMessages(lTmp)) + { + Console.WriteLine($" -> {ReadMessageData(lTmp)} from {ConnectionPort(lTmp)}"); + } + } + + PauseTest(); + } + else + { + Console.WriteLine("No messages received"); + } +} + +Console.WriteLine("Starting"); + +svr = CreateServer("svr1", Server1Port); +CreateServer("svr2", Server2Port); + +Console.WriteLine($"Listening on {Server1Port} and {Server2Port}."); +PauseTest(); + +Console.WriteLine($"Connecting to Port (x2) {Server1Port}"); +lConA = OpenConnection("lConA", "127.0.0.1", Server1Port); +OpenConnection("ToSvr", "127.0.0.1", Server1Port); + +Console.WriteLine($"ToSvr is open: {IsConnectionOpen("ToSvr")}"); +Console.WriteLine("Fred is open? Expect warning/false:"); +Console.WriteLine(IsConnectionOpen("Fred")); +Console.WriteLine("Expect warning below:"); + +CheckNetworkActivity(); + +Console.WriteLine($"Are there new connections? {HasNewConnections()}"); +Console.WriteLine($"New Connection to {Server1Port}:{ServerHasNewConnection(svr)}"); +Console.WriteLine($" Number of connections: {ConnectionCount(svr)}"); + +lConB = LastConnection(svr); + +CheckNetworkActivity(); +Console.WriteLine($"Are there new connections? {HasNewConnections()}"); +Console.WriteLine($"New Connection to {Server1Port}:{ServerHasNewConnection(svr)}"); +Console.WriteLine($" Number of connections: {ConnectionCount(svr)}"); + +PauseTest(); +Console.WriteLine("Checking for messages -- shouldn't be any"); +CheckMessages(); + +Console.WriteLine("Sending messages"); +SendMessageTo("To server --> from client", lConA); +SendMessageTo("How are you :)", lConA); +SendMessageTo("To server --> from named client", "ToSvr"); +SendMessageTo(new string('7', 509 - 4), lConA); +SendMessageTo("1234567", lConA); +SendMessageTo("0987654", lConA); +SendMessageTo(new string('A', 876), lConA); + +SendMessageTo(new string('7', 509 - 4), lConB); +SendMessageTo("Hello Client", lConB); +SendMessageTo(new string('A', 876), lConB); + +PauseTest(); +CheckMessages(); +CheckMessages(); +CheckMessages(); + +Console.WriteLine($"Closing client - {CloseConnection(lConA)}"); +PauseTest(); + +Console.WriteLine($"Client still: {lConA}"); +Console.WriteLine($"Test message send (to closed client): {SendMessageTo(new string('A', 876), lConB)}"); + +PauseTest(); +Console.WriteLine($"Test message send (expect false): {SendMessageTo(new string('A', 876), lConB)}"); + +Console.WriteLine($"Server still connected to client: {IsConnectionOpen(RetrieveConnection(svr, 0))}"); + +Console.WriteLine($"Closing server's client connection (should already by closed -- just testing): {CloseConnection(lConB)}"); +Console.WriteLine($"Server connections: {ConnectionCount(svr)}"); +PauseTest(); + +Console.WriteLine("Checking for activity"); +CheckNetworkActivity(); + +Console.WriteLine("Opening a new connection"); + +lConA = OpenConnection("lConA1", "127.0.0.1", Server1Port); +Console.WriteLine($"Reconnected: {lConA}"); + +CheckNetworkActivity(); +lConB = LastConnection(svr); +Console.WriteLine($"Connections = {ConnectionCount(svr)}"); + +SendMessageTo("New connection --> to server", lConA); +SendMessageTo("New connection --> to client", lConB); + +CheckMessages(); + +Console.WriteLine($"Closing server: {CloseServer(svr)}"); +PauseTest(); + +Console.WriteLine("Can connect to old server? Expect error/false:"); +Console.WriteLine(OpenConnection("oldsvr", "127.0.0.1", Server1Port) != null); +PauseTest(); + +Console.WriteLine("Restarting server..."); +svr = CreateServer("svr1", Server1Port); + +Reconnect(lConA); +Reconnect("ToSvr"); + +CheckNetworkActivity(); +lConB = LastConnection(svr); + +CheckNetworkActivity(); + +BroadcastMessage("Hello Everyone"); +BroadcastMessage("Hello Everyone on svr", svr); + +SendMessageTo("Another message --> to server", lConA); +SendMessageTo("Another message --> to client", lConB); +SendMessageTo("Another message --> from named client", "ToSvr"); +SendMessageTo("Another message --> to named client", LastConnection(svr)); + +CheckMessages(); +CheckMessages(); + +Console.WriteLine("Close all"); +CloseAllConnections(); +CloseAllServers(); diff --git a/tools/scripts/test/TcpNetworking/TcpNetworking.csproj b/tools/scripts/test/TcpNetworking/TcpNetworking.csproj new file mode 100644 index 00000000..65779695 --- /dev/null +++ b/tools/scripts/test/TcpNetworking/TcpNetworking.csproj @@ -0,0 +1,9 @@ + + + + Exe + enable + enable + + + diff --git a/tools/scripts/test/UdpNetworking/Program.cs b/tools/scripts/test/UdpNetworking/Program.cs new file mode 100644 index 00000000..0cc012bf --- /dev/null +++ b/tools/scripts/test/UdpNetworking/Program.cs @@ -0,0 +1,50 @@ +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +const int ListenPortB = 5000; + +void PauseUdpTest() +{ + Console.WriteLine("Press any key to continue"); + Console.ReadLine(); +} + +Console.WriteLine($"Listening for UDP connections on port {ListenPortB}"); +ServerSocket server = CreateServer("MyServer", ListenPortB, ConnectionType.UDP); +PauseUdpTest(); + +Console.WriteLine("Creating connection to send data to server"); +Connection toServer = OpenConnection("to_server", "127.0.0.1", ListenPortB, ConnectionType.UDP); +PauseUdpTest(); + +Console.WriteLine("Sending message to server"); +SendMessageTo("Hello UDP", toServer); +Delay(1000); + +Console.WriteLine("Checking activity"); +CheckNetworkActivity(); +Console.WriteLine($"Server got message: {HasMessages(server)}"); +Message msg = ReadMessage(server); +Console.WriteLine($"Message: {MessageData(msg)}"); +PauseUdpTest(); + +Console.WriteLine($"Sending message to client {MessageHost(msg)}:{MessagePort(msg)}"); +Connection toClient = OpenConnection("to_client", MessageHost(msg), MessagePort(msg), ConnectionType.UDP); +CloseMessage(msg); + +Console.WriteLine("Connection created"); +SendMessageTo("Hello Client", toClient); +Delay(100); +CheckNetworkActivity(); + +Console.WriteLine($"Client got message: {HasMessages("to_server")}"); +Console.WriteLine($"Message: {ReadMessageData(toServer)}"); + +CloseConnection(toServer); + +Console.WriteLine($"Closing UDP socket on port {ListenPortB}"); +CloseServer(server); + +Console.WriteLine("Close all"); +CloseAllConnections(); +CloseAllServers(); diff --git a/tools/scripts/test/UdpNetworking/UdpNetworking.csproj b/tools/scripts/test/UdpNetworking/UdpNetworking.csproj new file mode 100644 index 00000000..65779695 --- /dev/null +++ b/tools/scripts/test/UdpNetworking/UdpNetworking.csproj @@ -0,0 +1,9 @@ + + + + Exe + enable + enable + + + diff --git a/tools/scripts/test/Windows/Program.cs b/tools/scripts/test/Windows/Program.cs new file mode 100644 index 00000000..8a160149 --- /dev/null +++ b/tools/scripts/test/Windows/Program.cs @@ -0,0 +1,39 @@ +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +SetResourcesPath(GlobalSettings.ResourcePath); + +Window w1 = OpenWindow("Hello World", 800, 600); + +DisplayDialog("Tests", "About to run window tests...", LoadFont("dialog", "hara.ttf"), 14); + +Font fnt = LoadFont("hara", "hara.ttf"); +Bitmap light = LoadBitmap("light", "on_med.png"); + +WindowSetIcon(w1, light); + +Bitmap test = DownloadBitmap("blah", "http://www.swinburne.edu.au/cwis/php_pages/webapps/marketing/promotiles-v3/assets/img/RgakQ.jpg", 80); + +Console.WriteLine("Expecting bad bitmap pointer error: "); +DrawBitmap("fred", 75, 100); + +while (!QuitRequested()) +{ + ProcessEvents(); + + DrawBitmap(test, 0, 0); + DrawBitmap(light, 10, 100); + DrawBitmap("light", 75, 100); + + DrawCircle(Color.Red, 10, 10, 10); + FillCircle(Color.Green, 50, 10, 10); + + DrawText("Hello World", Color.Blue, fnt, 64, 200, 100); + + RefreshScreen(); +} + +FreeBitmap(light); +CloseWindow(WindowNamed("Hello World")); + +Delay(500); diff --git a/tools/scripts/test/Windows/Windows.csproj b/tools/scripts/test/Windows/Windows.csproj new file mode 100644 index 00000000..65779695 --- /dev/null +++ b/tools/scripts/test/Windows/Windows.csproj @@ -0,0 +1,9 @@ + + + + Exe + enable + enable + + + From 492ee982f89a094a2a3e5a6377fc2353b4c79754 Mon Sep 17 00:00:00 2001 From: rory-cd Date: Fri, 12 Dec 2025 22:52:20 +1100 Subject: [PATCH 08/12] FIX: Remove symbolic link to C# bindings, include in .csproj instead Removes the symbolic link to the C# bindings (SplashKit.cs) in favor of a compilation link in .csproj. Symbolic links are not respected by MSYS2, and therefore the NuGet package build was failing. Using the MSBuild compile item improves cross-platform compatibility. --- tools/scripts/nuget-pkg/SplashKit.cs | 1 - tools/scripts/nuget-pkg/SplashKitSDK.csproj | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) delete mode 120000 tools/scripts/nuget-pkg/SplashKit.cs diff --git a/tools/scripts/nuget-pkg/SplashKit.cs b/tools/scripts/nuget-pkg/SplashKit.cs deleted file mode 120000 index b2e169c3..00000000 --- a/tools/scripts/nuget-pkg/SplashKit.cs +++ /dev/null @@ -1 +0,0 @@ -../../../generated/csharp/SplashKit.cs \ No newline at end of file diff --git a/tools/scripts/nuget-pkg/SplashKitSDK.csproj b/tools/scripts/nuget-pkg/SplashKitSDK.csproj index 3e971ab4..857f992f 100644 --- a/tools/scripts/nuget-pkg/SplashKitSDK.csproj +++ b/tools/scripts/nuget-pkg/SplashKitSDK.csproj @@ -38,6 +38,9 @@ + + + true From f384c195e4958f2dc9cf4add0c8cad405942a1fe Mon Sep 17 00:00:00 2001 From: rory-cd Date: Mon, 15 Dec 2025 00:46:03 +1100 Subject: [PATCH 09/12] FIX: Add newline to end of files --- tools/scripts/test/Directory.Packages.props | 2 +- tools/scripts/test/GlobalSettings.cs | 4 ++-- tools/scripts/test/NuGet.config | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/scripts/test/Directory.Packages.props b/tools/scripts/test/Directory.Packages.props index 23d25666..fe0e6362 100644 --- a/tools/scripts/test/Directory.Packages.props +++ b/tools/scripts/test/Directory.Packages.props @@ -3,4 +3,4 @@ - \ No newline at end of file + diff --git a/tools/scripts/test/GlobalSettings.cs b/tools/scripts/test/GlobalSettings.cs index a9cdb4ba..9f7059c6 100644 --- a/tools/scripts/test/GlobalSettings.cs +++ b/tools/scripts/test/GlobalSettings.cs @@ -3,5 +3,5 @@ public static class GlobalSettings // This path references resources used by the SplashKit Core integration test suite. // By referencing the below field, NuGet test projects are able to share assets with the core tests. // To utilise, put "SetResourcesPath(GlobalSettings.ResourcePath);" at the beginning of a test project - public static string ResourcePath = "../../../../coresdk/src/test/Resources"; -} \ No newline at end of file + public static readonly string ResourcePath = "../../../../coresdk/src/test/Resources"; +} diff --git a/tools/scripts/test/NuGet.config b/tools/scripts/test/NuGet.config index a13060f5..5c858a19 100644 --- a/tools/scripts/test/NuGet.config +++ b/tools/scripts/test/NuGet.config @@ -4,4 +4,4 @@ - \ No newline at end of file + From 1f32ef3c6120a401919582b4ea416116998e397f Mon Sep 17 00:00:00 2001 From: rory-cd Date: Mon, 15 Dec 2025 00:48:25 +1100 Subject: [PATCH 10/12] FIX: Remove misleading Console.Writeline() to improve test clarity --- tools/scripts/test/TcpNetworking/Program.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/scripts/test/TcpNetworking/Program.cs b/tools/scripts/test/TcpNetworking/Program.cs index 1ff53be4..a2684b88 100644 --- a/tools/scripts/test/TcpNetworking/Program.cs +++ b/tools/scripts/test/TcpNetworking/Program.cs @@ -69,7 +69,6 @@ void CheckMessages() Console.WriteLine($"ToSvr is open: {IsConnectionOpen("ToSvr")}"); Console.WriteLine("Fred is open? Expect warning/false:"); Console.WriteLine(IsConnectionOpen("Fred")); -Console.WriteLine("Expect warning below:"); CheckNetworkActivity(); From 1743713129874c6cdf6f7624cdb04113f8a05efa Mon Sep 17 00:00:00 2001 From: rory-cd Date: Fri, 2 Jan 2026 12:23:35 +1100 Subject: [PATCH 11/12] DOCS: Document removal of SplashKit.cs symbolic link --- tools/scripts/nuget-pkg/SplashKitSDK.csproj | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/scripts/nuget-pkg/SplashKitSDK.csproj b/tools/scripts/nuget-pkg/SplashKitSDK.csproj index 857f992f..6695df66 100644 --- a/tools/scripts/nuget-pkg/SplashKitSDK.csproj +++ b/tools/scripts/nuget-pkg/SplashKitSDK.csproj @@ -38,7 +38,10 @@ - + From c8739ee9b29bcec8689696ae3b260009261a674c Mon Sep 17 00:00:00 2001 From: rory-cd Date: Fri, 2 Jan 2026 12:57:32 +1100 Subject: [PATCH 12/12] DOCS: Add note explaining lack of Linux references --- tools/scripts/nuget-pkg/download-libraries.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/scripts/nuget-pkg/download-libraries.sh b/tools/scripts/nuget-pkg/download-libraries.sh index b518b1ec..0a288d7f 100755 --- a/tools/scripts/nuget-pkg/download-libraries.sh +++ b/tools/scripts/nuget-pkg/download-libraries.sh @@ -1,7 +1,5 @@ #!/bin/bash -# See comments at end about adding libraries to NuGet package - # Set the GitHub repository URL repo_url="https://github.com/splashkit/skm.git" @@ -9,6 +7,7 @@ repo_url="https://github.com/splashkit/skm.git" branch="master" # Set the folders to download +# Note: SKM does not include pre-compiled libraries for Linux folders=("lib/macos" "lib/win64") # Create the destination directory if it doesn't exist