using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using KernelPanic.Core; using KernelPanic.Data; using KernelPanic.Meta; using KernelPanic.Run; using KernelPanic.UI; using NUnit.Framework; using UnityEditor; using UnityEngine; using UnityEngine.UIElements; using UnityEngine.TestTools; public class MenuPersistenceTests { private const BindingFlags Private = BindingFlags.Instance | BindingFlags.NonPublic; private GameObject _owner; private MainMenuController _menu; private VisualElement _root; private VisualElement _shell; private string _directory; private SaveService _save; private TerminalFocusTestWindow _window; [SetUp] public void SetUp() { _directory = Path.Combine(Path.GetTempPath(), "KernelPanic.MenuTests." + Guid.NewGuid().ToString("N")); Directory.CreateDirectory(_directory); _save = new SaveService(Path.Combine(_directory, "save.json")); _owner = new GameObject("menu persistence regression"); _owner.SetActive(false); // Build only the dependencies under test; do not touch a real player save. _menu = _owner.AddComponent(); _root = new VisualElement(); _shell = new VisualElement { name = "ShellRoot" }; _root.Add(_shell); Set("_root", _root); Set("_shellRoot", _shell); Call("ComposeMetaServices"); Set("_saveService", _save); } [TearDown] public void TearDown() { if (_window != null) _window.Close(); UnityEngine.Object.DestroyImmediate(_owner); if (Directory.Exists(_directory)) Directory.Delete(_directory, true); } [TestCase("{ broken json")] [TestCase("{\"schemaVersion\":2147483647,\"payload\":\"future\"}")] public void UnreadableSaveBlocksProgressionAndCannotBeReplacedByStartupAutosave(string contents) { File.WriteAllText(_save.SavePath, contents); Call("LoadMetaState"); Assert.That(_shell.enabledSelf, Is.False); Assert.That(_root.Q