Skip to content
Merged
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
38 changes: 38 additions & 0 deletions lib/tests/record.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (C) 2025 Intel Corporation
// SPDX-License-Identifier: MIT
#![feature(assert_matches)]

use intel_crashlog::prelude::*;
use std::assert_matches::assert_matches;
use std::fs;
use std::path::Path;

Expand Down Expand Up @@ -110,3 +112,39 @@ fn header_checksum() {
assert!(record.checksum().unwrap())
}
}

#[test]
fn invalid_decode_defs() {
let record = Record {
header: Header::default(),
data: vec![0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87],
};

let csv = "name;offset;size;description;bitfield
foo;0;64;;0
foo.bar;=2+2;8;;0";
assert_matches!(
record.decode_with_csv(csv.as_bytes(), 0),
Err(Error::ParseIntError(_))
);

let csv = "fullname;size;offset
aaa;4;8
";
let root = record.decode_with_csv(csv.as_bytes(), 0).unwrap();
assert_eq!(root, Node::root());

let csv = "name;size;offset
foo.bar;8
";
let root = record.decode_with_csv(csv.as_bytes(), 0).unwrap();
let field = root.get_by_path("foo.bar").unwrap();
assert_eq!(field.kind, NodeType::Field { value: 0x80 });

let csv = "name;size;offset;size
....foo.bar;8;0
";
let root = record.decode_with_csv(csv.as_bytes(), 0).unwrap();
let field = root.get_by_path("foo.bar").unwrap();
assert_eq!(field.kind, NodeType::Field { value: 0x80 });
}