feat: improve object pool

- improve object pool
- add docstring for test coverage
This commit is contained in:
2026-08-01 17:25:38 +08:00
parent f84e1a5d9c
commit 7834741d90
7 changed files with 356 additions and 97 deletions
+8
View File
@@ -27,6 +27,7 @@ fn parse_cstr(ptr: CStrPtr) -> String {
.into_owned()
}
/// Coverage: the cleared/default state -- no outcome recorded, code is `CERROR_OK`, message empty.
#[test]
fn fresh_state_is_absolute_success() {
last_error::clear_last_error();
@@ -35,6 +36,8 @@ fn fresh_state_is_absolute_success() {
assert_eq!(parse_cstr(last_error::get_error_message()), "");
}
/// Coverage: `set_last_error` records both the `Into<CError>`-mapped code and the `Display`-derived
/// message, and `has_last_message` becomes true.
#[test]
fn set_records_code_and_message() {
last_error::clear_last_error();
@@ -44,6 +47,8 @@ fn set_records_code_and_message() {
assert_eq!(parse_cstr(last_error::get_error_message()), "boom error");
}
/// Coverage: `clear_last_error` resets a previously-recorded outcome back to the absolute-success
/// state (no code, empty message).
#[test]
fn clear_resets_to_absolute_success() {
last_error::set_last_error(TestErr::Boom);
@@ -54,6 +59,8 @@ fn clear_resets_to_absolute_success() {
assert_eq!(parse_cstr(last_error::get_error_message()), "");
}
/// Coverage: interior NUL bytes in an error's `Display` text are replaced so the message C string
/// builds without panicking, and the code is still recorded.
#[test]
fn interior_nul_in_message_is_sanitized() {
last_error::clear_last_error();
@@ -65,6 +72,7 @@ fn interior_nul_in_message_is_sanitized() {
assert!(msg.contains("value"));
}
/// Coverage: a second `set_last_error` fully overwrites the previously recorded code and message.
#[test]
fn overwriting_replaces_previous_state() {
last_error::clear_last_error();