Skip to content

Commit f981446

Browse files
Split WebBundle testing into its own class
The UnityDataToolTests test class repeats the test through each folder in Data/AssetBundles, but webbundle tests are covering a file in Data/WebBundles and only need to run once.
1 parent 88498f7 commit f981446

File tree

1 file changed

+112
-85
lines changed

1 file changed

+112
-85
lines changed

UnityDataTool.Tests/UnityDataToolTests.cs

Lines changed: 112 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ namespace UnityDataTools.UnityDataTool.Tests;
1212

1313
#pragma warning disable NUnit2005, NUnit2006
1414

15-
public class UnityDataToolTests : AssetBundleTestFixture
15+
public class UnityDataToolAssetBundleTests : AssetBundleTestFixture
1616
{
1717
private string m_TestOutputFolder;
1818

19-
public UnityDataToolTests(Context context) : base(context)
19+
public UnityDataToolAssetBundleTests(Context context) : base(context)
2020
{
2121
}
2222

@@ -59,20 +59,6 @@ public async Task InvalidFile(
5959
Assert.AreNotEqual(0, await Program.Main(command.ToArray()));
6060
}
6161

62-
public void IsWebBundle_True()
63-
{
64-
65-
var webBundlePath = Path.Combine(Context.TestDataFolder, "WebBundles", "HelloWorld.data");
66-
Assert.IsTrue(Archive.IsWebBundle(new FileInfo(webBundlePath)));
67-
}
68-
69-
[Test]
70-
public void IsWebBundle_False()
71-
{
72-
var nonWebBundlePath = Path.Combine(Context.TestDataFolder, "WebBundles", "NotAWebBundle.txt");
73-
Assert.IsFalse(Archive.IsWebBundle(new FileInfo(nonWebBundlePath)));
74-
}
75-
7662
[Test]
7763
public async Task ArchiveExtract_AssetBundle_FilesExtractedSuccessfully(
7864
[Values("", "-o archive", "--output-path archive")] string options)
@@ -85,27 +71,6 @@ public async Task ArchiveExtract_AssetBundle_FilesExtractedSuccessfully(
8571
Assert.IsTrue(File.Exists(Path.Combine(m_TestOutputFolder, "archive", "CAB-5d40f7cad7c871cf2ad2af19ac542994.resource")));
8672
}
8773

88-
[Test]
89-
public async Task ArchiveExtract_WebBundle_FileExtractedSuccessfully(
90-
[Values("", "-o archive", "--output-path archive")] string options,
91-
[Values("HelloWorld.data", "HelloWorld.data.gz", "HelloWorld.data.br")] string bundlePath)
92-
{
93-
var path = Path.Combine(Context.TestDataFolder, "WebBundles", bundlePath);
94-
string[] expectedFiles = {
95-
"boot.config",
96-
"data.unity3d",
97-
"RuntimeInitializeOnLoads.json",
98-
"ScriptingAssemblies.json",
99-
Path.Combine("Il2CppData", "Metadata", "global-metadata.dat"),
100-
Path.Combine("Resources", "unity_default_resources"),
101-
};
102-
Assert.AreEqual(0, await Program.Main(new string[] { "archive", "extract", path }.Concat(options.Split(" ", StringSplitOptions.RemoveEmptyEntries)).ToArray()));
103-
foreach (var file in expectedFiles)
104-
{
105-
Assert.IsTrue(File.Exists(Path.Combine(m_TestOutputFolder, "archive", file)));
106-
}
107-
}
108-
10974
[Test]
11075
public async Task ArchiveList_AssetBundle_ListFilesCorrectly()
11176
{
@@ -139,54 +104,6 @@ public async Task ArchiveList_AssetBundle_ListFilesCorrectly()
139104
}
140105
}
141106

