Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions tests/input/optional.x
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ struct ListNode {

struct ListBegin {
ListNode *list;
bool eof;
};

struct NonRecursive {
Expand Down Expand Up @@ -33,16 +34,17 @@ struct groupnode {
groups gr_next;
};

struct exports {
exportnode *inner;
};

struct exportnode {
dirpath ex_dir;
groups ex_groups;
exportnode *ex_next;
};


struct exports {
exportnode *inner;
};

enum MyEnum {
ZERO = 0,
ONE = 1
Expand Down
8 changes: 4 additions & 4 deletions tests/no_alloc/tests/optionals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ fn recursive_optional() {
let node = ListNode { data: i };
before.list.push(node);
}
assert_eq!(before.get_width(), 44);
assert_eq!(before.get_width(), 48);

let mut bytes = vec![1; 44];
assert_eq!(44, before.serialize(&mut bytes));
let mut bytes = vec![1; 48];
assert_eq!(48, before.serialize(&mut bytes));

let mut after = ListBegin::default();

after.deserialize(&mut bytes.as_slice()).unwrap();
assert_eq!(44, after.get_width());
assert_eq!(48, after.get_width());

assert_eq!(before, after);
}
Expand Down
14 changes: 9 additions & 5 deletions tests/zcopy/tests/optional.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-License-Identifier: BSD-3-Clauss
// Copyright 2025. Triad National Security, LLC.

use std::os::unix::ffi::OsStrExt;
Expand Down Expand Up @@ -58,7 +58,8 @@ fn test_optionals_recursive() {
integers.push(i);
}

for i in 0i32..110 {
// the first entry should read as an eof() == true
for i in 1i32..110 {
data.extend([0x0, 0x0, 0x0, 0x0]);
data.extend(i.to_be_bytes());
}
Expand All @@ -67,7 +68,8 @@ fn test_optionals_recursive() {
let actual_ints: Vec<i32> = reader.get_list().map(|v| v.unwrap().get_data()).collect();

assert_eq!(integers, actual_ints);
assert_eq!(reader.get_width(), Ok(8 * 100 + 4));
assert_eq!(reader.get_width(), Ok(8 * 100 + 8));
assert!(reader.get_eof());
}

#[test]
Expand All @@ -92,6 +94,7 @@ fn test_optionals_recursive_missing_last_discriminant() {
data.extend(i.to_be_bytes());
integers.push(Ok(i));
}
data.extend([0x0, 0x0, 0x0, 0x0]);
integers.push(Err(DeserializeError));

let reader = ListBeginReader::new(&data.as_slice()[..data.len()]).unwrap();
Expand Down Expand Up @@ -151,7 +154,7 @@ fn test_optionals_recursive_varlen_interiors() {
let reader = exportsReader::new(data.as_slice()).unwrap();
for (i, en) in reader.get_inner().enumerate() {
assert_eq!(
export_groups.get(i).unwrap().dirpath.as_str().as_bytes(),
export_groups.get(i).unwrap().dirpath.as_bytes(),
en.as_ref().unwrap().get_ex_dir().as_bytes()
);

Expand All @@ -164,7 +167,8 @@ fn test_optionals_recursive_varlen_interiors() {
.unwrap()
.name
.as_bytes();
let second_string = gn.unwrap().get_gr_name().as_bytes();
let gn = gn.unwrap();
let second_string = gn.get_gr_name().as_bytes();
assert_eq!(first_string, second_string);
}
}
Expand Down
2 changes: 1 addition & 1 deletion xdr_codegen/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ impl XdrType {
///
/// Such types are represented in Rust as Vectors, rather than linked lists.
/// Non-self-referential optional types are represented as Rust Options.
fn self_referential_optional(&self, tab: &ValidatedSymbolTable) -> bool {
pub(crate) fn self_referential_optional(&self, tab: &ValidatedSymbolTable) -> bool {
let XdrType::Name(n) = self else {
return false;
};
Expand Down
Loading
Loading