/// <summary> /// Ensure a newly created button icon set instance contains all default textures / characters. /// </summary> public IEnumerator TestDefaultIconSetInstance() { // Create a button icon set and insert arrays with null references ButtonIconSet buttonIconSet = ScriptableObject.CreateInstance <ButtonIconSet>(); // The icon set will nave no quad icons. Assert.IsNotNull(buttonIconSet.QuadIcons); Assert.IsTrue(buttonIconSet.QuadIcons.Length == 0); Assert.IsFalse(buttonIconSet.TryGetQuadIcon("EmptyIcon", out _)); // The icon set will nave no sprite icons. Assert.IsNotNull(buttonIconSet.SpriteIcons); Assert.IsTrue(buttonIconSet.SpriteIcons.Length == 0); Assert.IsFalse(buttonIconSet.TryGetSpriteIcon("EmptyIcon", out _)); // The icon set should have the following icons by default. Assert.IsNotNull(buttonIconSet.CharIcons); Assert.IsTrue(buttonIconSet.TryGetCharIcon("AppBarAdjust", out _)); Assert.IsTrue(buttonIconSet.TryGetCharIcon("AppBarClose", out _)); Assert.IsTrue(buttonIconSet.TryGetCharIcon("AppBarDone", out _)); Assert.IsTrue(buttonIconSet.TryGetCharIcon("AppBarHide", out _)); Assert.IsTrue(buttonIconSet.TryGetCharIcon("AppBarShow", out _)); Assert.IsTrue(buttonIconSet.TryGetCharIcon("AppBarHome", out _)); yield break; }
/// <summary> /// Test creating a button icon set and inserting null elements. /// </summary> public IEnumerator TestBadlyConfiguredIconSet() { // Create a button icon set and insert arrays with null references ButtonIconSet buttonIconSet = ScriptableObject.CreateInstance <ButtonIconSet>(); SerializedObject buttonIconSetObject = new SerializedObject(buttonIconSet); SerializedProperty quadIconsProp = buttonIconSetObject.FindProperty("quadIcons"); SerializedProperty spriteIconsProp = buttonIconSetObject.FindProperty("spriteIcons"); SerializedProperty charIconsProp = buttonIconSetObject.FindProperty("charIcons"); quadIconsProp.InsertArrayElementAtIndex(0); spriteIconsProp.InsertArrayElementAtIndex(0); charIconsProp.InsertArrayElementAtIndex(0); buttonIconSetObject.ApplyModifiedProperties(); // These calls should not fail even if we have null / empty elements. Texture2D quadIcon; Assert.IsFalse(buttonIconSet.TryGetQuadIcon("EmptyIcon", out quadIcon)); Sprite spritecon; Assert.IsFalse(buttonIconSet.TryGetSpriteIcon("EmptyIcon", out spritecon)); uint charIcon; Assert.IsFalse(buttonIconSet.TryGetCharIcon("EmptyIcon", out charIcon)); yield break; }