Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 42 additions & 6 deletions Assets/Tests/CustomElementTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NUnit.Framework;
Expand Down Expand Up @@ -30,7 +30,7 @@ public override async Task TearDown()
await base.TearDown();

// Destroy the instance. In some cases, it might be better not to do this.
_debugViewCustomElementTest= null;
_debugViewCustomElementTest = null;
}

[Test]
Expand All @@ -48,10 +48,10 @@ public async Task AddProfileInfoLabel_DisplaysCorrectProfileInfo()
var expectedMemory = ProfileUtils.GetTotalMemoryGB();
var frameTiming = ProfileUtils.GetLatestFrameTiming();
var expectedMemoryString = expectedMemory.ToString("F2");
var expectedCpuFpsString = (1000 / frameTiming.cpuFrameTime).ToString("F0");
var expectedCpuFpsString = (1000 / frameTiming.cpuFrameTime).ToString("F0");
var expectedCpuFrameTimeString = frameTiming.cpuFrameTime.ToString("F1");
var expectedGpuFpsString = (1000 / frameTiming.gpuFrameTime).ToString("F0");
var expectedGpuFrameTimeString = frameTiming.gpuFrameTime.ToString("F1");
var expectedGpuFrameTimeString = frameTiming.gpuFrameTime.ToString("F1");

Assert.That(label.text, Does.Contain(expectedMemoryString), "memory value should be contained in label.");
Assert.That(label.text, Does.Contain(expectedCpuFpsString), "cpu fps value should be contained in label.");
Expand All @@ -61,7 +61,7 @@ public async Task AddProfileInfoLabel_DisplaysCorrectProfileInfo()
}

[Test]
[TestCase (220, 332, 441, LogType.Error)]
[TestCase(220, 332, 441, LogType.Error)]
[TestCase(220, 441, 332, LogType.Warning)]
[TestCase(332, 441, 220, LogType.Log)]
[TestCase(332, 220, 441, LogType.Error)]
Expand Down Expand Up @@ -111,5 +111,41 @@ public async Task ConsoleView_SearchAndCategorizeMessages_WorksCorrectly(
Assert.That(filteredItems, Is.Not.Null, "3: The type of the filter result is incorrect.");
Assert.That(filteredItems.Count, Is.EqualTo(0), "3: The search results are not filtered correctly.");
}

[Test]
public async Task ConsoleView_ClickLogEntry_CopiesPressedLogText()
{
ConsoleView.Initialize();
GUIUtility.systemCopyBuffer = "";

var window = _debugViewCustomElementTest.Root.AddWindow("TestWindow");
window.parent.style.display = DisplayStyle.Flex;
var consoleView = window.AddConsoleView();

Debug.Log("Pressed log message");
Debug.LogWarning("Other warning message");

await Awaitable.NextFrameAsync();

var listView = consoleView.Q<ListView>();
Assert.That(listView, Is.Not.Null, "The ListView does not exist.");
Assert.That(listView.itemsSource.Count, Is.GreaterThanOrEqualTo(2), "The ListView should contain test logs.");

var buttons = consoleView.Query<Button>().ToList();
Assert.That(buttons.Exists(button => button.text == "Copy"), Is.False, "Bulk copy button should not exist.");

var labels = consoleView.Query<Label>().ToList();
var logLabel = labels.Find(label => label.text.Contains("Pressed log message"));
Assert.That(logLabel, Is.Not.Null, "The log entry label should exist.");

using var clickEvent = ClickEvent.GetPooled();
clickEvent.target = logLabel;
logLabel.SendEvent(clickEvent);

Assert.That(GUIUtility.systemCopyBuffer, Does.Contain("Pressed log message"));
Assert.That(GUIUtility.systemCopyBuffer, Does.Not.Contain("Other warning message"));
Assert.That(logLabel.style.borderLeftWidth.value, Is.GreaterThan(0f));
Assert.That(logLabel.style.unityFontStyleAndWeight.value, Is.EqualTo(FontStyle.Bold));
}
}
}
}
8 changes: 4 additions & 4 deletions Assets/Tests/DebugViewTabTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEngine.UIElements;
using UnityEngine.UIElements;

