mirror of
https://github.com/cccb/servicepoint.git
synced 2025-01-18 18:10:14 +01:00
clippy fix, fmt
This commit is contained in:
parent
5a717beda5
commit
8426698b9f
|
@ -3,11 +3,11 @@ use std::time::Duration;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
|
use servicepoint2::Command::{BitmapLinearWin, Brightness, CharBrightness};
|
||||||
use servicepoint2::{
|
use servicepoint2::{
|
||||||
ByteGrid, CompressionCode, Connection, Origin, PixelGrid, TILE_HEIGHT,
|
ByteGrid, CompressionCode, Connection, Origin, PixelGrid, TILE_HEIGHT,
|
||||||
TILE_WIDTH,
|
TILE_WIDTH,
|
||||||
};
|
};
|
||||||
use servicepoint2::Command::{BitmapLinearWin, Brightness, CharBrightness};
|
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
|
|
|
@ -237,15 +237,15 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn get_set() {
|
fn get_set() {
|
||||||
let mut vec = BitVec::new(8 * 3);
|
let mut vec = BitVec::new(8 * 3);
|
||||||
assert_eq!(vec.get(1), false);
|
assert!(!vec.get(1));
|
||||||
assert_eq!(vec.get(11), false);
|
assert!(!vec.get(11));
|
||||||
|
|
||||||
vec.set(1, true);
|
vec.set(1, true);
|
||||||
vec.set(11, true);
|
vec.set(11, true);
|
||||||
assert_eq!(vec.data, [0x40, 0x10, 0x00]);
|
assert_eq!(vec.data, [0x40, 0x10, 0x00]);
|
||||||
assert_eq!(vec.get(0), false);
|
assert!(!vec.get(0));
|
||||||
assert_eq!(vec.get(1), true);
|
assert!(vec.get(1));
|
||||||
assert_eq!(vec.get(11), true);
|
assert!(vec.get(11));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -267,22 +267,22 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mut_data_ref(){
|
fn mut_data_ref() {
|
||||||
let mut vec = BitVec::new(8 * 3);
|
let mut vec = BitVec::new(8 * 3);
|
||||||
|
|
||||||
let data_ref = vec.mut_data_ref();
|
let data_ref = vec.mut_data_ref();
|
||||||
data_ref.copy_from_slice(&[0x40, 0x10, 0x00]);
|
data_ref.copy_from_slice(&[0x40, 0x10, 0x00]);
|
||||||
|
|
||||||
assert_eq!(vec.data, [0x40, 0x10, 0x00]);
|
assert_eq!(vec.data, [0x40, 0x10, 0x00]);
|
||||||
assert_eq!(vec.get(1), true);
|
assert!(vec.get(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_empty() {
|
fn is_empty() {
|
||||||
let vec = BitVec::new(8 * 3);
|
let vec = BitVec::new(8 * 3);
|
||||||
assert_eq!(vec.is_empty(), false);
|
assert!(!vec.is_empty());
|
||||||
|
|
||||||
let vec = BitVec::new(0);
|
let vec = BitVec::new(0);
|
||||||
assert_eq!(vec.is_empty(), true);
|
assert!(vec.is_empty());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -222,12 +222,11 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
assert_eq!(grid.data, [0, 1, 1, 2, 2, 3]);
|
assert_eq!(grid.data, [0, 1, 1, 2, 2, 3]);
|
||||||
|
|
||||||
let data: Vec<u8> = grid.into();
|
let data: Vec<u8> = grid.into();
|
||||||
|
|
||||||
let grid = ByteGrid::load(2, 3, &*data);
|
let grid = ByteGrid::load(2, 3, &data);
|
||||||
assert_eq!(grid.data, [0, 1, 1, 2, 2, 3]);
|
assert_eq!(grid.data, [0, 1, 1, 2, 2, 3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
use crate::command_code::CommandCode;
|
||||||
|
use crate::compression::{into_compressed, into_decompressed};
|
||||||
use crate::{
|
use crate::{
|
||||||
BitVec, ByteGrid, CompressionCode, Header, Packet, PixelGrid, TILE_SIZE,
|
BitVec, ByteGrid, CompressionCode, Header, Packet, PixelGrid, TILE_SIZE,
|
||||||
};
|
};
|
||||||
use crate::command_code::CommandCode;
|
|
||||||
use crate::compression::{into_compressed, into_decompressed};
|
|
||||||
|
|
||||||
/// An origin marks the top left position of a window sent to the display.
|
/// An origin marks the top left position of a window sent to the display.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
|
@ -526,7 +526,9 @@ pub mod c_api {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{BitVec, ByteGrid, Command, CompressionCode, Origin, Packet, PixelGrid};
|
use crate::{
|
||||||
|
BitVec, ByteGrid, Command, CompressionCode, Origin, Packet, PixelGrid,
|
||||||
|
};
|
||||||
|
|
||||||
fn round_trip(original: Command) {
|
fn round_trip(original: Command) {
|
||||||
let packet: Packet = original.clone().into();
|
let packet: Packet = original.clone().into();
|
||||||
|
@ -538,20 +540,30 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn round_trip_clear() { round_trip(Command::Clear); }
|
fn round_trip_clear() {
|
||||||
|
round_trip(Command::Clear);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn round_trip_hard_reset() { round_trip(Command::HardReset); }
|
fn round_trip_hard_reset() {
|
||||||
|
round_trip(Command::HardReset);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn round_trip_fade_out() { round_trip(Command::FadeOut); }
|
fn round_trip_fade_out() {
|
||||||
|
round_trip(Command::FadeOut);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn round_trip_brightness() { round_trip(Command::Brightness(6)); }
|
fn round_trip_brightness() {
|
||||||
|
round_trip(Command::Brightness(6));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
fn round_trip_bitmap_legacy() { round_trip(Command::BitmapLegacy); }
|
fn round_trip_bitmap_legacy() {
|
||||||
|
round_trip(Command::BitmapLegacy);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn round_trip_char_brightness() {
|
fn round_trip_char_brightness() {
|
||||||
|
@ -565,14 +577,35 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn round_trip_bitmap_linear() {
|
fn round_trip_bitmap_linear() {
|
||||||
let codes = [CompressionCode::Uncompressed, CompressionCode::Lzma,
|
let codes = [
|
||||||
CompressionCode::Bzip2, CompressionCode::Zlib, CompressionCode::Zstd];
|
CompressionCode::Uncompressed,
|
||||||
|
CompressionCode::Lzma,
|
||||||
|
CompressionCode::Bzip2,
|
||||||
|
CompressionCode::Zlib,
|
||||||
|
CompressionCode::Zstd,
|
||||||
|
];
|
||||||
for compression in codes {
|
for compression in codes {
|
||||||
round_trip(Command::BitmapLinear(23, BitVec::new(40), compression));
|
round_trip(Command::BitmapLinear(23, BitVec::new(40), compression));
|
||||||
round_trip(Command::BitmapLinearAnd(23, BitVec::new(40), compression));
|
round_trip(Command::BitmapLinearAnd(
|
||||||
round_trip(Command::BitmapLinearOr(23, BitVec::new(40), compression));
|
23,
|
||||||
round_trip(Command::BitmapLinearXor(23, BitVec::new(40), compression));
|
BitVec::new(40),
|
||||||
round_trip(Command::BitmapLinearWin(Origin(0, 0), PixelGrid::max_sized(), compression));
|
compression,
|
||||||
|
));
|
||||||
|
round_trip(Command::BitmapLinearOr(
|
||||||
|
23,
|
||||||
|
BitVec::new(40),
|
||||||
|
compression,
|
||||||
|
));
|
||||||
|
round_trip(Command::BitmapLinearXor(
|
||||||
|
23,
|
||||||
|
BitVec::new(40),
|
||||||
|
compression,
|
||||||
|
));
|
||||||
|
round_trip(Command::BitmapLinearWin(
|
||||||
|
Origin(0, 0),
|
||||||
|
PixelGrid::max_sized(),
|
||||||
|
compression,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -51,10 +51,18 @@ impl TryFrom<u16> for CommandCode {
|
||||||
value if value == BitmapLinearAnd as u16 => Ok(BitmapLinearAnd),
|
value if value == BitmapLinearAnd as u16 => Ok(BitmapLinearAnd),
|
||||||
value if value == BitmapLinearOr as u16 => Ok(BitmapLinearOr),
|
value if value == BitmapLinearOr as u16 => Ok(BitmapLinearOr),
|
||||||
value if value == BitmapLinearXor as u16 => Ok(BitmapLinearXor),
|
value if value == BitmapLinearXor as u16 => Ok(BitmapLinearXor),
|
||||||
value if value == BitmapLinearWinZstd as u16 => Ok(BitmapLinearWinZstd),
|
value if value == BitmapLinearWinZstd as u16 => {
|
||||||
value if value == BitmapLinearWinLzma as u16 => Ok(BitmapLinearWinLzma),
|
Ok(BitmapLinearWinZstd)
|
||||||
value if value == BitmapLinearWinZlib as u16 => Ok(BitmapLinearWinZlib),
|
}
|
||||||
value if value == BitmapLinearWinBzip2 as u16 => Ok(BitmapLinearWinBzip2),
|
value if value == BitmapLinearWinLzma as u16 => {
|
||||||
|
Ok(BitmapLinearWinLzma)
|
||||||
|
}
|
||||||
|
value if value == BitmapLinearWinZlib as u16 => {
|
||||||
|
Ok(BitmapLinearWinZlib)
|
||||||
|
}
|
||||||
|
value if value == BitmapLinearWinBzip2 as u16 => {
|
||||||
|
Ok(BitmapLinearWinBzip2)
|
||||||
|
}
|
||||||
_ => Err(()),
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,9 +104,9 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn round_trip() {
|
fn round_trip() {
|
||||||
let p = Packet(Header(0,1,2,3,4), vec![42u8; 23]);
|
let p = Packet(Header(0, 1, 2, 3, 4), vec![42u8; 23]);
|
||||||
let data: Vec<u8> = p.into();
|
let data: Vec<u8> = p.into();
|
||||||
let p = Packet::try_from(&*data).unwrap();
|
let p = Packet::try_from(&*data).unwrap();
|
||||||
assert_eq!(p, Packet(Header(0,1,2,3,4), vec![42u8; 23]));
|
assert_eq!(p, Packet(Header(0, 1, 2, 3, 4), vec![42u8; 23]));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue