Skip to content

Commit 3b5408b

Browse files
committed
Added PlayerData test
1 parent fd7077a commit 3b5408b

22 files changed

Lines changed: 201 additions & 129 deletions

File tree

Analyzer.Tests/ExpectedDataGenerator.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,10 @@ namespace UnityDataTools.UnityDataTool.Tests;
77

88
public static class ExpectedDataGenerator
99
{
10-
public static void GenerateAll()
11-
{
12-
foreach (var context in Context.GetAll())
13-
{
14-
Generate(context);
15-
}
16-
}
17-
1810
public static void Generate(Context context)
1911
{
2012
UnityFileSystem.Init();
21-
using var archive = UnityFileSystem.MountArchive(Path.Combine(context.UnityDataFolder, "AssetBundles", "assetbundle"), "/");
13+
using var archive = UnityFileSystem.MountArchive(Path.Combine(context.UnityDataFolder, "assetbundle"), "/");
2214

2315
using var serializedFile = UnityFileSystem.OpenSerializedFile("/CAB-5d40f7cad7c871cf2ad2af19ac542994");
2416
using var fileReader = new UnityFileReader("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994", 1024*1024);
@@ -30,9 +22,9 @@ public static void Generate(Context context)
3022
AddObject(4693305862354978555, "Mesh", serializedFile, fileReader, context, Mesh.Read);
3123
AddObject(-8074603400156879931, "AudioClip", serializedFile, fileReader, context, AudioClip.Read);
3224
AddObject(1, "AssetBundle", serializedFile, fileReader, context, AssetBundle.Read);
33-
34-
var di = new DirectoryInfo(context.TestDataFolder);
35-
var outputFolder = Path.Combine(di.Parent.Parent.Parent.Parent.FullName, "ExpectedData", context.UnityDataVersion);
25+
26+
var csprojFolder = Directory.GetParent(context.TestDataFolder).Parent.Parent.Parent.FullName;
27+
var outputFolder = Path.Combine(csprojFolder, "ExpectedData", context.UnityDataVersion);
3628

3729
Directory.CreateDirectory(outputFolder);
3830
context.ExpectedData.Save(outputFolder);

Analyzer.Tests/SerializedObjectsTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace UnityDataTools.Analyzer.Tests;
99

1010
#pragma warning disable NUnit2005, NUnit2006
1111

12-
public class SerializedObjectsTests : TestForAllVersions
12+
public class SerializedObjectsTests : AssetBundleTestFixture
1313
{
1414
private UnityArchive m_Archive;
1515
private SerializedFile m_SerializedFile;
@@ -19,18 +19,18 @@ public SerializedObjectsTests(Context context) : base(context)
1919
{
2020
}
2121

22-
protected override void OnCreate()
22+
protected override void OnLoadExpectedData(Context context)
2323
{
2424
// Uncomment to regenerate expected data.
25-
//ExpectedDataGenerator.GenerateAll();
25+
//ExpectedDataGenerator.Generate(context);
2626
}
2727

2828
[OneTimeSetUp]
2929
public void OneTimeSetup()
3030
{
3131
UnityFileSystem.Init();
3232

33-
var path = Path.Combine(Context.UnityDataFolder, "AssetBundles", "assetbundle");
33+
var path = Path.Combine(Context.UnityDataFolder, "assetbundle");
3434
m_Archive = UnityFileSystem.MountArchive(path, "archive:/");
3535
m_SerializedFile = UnityFileSystem.OpenSerializedFile("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994");
3636
m_FileReader = new UnityFileReader("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994", 1024*1024);

Analyzer/AnalyzerTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public int Analyze(string path, string databaseName, string searchPattern, bool
6161
Console.Write(new string(' ', Console.BufferWidth));
6262
Console.Write($"\rProcessing {i * 100 / files.Length}% ({i}/{files.Length}) {file}");
6363

64-
writer.WriteSerializedFile(serializedFileName, path);
64+
writer.WriteSerializedFile(serializedFileName, file);
6565
}
6666
}
6767
catch (Exception e)

TestCommon/Context.cs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,30 @@ namespace UnityDataTools.TestCommon;
44

55
public class Context
66
{
7+
// e.g. <CurrentProjectFolder>/bin/Debug/net6.0/Data/AssetBundles/2021.1.0f1
78
public string UnityDataFolder { get; }
9+
10+
// e.g. 2021.1.0f1
811
public string UnityDataVersion { get; }
12+
13+
// e.g. <CurrentProjectFolder>/bin/Debug/net6.0/Data
914
public string TestDataFolder { get; }
15+
16+
// e.g. <CurrentProjectFolder>/bin/Debug/net6.0/ExpectedData/2021.1.0f1
1017
public string ExpectedDataFolder { get; }
18+
1119
public ExpectedData ExpectedData { get; } = new();
1220

13-
private static Dictionary<string, List<Context>> m_Cache = new();
14-
15-
private Context(string folder)
21+
public Context(string folder)
1622
{
1723
var di = new DirectoryInfo(folder);
1824

1925
UnityDataFolder = folder;
2026
UnityDataVersion = di.Name;
21-
TestDataFolder = di.Parent.FullName;
22-
ExpectedDataFolder = Path.Combine(di.Parent.Parent.FullName, "ExpectedData", UnityDataVersion);
23-
}
24-
25-
public static IEnumerable<Context> GetAll()
26-
{
27-
if (m_Cache.TryGetValue(TestContext.CurrentContext.TestDirectory, out var cases))
28-
{
29-
return cases;
30-
}
31-
32-
cases = new List<Context>();
33-
m_Cache[TestContext.CurrentContext.TestDirectory] = cases;
34-
foreach (var folder in Directory.EnumerateDirectories(Path.Combine(TestContext.CurrentContext.TestDirectory, "Data")))
35-
{
36-
cases.Add(new Context(folder));
37-
}
38-
39-
return cases;
27+
TestDataFolder = di.Parent.Parent.FullName;
28+
ExpectedDataFolder = Path.Combine(di.Parent.Parent.Parent.FullName, "ExpectedData", UnityDataVersion);
29+
30+
ExpectedData.Load(ExpectedDataFolder);
4031
}
4132

4233
public override string ToString()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)