Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve test coverage #70

Merged
merged 3 commits into from
Jun 23, 2024
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
11 changes: 0 additions & 11 deletions GI/src/GLibBase/GLibBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ export GInterface, GType, GObject, GBoxed, GTypeInstance
export GEnum, GError, GValue, g_type
export GHashTable, GByteArray, GArray, GPtrArray
export GList, _GSList, _GList
export cfunction_


cfunction_(@nospecialize(f), r, a::Tuple) = cfunction_(f, r, Tuple{a...})

@generated function cfunction_(f, R::Type{rt}, A::Type{at}) where {rt, at<:Tuple}
quote
@cfunction($(Expr(:$,:f)), $rt, ($(at.parameters...),))
end
end

# local function, handles Symbol and makes UTF8-strings easier
const AbstractStringLike = Union{AbstractString, Symbol}
Expand All @@ -33,7 +23,6 @@ bytestring(s::Symbol) = s
bytestring(s::Ptr{UInt8}) = s == C_NULL ? nothing : unsafe_string(s)
# bytestring(s::Ptr{UInt8}, own::Bool=false) = unsafe_string(s)

g_malloc(s::Integer) = ccall((:g_malloc, libglib), Ptr{Nothing}, (Csize_t,), s)
g_free(p::Ptr) = ccall((:g_free, libglib), Nothing, (Ptr{Nothing},), p)

gtkdoc_const_url(ns,name)="https://docs.gtk.org/$(ns)/const.$(name).html"
Expand Down
1 change: 0 additions & 1 deletion GI/src/GLibBase/gtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ end
g_isa(gtyp::GType, is_a_type::GType) = ccall((:g_type_is_a, libgobject), Cint, (GType, GType), gtyp, is_a_type) != 0
g_type_name(g_type::GType) = Symbol(bytestring(ccall((:g_type_name, libgobject), Ptr{UInt8}, (GType,), g_type)))

g_type_test_flags(g_type::GType, flag) = ccall((:g_type_test_flags, libgobject), Bool, (GType, GEnum), g_type, flag)
const G_TYPE_FLAG_CLASSED = 1 << 0
const G_TYPE_FLAG_INSTANTIATABLE = 1 << 1
const G_TYPE_FLAG_DERIVABLE = 1 << 2
Expand Down
7 changes: 0 additions & 7 deletions GI/src/girepo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function info_unref(info::GIInfo)
info.handle = C_NULL
end

convert(::Type{Ptr{GIBaseInfo}},w::GIInfo) = w.handle
unsafe_convert(::Type{Ptr{GIBaseInfo}},w::GIInfo) = w.handle

const GIInfoTypesShortNames = (:Invalid, :Function, :Callback, :Struct, :Boxed, :Enum,
Expand Down Expand Up @@ -115,13 +114,7 @@ struct GINamespace
new(namespace)
end
end
convert(::Type{Symbol}, ns::GINamespace) = ns.name
convert(::Type{Cstring}, ns::GINamespace) = ns.name
convert(::Type{Ptr{UInt8}}, ns::GINamespace) = convert(Ptr{UInt8}, ns.name)
unsafe_convert(::Type{Symbol}, ns::GINamespace) = ns.name
unsafe_convert(::Type{Ptr{UInt8}}, ns::GINamespace) = convert(Ptr{UInt8}, ns.name)

Base.:(==)(a::GINamespace, b::GINamespace) = (a.name === b.name)

function gi_require(namespace::Symbol, version = nothing)
if isnothing(version)
Expand Down
1 change: 0 additions & 1 deletion src/buttons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,3 @@ end
GtkPopoverMenuBar(model::GMenu) = G_.PopoverMenuBar_new_from_model(model)

menu_model(b::Union{GtkMenuButton,GtkPopoverMenu, GtkPopoverMenuBar}, model) = G_.set_menu_model(b, GMenuModel(model))
menu_model(b::Union{GtkMenuButton,GtkPopoverMenu, GtkPopoverMenuBar}) = G_.get_menu_model(b)
2 changes: 1 addition & 1 deletion src/cairo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ end

function _canvas_on_resize(::Ptr, width, height, canvas)
canvas.is_sized = true
if G_.get_realized(canvas)
if isrealized(canvas)
_init_canvas!(canvas, width, height)

if isa(canvas.resize, Function)
Expand Down
4 changes: 2 additions & 2 deletions src/gen/gdkpixbuf_consts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ quote
$(Expr(:toplevel, quote
begin
const PIXBUF_MAJOR = 2
const PIXBUF_MICRO = 8
const PIXBUF_MICRO = 10
const PIXBUF_MINOR = 42
const PIXBUF_VERSION = "2.42.8"
const PIXBUF_VERSION = "2.42.10"
begin
@cenum Colorspace::Int32 Colorspace_RGB = 0
(GLib.g_type(::Type{T}) where T <: Colorspace) = begin
Expand Down
2 changes: 2 additions & 0 deletions test/gdkpixbuf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ using Test, Gtk4, Gtk4.GdkPixbufLib, Colors, TestImages

t2 = GdkMemoryTexture(img,false)
@test size(t2) == size(img)
arr = Gtk4.toarray(t2)
@test size(arr) == size(img)
end

@testset "pixbuf" begin
Expand Down
3 changes: 2 additions & 1 deletion test/gui/canvas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ gs = GtkEventControllerScroll(Gtk4.EventControllerScrollFlags_VERTICAL,c)
gk = GtkEventControllerKey(c)
ggc = GtkGestureClick(c)
ggd = GtkGestureDrag(c)
gsc = GtkShortcutController(c)
gsc = GtkShortcutController(c)
Gtk4.add_action_shortcut(gsc,"<Control>S","win.copy")
ggz = GtkGestureZoom(c)
t = Gtk4.find_controller(c,GtkEventControllerMotion)
@test t==gm
Expand Down
9 changes: 9 additions & 0 deletions test/gui/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,13 @@ end
destroy(main_window)
end

@testset "Show Image" begin
include(joinpath(@__DIR__, "..", "..", "examples", "show_image.jl"))
destroy(win)
end

@testset "CSS Style" begin
include(joinpath(@__DIR__, "..", "..", "examples", "css-style.jl"))
end

end
2 changes: 2 additions & 0 deletions test/gui/layout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ end
push!(nb, four, "tab _four")
@test pagenumber(nb, four) == 4
@test length(nb) == 4
deleteat!(nb, 3)
@test length(nb) == 3
empty!(nb)
@test length(nb) == 0
destroy(w)
Expand Down
28 changes: 22 additions & 6 deletions test/gui/misc.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using Test, Gtk4, Gtk4.G_, Gtk4.GLib

@testset "Initialization" begin
@test Gtk4.isinitialized()
end

@testset "get/set property and binding" begin
w = GtkWindow("Window", 400, 300)
@test w.title == "Window"
Expand Down Expand Up @@ -125,6 +129,9 @@ Gtk4.child(w,f)
l = GtkLabel("label"); push!(f,l)
b = GtkButton("button"); push!(f,b)

add_css_class(b,"error")
remove_css_class(b,"error")

counter = 0
id = signal_connect(b, "activate") do widget
counter::Int += 1
Expand All @@ -151,7 +158,7 @@ destroy(w)
end

@testset "Builder" begin
b=GtkBuilder("test.ui")
b=GtkBuilder(joinpath(dirname(@__FILE__), "test.ui"))
widgets = [w for w in b]
@test length(widgets)==length(b)
@test length(b)==6
Expand All @@ -165,15 +172,17 @@ destroy(a_window)

@test button == b["a_button"]

s = open("test.ui","r") do f
testui = joinpath(dirname(@__FILE__), "test.ui")

s = open(testui,"r") do f
read(f,String)
end
b3 = GtkBuilder(s,-1)
win = b3["a_window"]
destroy(win)

b4 = GtkBuilder()
push!(b4; filename="test.ui")
push!(b4; filename=testui)

win = b4["a_window"]
destroy(win)
Expand Down Expand Up @@ -206,7 +215,7 @@ end
w = GtkWindow(l)
show(w)

### add css tests here
delete!(sc, provider)

destroy(w)
end
Expand All @@ -215,9 +224,15 @@ end
@test keyval("H") == Gtk4.KEY_H
end

@testset "IconTheme" begin
i = GtkIconTheme(GdkDisplay())
@testset "IconTheme and CSS for GdkDisplay" begin
d = GdkDisplay()
i = GtkIconTheme(d)
Gtk4.icon_theme_add_search_path(i, ".")

css = "GtkLabel { color: blue; }"
provider = GtkCssProvider(css)
push!(d, provider, 500)
delete!(d, provider)
end

@testset "Menus" begin
Expand All @@ -239,6 +254,7 @@ push!(filemenu, quit)
GLib.submenu(menubar,"File",filemenu)

mb = GtkPopoverMenuBar(menubar)
@test Gtk4.menu_model(mb) == menubar
b = GtkBox(:h)
push!(b,mb)
win = GtkWindow(b, "Menus", 200, 40)
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ include("gui/input.jl")
include("gui/layout.jl")
include("gui/window.jl")
include("gui/listviews.jl")
#include("gui/examples.jl")
#include("gui/application.jl") # needs to be last because it messes with the main loop
include("gui/examples.jl")
include("gui/application.jl") # needs to be last because it messes with the main loop
end

GC.gc()
Expand Down
Loading