summaryrefslogtreecommitdiff
path: root/sid_test.ml
diff options
context:
space:
mode:
Diffstat (limited to 'sid_test.ml')
-rw-r--r--sid_test.ml57
1 files changed, 57 insertions, 0 deletions
diff --git a/sid_test.ml b/sid_test.ml
index aaee961..5f9f0b2 100644
--- a/sid_test.ml
+++ b/sid_test.ml
@@ -95,6 +95,25 @@ let pr_encode_null_ok () =
~msg:(Printf.sprintf "[%s] ≠ [%s]" x expect)
x expect
+let pr_encode_be_ok () =
+ let sid = "S-1-0-42" in
+ let sle = Sid.of_string sid
+ |> Sid.PacketRep.encode
+ |> Xxd.xxd_of_bytes ~blocklen:2
+ and sbe = Sid.of_string sid
+ |> Sid.PacketRep.encode ~endian:Big
+ |> Xxd.xxd_of_bytes ~blocklen:2
+ in
+ let expect_le = "0101 0000 0000 0000 2a00 0000"
+ and expect_be = "0101 0000 0000 0000 0000 002a" in
+ (* vvcc iiii iiii iiii ssss ssss *)
+ assert_equal
+ ~msg:(Printf.sprintf "[%s] ≠ [%s]" sle expect_le)
+ sle expect_le;
+ assert_equal
+ ~msg:(Printf.sprintf "[%s] ≠ [%s]" sbe expect_be)
+ sbe expect_be
+
let pr_encode_all_ok () =
let x =
Sid.WellKnown.everyone
@@ -125,6 +144,42 @@ let pr_decode_all_ok () =
(Sid.to_string s) (Sid.to_string w))
(Sid.equal s w)
+let pr_decode_be_ok () =
+ let sid = Sid.of_string "S-1-1-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15"
+ and sle =
+ match Xxd.bytes_of_xxd
+ "010f 0000 0000 0001 \
+ 0100 0000 0200 0000 0300 0000 0400 0000 \
+ 0500 0000 0600 0000 0700 0000 0800 0000 \
+ 0900 0000 0a00 0000 0b00 0000 0c00 0000 \
+ 0d00 0000 0e00 0000 0f00 0000"
+ |> Sid.PacketRep.decode
+ with
+ | Ok s -> s
+ | Error e ->
+ assert_failure
+ (Printf.sprintf "error decoding SID: %s" e)
+ and sbe =
+ match Xxd.bytes_of_xxd
+ "010f 0000 0000 0001 \
+ 0000 0001 0000 0002 0000 0003 0000 0004 \
+ 0000 0005 0000 0006 0000 0007 0000 0008 \
+ 0000 0009 0000 000a 0000 000b 0000 000c \
+ 0000 000d 0000 000e 0000 000f"
+ |> Sid.PacketRep.decode ~endian:Big
+ with
+ | Ok s -> s
+ | Error e ->
+ assert_failure
+ (Printf.sprintf "error decoding SID: %s" e)
+ in
+ assert_bool
+ (Printf.sprintf "le: [%s] ≠ [%s]" (Sid.to_string sid) (Sid.to_string sle))
+ (Sid.equal sid sle);
+ assert_bool
+ (Printf.sprintf "be: [%s] ≠ [%s]" (Sid.to_string sid) (Sid.to_string sbe))
+ (Sid.equal sid sbe)
+
let pr_decode_version_fail () =
let b = Xxd.bytes_of_xxd "0201 0000 0000 0001 0000 0000" in
(* vvcc iiii iiii iiii ssss ssss *)
@@ -222,7 +277,9 @@ let string_format_test = "string-format-syntax" >:::
let packet_rep_test = "packet-rep" >:::
[ "encode-null-ok" >:: pr_encode_null_ok
; "encode-all-ok" >:: pr_encode_all_ok
+ ; "encode-be-ok" >:: pr_encode_be_ok
; "decode-all-ok" >:: pr_decode_all_ok
+ ; "decode-be-ok" >:: pr_decode_be_ok
; "decode-version-fail" >:: pr_decode_version_fail
; "decode-sacount-fail" >:: pr_decode_sacount_fail
; "decode-short-fail" >:: pr_decode_short_fail