Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: stub tests #8

Merged
merged 4 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build
name: Build & Test

on:
push:
Expand Down Expand Up @@ -34,9 +34,12 @@ jobs:
- name: Build
run: dotnet build Osu.Patcher.Injector

- name: Upload artifacts
- name: Upload Injector artifact
uses: actions/upload-artifact@v4
with:
name: osu!patcher-debug
if-no-files-found: error
path: .\Osu.Patcher.Injector\bin\Debug\net8.0\**

- name: Run stub tests
run: dotnet run --project Osu.Stubs.Tests
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ target/
*.idea
*.iml
*DotSettings.user
**/TestResult.xml
1 change: 0 additions & 1 deletion Osu.Patcher.Hook/Patches/BeatmapMirror/EnableOsuDirect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Reflection;
using HarmonyLib;
using JetBrains.Annotations;
using Osu.Stubs;
using Osu.Stubs.Other;
using Osu.Utils.Extensions;
using static System.Reflection.Emit.OpCodes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Reflection;
using HarmonyLib;
using JetBrains.Annotations;
using Osu.Stubs;
using Osu.Stubs.Framework;
using Osu.Stubs.GameModes;
using Osu.Stubs.Graphics;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Diagnostics;
using Osu.Performance;
using Osu.Stubs;
using Osu.Stubs.GameModes;
using Osu.Stubs.Other;
using Osu.Stubs.Scoring;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Osu.Stubs;
using Osu.Stubs.Framework;

namespace Osu.Patcher.Hook.Patches.LivePerformance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using HarmonyLib;
using JetBrains.Annotations;
using Osu.Performance;
using Osu.Stubs;
using Osu.Stubs.Rulesets;
using Osu.Stubs.Scoring;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Reflection;
using HarmonyLib;
using JetBrains.Annotations;
using Osu.Stubs;
using Osu.Stubs.Rulesets;

namespace Osu.Patcher.Hook.Patches.LivePerformance;
Expand Down
1 change: 0 additions & 1 deletion Osu.Patcher.Hook/Patches/Misc/AllowPlayModeReload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using HarmonyLib;
using JetBrains.Annotations;
using Osu.Patcher.Hook.Patches.UI;
using Osu.Stubs;
using Osu.Stubs.Other;
using Osu.Utils.Extensions;
using static System.Reflection.Emit.OpCodes;
Expand Down
1 change: 0 additions & 1 deletion Osu.Patcher.Hook/Patches/Misc/DisableErrorReporting.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Reflection;
using HarmonyLib;
using JetBrains.Annotations;
using Osu.Stubs;
using Osu.Stubs.Helpers;

namespace Osu.Patcher.Hook.Patches.Misc;
Expand Down
1 change: 0 additions & 1 deletion Osu.Patcher.Hook/Patches/Misc/FixDoubleSkipping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Reflection;
using HarmonyLib;
using JetBrains.Annotations;
using Osu.Stubs;
using Osu.Stubs.GameModes;
using Osu.Stubs.Other;

Expand Down
1 change: 0 additions & 1 deletion Osu.Patcher.Hook/Patches/Misc/LogOsuLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Reflection;
using HarmonyLib;
using JetBrains.Annotations;
using Osu.Stubs;
using Osu.Stubs.Helpers;

namespace Osu.Patcher.Hook.Patches.Misc;
Expand Down
1 change: 0 additions & 1 deletion Osu.Patcher.Hook/Patches/Misc/LogSoftErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Reflection;
using HarmonyLib;
using JetBrains.Annotations;
using Osu.Stubs;
using Osu.Stubs.Other;

namespace Osu.Patcher.Hook.Patches.Misc;
Expand Down
1 change: 0 additions & 1 deletion Osu.Patcher.Hook/Patches/Mods/PatchSuddenDeathAutoRetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Reflection;
using HarmonyLib;
using JetBrains.Annotations;
using Osu.Stubs;
using Osu.Stubs.Rulesets;
using static System.Reflection.Emit.OpCodes;

Expand Down
1 change: 0 additions & 1 deletion Osu.Patcher.Hook/Patches/UI/AllowOpenOptionsInGameplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Reflection;
using HarmonyLib;
using JetBrains.Annotations;
using Osu.Stubs;
using Osu.Stubs.Other;
using Osu.Utils.Extensions;
using static System.Reflection.Emit.OpCodes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Reflection;
using HarmonyLib;
using JetBrains.Annotations;
using Osu.Stubs;
using Osu.Stubs.SongSelect;
using Osu.Utils.Extensions;
using static System.Reflection.Emit.OpCodes;
Expand Down
1 change: 0 additions & 1 deletion Osu.Patcher.Hook/Patches/UI/RevertSortWhenNoGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Reflection.Emit;
using HarmonyLib;
using JetBrains.Annotations;
using Osu.Stubs;
using Osu.Stubs.Helpers;
using Osu.Stubs.SongSelect;
using Osu.Utils.Extensions;
Expand Down
1 change: 0 additions & 1 deletion Osu.Patcher.Hook/Patches/UI/ShowModsInGameplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Reflection;
using HarmonyLib;
using JetBrains.Annotations;
using Osu.Stubs;
using Osu.Stubs.GameModes;
using static System.Reflection.Emit.OpCodes;

