#![cfg(feature = "std")]

use os_observatory::logging::{Level, Logger};
use os_observatory::prelude::*;

#[test]
fn ring_buffer_sink_writes() {
    static SINK: RingBufferSink<64> = RingBufferSink::new();
    let logger = Logger::new(&SINK).with_level(Level::Trace);
    os_log!(&logger, "hello {}", 1);
    os_warn!(&logger, "warn {}", 2);
    os_error!(&logger, "error {}", 3);

    let mut out = [0u8; 64];
    let n = SINK.snapshot(&mut out);
    assert!(n > 0);
    let text = String::from_utf8_lossy(&out[..n]);
    assert!(text.contains("hello"));
    assert!(text.contains("warn"));
    assert!(text.contains("error"));
}

#[test]
fn tracer_records_and_exports() {
    static TR: EventTracer<8> = EventTracer::new();
    TR.record(1, EventId(1), 10, 20);
    TR.record(2, EventId(2), 30, 40);
    let mut out = [EventRecord { ts: 0, id: EventId(0), payload0: 0, payload1: 0 }; 8];
    let n = TR.snapshot(&mut out);
    assert!(n >= 2);
    assert_eq!(out[n - 2].id, EventId(1));
    assert_eq!(out[n - 1].id, EventId(2));
}

