Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNumbat committed Jan 9, 2025
1 parent 61fa77d commit d2eb6f5
Showing 1 changed file with 50 additions and 5 deletions.
55 changes: 50 additions & 5 deletions testsuite/tests/capsule-api/data.ml
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,23 @@ let () =
assert (Capsule.Data.project ptr' = 111)
;;

(* [protect]. *)
(* [protect_portable]. *)
exception Exn of string

let () =
match Capsule.protect (fun _password -> "ok") with
match Capsule.protect_portable (fun _password -> "ok") with
| s -> assert (s = "ok")
| exception _ -> assert false
;;

let () =
match Capsule.protect (fun _password -> Exn "ok") with
match Capsule.protect_portable (fun _password -> Exn "ok") with
| Exn s -> assert (s = "ok")
| _ -> assert false
;;

let () =
match Capsule.protect (fun _password -> reraise (Exn "fail")) with
match Capsule.protect_portable (fun _password -> reraise (Exn "fail")) with
| exception (Capsule.Protected (mut, exn)) ->
let s = Capsule.Mutex.with_lock mut (fun password ->
Capsule.Data.extract password (fun exn ->
Expand All @@ -204,7 +204,7 @@ let () =
;;

let () =
match Capsule.protect (fun (Capsule.Password.P password) ->
match Capsule.protect_portable (fun (Capsule.Password.P password) ->
let data = Capsule.Data.create (fun () -> "fail") in
let msg = Capsule.Data.extract password (fun s : string -> s) data in
reraise (Exn msg))
Expand All @@ -219,6 +219,51 @@ let () =
| _ -> assert false
;;

let () =
match Capsule.protect_portable (fun (Capsule.Password.P password) ->
let data = Capsule.Data.create (fun () -> "fail") in
let () = Capsule.Data.extract password (fun s -> reraise (Exn s)) data in
())
with
| exception (Capsule.Protected (mut, exn)) ->
let s = Capsule.Mutex.with_lock mut (fun password ->
Capsule.Data.extract password (fun exn ->
match exn with
| Exn s -> s
| _ -> assert false) exn) in
assert (s = "fail")
| _ -> assert false
;;

(* [protect]. *)
let () =
match Capsule.protect (fun _password -> "ok") with
| s -> assert (s = "ok")
| exception _ -> assert false
;;

let () =
match Capsule.protect (fun _password -> Exn "ok") with
| Exn s -> assert (s = "ok")
| _ -> assert false
;;

let () =
match Capsule.protect (fun _password -> reraise (Exn "fail")) with
| exception Exn s -> assert (s = "fail")
| _ -> assert false
;;

let () =
match Capsule.protect (fun (Capsule.Password.P password) ->
let data = Capsule.Data.create (fun () -> "fail") in
let msg = Capsule.Data.extract password (fun s : string -> s) data in
reraise (Exn msg))
with
| exception Exn s -> assert (s = "fail")
| _ -> assert false
;;

let () =
match Capsule.protect (fun (Capsule.Password.P password) ->
let data = Capsule.Data.create (fun () -> "fail") in
Expand Down

0 comments on commit d2eb6f5

Please sign in to comment.