#![cfg(feature = "live-engine")]
use std::path::PathBuf;
use rs_teststand::{AdapterKeyName, ConflictHandler, Engine, Error, GetSeqFileOptions, StepGroup};
fn written_sequence_file(engine: &Engine) -> Result<PathBuf, Error> {
let path = std::env::temp_dir().join("rs_teststand_open_read_release.seq");
let sequence_file = engine.new_sequence_file()?;
let main_sequence = sequence_file.get_sequence_by_name("MainSequence")?;
let step = engine.new_step(AdapterKeyName::NoneAdapter.as_str(), "Statement")?;
step.set_name("Recorded Step")?;
main_sequence.insert_step(&step, 0, StepGroup::Main)?;
sequence_file.save(&path.to_string_lossy())?;
engine.release_sequence_file_ex(sequence_file, 0)?;
Ok(path)
}
#[test]
#[ignore = "requires a live engine"]
fn sequence_file_opens_reads_and_releases() -> Result<(), Error> {
let engine = Engine::new()?;
let path = written_sequence_file(&engine)?;
let path_text = path.to_string_lossy().into_owned();
let sequence_file = engine.get_sequence_file_ex(
&path_text,
GetSeqFileOptions::DO_NOT_RUN_LOAD_CALLBACK,
ConflictHandler::Error,
)?;
let reported = sequence_file.path()?;
assert!(
reported.eq_ignore_ascii_case(&path_text),
"engine reported {reported}, expected {path_text}"
);
assert!(
sequence_file.num_sequences()? > 0,
"an installed example must contain at least one sequence"
);
assert!(
engine.release_sequence_file_ex(sequence_file, 0)?,
"the last load reference should release the file from the engine cache"
);
Ok(())
}