File: test_validation.ml

package info (click to toggle)
obus 1.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,480 kB
  • sloc: ml: 14,675; lisp: 52; makefile: 11; xml: 8
file content (59 lines) | stat: -rw-r--r-- 1,326 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
(*
 * test_validation.ml
 * ------------------
 * Copyright : (c) 2009, Jeremie Dimino <jeremie@dimino.org>
 * Licence   : BSD3
 *
 * This file is a part of obus, an ocaml implementation of D-Bus.
 *)

open Lwt
open Lwt_io

let good = [
  OBus_string.validate "azerty";
  OBus_string.validate "Jérémie";

  OBus_path.validate "/";
  OBus_path.validate "/a";
  OBus_path.validate "/a/b";

  OBus_name.validate_bus ":1.1";
  OBus_name.validate_bus ":a.2";
  OBus_name.validate_bus "foo.bar";
  OBus_name.validate_bus "a.b.c.d";
]

let bad = [
  OBus_string.validate "\xe9";

  OBus_path.validate "/dd//dd";
  OBus_path.validate "/dd//";
  OBus_path.validate "/dd/";
  OBus_path.validate "";

  OBus_name.validate_bus ":1..2";
  OBus_name.validate_bus "a..b";
]

let test () =
  let%lwt () = printl "Validation of all types of D-Bus strings" in
  let%lwt () =
    Lwt_list.iter_s
      (function
         | Some err ->
             printlf "valid string recognized as bad: %s" (OBus_string.error_message err)
         | None ->
             return ())
      good
  in
  let%lwt () =
    Lwt_list.iter_s
      (function
         | None ->
             printlf "invalid string recognized as good"
         | Some _ ->
             return ())
      bad
  in
  return (List.for_all ((=) None) good && List.for_all ((<>) None) bad)