diff --git a/Assets/Scripts/OpenTS2/Content/EPManager.cs b/Assets/Scripts/OpenTS2/Content/EPManager.cs index 9aa1956..59aa8c9 100644 --- a/Assets/Scripts/OpenTS2/Content/EPManager.cs +++ b/Assets/Scripts/OpenTS2/Content/EPManager.cs @@ -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 GetProductsInMask(int productMask) { var finalList = new List(); diff --git a/Assets/Tests/OpenTS2/Content/ContentManagerTest.cs b/Assets/Tests/OpenTS2/Content/ContentManagerTest.cs new file mode 100644 index 0000000..512f6f5 --- /dev/null +++ b/Assets/Tests/OpenTS2/Content/ContentManagerTest.cs @@ -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(new ResourceKey(1, "testpackage", TypeIDs.STR)); + Assert.IsNotNull(stringAsset); + } +} diff --git a/Assets/Tests/OpenTS2/Content/ContentManagerTest.cs.meta b/Assets/Tests/OpenTS2/Content/ContentManagerTest.cs.meta new file mode 100644 index 0000000..8e6aade --- /dev/null +++ b/Assets/Tests/OpenTS2/Content/ContentManagerTest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bfd63c2c05bba0344a8889eda9c99c3c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/OpenTS2/Content/DBPF.meta b/Assets/Tests/OpenTS2/Content/DBPF.meta new file mode 100644 index 0000000..3417143 --- /dev/null +++ b/Assets/Tests/OpenTS2/Content/DBPF.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c1227e4188138954ca6e937273442c4e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/OpenTS2/Content/ContentTest.cs b/Assets/Tests/OpenTS2/Content/DBPF/StringSetTest.cs similarity index 97% rename from Assets/Tests/OpenTS2/Content/ContentTest.cs rename to Assets/Tests/OpenTS2/Content/DBPF/StringSetTest.cs index a98e565..1f07e99 100644 --- a/Assets/Tests/OpenTS2/Content/ContentTest.cs +++ b/Assets/Tests/OpenTS2/Content/DBPF/StringSetTest.cs @@ -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() diff --git a/Assets/Tests/OpenTS2/Content/ContentTest.cs.meta b/Assets/Tests/OpenTS2/Content/DBPF/StringSetTest.cs.meta similarity index 100% rename from Assets/Tests/OpenTS2/Content/ContentTest.cs.meta rename to Assets/Tests/OpenTS2/Content/DBPF/StringSetTest.cs.meta diff --git a/Assets/Tests/TestMain.cs b/Assets/Tests/TestMain.cs new file mode 100644 index 0000000..7dfdfc0 --- /dev/null +++ b/Assets/Tests/TestMain.cs @@ -0,0 +1,26 @@ +using OpenTS2.Assemblies; +using OpenTS2.Content; +using OpenTS2.Files; +using OpenTS2.Files.Formats.DBPF; + +/// +/// Main initialization class for OpenTS2 unit testing. +/// +public static class TestMain +{ + static bool s_initialized = false; + /// + /// Initializes all singletons, systems and the game assembly. + /// + 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; + } +} \ No newline at end of file diff --git a/Assets/Tests/TestMain.cs.meta b/Assets/Tests/TestMain.cs.meta new file mode 100644 index 0000000..a922dae --- /dev/null +++ b/Assets/Tests/TestMain.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f85fdb2b65bb11148b76bb8dfc971d6b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/TestPathProvider.cs b/Assets/Tests/TestPathProvider.cs new file mode 100644 index 0000000..4df8ef1 --- /dev/null +++ b/Assets/Tests/TestPathProvider.cs @@ -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 ""; + } +} diff --git a/Assets/Tests/TestPathProvider.cs.meta b/Assets/Tests/TestPathProvider.cs.meta new file mode 100644 index 0000000..da92465 --- /dev/null +++ b/Assets/Tests/TestPathProvider.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 87869e2ff0e378845be76ec727d197d0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/TestAssets/README.md b/TestAssets/README.md new file mode 100644 index 0000000..82d3010 --- /dev/null +++ b/TestAssets/README.md @@ -0,0 +1 @@ +Resources made specifically for unit testing go here. \ No newline at end of file diff --git a/TestAssets/TestPackage.package b/TestAssets/TestPackage.package new file mode 100644 index 0000000..b356da7 Binary files /dev/null and b/TestAssets/TestPackage.package differ