ModernUO/Projects/UOContent.Tests/Tests/Commands/Objects/ObjectIndexSerializationTests.cs
Kamron Batman bff08c69d2
perf(objects): batch CAGLoader.BuildTree leaf insertion to O(N)
BuildTree previously grew each category's Nodes array by one element per
object via AppendObject/AppendNode, causing O(N^2) array copies across large
categories (e.g. Items.Uncategorized) on every server startup. Leaves are
now accumulated per-category in a List and flushed with a single array
allocation per category via a new AppendNodes helper. AddFallbackForStaleCache
and LoadLegacy are untouched.

Also adds a JSON round-trip test for ObjectIndexFile/ObjectIndexEntry to
guard the gfx/hue property mapping and the Objects = [] initializer against
double-appending on deserialize.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-19 12:38:05 -07:00

52 lines
1.4 KiB
C#

using System.IO;
using Server.Commands;
using Server.Json;
using Xunit;
namespace UOContent.Tests.Commands.Objects;
public class ObjectIndexSerializationTests
{
[Fact]
public void ObjectIndexFile_round_trips_through_json()
{
var index = new ObjectIndexFile
{
GeneratedUtc = "2026-07-19T00:00:00Z",
Objects =
[
new ObjectIndexEntry
{
Type = "Katana",
Entity = "item",
Category = "Items.Weapons.Swords",
Chunk = "items.weapons.swords",
ItemID = 8901,
Hue = 0x461,
Name = "katana",
Cliloc = 1041267
}
]
};
var tempPath = Path.GetTempFileName();
try
{
JsonConfig.Serialize(tempPath, index);
var roundTripped = JsonConfig.Deserialize<ObjectIndexFile>(tempPath);
Assert.NotNull(roundTripped);
var entry = Assert.Single(roundTripped.Objects);
Assert.Equal("Katana", entry.Type);
Assert.Equal("items.weapons.swords", entry.Chunk);
Assert.Equal(8901, entry.ItemID);
Assert.Equal(0x461, entry.Hue);
Assert.Equal(1041267, entry.Cliloc);
}
finally
{
File.Delete(tempPath);
}
}
}