namespace DebugToolkit.Tests
{
Expand All @@ -11,9 +11,9 @@ protected override VisualElement CreateViewGUI()
var root = base.CreateViewGUI();
Root = root;
var window0 = root.AddWindow("TestWindow1");
var (tabRoot, tab1 ) = window0.AddTab("Tab1");
tab1.Add(new Label(){text = "TestTab1"});
tab1.Add(new Button(){text = "TestButton1"});
var (tabRoot, tab1) = window0.AddTab("Tab1");
tab1.Add(new Label() { text = "TestTab1" });
tab1.Add(new Button() { text = "TestButton1" });
var tab2 = tabRoot.AddTab("Tab2");
tab2.AddProfileInfoLabel();
return root;
Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/DebugViewTestBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEngine.UIElements;
using UnityEngine.UIElements;

namespace DebugToolkit.Tests
{
Expand Down
4 changes: 2 additions & 2 deletions Assets/Tests/DebugViewWindowTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEngine.UIElements;
using UnityEngine.UIElements;

namespace DebugToolkit.Tests
{
Expand All @@ -11,7 +11,7 @@ protected override VisualElement CreateViewGUI()
var root = base.CreateViewGUI();
Root = root;
var window0 = root.AddWindow("TestWindow1");
window0.Add(new Button(){text = "TestButton"});
window0.Add(new Button() { text = "TestButton" });
var window1 = root.AddWindow("TestWindow2");
window1.AddProfileInfoLabel();
return root;
Expand Down
4 changes: 2 additions & 2 deletions Assets/Tests/TabTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if UNITY_2023_2_OR_NEWER
#if UNITY_2023_2_OR_NEWER
using System.Threading.Tasks;
using NUnit.Framework;
using UnityEngine.UIElements;
Expand Down Expand Up @@ -57,4 +57,4 @@ public void TabLabel_IsCorrectlySet()
}
}
}
#endif
#endif
8 changes: 4 additions & 4 deletions Assets/Tests/TestBase.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Threading.Tasks;
using NUnit.Framework;
using UnityEngine;
using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
using UnityEngine.UIElements;
using UnityEngine.InputSystem;
using System.Threading.Tasks;

namespace DebugToolkit.Tests
{
Expand Down Expand Up @@ -70,4 +70,4 @@ protected async Awaitable ScrollAtPositionAsync(Mouse mouse, Vector2 position, V
await Awaitable.NextFrameAsync();
}
}
}
}
11 changes: 5 additions & 6 deletions Assets/Tests/UssTest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using NUnit.Framework;
using UnityEngine;
using UnityEngine.UIElements;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.InputSystem;
using System.Collections.Generic;
using UnityEngine.UIElements;

namespace DebugToolkit.Tests
{
Expand Down Expand Up @@ -181,5 +181,4 @@ private static void AddAllUIElements(VisualElement container)
container.Add(radioButtonGroup);
}
}
}

}
24 changes: 12 additions & 12 deletions Assets/Tests/WindowTest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using NUnit.Framework;
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.InputSystem;
using System.Threading.Tasks;
using System.Linq;
using UnityEngine.UIElements;

