Skip to content

Commit 1335a36

Browse files
And initial test for Addressables BuildLayout import support
Using two buildlayout files from building the AudioExample project. The test does some checks of hardcoded values across some of the main tables, to confirm that the database tables were populated as expected. This is just a "sanity check", but demonstrates how anything can be checked in the the reference data.
1 parent b299726 commit 1335a36

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

TestCommon/Data/AddressableBuildLayouts/buildlayout_2025.01.28.16.35.01.json

Lines changed: 2 additions & 0 deletions
Large diffs are not rendered by default.

TestCommon/Data/AddressableBuildLayouts/buildlayout_2025.01.28.16.51.14.json

Lines changed: 2 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System;
2+
using Microsoft.Data.Sqlite;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using NUnit.Framework;
7+
8+
namespace UnityDataTools.UnityDataTool.Tests;
9+
10+
#pragma warning disable NUnit2005, NUnit2006
11+
12+
public class AddressablesBuildLayoutTests
13+
{
14+
private string m_TestOutputFolder;
15+
private string m_TestDataFolder;
16+
17+
[OneTimeSetUp]
18+
public void OneTimeSetup()
19+
{
20+
m_TestOutputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, "test_folder");
21+
m_TestDataFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, "Data");
22+
Directory.CreateDirectory(m_TestOutputFolder);
23+
Directory.SetCurrentDirectory(m_TestOutputFolder);
24+
}
25+
26+
[TearDown]
27+
public void Teardown()
28+
{
29+
SqliteConnection.ClearAllPools();
30+
31+
var testDir = new DirectoryInfo(m_TestOutputFolder);
32+
testDir.EnumerateFiles()
33+
.ToList().ForEach(f => f.Delete());
34+
testDir.EnumerateDirectories()
35+
.ToList().ForEach(d => d.Delete(true));
36+
}
37+
38+
[Test]
39+
public async Task Analyze_BuildLayout_ContainsExpectedSQLContent()
40+
{
41+
// This folder contains reference files from two builds of the "AudioExample"
42+
// Addressables test project.
43+
// The test confirms some expected content in the database
44+
var path = Path.Combine(m_TestDataFolder, "AddressableBuildLayouts");
45+
46+
var databasePath = Path.Combine(m_TestOutputFolder, "database.db");
47+
48+
Assert.AreEqual(0, await Program.Main(new string[] { "analyze", path, "-p", "*.json" }));
49+
using var db = new SqliteConnection(new SqliteConnectionStringBuilder
50+
{
51+
DataSource = databasePath,
52+
Mode = SqliteOpenMode.ReadWriteCreate,
53+
Pooling = false,
54+
ForeignKeys = false,
55+
}.ConnectionString);
56+
db.Open();
57+
58+
using var cmd = db.CreateCommand();
59+
60+
// Sanity check some expected content in the output SQLite database
61+
cmd.CommandText =
62+
@"SELECT
63+
(SELECT COUNT(*) FROM addressables_builds),
64+
(SELECT COUNT(*) FROM addressables_builds WHERE name = ""buildlayout_2025.01.28.16.35.01.json""),
65+
(SELECT unity_version FROM addressables_builds WHERE id = 1),
66+
(SELECT package_version FROM addressables_builds WHERE id = 1),
67+
(SELECT COUNT(*) FROM addressables_build_bundles WHERE build_id = 1 and name = ""samplepack1_assets_0.bundle""),
68+
(SELECT file_size FROM addressables_build_bundles WHERE build_id = 2 and name = ""samplepack1_assets_0.bundle""),
69+
(SELECT packing_mode FROM addressables_build_groups WHERE build_id = 1 and name = ""SamplePack1""),
70+
(SELECT COUNT(*) FROM asset_bundles)";
71+
72+
using var reader = cmd.ExecuteReader();
73+
reader.Read();
74+
75+
Assert.AreEqual(2, reader.GetInt32(0), "Unexpected number of builds");
76+
Assert.AreEqual(1, reader.GetInt32(1), "Failed to find build matching reference filename");
77+
Assert.AreEqual("6000.1.0b2", reader.GetString(2), "Unexpected Unity Version");
78+
Assert.AreEqual("com.unity.addressables: 2.2.2", reader.GetString(3), "Unexpected Addressables version");
79+
Assert.AreEqual(1, reader.GetInt32(4), "Expected to find specific AssetBundle by name");
80+
Assert.AreEqual(33824, reader.GetInt32(5), "Unexpected size for specific AssetBundle in build 2");
81+
Assert.AreEqual("PackSeparately", reader.GetString(6), "Unexpected packing_mode for group");
82+
Assert.AreEqual(0, reader.GetInt32(7), "Expected no AssetBundles found in reference folder");
83+
}
84+
}

0 commit comments

Comments
 (0)