aboutsummaryrefslogtreecommitdiffstats
path: root/src/protocol.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocol.rs')
-rw-r--r--src/protocol.rs46
1 files changed, 44 insertions, 2 deletions
diff --git a/src/protocol.rs b/src/protocol.rs
index 0894aea..c76a8a7 100644
--- a/src/protocol.rs
+++ b/src/protocol.rs
@@ -54,7 +54,7 @@ impl<T: tokio::io::AsyncWrite> FramedWriter<T> {
pub const PROTO_VERSION: u8 = 1;
#[repr(u8)]
-#[derive(Copy, Clone, Debug)]
+#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
pub enum AuthType {
Plain = 0,
RecurseCenter,
@@ -124,7 +124,7 @@ impl Auth {
}
#[repr(u8)]
-#[derive(Copy, Clone, Debug)]
+#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
pub enum MessageType {
Login = 0,
StartStreaming,
@@ -811,6 +811,48 @@ mod test {
}
}
+ #[test]
+ fn test_auth_values() {
+ let mut set = std::collections::HashSet::new();
+ let mut seen_err = false;
+ for i in 0..=255 {
+ if seen_err {
+ assert!(AuthType::try_from(i).is_err());
+ } else {
+ match AuthType::try_from(i) {
+ Ok(ty) => {
+ assert!(!set.contains(&ty));
+ set.insert(ty);
+ }
+ Err(_) => {
+ seen_err = true;
+ }
+ }
+ }
+ }
+ }
+
+ #[test]
+ fn test_message_values() {
+ let mut set = std::collections::HashSet::new();
+ let mut seen_err = false;
+ for i in 0..=255 {
+ if seen_err {
+ assert!(MessageType::try_from(i).is_err());
+ } else {
+ match MessageType::try_from(i) {
+ Ok(ty) => {
+ assert!(!set.contains(&ty));
+ set.insert(ty);
+ }
+ Err(_) => {
+ seen_err = true;
+ }
+ }
+ }
+ }
+ }
+
fn valid_messages() -> Vec<Message> {
vec![
Message::login(