Skip to content

Commit

Permalink
add some basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martindemello committed Feb 5, 2023
1 parent ebc4023 commit 90cb3fc
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
run: |
echo '' | bash -c "sh <(curl -fsSL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh)"
opam init
opam install -y dune dune-configurator
opam install -y dune dune-configurator alcotest
- name: Build ocaml-gtk
run: |
eval `opam env`
Expand All @@ -38,7 +38,7 @@ jobs:
run: |
echo '' | bash -c "sh <(curl -fsSL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh)"
opam init
opam install -y dune dune-configurator
opam install -y dune dune-configurator alcotest
- name: Build ocaml-gtk
run: |
eval `opam env`
Expand Down
4 changes: 4 additions & 0 deletions tests/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(tests
(names get_set)
(modes exe)
(libraries alcotest ocamlgtk))
58 changes: 58 additions & 0 deletions tests/get_set.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
let e = epsilon_float

(* For tests that need to be run within an initialised Gtk.application *)
let run_app f =
let app = Gtk.application "org.gtk.example" Gio.ApplicationFlags.flags_none in
ignore @@ app#signal_connect_activate f;
ignore @@ app#run [||]

let int () =
run_app begin fun () ->
let p = Gtk.picture () in
let _ = p#set_margin_start 1 in
let v = p#get_margin_start in
Alcotest.(check int) "Set and retrieved gint" v 1
end

let double () =
run_app begin fun () ->
let ps = Gtk.page_setup () in
let _ = ps#set_left_margin 1.0 1 in
let margin = ps#get_left_margin 1 in
Alcotest.(check @@ float e) "Set and retrieved gdouble" margin 1.0
end

let float () =
run_app begin fun () ->
let a = Gtk.aspect_frame 1.0 1.0 1.0 true in
a#set_xalign 0.5;
let v = a#get_xalign in
Alcotest.(check @@ float e) "Set and retrieved gfloat" v 0.5
end

let string () =
run_app begin fun () ->
let label = Gtk.label "hello" in
let v = label#get_label in
Alcotest.(check string) "Set and retrieved string" v "hello"
end

let string_option () =
run_app begin fun () ->
let button = Gtk.Button.new_with_label "hello" in
let v = button#get_label in
let v = match v with (Some s) -> s | None -> "none" in
Alcotest.(check string) "Set and retrieved string option" v "hello"
end

let test_set = [
("int", `Quick, int);
("double", `Quick, double);
("float", `Quick, float);
("string", `Quick, string);
("string_option", `Quick, string_option)
]

let () =
Alcotest.run "Get and set tests"
[ ("Tests", test_set) ]

0 comments on commit 90cb3fc

Please sign in to comment.