cdb_test.ml 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. open Seppo_lib
  2. let o i = i |> Optint.of_int
  3. let oi i = i |> Optint.of_unsigned_int32
  4. let oo i = i |> Optint.of_int64
  5. let b = Bytes.of_string
  6. let test_ds_mini () =
  7. let cdb = "mini.cdb" |> Ds_cdb.open_cdb_in in
  8. assert (b "Ä" = ("a" |> b |> Ds_cdb.find_first cdb |> Option.get));
  9. assert (b "B" = ("b" |> b |> Ds_cdb.find_first cdb |> Option.get));
  10. assert (b "ß" = ("s" |> b |> Ds_cdb.find_first cdb |> Option.get));
  11. Ds_cdb.close_cdb_in cdb
  12. (*
  13. let test_pipe_big () =
  14. let fd0 = Unix.openfile "mini.cdb" [ Unix.O_RDONLY ] 0
  15. and fd1 =
  16. Unix.openfile "dst.cdb"
  17. [ Unix.O_WRONLY; Unix.O_CREAT; Unix.O_TRUNC; Unix.O_EXCL ]
  18. 0
  19. in
  20. let ctx = Cdb.start fd1 in
  21. let fkt ctx pair =
  22. let _ = pair |> Cdb.add fd1 ctx in
  23. true
  24. in
  25. let _ = Cdb.dump fd0 fkt in
  26. let _ = Cdb.finish fd1 in
  27. assert true;
  28. Unix.close fd1;
  29. Unix.close fd0
  30. *)
  31. let test_ds_hash () =
  32. assert (0x2b5c4l = ("a" |> b |> Ds_cdb.hash));
  33. let k0 =
  34. "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"
  35. in
  36. assert (0xc7410a37l = (k0 |> b |> Ds_cdb.hash));
  37. Assrt.equals_optint __LOC__ (oo 0xc7410a37L) (oi 0xc7410a37l);
  38. Assrt.equals_optint __LOC__ (oo 0xc7410a37L) (k0 |> b |> Ds_cdb.hash |> Optint.of_unsigned_int32)
  39. let test_hash () =
  40. (* Printf.printf "0x%x\n" ("a" |> b |> Cdb.hash); *)
  41. Assrt.equals_optint __LOC__ (o 0x2b5c4) ("a" |> b |> Mapcdb.hash32_byt);
  42. let k0 =
  43. "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"
  44. in
  45. (* Printf.printf "%x\n" (k0 |> b |> Cdb.hash); *)
  46. Assrt.equals_optint __LOC__ (oo 0xc7410a37L) (k0 |> b |> Mapcdb.hash32_byt)
  47. let _test_ds_big () =
  48. let k0 =
  49. "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"
  50. in
  51. let cdb = "big.cdb" |> Ds_cdb.open_cdb_in in
  52. (* Printf.printf "%d\n" (k0 |> b |> Ds_cdb.find cdb |> Bytes.length); *)
  53. assert (1000 = (k0 |> b |> Ds_cdb.find_first cdb |> Option.get |> Bytes.length));
  54. Ds_cdb.close_cdb_in cdb
  55. let () =
  56. Unix.chdir "../../../test/";
  57. test_ds_mini ();
  58. test_ds_hash ();
  59. test_hash ();
  60. (* test_ds_big (); *)
  61. assert true