Expand Down
45 changes: 45 additions & 0 deletions Osu.Stubs.Tests/Osu.Stubs.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Build">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>Osu.Stubs.Tests</RootNamespace>
<TargetFramework>net462</TargetFramework>
<PlatformTarget>x86</PlatformTarget> <!-- Running in 32bit is necessary for loading in osu! -->
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Net.Http"/>
<ProjectReference Include="../Osu.Stubs/Osu.Stubs.csproj"/>
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" PrivateAssets="all"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0"/>
<PackageReference Include="NUnit" Version="4.1.0"/>
<PackageReference Include="NUnitLite" Version="4.1.0"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/>
<PackageReference Include="NUnit.Analyzers" Version="4.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
77 changes: 77 additions & 0 deletions Osu.Stubs.Tests/OsuApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Newtonsoft.Json;

namespace Osu.Stubs.Tests;

[PublicAPI]
public static class OsuApi
{
[PublicAPI]
public enum ReleaseStream
{
CuttingEdge,
Stable40,
Beta40,
}

private static readonly HttpClient Http = new();

/// <summary>
/// Gets the latest release files for a specific release stream.
/// </summary>
public static async Task<List<OsuUpdateFile>> GetReleaseFiles(ReleaseStream stream)
{
Console.WriteLine("Fetching latest osu! update info");

var url = $"https://osu.ppy.sh/web/check-updates.php" +
$"?action=check" +
$"&stream={stream.ToString().ToLower()}" +
$"&time={DateTime.Now.Ticks}";

using var response = await Http.GetAsync(url);
response.EnsureSuccessStatusCode();

var bodyText = await response.Content.ReadAsStringAsync();
if (bodyText == null) throw new Exception("Response returned no body");

var releaseFiles = JsonConvert.DeserializeObject<List<OsuUpdateFile>>(bodyText);
if (releaseFiles == null) throw new Exception("Failed to deserialize update files");

return releaseFiles;
}

/// <summary>
/// Downloads the full osu! update file list to a specific directory.
/// </summary>
/// <param name="dir">An empty directory.</param>
/// <param name="stream">The release stream to download.</param>
public static async Task DownloadOsu(string dir, ReleaseStream stream = ReleaseStream.Stable40)
{
var updateFiles = await GetReleaseFiles(ReleaseStream.Stable40);

Parallel.ForEach(updateFiles, updateFile =>
{
Console.WriteLine($"Downloading {updateFile.FileName}");
DownloadFile(updateFile.DownloadUrl, Path.Combine(dir, updateFile.FileName)).Wait();
});

Console.WriteLine("Finished downloading osu!");
}

private static async Task DownloadFile(string url, string path)
{
using var response = await Http.GetAsync(url);
response.EnsureSuccessStatusCode();

var bodyStream = await response.Content.ReadAsStreamAsync();
if (bodyStream == null) throw new Exception("Response returned no body");

using var file = File.Create(path);
await bodyStream.CopyToAsync(file);
}
}
30 changes: 30 additions & 0 deletions Osu.Stubs.Tests/OsuUpdateFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Newtonsoft.Json;

namespace Osu.Stubs.Tests;

public class OsuUpdateFile
{
[JsonRequired]
[JsonProperty("file_version")]
public int FileVersion { get; set; }

[JsonRequired]
[JsonProperty("filesize")]
public int FileSize { get; set; }

[JsonRequired]
[JsonProperty("filename")]
public string FileName { get; set; } = null!;

[JsonRequired]
[JsonProperty("file_hash")]
public string FileHash { get; set; } = null!;

[JsonRequired]
[JsonProperty("timestamp")]
public string Timestamp { get; set; } = null!;

[JsonRequired]
[JsonProperty("url_full")]
public string DownloadUrl { get; set; } = null!;
}
8 changes: 8 additions & 0 deletions Osu.Stubs.Tests/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using NUnitLite;

namespace Osu.Stubs.Tests;

public static class Program
{
public static int Main(string[] args) => new AutoRun().Execute(args);
}
Loading
Loading