change StreamIsMuted and ComputerSoundIsOn names

This commit is contained in:
Nickiel12 2021-12-20 16:24:59 -08:00
parent 9f83884a18
commit 23dd99eb1f
4 changed files with 39 additions and 14 deletions

View file

@ -48,8 +48,8 @@ impl StreamState {
pub fn update(&mut self, update: StateUpdate) { pub fn update(&mut self, update: StateUpdate) {
match update { match update {
StateUpdate::StreamRunning(new_val) => {self.stream_running = new_val;}, StateUpdate::StreamRunning(new_val) => {self.stream_running = new_val;},
StateUpdate::StreamIsMuted(new_val) => {self.stream_is_muted = new_val;}, StateUpdate::StreamSoundToggleOn(new_val) => {self.stream_is_muted = new_val;},
StateUpdate::ComputerSoundIsOn(new_val) => {self.computer_sound_is_on = new_val;}, StateUpdate::ToggleComputerSoundOn(new_val) => {self.computer_sound_is_on = new_val;},
StateUpdate::ChangeSceneOnChangeSlide(new_val) => {self.change_scene_on_change_slide_hotkey = new_val;}, StateUpdate::ChangeSceneOnChangeSlide(new_val) => {self.change_scene_on_change_slide_hotkey = new_val;},
StateUpdate::TimerCanRun(new_val) => {self.timer_can_run = new_val;}, StateUpdate::TimerCanRun(new_val) => {self.timer_can_run = new_val;},
StateUpdate::TimerLength(new_val) => {self.timer_length = new_val;}, StateUpdate::TimerLength(new_val) => {self.timer_length = new_val;},

View file

@ -6,7 +6,7 @@ use crate::modules::{message_handler::{MessageHandler, StateMessage}, stream_sta
#[test] #[test]
fn does_stream_state_implement_message_handler() { fn does_stream_state_implement_message_handler() {
let mut state = StreamState::new(); let mut state = StreamState::new();
state.handle_update(StateUpdate::ComputerSoundIsOn(false)); state.handle_update(StateUpdate::ToggleComputerSoundOn(false));
assert_eq!(state.computer_sound_is_on, false); assert_eq!(state.computer_sound_is_on, false);
} }
@ -30,7 +30,7 @@ fn message_hander_can_handle_basic_message() {
let handler = StreamState::new(); let handler = StreamState::new();
let join_handle = listen(handler, rx); let join_handle = listen(handler, rx);
tx.send(StateMessage::StateUpdate(StateUpdate::ComputerSoundIsOn(false))).unwrap(); tx.send(StateMessage::StateUpdate(StateUpdate::ToggleComputerSoundOn(false))).unwrap();
thread::sleep(std::time::Duration::from_millis(1000)); thread::sleep(std::time::Duration::from_millis(1000));
tx.send(StateMessage::CloseListener).unwrap(); tx.send(StateMessage::CloseListener).unwrap();
join_handle.join().unwrap(); join_handle.join().unwrap();
@ -62,7 +62,7 @@ fn message_handler_can_handle_multiple_messages() {
let handler = StreamState::new(); let handler = StreamState::new();
let join_handle = listen(handler, rx); let join_handle = listen(handler, rx);
tx.send(StateMessage::StateUpdate(StateUpdate::ComputerSoundIsOn(false))).unwrap(); tx.send(StateMessage::StateUpdate(StateUpdate::ToggleComputerSoundOn(false))).unwrap();
tx.send(StateMessage::StateUpdate(StateUpdate::SceneIsAugmented(true))).unwrap(); tx.send(StateMessage::StateUpdate(StateUpdate::SceneIsAugmented(true))).unwrap();
tx.send(StateMessage::StateUpdate(StateUpdate::TimerCanRun(false))).unwrap(); tx.send(StateMessage::StateUpdate(StateUpdate::TimerCanRun(false))).unwrap();
thread::sleep(std::time::Duration::from_millis(1000)); thread::sleep(std::time::Duration::from_millis(1000));

View file

@ -34,19 +34,19 @@ fn test_json_to_state_update() {
assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str(
"{\"type\": \"update\", \"update\": \"Toggle_Computer_Volume\", \"data\": \"true\"}" "{\"type\": \"update\", \"update\": \"Toggle_Computer_Volume\", \"data\": \"true\"}"
).unwrap()), StateUpdate::ComputerSoundIsOn(true)); ).unwrap()), StateUpdate::ToggleComputerSoundOn(true));
assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str(
"{\"type\": \"update\", \"update\": \"Toggle_Computer_Volume\", \"data\": \"false\"}" "{\"type\": \"update\", \"update\": \"Toggle_Computer_Volume\", \"data\": \"false\"}"
).unwrap()), StateUpdate::ComputerSoundIsOn(false)); ).unwrap()), StateUpdate::ToggleComputerSoundOn(false));
assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str(
"{\"type\": \"update\", \"update\": \"Toggle_Stream_Volume\", \"data\": \"true\"}" "{\"type\": \"update\", \"update\": \"Toggle_Stream_Volume\", \"data\": \"true\"}"
).unwrap()), StateUpdate::StreamIsMuted(true)); ).unwrap()), StateUpdate::StreamSoundToggleOn(true));
assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str(
"{\"type\": \"update\", \"update\": \"Toggle_Stream_Volume\", \"data\": \"false\"}" "{\"type\": \"update\", \"update\": \"Toggle_Stream_Volume\", \"data\": \"false\"}"
).unwrap()), StateUpdate::StreamIsMuted(false)); ).unwrap()), StateUpdate::StreamSoundToggleOn(false));
assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str(
"{\"type\": \"update\", \"update\": \"Media_Pause_Play\", \"data\": \"true\"}" "{\"type\": \"update\", \"update\": \"Media_Pause_Play\", \"data\": \"true\"}"
@ -85,7 +85,7 @@ fn test_json_to_state_update() {
).unwrap()), StateUpdate::SubScene(SubScenes::ScreenWithLowerRight)); ).unwrap()), StateUpdate::SubScene(SubScenes::ScreenWithLowerRight));
assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str(
"{\"type\": \"update\", \"update\": \"Timer_Length\", \"data\": 5.5}" "{\"type\": \"update\", \"update\": \"Timer_Length\", \"data\": \"5.5\"}"
).unwrap()), StateUpdate::TimerLength(5.5)); ).unwrap()), StateUpdate::TimerLength(5.5));
assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str(
@ -111,7 +111,32 @@ fn test_json_to_state_update_fails() {
#[test] #[test]
fn test_state_update_to_json() { fn test_state_update_to_json() {
println!("{:?}", StateUpdate::StreamRunning(true).to_json());
//Note, this one needs to is dependant on test_json_to_update for correctedness //Note, this one needs to is dependant on test_json_to_update for correctedness
assert_eq!(StateUpdate::StreamRunning(true), (StateUpdate::json_to_state_update(StateUpdate::StreamRunning(true).to_json()))); assert_eq!(StateUpdate::StreamRunning(true), (StateUpdate::json_to_state_update(StateUpdate::StreamRunning(true).to_json())));
assert_eq!(StateUpdate::StreamRunning(false), StateUpdate::json_to_state_update(StateUpdate::StreamRunning(false).to_json()));
assert_eq!(StateUpdate::StreamSoundToggleOn(true), StateUpdate::json_to_state_update(StateUpdate::StreamSoundToggleOn(true).to_json()));
assert_eq!(StateUpdate::StreamSoundToggleOn(false), StateUpdate::json_to_state_update(StateUpdate::StreamSoundToggleOn(false).to_json()));
assert_eq!(StateUpdate::ToggleComputerSoundOn(true), StateUpdate::json_to_state_update(StateUpdate::ToggleComputerSoundOn(true).to_json()));
assert_eq!(StateUpdate::ToggleComputerSoundOn(false), StateUpdate::json_to_state_update(StateUpdate::ToggleComputerSoundOn(false).to_json()));
assert_eq!(StateUpdate::ChangeSceneOnChangeSlide(true), StateUpdate::json_to_state_update(StateUpdate::ChangeSceneOnChangeSlide(true).to_json()));
assert_eq!(StateUpdate::ChangeSceneOnChangeSlide(false), StateUpdate::json_to_state_update(StateUpdate::ChangeSceneOnChangeSlide(false).to_json()));
assert_eq!(StateUpdate::SceneIsAugmented(true), StateUpdate::json_to_state_update(StateUpdate::SceneIsAugmented(true).to_json()));
assert_eq!(StateUpdate::SceneIsAugmented(false), StateUpdate::json_to_state_update(StateUpdate::SceneIsAugmented(false).to_json()));
assert_eq!(StateUpdate::TimerCanRun(true), StateUpdate::json_to_state_update(StateUpdate::TimerCanRun(true).to_json()));
assert_eq!(StateUpdate::TimerCanRun(false), StateUpdate::json_to_state_update(StateUpdate::TimerCanRun(false).to_json()));
assert_eq!(StateUpdate::TimerLength(17.5), StateUpdate::json_to_state_update(StateUpdate::TimerLength(17.5).to_json()));
assert_eq!(StateUpdate::TimerText(String::from("15.6")), StateUpdate::json_to_state_update(StateUpdate::TimerText(String::from("15.6")).to_json()));
assert_eq!(StateUpdate::SubScene(SubScenes::CameraDefault), StateUpdate::json_to_state_update(StateUpdate::SubScene(SubScenes::CameraDefault).to_json()));
assert_eq!(StateUpdate::SubScene(SubScenes::CameraWithUpperRight), StateUpdate::json_to_state_update(StateUpdate::SubScene(SubScenes::CameraWithUpperRight).to_json()));
assert_eq!(StateUpdate::SubScene(SubScenes::CameraWithLowerRight), StateUpdate::json_to_state_update(StateUpdate::SubScene(SubScenes::CameraWithLowerRight).to_json()));
assert_eq!(StateUpdate::SubScene(SubScenes::CameraWithLargeUpperRight), StateUpdate::json_to_state_update(StateUpdate::SubScene(SubScenes::CameraWithLargeUpperRight).to_json()));
assert_eq!(StateUpdate::SubScene(SubScenes::ScreenDefault), StateUpdate::json_to_state_update(StateUpdate::SubScene(SubScenes::ScreenDefault).to_json()));
assert_eq!(StateUpdate::SubScene(SubScenes::ScreenWithUpperRight), StateUpdate::json_to_state_update(StateUpdate::SubScene(SubScenes::ScreenWithUpperRight).to_json()));
assert_eq!(StateUpdate::SubScene(SubScenes::ScreenWithLowerRight), StateUpdate::json_to_state_update(StateUpdate::SubScene(SubScenes::ScreenWithLowerRight).to_json()));
assert_eq!(StateUpdate::Scene(Scenes::Camera), StateUpdate::json_to_state_update(StateUpdate::Scene(Scenes::Camera).to_json()));
assert_eq!(StateUpdate::Scene(Scenes::Screen), StateUpdate::json_to_state_update(StateUpdate::Scene(Scenes::Screen).to_json()));
assert_eq!(StateUpdate::ChangeSlide(SlideChange::Next), StateUpdate::json_to_state_update(StateUpdate::ChangeSlide(SlideChange::Next).to_json()));
assert_eq!(StateUpdate::ChangeSlide(SlideChange::Previous), StateUpdate::json_to_state_update(StateUpdate::ChangeSlide(SlideChange::Previous).to_json()));
assert_eq!(StateUpdate::UpdateClient, StateUpdate::json_to_state_update(StateUpdate::UpdateClient.to_json()));
} }

View file

@ -12,7 +12,7 @@ fn test_make_socket() {
let tx = io_handler.message_thread_tx.clone().unwrap(); let tx = io_handler.message_thread_tx.clone().unwrap();
tx.send(StateMessage::StateUpdate(StateUpdate::SceneIsAugmented(true))).unwrap(); tx.send(StateMessage::StateUpdate(StateUpdate::SceneIsAugmented(true))).unwrap();
tx.send(StateMessage::StateUpdate(StateUpdate::StreamIsMuted(true))).unwrap(); tx.send(StateMessage::StateUpdate(StateUpdate::StreamSoundToggleOn(true))).unwrap();
thread::sleep(std::time::Duration::from_millis(1000)); thread::sleep(std::time::Duration::from_millis(1000));
let final_state = io_handler.close(); let final_state = io_handler.close();
@ -38,8 +38,8 @@ fn send_on_multiple_threads() {
tx2.send(StateMessage::StateUpdate(StateUpdate::ChangeSceneOnChangeSlide(false))).unwrap(); tx2.send(StateMessage::StateUpdate(StateUpdate::ChangeSceneOnChangeSlide(false))).unwrap();
}); });
thread::spawn(move || { thread::spawn(move || {
tx3.send(StateMessage::StateUpdate(StateUpdate::StreamIsMuted(false))).unwrap(); tx3.send(StateMessage::StateUpdate(StateUpdate::StreamSoundToggleOn(false))).unwrap();
tx3.send(StateMessage::StateUpdate(StateUpdate::StreamIsMuted(true))).unwrap(); tx3.send(StateMessage::StateUpdate(StateUpdate::StreamSoundToggleOn(true))).unwrap();
}); });
thread::sleep(std::time::Duration::from_millis(1000)); thread::sleep(std::time::Duration::from_millis(1000));