Debian Codegraph @

tests/oid_ref.rs

raw symbols SCIP
1 //! Tests for `ObjectIdentifierRef`.
2
3 use const_oidrust-analyzer cargo const-oid 0.10.2 crate/::{Errorrust-analyzer cargo const-oid 0.10.2 error/Error#, ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#, ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#};
4 use hex_literalrust-analyzer cargo hex-literal 1.1.0 crate/::hexrust-analyzer cargo hex-literal 1.1.0 hex!;
5
6 /// Example OID value with a root arc of `0` (and large arc).
7 const EXAMPLE_OID_0_STRrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_0_STR.: &str = "0.9.2342.19200300.100.1.1";
8 const EXAMPLE_OID_0_BERrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_0_BER.: &[u8] = &hexrust-analyzer cargo hex-literal 1.1.0 hex!!("0992268993F22C640101");
9 const EXAMPLE_OID_0rust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_0.: ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier# = ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#::new_unwraprust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier]new_unwrap().(EXAMPLE_OID_0_STRrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_0_STR.);
10
11 /// Example OID value with a root arc of `1`.
12 const EXAMPLE_OID_1_STRrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_1_STR.: &str = "1.2.840.10045.2.1";
13 const EXAMPLE_OID_1_BERrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_1_BER.: &[u8] = &hexrust-analyzer cargo hex-literal 1.1.0 hex!!("2A8648CE3D0201");
14 const EXAMPLE_OID_1rust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_1.: ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier# = ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#::new_unwraprust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier]new_unwrap().(EXAMPLE_OID_1_STRrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_1_STR.);
15
16 /// Example OID value with a root arc of `2`.
17 const EXAMPLE_OID_2_STRrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_2_STR.: &str = "2.16.840.1.101.3.4.1.42";
18 const EXAMPLE_OID_2_BERrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_2_BER.: &[u8] = &hexrust-analyzer cargo hex-literal 1.1.0 hex!!("60864801650304012A");
19 const EXAMPLE_OID_2rust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_2.: ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier# = ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#::new_unwraprust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier]new_unwrap().(EXAMPLE_OID_2_STRrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_2_STR.);
20
21 /// Example OID value with a large arc
22 const EXAMPLE_OID_LARGE_ARC_STRrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_LARGE_ARC_STR.: &str = "0.9.2342.19200300.100.1.1";
23 const EXAMPLE_OID_LARGE_ARC_BERrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_LARGE_ARC_BER.: &[u8] = &hexrust-analyzer cargo hex-literal 1.1.0 hex!!("0992268993F22C640101");
24 const EXAMPLE_OID_LARGE_ARCrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_LARGE_ARC.: ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier# =
25 ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#::new_unwraprust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier]new_unwrap().("0.9.2342.19200300.100.1.1");
26
27 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
28 fn from_bytesrust-analyzer cargo const-oid 0.10.2 from_bytes().() {
29 let oid0 = ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#::from_bytesrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]from_bytes().(EXAMPLE_OID_0_BERrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_0_BER.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
30 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid0.arcrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]arc().(0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), 0);
31 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid0.arcrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]arc().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), 9);
32 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid0, &EXAMPLE_OID_0rust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_0.);
33
34 let oid1 = ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#::from_bytesrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]from_bytes().(EXAMPLE_OID_1_BERrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_1_BER.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
35 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid1.arcrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]arc().(0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), 1);
36 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid1.arcrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]arc().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), 2);
37 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid1, &EXAMPLE_OID_1rust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_1.);
38
39 let oid2 = ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#::from_bytesrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]from_bytes().(EXAMPLE_OID_2_BERrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_2_BER.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
40 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid2.arcrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]arc().(0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), 2);
41 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid2.arcrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]arc().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), 16);
42 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid2, &EXAMPLE_OID_2rust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_2.);
43
44 let oid3 = ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#::from_bytesrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]from_bytes().(EXAMPLE_OID_LARGE_ARC_BERrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_LARGE_ARC_BER.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
45 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid3.arcrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]arc().(0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), 0);
46 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid3.arcrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]arc().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), 9);
47 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid3.arcrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]arc().(2).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), 2342);
48 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid3.arcrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]arc().(3).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), 19200300);
49 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid3.arcrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]arc().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), 100);
50 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid3.arcrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]arc().(5).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), 1);
51 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid3.arcrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]arc().(6).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), 1);
52 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid3, &EXAMPLE_OID_LARGE_ARCrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_LARGE_ARC.);
53
54 // Empty
55 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#::from_bytesrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]from_bytes().(&[]), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::Emptyrust-analyzer cargo const-oid 0.10.2 error/Error#Empty#));
56 }
57
58 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
59 fn displayrust-analyzer cargo const-oid 0.10.2 display().() {
60 let oid0 = ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#::from_bytesrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]from_bytes().(EXAMPLE_OID_0_BERrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_0_BER.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
61 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid0.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), EXAMPLE_OID_0_STRrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_0_STR.);
62
63 let oid1 = ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#::from_bytesrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]from_bytes().(EXAMPLE_OID_1_BERrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_1_BER.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
64 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid1.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), EXAMPLE_OID_1_STRrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_1_STR.);
65
66 let oid2 = ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#::from_bytesrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]from_bytes().(EXAMPLE_OID_2_BERrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_2_BER.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
67 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid2.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), EXAMPLE_OID_2_STRrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_2_STR.);
68
69 let oid3 = ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#::from_bytesrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]from_bytes().(EXAMPLE_OID_LARGE_ARC_BERrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_LARGE_ARC_BER.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
70 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid3.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), EXAMPLE_OID_LARGE_ARC_STRrust-analyzer cargo const-oid 0.10.2 EXAMPLE_OID_LARGE_ARC_STR.);
71 }