mirror of
https://github.com/cccb/servicepoint.git
synced 2025-01-18 18:10:14 +01:00
add more unit tests
This commit is contained in:
parent
c61c267b02
commit
36fc109d91
|
@ -702,25 +702,36 @@ mod tests {
|
||||||
Err(TryFromPacketError::UnexpectedPayloadSize(1, 2)));
|
Err(TryFromPacketError::UnexpectedPayloadSize(1, 2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO unexpected payload size
|
#[test]
|
||||||
|
fn error_reserved_used() {
|
||||||
|
let Packet(header, payload)
|
||||||
|
= Command::BitmapLinear(0, BitVec::new(8), CompressionCode::Uncompressed).into();
|
||||||
|
let Header(command, offset, length, sub, reserved) = header;
|
||||||
|
let p = Packet(Header(command, offset, length, sub, 69), payload);
|
||||||
|
assert_eq!(
|
||||||
|
Command::try_from(p),
|
||||||
|
Err(TryFromPacketError::ExtraneousHeaderValues));
|
||||||
|
}
|
||||||
|
|
||||||
/// Set the brightness of tiles
|
#[test]
|
||||||
CharBrightness(Origin, crate::byte_grid::ByteGrid),
|
fn error_invalid_compression() {
|
||||||
/// Set pixel data starting at the offset.
|
let Packet(header, payload)
|
||||||
/// The contained BitVec is always uncompressed.
|
= Command::BitmapLinear(0, BitVec::new(8), CompressionCode::Uncompressed).into();
|
||||||
BitmapLinear(Offset, crate::bit_vec::BitVec, crate::compression_code::CompressionCode),
|
let Header(command, offset, length, sub, reserved) = header;
|
||||||
/// Set pixel data according to an and-mask starting at the offset.
|
let p = Packet(Header(command, offset, length, 42, reserved), payload);
|
||||||
/// The contained BitVec is always uncompressed.
|
assert_eq!(
|
||||||
BitmapLinearAnd(Offset, crate::bit_vec::BitVec, crate::compression_code::CompressionCode),
|
Command::try_from(p),
|
||||||
/// Set pixel data according to an or-mask starting at the offset.
|
Err(TryFromPacketError::InvalidCompressionCode(42)));
|
||||||
/// The contained BitVec is always uncompressed.
|
}
|
||||||
BitmapLinearOr(Offset, crate::bit_vec::BitVec, crate::compression_code::CompressionCode),
|
|
||||||
/// Set pixel data according to an xor-mask starting at the offset.
|
#[test]
|
||||||
/// The contained BitVec is always uncompressed.
|
fn error_unexpected_size() {
|
||||||
BitmapLinearXor(Offset, crate::bit_vec::BitVec, crate::compression_code::CompressionCode),
|
let Packet(header, payload)
|
||||||
/// Show text on the screen. Note that the byte data has to be CP437 encoded.
|
= Command::BitmapLinear(0, BitVec::new(8), CompressionCode::Uncompressed).into();
|
||||||
Cp437Data(Origin, crate::byte_grid::ByteGrid),
|
let Header(command, offset, length, compression, reserved) = header;
|
||||||
/// Sets a window of pixels to the specified values
|
let p = Packet(Header(command, offset, 420, compression, reserved), payload);
|
||||||
BitmapLinearWin(Origin, crate::pixel_grid::PixelGrid, crate::compression_code::CompressionCode),
|
assert_eq!(
|
||||||
*/
|
Command::try_from(p),
|
||||||
|
Err(TryFromPacketError::UnexpectedPayloadSize(420, length as usize)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,3 +208,52 @@ pub mod c_api {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::PixelGrid;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn fill() {
|
||||||
|
let mut grid = PixelGrid::new(8, 2);
|
||||||
|
assert_eq!(grid.mut_data_ref(), [0x00, 0x00]);
|
||||||
|
|
||||||
|
grid.fill(true);
|
||||||
|
assert_eq!(grid.mut_data_ref(), [0xFF, 0xFF]);
|
||||||
|
|
||||||
|
grid.fill(false);
|
||||||
|
assert_eq!(grid.mut_data_ref(), [0x00, 0x00]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn get_set() {
|
||||||
|
let mut grid = PixelGrid::new(8, 2);
|
||||||
|
assert_eq!(grid.get(0, 0), false);
|
||||||
|
assert_eq!(grid.get(1, 1), false);
|
||||||
|
|
||||||
|
grid.set(5, 0, true);
|
||||||
|
grid.set(1, 1, true);
|
||||||
|
assert_eq!(grid.mut_data_ref(), [0x04, 0x40]);
|
||||||
|
|
||||||
|
assert_eq!(grid.get(5, 0), true);
|
||||||
|
assert_eq!(grid.get(1, 1), true);
|
||||||
|
assert_eq!(grid.get(1, 0), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn load() {
|
||||||
|
let mut grid = PixelGrid::new(8, 3);
|
||||||
|
for x in 0..grid.width {
|
||||||
|
for y in 0..grid.height {
|
||||||
|
grid.set(x, y, (x + y) % 2 == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq!(grid.mut_data_ref(), [0xAA, 0x55, 0xAA]);
|
||||||
|
|
||||||
|
let data: Vec<u8> = grid.into();
|
||||||
|
|
||||||
|
let mut grid = PixelGrid::load(8, 3, &data);
|
||||||
|
assert_eq!(grid.mut_data_ref(), [0xAA, 0x55, 0xAA]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue