diff --git a/Project.toml b/Project.toml index 9424bfe..04e22ea 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ImGuiTestEngine" uuid = "464e2eba-0a11-4ed3-b274-413caa1a1cca" authors = ["JamesWrigley "] -version = "0.1.0" +version = "0.1.1" [deps] CImGui = "5d785b6c-b76f-510e-a07c-3070796c7e87" @@ -13,8 +13,8 @@ ScopedValues = "7e506255-f358-4e82-b7e4-beb19740aa63" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] -CImGui = "2" -CImGuiPack_jll = "0.3" +CImGui = "2,3" +CImGuiPack_jll = "0.3,0.4" Compat = "4.15.0" CxxWrap = "0.16.0" DocStringExtensions = "0.9.3" diff --git a/docs/src/_changelog.md b/docs/src/_changelog.md index 62d0fe1..a25e359 100644 --- a/docs/src/_changelog.md +++ b/docs/src/_changelog.md @@ -7,10 +7,19 @@ CurrentModule = ImGuiTestEngine This documents notable changes in ImGuiTestEngine.jl. The format is based on [Keep a Changelog](https://keepachangelog.com). -## Unreleased +## [v1.0.0] - 2024-09-03 + +This release is compatible with CImGui.jl v2 and v3. ### Added - Bindings for [`ComboClick()`](@ref) and [`ComboClickAll()`](@ref) ([#4]). +- Bindings for [`MouseClick()`](@ref), [`MouseMove()`](@ref), + [`ItemOpen()`](@ref), [`ItemClose()`](@ref), and a helper + [`OpenAndClose()`](@ref) ([#5]). + +### Changed +- [`ItemClick()`](@ref) now supports passing a `button` argument to select which + button to click ([#5]). ## [v0.1.0] - 2024-06-27 diff --git a/docs/src/api.md b/docs/src/api.md index 2502def..382c0c6 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -120,6 +120,11 @@ TestContext @imcheck_noret SetRef GetRef +MouseClick +MouseMove +ItemOpen +ItemClose +OpenAndClose ItemClick ItemDoubleClick ItemCheck diff --git a/src/ImGuiTestEngine.jl b/src/ImGuiTestEngine.jl index f2007fb..876dc96 100644 --- a/src/ImGuiTestEngine.jl +++ b/src/ImGuiTestEngine.jl @@ -7,9 +7,12 @@ import DocStringExtensions: TYPEDEF, TYPEDSIGNATURES export @register_test, @imcheck, @imcheck_noret, SetRef, GetRef, GetWindowByRef, - ItemClick, ItemDoubleClick, ItemCheck, MenuClick, + ItemClick, ItemDoubleClick, ItemCheck, ItemOpen, ItemClose, + MenuClick, ComboClick, ComboClickAll, - Yield + MouseClick, MouseMove, + Yield, + OpenAndClose @compat public (Engine, EngineIO, ImGuiTest, TestRef, TestContext, TestGroup, TestRunFlags, TestVerboseLevel, RunSpeed, @@ -45,9 +48,9 @@ if !isdefined(Base, :ScopedValues) else import Base.ScopedValues: ScopedValue, @with end +import CImGui as ig include("context.jl") -import CImGui as ig include("engine.jl") """ diff --git a/src/context.jl b/src/context.jl index 6f9b532..cbe049e 100644 --- a/src/context.jl +++ b/src/context.jl @@ -195,11 +195,46 @@ Simulate a click on the reference. end ``` """ -function ItemClick(test_ref::TestRef, ctx=nothing) +function ItemClick(test_ref::TestRef, button::ig.ImGuiMouseButton_ = ig.ImGuiMouseButton_Left, ctx=nothing) @_default_ctx - lib.ItemClick(ctx, lib.ImGuiTestRef(test_ref)) + lib.ItemClick(ctx, lib.ImGuiTestRef(test_ref), Int(button)) end +""" +$(TYPEDSIGNATURES) + +Ensure an item is opened. + +# Examples +```julia +@register_test(engine, "foo", "bar") do ctx + ItemOpen("My menu") +end +``` +""" +function ItemOpen(test_ref::TestRef, flags=0, ctx=nothing) + @_default_ctx + lib.ItemOpen(ctx, lib.ImGuiTestRef(test_ref), Int(flags)) +end + +""" +$(TYPEDSIGNATURES) + +Ensure an item is closed. + +# Examples +```julia +@register_test(engine, "foo", "bar") do ctx + ItemClose("My menu") +end +``` +""" +function ItemClose(test_ref::TestRef, flags=0, ctx=nothing) + @_default_ctx + lib.ItemClose(ctx, lib.ImGuiTestRef(test_ref), Int(flags)) +end + + """ $(TYPEDSIGNATURES) @@ -288,6 +323,41 @@ end """ $(TYPEDSIGNATURES) +Move the mouse to `test_ref`. + +# Examples +```julia +@register_test(engine, "foo", "bar") do ctx + MouseMove("My button") +end +``` +""" +function MouseMove(test_ref::TestRef, ctx=nothing) + @_default_ctx + lib.MouseMove(ctx, lib.ImGuiTestRef(test_ref)) +end + +""" +$(TYPEDSIGNATURES) + +Register a click of `button`. + +# Examples +```julia +@register_test(engine, "foo", "bar") do ctx + MouseClick() # LMB + MouseClick(ig.ImGuiMouseButton_Right) # RMB +end +``` +""" +function MouseClick(button::ig.ImGuiMouseButton_ = ig.ImGuiMouseButton_Left, ctx=nothing) + @_default_ctx + lib.MouseClick(ctx, Int(button)) +end + +""" +$(TYPEDSIGNATURES) + Retrieve a `ImGuiWindow` by reference. This will return `nothing` if the window was not found. @@ -317,3 +387,40 @@ function Yield(count::Int=1, ctx=nothing) @_default_ctx lib.Yield(ctx, count) end + +""" +$(TYPEDSIGNATURES) + +A helper function that will ensure `test_ref` is open, execute `f()`, and close +`test_ref` again. A typical use would be to open a section, run some tests, and +then close the section again (handy for re-runnable tests). + +# Examples +```julia +@register_test(engine, "foo", "bar") do ctx + OpenAndClose("My section") do + # ... + end +end +``` +""" +function OpenAndClose(f, test_ref::TestRef, ctx=nothing) + @_default_ctx + ItemOpen(test_ref) + f() + ItemClose(test_ref) +end + +""" +$(TYPEDSIGNATURES) + +Open and then close `test_ref`. + +# Examples +```julia +@register_test(engine, "foo", "bar") do ctx + OpenAndClose("My section") +end +``` +""" +OpenAndClose(test_ref::TestRef, ctx=nothing) = OpenAndClose(Returns(nothing), test_ref, ctx) diff --git a/test/Project.toml b/test/Project.toml index 6188116..e9b7140 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -2,6 +2,5 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" CImGui = "5d785b6c-b76f-510e-a07c-3070796c7e87" GLFW = "f7f18e0c-5ee9-5ccd-a5bf-e8befd85ed98" -ImGuiTestEngine = "464e2eba-0a11-4ed3-b274-413caa1a1cca" ModernGL = "66fc600b-dfda-50eb-8b99-91cfa97b1301" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/runtests.jl b/test/runtests.jl index fb71ba2..bb8c4d1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -328,6 +328,80 @@ end @imcheck double_clicked end + tree1_open = nothing + tree2_opened = false + t = @register_test(engine, "Context", "Item opening/closing") + t.GuiFunc = ctx -> begin + ig.Begin("Window") + if ig.TreeNode("Tree1") + tree1_open = true + ig.TreePop() + else + tree1_open = false + end + + if ig.TreeNode("Tree2") + tree2_opened = true + ig.TreePop() + end + + ig.End() + end + t.TestFunc = ctx -> begin + SetRef("Window") + + @imcheck !tree1_open + ItemOpen("Tree1") + @imcheck tree1_open + ItemClose("Tree1") + @imcheck !tree1_open + + @imcheck !tree2_opened + OpenAndClose("Tree2") + @imcheck tree2_opened + end + + mouse_clicked = false + mouse_rightclicked = false + t = @register_test(engine, "Context", "MouseClick") + t.GuiFunc = ctx -> begin + ig.Begin("Window") + + if ig.IsMouseClicked(ig.ImGuiMouseButton_Left) + mouse_clicked = true + end + if ig.IsMouseClicked(ig.ImGuiMouseButton_Right) + mouse_rightclicked = true + end + + ig.End() + end + t.TestFunc = ctx -> begin + @imcheck !mouse_clicked + @imcheck !mouse_rightclicked + + MouseClick() + @imcheck mouse_clicked + MouseClick(ig.ImGuiMouseButton_Right) + @imcheck mouse_rightclicked + end + + is_hovered = false + t = @register_test(engine, "Context", "MouseMove") + t.GuiFunc = ctx -> begin + ig.Begin("Window") + ig.Button("Button") + is_hovered = ig.IsItemHovered() + ig.End() + end + t.TestFunc = ctx -> begin + SetRef("Window") + + @imcheck !is_hovered + MouseMove("Button") + @imcheck is_hovered + end + ig.render(ctx; engine) do ; end end end