namespace DebugToolkit.Tests
{
Expand Down Expand Up @@ -35,8 +35,8 @@ public override async Task TearDown()
[Test]
public void MasterWindow_IsCorrectlyGenerated()
{
Assert.That( _debugViewWindowTest.MasterWindow, Is.Not.Null, "MasterWindow should be generated.");
Assert.That( _debugViewWindowTest.MasterWindow.parent.Q<Label>(
Assert.That(_debugViewWindowTest.MasterWindow, Is.Not.Null, "MasterWindow should be generated.");
Assert.That(_debugViewWindowTest.MasterWindow.parent.Q<Label>(
name: "window-label",
className: DebugConst.WindowLabelClassName)
.text, Is.EqualTo("Debug Toolkit"), "MasterWindow title is incorrect.");
Expand All @@ -46,7 +46,7 @@ public void MasterWindow_IsCorrectlyGenerated()
[Test]
public void MasterWindow_ContainsWindowListButtonsForOtherWindows()
{
var toggles = _debugViewWindowTest.MasterWindow.Query<Toggle>(className: DebugConst.ToggleWindowDisplayClassName)
var toggles = _debugViewWindowTest.MasterWindow.Query<Toggle>(className: DebugConst.ToggleWindowDisplayClassName)
.ToList();
Assert.That(toggles.Count, Is.EqualTo(2), "Incorrect number of window display toggles in MasterWindow.");
Assert.That(toggles.Any(t => t.text == "TestWindow1"), Is.True, "Toggle for TestWindow1 not found.");
Expand All @@ -60,7 +60,7 @@ public void MasterWindow_ContainsWindowListButtonsForOtherWindows()
public async Task MasterWindow_WindowListButton_TogglesWindowVisibility(string windowName, float screenPosX,
float screenPosY)
{
var toggle = _debugViewWindowTest.MasterWindow
var toggle = _debugViewWindowTest.MasterWindow
.Query<Toggle>(className: DebugConst.ToggleWindowDisplayClassName)
.Where(t => t.text == windowName).First();

Expand All @@ -80,7 +80,7 @@ public async Task MasterWindow_WindowListButton_TogglesWindowVisibility(string w
Assert.That(toggle.style.backgroundColor.value, Is.EqualTo(new Color(0.4f, 0.8f, 0.4f)),
"Toggle color for visible window is incorrect.");

await ClickAtPositionAsync(mouse, new Vector2(screenPosX, screenPosY));
await ClickAtPositionAsync(mouse, new Vector2(screenPosX, screenPosY));

Assert.That(testWindow.style.display.value, Is.EqualTo(DisplayStyle.None),
"Window should be hidden after toggle.");
Expand Down Expand Up @@ -227,7 +227,7 @@ public void WindowHeader_IsCorrectlyAdded()
public async Task WindowCloseButton_HidesWindowAndUpdatesToggle(string windowName, float screenPosX,
float screenPosY)
{
var toggle = _debugViewWindowTest.MasterWindow
var toggle = _debugViewWindowTest.MasterWindow
.Query<Toggle>(className: DebugConst.ToggleWindowDisplayClassName)
.Where(t => t.text == windowName).First();

Expand All @@ -241,12 +241,12 @@ public async Task WindowCloseButton_HidesWindowAndUpdatesToggle(string windowNam
Assert.That(toggle.style.backgroundColor.value, Is.EqualTo(new Color(0.4f, 0.8f, 0.4f)),
"Toggle color should indicate visible window.");

await ClickAtPositionAsync(mouse,new Vector2(screenPosX, screenPosY));
await ClickAtPositionAsync(mouse, new Vector2(screenPosX, screenPosY));

Assert.That(window.style.display.value, Is.EqualTo(DisplayStyle.None),
"Window should be hidden after clicking close button.");
Assert.That(toggle.style.backgroundColor.value, Is.EqualTo(new Color(0.6f, 0.2f, 0.2f)),
"Toggle color should indicate hidden window.");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("DebugToolkit.Editor")]
[assembly: InternalsVisibleTo("DebugToolkit.Tests")]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable enable
#nullable enable

using UnityEngine;

Expand Down
22 changes: 11 additions & 11 deletions Packages/jp.andantetribe.debugtoolkit/Runtime/DebugExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#nullable enable
#nullable enable

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine.UIElements;
using UnityEngine;
using UnityEngine.UIElements;

namespace DebugToolkit
{
Expand All @@ -17,7 +17,7 @@ public static void AddProfileInfoLabel(this VisualElement visualElement)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AddProfileInfoLabel(this VisualElement visualElement, in TimeSpan interval)
{
var label = new Label{ enableRichText = true };
var label = new Label { enableRichText = true };
visualElement.Add(label);
label.schedule.Execute(() =>
{
Expand Down Expand Up @@ -92,7 +92,7 @@ public static VisualElement AddConsoleView(this VisualElement root)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static VisualElement AddWindow(this VisualElement root, string windowName = "")
{
var window = new DebugWindow(){name = windowName};
var window = new DebugWindow() { name = windowName };
root.GetSafeAreaContainer().Add(window);

window.AddToClassList(DebugConst.ClassName + "__master");
Expand Down Expand Up @@ -165,7 +165,7 @@ private static void AddWindowToggle(this VisualElement root, VisualElement windo
toggle.text = windowName;
toggle.AddToClassList(DebugConst.ToggleWindowDisplayClassName);

toggle.RegisterCallback<ChangeEvent<bool>, (VisualElement window, Toggle toggle)>(static (evt,args) =>
toggle.RegisterCallback<ChangeEvent<bool>, (VisualElement window, Toggle toggle)>(static (evt, args) =>
{
args.window.style.display = evt.newValue
? DisplayStyle.Flex
Expand Down Expand Up @@ -205,16 +205,16 @@ private static StyleColor GetWindowStateColor(VisualElement window)
/// <returns>The created header element</returns>
private static VisualElement AddWindowHeader(this VisualElement root, string windowName = "")
{
var windowHeader = new VisualElement(){name = "window-header"};
var windowHeader = new VisualElement() { name = "window-header" };
windowHeader.AddToClassList(DebugConst.WindowHeaderClassName);

var manipulator = new DragManipulator(root);
var dragArea = new VisualElement(){ name = "drag-area" };
var dragArea = new VisualElement() { name = "drag-area" };
dragArea.AddToClassList(DebugConst.ClassName + "__drag-area");
dragArea.AddManipulator(manipulator);
windowHeader.Add(dragArea);

var windowLabel = new Label(){ name = "window-label",text = windowName };
var windowLabel = new Label() { name = "window-label", text = windowName };
windowLabel.AddToClassList(DebugConst.WindowLabelClassName);
dragArea.Add(windowLabel);

Expand Down Expand Up @@ -250,7 +250,7 @@ internal static VisualElement GetSafeAreaContainer(this VisualElement element)

internal static VisualElement GetDebugWindowParent(this DebugWindow element)
{
for (VisualElement current = element.VisibilityToggleButton; current != null; current = current.parent)
for (VisualElement? current = element.VisibilityToggleButton; current != null; current = current.parent)
{
if (current.ClassListContains(DebugConst.MasterWindowClassName) ||
current.ClassListContains(DebugConst.NormalWindowClassName))
Expand Down Expand Up @@ -288,12 +288,12 @@ public static ScrollView AddTab(this TabView tabView, string label = "")
/// <param name="label">The label for the tab</param>
/// <returns>A tuple containing the added TabView and ScrollView</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static (TabView, ScrollView) AddTab(this VisualElement root, string label = "")
public static (TabView, ScrollView) AddTab(this VisualElement root, string label = "")
{
var tabView = new TabView();
root.Add(tabView);
return (tabView, tabView.AddTab(label));
}
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ private void ToggleAllVisible()
if (isAnyVisibleEnable)
{
SetVisibility(window, false);
}else if (ShouldBeVisibleByDefault(window))
}
else if (ShouldBeVisibleByDefault(window))
{
SetVisibility(window, true);
}
Expand All @@ -138,9 +139,9 @@ private static bool ShouldBeVisibleByDefault(DebugWindow window) =>
/// <param name="visible">True to show the window, false to hide it.</param>
private static void SetVisibility(DebugWindow window, bool visible)
{
if(window.VisibilityToggleButton != null)
if (window.VisibilityToggleButton != null)
window.VisibilityToggleButton.value = visible;
window.style.display = visible ? DisplayStyle.Flex : DisplayStyle.None;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#nullable enable

using System.Collections.Generic;
using UnityEngine.UIElements;
using UnityEngine;
using UnityEngine.UIElements;

namespace DebugToolkit
{
Expand Down Expand Up @@ -73,4 +73,4 @@ private void Redo()
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable enable
#nullable enable

using System;
using System.Collections.Generic;
Expand Down
Loading
Loading