From 081ed0d88347deb0fe9c49edb6ab2e8fca8de442 Mon Sep 17 00:00:00 2001 From: Ding Yuntian <1491671119@qq.com> Date: Sun, 19 Jul 2026 00:00:01 +0800 Subject: [PATCH] =?UTF-8?q?test(save):=20=E6=B7=BB=E5=8A=A0=E6=BC=94?= =?UTF-8?q?=E5=87=BA=E5=BF=AB=E7=85=A7=E5=A5=91=E7=BA=A6=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 校验 showcase/playTool/screen 的 SaveId 与还原顺序, 以及快照 section 的 JSON 序列化往返。 --- .../PresentationSnapshotContractTests.cs | 69 +++++++++++++++++++ .../PresentationSnapshotContractTests.cs.meta | 2 + 2 files changed, 71 insertions(+) create mode 100644 Assets/Editor/PresentationSnapshotContractTests.cs create mode 100644 Assets/Editor/PresentationSnapshotContractTests.cs.meta diff --git a/Assets/Editor/PresentationSnapshotContractTests.cs b/Assets/Editor/PresentationSnapshotContractTests.cs new file mode 100644 index 000000000..0617ef723 --- /dev/null +++ b/Assets/Editor/PresentationSnapshotContractTests.cs @@ -0,0 +1,69 @@ +using AibisDream.SaveSystem; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using NUnit.Framework; + +namespace AibisDream.SystemEditor.Tests +{ + public sealed class PresentationSnapshotContractTests + { + [Test] + public void Providers_UseDistinctStableIdsAndRestoreBeforeScreen() + { + var showcase = new ShowcaseSnapshotProvider(); + var playTool = new PlayToolSnapshotProvider(); + var screen = new ScreenSnapshotProvider(); + + Assert.That(showcase.SaveId, Is.EqualTo("showcase")); + Assert.That(playTool.SaveId, Is.EqualTo("playTool")); + Assert.That(showcase.RestoreOrder, Is.LessThan(playTool.RestoreOrder)); + Assert.That(playTool.RestoreOrder, Is.LessThan(screen.RestoreOrder)); + } + + [Test] + public void PresentationSections_RoundTripThroughSnapshotJson() + { + var source = new SaveSnapshot(); + source.sections[SnapshotProviderIds.PlayTool] = new PlayToolSnapshotDto + { + isObjVisible = true, + objPicName = "证物", + isFullScreenVisible = true, + fullScreenPicName = "教室" + }; + source.sections[SnapshotProviderIds.Showcase] = new ShowcaseSnapshotDto + { + displayMode = nameof(ShowcaseDisplayMode.Small), + picName = "D2S轱辘", + usesSplitLayers = true + }; + + var json = JsonConvert.SerializeObject(source); + var restored = JsonConvert.DeserializeObject(json); + var playTool = ((JObject)restored.sections[SnapshotProviderIds.PlayTool]) + .ToObject(); + var showcase = ((JObject)restored.sections[SnapshotProviderIds.Showcase]) + .ToObject(); + + Assert.That(playTool.isObjVisible, Is.True); + Assert.That(playTool.objPicName, Is.EqualTo("证物")); + Assert.That(playTool.isFullScreenVisible, Is.True); + Assert.That(playTool.fullScreenPicName, Is.EqualTo("教室")); + Assert.That(showcase.displayMode, Is.EqualTo(nameof(ShowcaseDisplayMode.Small))); + Assert.That(showcase.picName, Is.EqualTo("D2S轱辘")); + Assert.That(showcase.usesSplitLayers, Is.True); + Assert.That(restored.schemaVersion, Is.EqualTo(1)); + } + + [Test] + public void OldSnapshotWithoutPresentationSections_RemainsCompatible() + { + var restored = JsonConvert.DeserializeObject( + "{\"schemaVersion\":1,\"sections\":{}}"); + + Assert.That(restored.schemaVersion, Is.EqualTo(SaveSnapshotSchema.CurrentVersion)); + Assert.That(restored.sections.ContainsKey(SnapshotProviderIds.PlayTool), Is.False); + Assert.That(restored.sections.ContainsKey(SnapshotProviderIds.Showcase), Is.False); + } + } +} diff --git a/Assets/Editor/PresentationSnapshotContractTests.cs.meta b/Assets/Editor/PresentationSnapshotContractTests.cs.meta new file mode 100644 index 000000000..137f965da --- /dev/null +++ b/Assets/Editor/PresentationSnapshotContractTests.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: aa21851c46624f77a67e29c86ec854c9