add all crates: domain, protocol, application, client, adapters, ESP32 firmware
Server: domain (entities, value objects, ports), protocol (postcard wire types), application (config service, data projection), adapters (config-memory, tcp-server), bootstrap (composition root with fake data). Client: client-domain (layout engine, render tree, HAL ports), client-application (message handling, repaint commands), adapters (tcp-client, display-terminal), client-desktop (end-to-end working). ESP32: client-esp32 firmware with ILI9341 display over SPI, WiFi networking. Display test verified on hardware — landscape orientation, text rendering works. 60 workspace tests, all passing.
This commit is contained in:
82
crates/protocol/tests/conversion_tests.rs
Normal file
82
crates/protocol/tests/conversion_tests.rs
Normal file
@@ -0,0 +1,82 @@
|
||||
use std::collections::BTreeMap;
|
||||
use domain::{
|
||||
Value, WidgetState, WidgetError, DisplayHint,
|
||||
LayoutNode, ContainerNode, LayoutChild, Direction, Sizing,
|
||||
};
|
||||
use protocol::{
|
||||
WireValue, WireWidgetState, WireWidgetError, WireDisplayHint,
|
||||
WireLayoutNode, WireContainerNode, WireLayoutChild, WireDirection, WireSizing,
|
||||
WireKeyValue,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn value_converts_to_wire_and_back() {
|
||||
let original = Value::Object(BTreeMap::from([
|
||||
("items".into(), Value::Array(vec![
|
||||
Value::String("hello".into()),
|
||||
Value::Number(42.0),
|
||||
Value::Bool(true),
|
||||
Value::Null,
|
||||
])),
|
||||
]));
|
||||
|
||||
let wire: WireValue = (&original).into();
|
||||
let roundtripped: Value = wire.into();
|
||||
assert_eq!(original, roundtripped);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn widget_state_with_error_converts_to_wire_and_back() {
|
||||
let original = WidgetState {
|
||||
data: BTreeMap::from([
|
||||
("temp".into(), Value::Number(5.4)),
|
||||
]),
|
||||
error: Some(WidgetError::SourceUnavailable),
|
||||
};
|
||||
|
||||
let wire: WireWidgetState = (&original).into();
|
||||
let roundtripped: WidgetState = wire.into();
|
||||
assert_eq!(original, roundtripped);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layout_tree_converts_to_wire_and_back() {
|
||||
let original = LayoutNode::Container(ContainerNode {
|
||||
direction: Direction::Row,
|
||||
gap: 4,
|
||||
padding: 2,
|
||||
children: vec![
|
||||
LayoutChild {
|
||||
sizing: Sizing::Flex(1),
|
||||
node: LayoutNode::Leaf(1),
|
||||
},
|
||||
LayoutChild {
|
||||
sizing: Sizing::Fixed(100),
|
||||
node: LayoutNode::Container(ContainerNode {
|
||||
direction: Direction::Column,
|
||||
gap: 2,
|
||||
padding: 0,
|
||||
children: vec![
|
||||
LayoutChild {
|
||||
sizing: Sizing::Flex(1),
|
||||
node: LayoutNode::Leaf(2),
|
||||
},
|
||||
],
|
||||
}),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
let wire: WireLayoutNode = (&original).into();
|
||||
let roundtripped: LayoutNode = wire.into();
|
||||
assert_eq!(original, roundtripped);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn display_hint_converts_to_wire_and_back() {
|
||||
for hint in [DisplayHint::IconValue, DisplayHint::TextBlock, DisplayHint::KeyValue] {
|
||||
let wire: WireDisplayHint = (&hint).into();
|
||||
let roundtripped: DisplayHint = wire.into();
|
||||
assert_eq!(hint, roundtripped);
|
||||
}
|
||||
}
|
||||
94
crates/protocol/tests/round_trip_tests.rs
Normal file
94
crates/protocol/tests/round_trip_tests.rs
Normal file
@@ -0,0 +1,94 @@
|
||||
use protocol::{
|
||||
ServerMessage, ClientMessage, WidgetDescriptor,
|
||||
WireDisplayHint, WireLayoutNode, WireContainerNode, WireLayoutChild,
|
||||
WireDirection, WireSizing, WireWidgetState, WireKeyValue, WireValue,
|
||||
encode, decode_server_message, encode_client, decode_client_message,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn screen_update_round_trips() {
|
||||
let msg = ServerMessage::ScreenUpdate {
|
||||
layout: WireLayoutNode::Container(WireContainerNode {
|
||||
direction: WireDirection::Row,
|
||||
gap: 4,
|
||||
padding: 2,
|
||||
children: vec![
|
||||
WireLayoutChild {
|
||||
sizing: WireSizing::Flex(1),
|
||||
node: WireLayoutNode::Leaf(1),
|
||||
},
|
||||
WireLayoutChild {
|
||||
sizing: WireSizing::Fixed(80),
|
||||
node: WireLayoutNode::Leaf(2),
|
||||
},
|
||||
],
|
||||
}),
|
||||
widgets: vec![
|
||||
WidgetDescriptor {
|
||||
id: 1,
|
||||
display_hint: WireDisplayHint::IconValue,
|
||||
state: WireWidgetState {
|
||||
data: vec![
|
||||
WireKeyValue { key: "temperature".into(), value: WireValue::String("5.4°C".into()) },
|
||||
WireKeyValue { key: "icon".into(), value: WireValue::String("cloud_rain".into()) },
|
||||
],
|
||||
error: None,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
let frame = encode(&msg).unwrap();
|
||||
let payload = &frame[4..];
|
||||
let decoded = decode_server_message(payload).unwrap();
|
||||
assert_eq!(msg, decoded);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn data_update_round_trips() {
|
||||
let msg = ServerMessage::DataUpdate {
|
||||
widgets: vec![
|
||||
WidgetDescriptor {
|
||||
id: 3,
|
||||
display_hint: WireDisplayHint::TextBlock,
|
||||
state: WireWidgetState {
|
||||
data: vec![
|
||||
WireKeyValue { key: "body".into(), value: WireValue::String("Breaking news...".into()) },
|
||||
],
|
||||
error: None,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
let frame = encode(&msg).unwrap();
|
||||
let payload = &frame[4..];
|
||||
let decoded = decode_server_message(payload).unwrap();
|
||||
assert_eq!(msg, decoded);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn server_heartbeat_round_trips() {
|
||||
let msg = ServerMessage::Heartbeat;
|
||||
let frame = encode(&msg).unwrap();
|
||||
let payload = &frame[4..];
|
||||
let decoded = decode_server_message(payload).unwrap();
|
||||
assert_eq!(msg, decoded);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn client_heartbeat_round_trips() {
|
||||
let msg = ClientMessage::Heartbeat;
|
||||
let frame = encode_client(&msg).unwrap();
|
||||
let payload = &frame[4..];
|
||||
let decoded = decode_client_message(payload).unwrap();
|
||||
assert_eq!(msg, decoded);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn frame_has_correct_length_prefix() {
|
||||
let msg = ServerMessage::Heartbeat;
|
||||
let frame = encode(&msg).unwrap();
|
||||
let len = u32::from_be_bytes([frame[0], frame[1], frame[2], frame[3]]) as usize;
|
||||
assert_eq!(len, frame.len() - 4);
|
||||
}
|
||||
Reference in New Issue
Block a user