mod support;
use std::path::PathBuf;
use llama_cpp_4::prelude::*;
use support::model::{llama_guard, load_full_model, skip_no_model, test_model_path};
#[test]
fn a_missing_adapter_file_is_reported_with_its_path() {
let _guard = llama_guard();
let Some(model) = load_full_model() else {
skip_no_model();
return;
};
let missing = PathBuf::from("definitely/not/a/real/adapter.gguf");
match model.lora_adapter_init_at_offset(&missing, 0) {
Err(LlamaLoraAdapterInitError::FileOpen { path, reason }) => {
assert_eq!(path, missing);
assert!(!reason.is_empty(), "the OS reason should be carried along");
}
other => panic!("expected FileOpen, got {other:?}"),
}
}
#[test]
fn a_non_lora_gguf_is_rejected() {
let _guard = llama_guard();
let Some(model) = load_full_model() else {
skip_no_model();
return;
};
let Some(path) = test_model_path() else {
skip_no_model();
return;
};
assert_eq!(
model.lora_adapter_init_at_offset(&path, 0).err(),
Some(LlamaLoraAdapterInitError::NullResult)
);
assert_eq!(
model.lora_adapter_init(&path).err(),
Some(LlamaLoraAdapterInitError::NullResult)
);
}
#[test]
fn an_offset_past_the_end_fails_in_the_reader() {
let _guard = llama_guard();
let Some(model) = load_full_model() else {
skip_no_model();
return;
};
let Some(path) = test_model_path() else {
skip_no_model();
return;
};
assert_eq!(
model.lora_adapter_init_at_offset(&path, 1 << 30).err(),
Some(LlamaLoraAdapterInitError::NullResult)
);
}
#[test]
fn a_null_file_pointer_is_rejected() {
let _guard = llama_guard();
let Some(model) = load_full_model() else {
skip_no_model();
return;
};
let result = unsafe { model.lora_adapter_init_from_file_ptr(std::ptr::null_mut()) };
assert_eq!(result.err(), Some(LlamaLoraAdapterInitError::NullResult));
}