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* 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 70cb9b2d..6695df66 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,52 @@ 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..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 @@ -26,32 +25,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 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/Directory.Build.props b/tools/scripts/test/Directory.Build.props new file mode 100644 index 00000000..b5591fed --- /dev/null +++ b/tools/scripts/test/Directory.Build.props @@ -0,0 +1,12 @@ + + + + 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..fe0e6362 --- /dev/null +++ b/tools/scripts/test/Directory.Packages.props @@ -0,0 +1,6 @@ + + + + + + diff --git a/tools/scripts/test/GlobalSettings.cs b/tools/scripts/test/GlobalSettings.cs new file mode 100644 index 00000000..9f7059c6 --- /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 readonly string ResourcePath = "../../../../coresdk/src/test/Resources"; +} 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/HelloWorld/HelloWorld.csproj b/tools/scripts/test/HelloWorld/HelloWorld.csproj new file mode 100644 index 00000000..65779695 --- /dev/null +++ b/tools/scripts/test/HelloWorld/HelloWorld.csproj @@ -0,0 +1,9 @@ + + + + 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/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/Main/Main.csproj b/tools/scripts/test/Main/Main.csproj new file mode 100644 index 00000000..65779695 --- /dev/null +++ b/tools/scripts/test/Main/Main.csproj @@ -0,0 +1,9 @@ + + + + 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..852fc0c7 --- /dev/null +++ b/tools/scripts/test/Main/Program.cs @@ -0,0 +1,79 @@ +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(" R: Reload tests"); + 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)); + } + projectNames.Sort(); + + // 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 && opt < projectNames.Count; + + // 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); 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/NuGet.config b/tools/scripts/test/NuGet.config index 863038c7..5c858a19 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 diff --git a/tools/scripts/test/TcpNetworking/Program.cs b/tools/scripts/test/TcpNetworking/Program.cs new file mode 100644 index 00000000..a2684b88 --- /dev/null +++ b/tools/scripts/test/TcpNetworking/Program.cs @@ -0,0 +1,171 @@ +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")); + +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 + + + diff --git a/tools/scripts/test/test.csproj b/tools/scripts/test/test.csproj deleted file mode 100644 index e8105523..00000000 --- a/tools/scripts/test/test.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - Exe - net7.0 - enable - enable - - - - - - -