142-
[Test]
143-
public async Task ArchiveList_WebBundle_ListFilesCorrectly(
144-
[Values(
145-
"HelloWorld.data",
146-
"HelloWorld.data.gz",
147-
"HelloWorld.data.br"
148-
)] string bundlePath)
149-
{
150-
var path = Path.Combine(Context.TestDataFolder, "WebBundles", bundlePath);
151-
using var sw = new StringWriter();
152-
var currentOut = Console.Out;
153-
try
154-
{
155-
Console.SetOut(sw);
156-
157-
Assert.AreEqual(0, await Program.Main(new string[] { "archive", "list", path }));
158-
159-
var actualOutput = sw.ToString();
160-
var expectedOutput = (
161-
@"data.unity3d
162-
Size: 253044
163-
164-
RuntimeInitializeOnLoads.json
165-
Size: 700
166-
167-
ScriptingAssemblies.json
168-
Size: 3060
169-
170-
boot.config
171-
Size: 93
172-
173-
Il2CppData/Metadata/global-metadata.dat
174-
Size: 1641180
175-
176-
Resources/unity_default_resources
177-
Size: 607376
178-
179-
"
180-
);
181-
182-
Assert.AreEqual(expectedOutput, actualOutput);
183-
}
184-
finally
185-
{
186-
Console.SetOut(currentOut);
187-
}
188-
}
189-
190107
[Test]
191108
public async Task DumpText_DefaultArgs_TextFileCreatedCorrectly(
192109
[Values("", "-f text", "--output-format text")] string options)
@@ -436,3 +353,113 @@ public async Task DumpText_PlayerData_TextFileCreatedCorrectly()
436353
Assert.AreEqual(expected, content);
437354
}
438355
}
356+
357+
public class WebBundleSupportTests
358+
{
359+
private string m_TestOutputFolder;
360+
private string m_TestDataFolder;
361+
362+
[OneTimeSetUp]
363+
public void OneTimeSetup()
364+
{
365+
m_TestOutputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, "test_folder");
366+
m_TestDataFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, "Data");
367+
Directory.CreateDirectory(m_TestOutputFolder);
368+
Directory.SetCurrentDirectory(m_TestOutputFolder);
369+
}
370+
371+
[TearDown]
372+
public void Teardown()
373+
{
374+
SqliteConnection.ClearAllPools();
375+
376+
var testDir = new DirectoryInfo(m_TestOutputFolder);
377+
testDir.EnumerateFiles()
378+
.ToList().ForEach(f => f.Delete());
379+
testDir.EnumerateDirectories()
380+
.ToList().ForEach(d => d.Delete(true));
381+
}
382+
383+
[Test]
384+
public void IsWebBundle_True()
385+
{
386+
var webBundlePath = Path.Combine(m_TestDataFolder, "WebBundles", "HelloWorld.data");
387+
Assert.IsTrue(Archive.IsWebBundle(new FileInfo(webBundlePath)));
388+
}
389+
390+
[Test]
391+
public void IsWebBundle_False()
392+
{
393+
var nonWebBundlePath = Path.Combine(m_TestDataFolder, "WebBundles", "NotAWebBundle.txt");
394+
Assert.IsFalse(Archive.IsWebBundle(new FileInfo(nonWebBundlePath)));
395+
}
396+
397+
[Test]
398+
public async Task ArchiveList_WebBundle_ListFilesCorrectly(
399+
[Values(
400+
"HelloWorld.data",
401+
"HelloWorld.data.gz",
402+
"HelloWorld.data.br"
403+
)] string bundlePath)
404+
{
405+
var path = Path.Combine(m_TestDataFolder, "WebBundles", bundlePath);
406+
using var sw = new StringWriter();
407+
var currentOut = Console.Out;
408+
try
409+
{
410+
Console.SetOut(sw);
411+
412+
Assert.AreEqual(0, await Program.Main(new string[] { "archive", "list", path }));
413+
414+
var actualOutput = sw.ToString();
415+
var expectedOutput = (
416+
@"data.unity3d
417+
Size: 253044
418+
419+
RuntimeInitializeOnLoads.json
420+
Size: 700
421+
422+
ScriptingAssemblies.json
423+
Size: 3060
424+
425+
boot.config
426+
Size: 93
427+
428+
Il2CppData/Metadata/global-metadata.dat
429+
Size: 1641180
430+
431+
Resources/unity_default_resources
432+
Size: 607376
433+
434+
"
435+
);
436+
437+
Assert.AreEqual(expectedOutput, actualOutput);
438+
}
439+
finally
440+
{
441+
Console.SetOut(currentOut);
442+
}
443+
}
444+
445+
[Test]
446+
public async Task ArchiveExtract_WebBundle_FileExtractedSuccessfully(
447+
[Values("", "-o archive", "--output-path archive")] string options,
448+
[Values("HelloWorld.data", "HelloWorld.data.gz", "HelloWorld.data.br")] string bundlePath)
449+
{
450+
var path = Path.Combine(m_TestDataFolder, "WebBundles", bundlePath);
451+
string[] expectedFiles = {
452+
"boot.config",
453+
"data.unity3d",
454+
"RuntimeInitializeOnLoads.json",
455+
"ScriptingAssemblies.json",
456+
Path.Combine("Il2CppData", "Metadata", "global-metadata.dat"),
457+
Path.Combine("Resources", "unity_default_resources"),
458+
};
459+
Assert.AreEqual(0, await Program.Main(new string[] { "archive", "extract", path }.Concat(options.Split(" ", StringSplitOptions.RemoveEmptyEntries)).ToArray()));
460+
foreach (var file in expectedFiles)
461+
{
462+
Assert.IsTrue(File.Exists(Path.Combine(m_TestOutputFolder, "archive", file)));
463+
}
464+
}
465+
}

0 commit comments

Comments
 (0)