Test contentmanager.

This commit is contained in:
LazyDuchess 2022-12-23 11:12:11 -03:00
parent e9170f9041
commit 8ceb48b0ec
12 changed files with 131 additions and 2 deletions

View file

@ -16,12 +16,28 @@ namespace OpenTS2.Content
}
static EPManager s_instance;
public int InstalledProducts
{
get
{
return _installedProducts;
}
set
{
_installedProducts = value;
}
}
//mask of all products, minus store.
readonly int _installedProducts = 0x3EFFF;
int _installedProducts = 0x3EFFF;
public EPManager()
{
s_instance = this;
}
public EPManager(int installedProducts) : this()
{
InstalledProducts = installedProducts;
}
public static List<ProductFlags> GetProductsInMask(int productMask)
{
var finalList = new List<ProductFlags>();

View file

@ -0,0 +1,20 @@
using NUnit.Framework;
using OpenTS2.Common;
using OpenTS2.Content;
using OpenTS2.Content.DBPF;
using OpenTS2.Engine;
using OpenTS2.Files;
using OpenTS2.Files.Formats.DBPF;
public class ContentManagerTest
{
[Test]
public void GetAssetByGlobalTGITest()
{
TestMain.Initialize();
var contentManager = ContentManager.Get();
contentManager.Provider.AddPackage("TestAssets/TestPackage.package");
var stringAsset = contentManager.Provider.GetAsset<StringSetAsset>(new ResourceKey(1, "testpackage", TypeIDs.STR));
Assert.IsNotNull(stringAsset);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bfd63c2c05bba0344a8889eda9c99c3c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c1227e4188138954ca6e937273442c4e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -3,7 +3,7 @@ using OpenTS2.Content.DBPF;
using OpenTS2.Client;
using System.Collections.Generic;
public class ContentTest
public class StringSetTest
{
[Test]
public void StringSetLocalizationTest()

26
Assets/Tests/TestMain.cs Normal file
View file

@ -0,0 +1,26 @@
using OpenTS2.Assemblies;
using OpenTS2.Content;
using OpenTS2.Files;
using OpenTS2.Files.Formats.DBPF;
/// <summary>
/// Main initialization class for OpenTS2 unit testing.
/// </summary>
public static class TestMain
{
static bool s_initialized = false;
/// <summary>
/// Initializes all singletons, systems and the game assembly.
/// </summary>
public static void Initialize()
{
if (s_initialized)
return;
var epManager = new EPManager((int)ProductFlags.BaseGame);
var contentManager = new ContentManager();
Filesystem.Initialize(new TestPathProvider(), epManager);
CodecAttribute.Initialize();
AssemblyHelper.InitializeLoadedAssemblies();
s_initialized = true;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f85fdb2b65bb11148b76bb8dfc971d6b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,25 @@
using OpenTS2.Content;
using OpenTS2.Content.Interfaces;
public class TestPathProvider : IPathProvider
{
public string GetBinPathForProduct(ProductFlags productFlag)
{
return "";
}
public string GetDataPathForProduct(ProductFlags productFlag)
{
return "";
}
public string GetPathForProduct(ProductFlags productFlag)
{
return "";
}
public string GetUserPath()
{
return "";
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 87869e2ff0e378845be76ec727d197d0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

1
TestAssets/README.md Normal file
View file

@ -0,0 +1 @@
Resources made specifically for unit testing go here.

Binary file not shown.