Browse Source

Derive Eq for ServerResponse and use it in tests.

wip
Titouan Rigoudy 7 years ago
parent
commit
01472b1b69
2 changed files with 22 additions and 22 deletions
  1. +20
    -20
      src/proto/server/response.rs
  2. +2
    -2
      src/user.rs

+ 20
- 20
src/proto/server/response.rs View File

@ -10,7 +10,7 @@ use user;
* SERVER RESPONSE * * SERVER RESPONSE *
*=================*/ *=================*/
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq)]
pub enum ServerResponse { pub enum ServerResponse {
ConnectToPeerResponse(ConnectToPeerResponse), ConnectToPeerResponse(ConnectToPeerResponse),
FileSearchResponse(FileSearchResponse), FileSearchResponse(FileSearchResponse),
@ -254,7 +254,7 @@ impl ProtoDecode for FileSearchResponse {
* LOGIN * * LOGIN *
*=======*/ *=======*/
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq)]
pub enum LoginResponse { pub enum LoginResponse {
LoginOk { LoginOk {
motd: String, motd: String,
@ -293,7 +293,7 @@ impl ReadFromPacket for LoginResponse {
* PARENT MIN SPEED * * PARENT MIN SPEED *
*==================*/ *==================*/
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq)]
pub struct ParentMinSpeedResponse { pub struct ParentMinSpeedResponse {
pub value: u32, pub value: u32,
} }
@ -309,7 +309,7 @@ impl ReadFromPacket for ParentMinSpeedResponse {
* PARENT SPEED RATIO * * PARENT SPEED RATIO *
*====================*/ *====================*/
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq)]
pub struct ParentSpeedRatioResponse { pub struct ParentSpeedRatioResponse {
pub value: u32, pub value: u32,
} }
@ -325,7 +325,7 @@ impl ReadFromPacket for ParentSpeedRatioResponse {
* PEER ADDRESS * * PEER ADDRESS *
*==============*/ *==============*/
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq)]
pub struct PeerAddressResponse { pub struct PeerAddressResponse {
username: String, username: String,
ip: net::Ipv4Addr, ip: net::Ipv4Addr,
@ -350,7 +350,7 @@ impl ReadFromPacket for PeerAddressResponse {
* PRIVILEGED USERS * * PRIVILEGED USERS *
*==================*/ *==================*/
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq)]
pub struct PrivilegedUsersResponse { pub struct PrivilegedUsersResponse {
pub users: Vec<String>, pub users: Vec<String>,
} }
@ -366,7 +366,7 @@ impl ReadFromPacket for PrivilegedUsersResponse {
* ROOM JOIN * * ROOM JOIN *
*===========*/ *===========*/
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq)]
pub struct RoomJoinResponse { pub struct RoomJoinResponse {
pub room_name: String, pub room_name: String,
pub users: Vec<(String, user::User)>, pub users: Vec<(String, user::User)>,
@ -470,7 +470,7 @@ impl RoomJoinResponse {
* ROOM LEAVE * * ROOM LEAVE *
*============*/ *============*/
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq)]
pub struct RoomLeaveResponse { pub struct RoomLeaveResponse {
pub room_name: String, pub room_name: String,
} }
@ -485,7 +485,7 @@ impl ReadFromPacket for RoomLeaveResponse {
* ROOM LIST * * ROOM LIST *
*===========*/ *===========*/
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq)]
pub struct RoomListResponse { pub struct RoomListResponse {
pub rooms: Vec<(String, u32)>, pub rooms: Vec<(String, u32)>,
pub owned_private_rooms: Vec<(String, u32)>, pub owned_private_rooms: Vec<(String, u32)>,
@ -540,7 +540,7 @@ impl RoomListResponse {
* ROOM MESSAGE * * ROOM MESSAGE *
*==============*/ *==============*/
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq)]
pub struct RoomMessageResponse { pub struct RoomMessageResponse {
pub room_name: String, pub room_name: String,
pub user_name: String, pub user_name: String,
@ -564,7 +564,7 @@ impl ReadFromPacket for RoomMessageResponse {
* ROOM MESSAGE * * ROOM MESSAGE *
*==============*/ *==============*/
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq)]
pub struct RoomTickersResponse { pub struct RoomTickersResponse {
pub room_name: String, pub room_name: String,
pub tickers: Vec<(String, String)>, pub tickers: Vec<(String, String)>,
@ -593,7 +593,7 @@ impl ReadFromPacket for RoomTickersResponse {
* ROOM USER JOINED * * ROOM USER JOINED *
*==================*/ *==================*/
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq)]
pub struct RoomUserJoinedResponse { pub struct RoomUserJoinedResponse {
pub room_name: String, pub room_name: String,
pub user_name: String, pub user_name: String,
@ -637,7 +637,7 @@ impl ReadFromPacket for RoomUserJoinedResponse {
* ROOM USER LEFT * * ROOM USER LEFT *
*================*/ *================*/
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq)]
pub struct RoomUserLeftResponse { pub struct RoomUserLeftResponse {
pub room_name: String, pub room_name: String,
pub user_name: String, pub user_name: String,
@ -658,7 +658,7 @@ impl ReadFromPacket for RoomUserLeftResponse {
* USER INFO * * USER INFO *
*===========*/ *===========*/
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq)]
pub struct UserInfoResponse { pub struct UserInfoResponse {
pub user_name: String, pub user_name: String,
pub average_speed: usize, pub average_speed: usize,
@ -688,7 +688,7 @@ impl ReadFromPacket for UserInfoResponse {
* USER STATUS * * USER STATUS *
*=============*/ *=============*/
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq)]
pub struct UserStatusResponse { pub struct UserStatusResponse {
pub user_name: String, pub user_name: String,
pub status: user::Status, pub status: user::Status,
@ -712,7 +712,7 @@ impl ReadFromPacket for UserStatusResponse {
* WISHLIST INTERVAL * * WISHLIST INTERVAL *
*===================*/ *===================*/
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq)]
pub struct WishlistIntervalResponse { pub struct WishlistIntervalResponse {
pub seconds: u32, pub seconds: u32,
} }
@ -742,22 +742,22 @@ mod tests {
#[test] #[test]
fn roundtrip_connect_to_peer() { fn roundtrip_connect_to_peer() {
roundtrip(ConnectToPeerResponse {
roundtrip(ServerResponse::ConnectToPeerResponse(ConnectToPeerResponse {
user_name: "alice".to_string(), user_name: "alice".to_string(),
connection_type: "P".to_string(), connection_type: "P".to_string(),
ip: net::Ipv4Addr::new(192, 168, 254, 1), ip: net::Ipv4Addr::new(192, 168, 254, 1),
port: 1337, port: 1337,
token: 42, token: 42,
is_privileged: true, is_privileged: true,
})
}))
} }
#[test] #[test]
fn roundtrip_file_search() { fn roundtrip_file_search() {
roundtrip(FileSearchResponse {
roundtrip(ServerResponse::FileSearchResponse(FileSearchResponse {
user_name: "alice".to_string(), user_name: "alice".to_string(),
ticket: 1337, ticket: 1337,
query: "foo.txt".to_string(), query: "foo.txt".to_string(),
})
}))
} }
} }

+ 2
- 2
src/user.rs View File

@ -10,7 +10,7 @@ const STATUS_AWAY: u32 = 2;
const STATUS_ONLINE: u32 = 3; const STATUS_ONLINE: u32 = 3;
/// This enumeration is the list of possible user statuses. /// This enumeration is the list of possible user statuses.
#[derive(Clone, Copy, Debug, RustcDecodable, RustcEncodable)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, RustcDecodable, RustcEncodable)]
pub enum Status { pub enum Status {
/// The user if offline. /// The user if offline.
Offline, Offline,
@ -47,7 +47,7 @@ impl proto::WriteToPacket for Status {
/// This structure contains the last known information about a fellow user. /// This structure contains the last known information about a fellow user.
/// It does not store the name, as that is stored implicitly as the key in the /// It does not store the name, as that is stored implicitly as the key in the
/// user hash table. /// user hash table.
#[derive(Clone, Debug, RustcDecodable, RustcEncodable)]
#[derive(Clone, Debug, Eq, PartialEq, RustcDecodable, RustcEncodable)]
pub struct User { pub struct User {
/// The last known status of the user. /// The last known status of the user.
pub status: Status, pub status: Status,


Loading…
Cancel
Save