Files
sbox-public/engine/Sandbox.Test/Package/PackageDownload.cs
Lorenz Junglas 6808d8768e Shutdown fixes (#3553)
* Stop generating solutions via -test flag add -generatesolution

* Add TestAppSystem remove Application.InitUnitTest

Avoids some hacks and also makes sure our tests are as close to a real AppSystem as possible.

* Add shutdown unit test

shuts down an re-inits the engine

* Properly dispose native resources hold by managed during shutdown

Should fix a bunch of crashes

* Fix filesystem and networking tests

* StandaloneTest does proper Game Close

* Make sure package tests clean up properly

* Make sure menu scene and resources are released on shutdown

* Report leaked scenes on shutdown

* Ensure DestroyImmediate is not used on scenes

* Fix unmounting in unit tests not clearing native refs

* Force destroy native resource on ResourceLib Clear
2025-12-08 15:55:11 +01:00

137 lines
3.6 KiB
C#

using System;
namespace Packages;
[TestClass]
public class PackageDownload
{
[TestMethod]
[DataRow( "facepunch.sandbox" )]
[DataRow( "garry.grassworld" )]
public async Task SingleDownload( string packageIdent )
{
// Find the package
var package = await Package.FetchAsync( packageIdent, false );
Assert.IsNotNull( package );
var dir = $"{Environment.CurrentDirectory}/download_test/{packageIdent}";
if ( System.IO.Directory.Exists( dir ) )
System.IO.Directory.Delete( dir, true );
System.IO.Directory.CreateDirectory( dir );
AssetDownloadCache.Initialize( dir );
var filesystem = await package.Download();
// We should have downloaded a bunch of stuff so this folder shouldn't be empty
{
var files = System.IO.Directory.EnumerateFiles( dir, "*", System.IO.SearchOption.AllDirectories ).ToArray();
Assert.AreNotEqual( 0, files.Length );
}
// The returned filesystem should have files that we can do stuff with now
{
var files = filesystem.FindFile( "", "*", true ).ToArray();
Assert.AreNotEqual( 0, files.Length );
foreach ( var file in files )
{
Console.WriteLine( $"{file}" );
var s = filesystem.ReadAllBytes( file ).ToArray();
}
}
System.IO.Directory.Delete( dir, true );
}
[TestMethod]
[DataRow( "facepunch.sandbox" )]
[DataRow( "garry.grassworld" )]
public async Task MultipleDownload( string packageIdent )
{
// Find the package
var package = await Package.FetchAsync( packageIdent, false );
Assert.IsNotNull( package );
var dir = $"{Environment.CurrentDirectory}/download_test/{packageIdent}";
if ( System.IO.Directory.Exists( dir ) )
System.IO.Directory.Delete( dir, true );
System.IO.Directory.CreateDirectory( dir );
AssetDownloadCache.Initialize( dir );
_ = await package.Download();
var filesystem = await package.Download();
// We should have downloaded a bunch of stuff so this folder shouldn't be empty
{
var files = System.IO.Directory.EnumerateFiles( dir, "*", System.IO.SearchOption.AllDirectories ).ToArray();
Assert.AreNotEqual( 0, files.Length );
}
// The returned filesystem should have files that we can do stuff with now
{
var files = filesystem.FindFile( "", "*", true ).ToArray();
Assert.AreNotEqual( 0, files.Length );
foreach ( var file in files )
{
Console.WriteLine( $"{file}" );
}
}
System.IO.Directory.Delete( dir, true );
}
[TestMethod]
[DataRow( "testingsomething.sandbox_escape__playground#82331" )]
public async Task NoDlls( string packageIdent )
{
// Find the package
var package = await Package.FetchAsync( packageIdent, false );
Assert.IsNotNull( package );
var dir = $"{Environment.CurrentDirectory}/download_test/dlltest";
if ( System.IO.Directory.Exists( dir ) )
System.IO.Directory.Delete( dir, true );
System.IO.Directory.CreateDirectory( dir );
AssetDownloadCache.Initialize( dir );
var filesystem = await package.Download();
Assert.IsNotNull( filesystem );
// We should have downloaded a bunch of stuff so this folder shouldn't be empty
{
var files = System.IO.Directory.EnumerateFiles( dir, "*", System.IO.SearchOption.AllDirectories ).ToArray();
Assert.AreNotEqual( 0, files.Length );
}
// The returned filesystem should have files that we can do stuff with now
{
var files = filesystem.FindFile( "", "*", true ).ToArray();
Assert.AreNotEqual( 0, files.Length );
foreach ( var file in files )
{
Console.WriteLine( $"{file}" );
Assert.IsFalse( file.EndsWith( ".dll" ) );
var s = filesystem.ReadAllBytes( file ).ToArray();
}
}
System.IO.Directory.Delete( dir, true );
}
}