Browse Source

Add tests for Context.

wip
Titouan Rigoudy 6 years ago
parent
commit
ef5f6acab8
2 changed files with 26 additions and 4 deletions
  1. +22
    -0
      src/context.rs
  2. +4
    -4
      src/room.rs

+ 22
- 0
src/context.rs View File

@ -7,6 +7,8 @@ use crate::room::RoomMap;
use crate::user::UserMap;
/// Contains all the different bits of client state.
///
/// Implements `Sync`.
pub struct Context {
pub rooms: Mutex<RoomMap>,
pub users: Mutex<UserMap>,
@ -21,3 +23,23 @@ impl Context {
}
}
}
#[cfg(test)]
mod tests {
use std::thread;
use std::sync::Arc;
use super::Context;
#[test]
fn new_context_is_empty() {
let context = Context::new();
assert_eq!(context.rooms.lock().get_room_list(), vec![]);
assert_eq!(context.users.lock().get_list(), vec![]);
}
#[test]
fn context_is_sync() {
let sync: &dyn Sync = &Context::new();
}
}

+ 4
- 4
src/room.rs View File

@ -6,7 +6,7 @@ use std::mem;
use crate::proto::{server, User};
/// This enumeration is the list of possible membership states for a chat room.
#[derive(Clone, Copy, Debug, RustcDecodable, RustcEncodable)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, RustcDecodable, RustcEncodable)]
pub enum Membership {
/// The user is not a member of this room.
NonMember,
@ -22,7 +22,7 @@ pub enum Membership {
/// This enumeration is the list of visibility types for rooms that the user is
/// a member of.
#[derive(Clone, Copy, Debug, RustcDecodable, RustcEncodable)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, RustcDecodable, RustcEncodable)]
pub enum Visibility {
/// This room is visible to any user.
Public,
@ -33,7 +33,7 @@ pub enum Visibility {
}
/// This structure contains a chat room message.
#[derive(Clone, Debug, RustcDecodable, RustcEncodable)]
#[derive(Clone, Debug, Eq, PartialEq, RustcDecodable, RustcEncodable)]
pub struct Message {
pub user_name: String,
pub message: String,
@ -42,7 +42,7 @@ pub struct Message {
/// This structure contains the last known information about a chat room.
/// It does not store the name, as that is stored implicitly as the key in the
/// room hash table.
#[derive(Clone, Debug, RustcDecodable, RustcEncodable)]
#[derive(Clone, Debug, Eq, PartialEq, RustcDecodable, RustcEncodable)]
pub struct Room {
/// The membership state of the user for the room.
pub membership: Membership,


Loading…
Cancel
Save