readme
[Seppo.git] / test / t_cdb.ml
blob2ee9d26f301f497e319a145d6a7d83cf0681e129
1 open Seppo_lib
3 let o i = i |> Optint.of_int
5 let oi i = i |> Optint.of_unsigned_int32
7 let oo i = i |> Optint.of_int64
9 let b = Bytes.of_string
11 let test_ds_mini () =
12 let cdb = "mini.cdb" |> Ds_cdb.open_cdb_in in
13 assert (b "Ä" = ("a" |> b |> Ds_cdb.find_first cdb |> Option.get));
14 assert (b "B" = ("b" |> b |> Ds_cdb.find_first cdb |> Option.get));
15 assert (b "ß" = ("s" |> b |> Ds_cdb.find_first cdb |> Option.get));
16 Ds_cdb.close_cdb_in cdb
19 let test_pipe_big () =
20 let fd0 = Unix.openfile "mini.cdb" [ Unix.O_RDONLY ] 0
21 and fd1 =
22 Unix.openfile "dst.cdb"
23 [ Unix.O_WRONLY; Unix.O_CREAT; Unix.O_TRUNC; Unix.O_EXCL ]
26 let ctx = Cdb.start fd1 in
27 let fkt ctx pair =
28 let _ = pair |> Cdb.add fd1 ctx in
29 true
31 let _ = Cdb.dump fd0 fkt in
32 let _ = Cdb.finish fd1 in
33 assert true;
34 Unix.close fd1;
35 Unix.close fd0
38 let test_ds_hash () =
39 assert (0x2b5c4l = ("a" |> b |> Ds_cdb.hash));
40 let k0 =
41 "http://www.traunsteiner-tagblatt.de/region+lokal/landkreis-traunstein/traunstein/pressemitteilungen-der-stadt-traunstein_artikel,-Traunstein-20-%E2%80%93-Neue-Medien-im-Mittelpunkt-_arid,198374.html"
43 assert (0xc7410a37l = (k0 |> b |> Ds_cdb.hash));
44 Assrt.equals_optint __LOC__ (oo 0xc7410a37L) (oi 0xc7410a37l);
45 Assrt.equals_optint __LOC__ (oo 0xc7410a37L) (k0 |> b |> Ds_cdb.hash |> Optint.of_unsigned_int32)
48 let test_hash () =
49 (* Printf.printf "0x%x\n" ("a" |> b |> Cdb.hash); *)
50 Assrt.equals_optint __LOC__ (o 0x2b5c4) ("a" |> b |> Mapcdb.hash32_byt);
51 let k0 =
52 "http://www.traunsteiner-tagblatt.de/region+lokal/landkreis-traunstein/traunstein/pressemitteilungen-der-stadt-traunstein_artikel,-Traunstein-20-%E2%80%93-Neue-Medien-im-Mittelpunkt-_arid,198374.html"
54 (* Printf.printf "%x\n" (k0 |> b |> Cdb.hash); *)
55 Assrt.equals_optint __LOC__ (oo 0xc7410a37L) (k0 |> b |> Mapcdb.hash32_byt)
57 let _test_ds_big () =
58 let k0 =
59 "http://www.traunsteiner-tagblatt.de/region+lokal/landkreis-traunstein/traunstein/pressemitteilungen-der-stadt-traunstein_artikel,-Traunstein-20-%E2%80%93-Neue-Medien-im-Mittelpunkt-_arid,198374.html"
61 let cdb = "big.cdb" |> Ds_cdb.open_cdb_in in
62 (* Printf.printf "%d\n" (k0 |> b |> Ds_cdb.find cdb |> Bytes.length); *)
63 assert (1000 = (k0 |> b |> Ds_cdb.find_first cdb |> Option.get |> Bytes.length));
64 Ds_cdb.close_cdb_in cdb
66 let () =
67 Unix.chdir "../../../test/";
68 test_ds_mini ();
69 test_ds_hash ();
70 test_hash ();
71 (* test_ds_big (); *)
72 assert true