From 3def04e8f315d6524088b3b189cb83026eb86fff Mon Sep 17 00:00:00 2001 From: sleepycatcoding <131554884+sleepycatcoding@users.noreply.github.com> Date: Fri, 21 Jul 2023 18:10:27 +0300 Subject: [PATCH 01/19] tests: Add experimental socket_mock tool This is used to help to create/test socket.json files against real Flash Player to verify behavior. --- Cargo.lock | 10 +++ Cargo.toml | 1 + tests/socket-mock/Cargo.toml | 14 ++++ tests/socket-mock/src/main.rs | 130 ++++++++++++++++++++++++++++++++++ 4 files changed, 155 insertions(+) create mode 100644 tests/socket-mock/Cargo.toml create mode 100644 tests/socket-mock/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 544ad06e949c..260978db2ea0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4047,6 +4047,16 @@ dependencies = [ "walkdir", ] +[[package]] +name = "ruffle_socket_mock" +version = "0.1.0" +dependencies = [ + "serde", + "serde_json", + "tracing", + "tracing-subscriber", +] + [[package]] name = "ruffle_video" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 5fa831910fa3..b4d9955fd994 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ members = [ "tests", "tests/input-format", + "tests/socket-mock", ] default-members = ["desktop"] resolver = "2" diff --git a/tests/socket-mock/Cargo.toml b/tests/socket-mock/Cargo.toml new file mode 100644 index 000000000000..5aeba17bf496 --- /dev/null +++ b/tests/socket-mock/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "ruffle_socket_mock" +authors.workspace = true +edition.workspace = true +homepage.workspace = true +license.workspace = true +repository.workspace = true +version.workspace = true + +[dependencies] +tracing = { workspace = true} +tracing-subscriber = { workspace = true } +serde = { version = "1.0.152", features = ["derive"] } +serde_json = "1.0.91" \ No newline at end of file diff --git a/tests/socket-mock/src/main.rs b/tests/socket-mock/src/main.rs new file mode 100644 index 000000000000..3dca3ca6413b --- /dev/null +++ b/tests/socket-mock/src/main.rs @@ -0,0 +1,130 @@ +use std::{net::TcpListener, io::{self, Read, Write}, path::Path, fs::File}; +use serde::{Serialize, Deserialize}; +use serde_json::from_reader; +use tracing_subscriber::filter::{EnvFilter, LevelFilter}; + +#[derive(Debug, Serialize, Deserialize)] +#[serde(tag = "type")] +pub enum SocketEvent { + /// Wait for input data that matches this. + Receive { + expected: Vec, + }, + /// Send data to client. + Send { + payload: Vec, + }, + /// Expect client to disconnect. + WaitForDisconnect, + /// Disconnect the client. + Disconnect, +} + +impl SocketEvent { + pub fn from_file

(path: P) -> Result, io::Error> + where + P: AsRef, + { + let file = File::open(path)?; + + Ok(from_reader(file)?) + } +} + +static POLICY: &'static [u8] = &*b" + + + +\0"; + + +fn main() { + let subscriber = tracing_subscriber::fmt::Subscriber::builder() + .with_env_filter(EnvFilter::builder().with_default_directive(LevelFilter::INFO.into()).from_env_lossy()) + .finish(); + // Ignore error if it's already been set + let _ = tracing::subscriber::set_global_default(subscriber); + + let events = SocketEvent::from_file("socket.json").unwrap(); + let event_count = events.len(); + + let listener = TcpListener::bind("0.0.0.0:8001").unwrap(); + tracing::info!("Listening on {}", listener.local_addr().unwrap()); + let (mut stream, addr) = listener.accept().unwrap(); + tracing::info!("Incoming connection from {}", addr); + + // Handle socket policy stuff. (Required as Flash Player wont want to connect otherwise.) + let mut buffer = [0; 4096]; + let _ = stream.read(&mut buffer); + stream.write_all(POLICY).unwrap(); + tracing::info!("Policy sent successfully!"); + + // Now we listen again as flash reopens socket connection. + let (mut stream, addr) = listener.accept().unwrap(); + tracing::info!("Incoming connection from {}", addr); + + for (index, event) in events.into_iter().enumerate() { + tracing::info!("Running step {}/{}", index + 1, event_count); + + match event { + SocketEvent::Receive { expected } => { + let mut output = vec![]; + + loop { + let mut buffer = [0; 4096]; + + match stream.read(&mut buffer) { + Err(_) | Ok(0) => { + tracing::error!("Expected data, but socket was closed."); + return; + } + Ok(read) => { + if read == 4096 { + output.extend(buffer); + } else { + let data = buffer.into_iter().take(read).collect::>(); + output.extend(data); + break; + } + } + } + } + + if output != expected { + tracing::error!("Received data did not match expected data\nExpected: {:?}\nActual: {:?}", expected, output); + } + }, + SocketEvent::Send { mut payload } => { + while !payload.is_empty() { + match stream.write(&payload) { + Err(_) | Ok(0) => { + tracing::error!("Socket was closed in middle of writing."); + return; + } + Ok(written) => { + let _ = payload.drain(..written); + } + } + } + }, + SocketEvent::WaitForDisconnect => { + let mut buffer = [0; 4096]; + + match stream.read(&mut buffer) { + Err(_) | Ok(0) => { + tracing::info!("Client has closed the connection!"); + return; + } + Ok(_) => { + tracing::error!("Expected client to close connection, but data was sent instead."); + } + } + }, + SocketEvent::Disconnect => { + tracing::info!("Disconnecting client."); + drop(stream); + break; + } + } + } +} From 68f8ff1a3be71aff8f6365824c47f3cb1e1f638d Mon Sep 17 00:00:00 2001 From: sleepycatcoding <131554884+sleepycatcoding@users.noreply.github.com> Date: Fri, 21 Jul 2023 18:27:44 +0300 Subject: [PATCH 02/19] tests: Move SocketEvent into ruffle_socket_format crate --- Cargo.lock | 9 ++++++++- Cargo.toml | 1 + tests/socket-format/Cargo.toml | 12 ++++++++++++ tests/socket-format/src/lib.rs | 32 ++++++++++++++++++++++++++++++++ tests/socket-mock/Cargo.toml | 3 +-- tests/socket-mock/src/main.rs | 33 ++------------------------------- 6 files changed, 56 insertions(+), 34 deletions(-) create mode 100644 tests/socket-format/Cargo.toml create mode 100644 tests/socket-format/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 260978db2ea0..37562e8483ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4048,11 +4048,18 @@ dependencies = [ ] [[package]] -name = "ruffle_socket_mock" +name = "ruffle_socket_format" version = "0.1.0" dependencies = [ "serde", "serde_json", +] + +[[package]] +name = "ruffle_socket_mock" +version = "0.1.0" +dependencies = [ + "ruffle_socket_format", "tracing", "tracing-subscriber", ] diff --git a/Cargo.toml b/Cargo.toml index b4d9955fd994..e81aafce50ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ members = [ "tests", "tests/input-format", + "tests/socket-format", "tests/socket-mock", ] default-members = ["desktop"] diff --git a/tests/socket-format/Cargo.toml b/tests/socket-format/Cargo.toml new file mode 100644 index 000000000000..52b55b97bf36 --- /dev/null +++ b/tests/socket-format/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "ruffle_socket_format" +authors.workspace = true +edition.workspace = true +homepage.workspace = true +license.workspace = true +repository.workspace = true +version.workspace = true + +[dependencies] +serde = { version = "1.0.152", features = ["derive"] } +serde_json = "1.0.91" diff --git a/tests/socket-format/src/lib.rs b/tests/socket-format/src/lib.rs new file mode 100644 index 000000000000..0cbdb3771610 --- /dev/null +++ b/tests/socket-format/src/lib.rs @@ -0,0 +1,32 @@ +use std::{io, fs::File, path::Path}; + +use serde::{Serialize, Deserialize}; +use serde_json::from_reader; + +#[derive(Debug, Serialize, Deserialize)] +#[serde(tag = "type")] +pub enum SocketEvent { + /// Wait for input data that matches this. + Receive { + expected: Vec, + }, + /// Send data to client. + Send { + payload: Vec, + }, + /// Expect client to disconnect. + WaitForDisconnect, + /// Disconnect the client. + Disconnect, +} + +impl SocketEvent { + pub fn from_file

(path: P) -> Result, io::Error> + where + P: AsRef, + { + let file = File::open(path)?; + + Ok(from_reader(file)?) + } +} \ No newline at end of file diff --git a/tests/socket-mock/Cargo.toml b/tests/socket-mock/Cargo.toml index 5aeba17bf496..2bce02ff47ef 100644 --- a/tests/socket-mock/Cargo.toml +++ b/tests/socket-mock/Cargo.toml @@ -10,5 +10,4 @@ version.workspace = true [dependencies] tracing = { workspace = true} tracing-subscriber = { workspace = true } -serde = { version = "1.0.152", features = ["derive"] } -serde_json = "1.0.91" \ No newline at end of file +ruffle_socket_format = { path = "../socket-format" } \ No newline at end of file diff --git a/tests/socket-mock/src/main.rs b/tests/socket-mock/src/main.rs index 3dca3ca6413b..1461921b43c1 100644 --- a/tests/socket-mock/src/main.rs +++ b/tests/socket-mock/src/main.rs @@ -1,36 +1,7 @@ -use std::{net::TcpListener, io::{self, Read, Write}, path::Path, fs::File}; -use serde::{Serialize, Deserialize}; -use serde_json::from_reader; +use std::{net::TcpListener, io::{Read, Write}}; +use ruffle_socket_format::SocketEvent; use tracing_subscriber::filter::{EnvFilter, LevelFilter}; -#[derive(Debug, Serialize, Deserialize)] -#[serde(tag = "type")] -pub enum SocketEvent { - /// Wait for input data that matches this. - Receive { - expected: Vec, - }, - /// Send data to client. - Send { - payload: Vec, - }, - /// Expect client to disconnect. - WaitForDisconnect, - /// Disconnect the client. - Disconnect, -} - -impl SocketEvent { - pub fn from_file

(path: P) -> Result, io::Error> - where - P: AsRef, - { - let file = File::open(path)?; - - Ok(from_reader(file)?) - } -} - static POLICY: &'static [u8] = &*b" From 0fcc9983637d4d655c75b9c13f309398ab2b5b83 Mon Sep 17 00:00:00 2001 From: sleepycatcoding <131554884+sleepycatcoding@users.noreply.github.com> Date: Fri, 21 Jul 2023 19:55:49 +0300 Subject: [PATCH 03/19] tests: Use socket.json when running tests --- Cargo.lock | 1 + tests/Cargo.toml | 1 + tests/socket-format/src/lib.rs | 16 ++++----- tests/tests/util/navigator.rs | 62 +++++++++++++++++++++++++++++++--- tests/tests/util/runner.rs | 5 ++- tests/tests/util/test.rs | 11 +++++- 6 files changed, 79 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 37562e8483ef..99cbad2b374d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4712,6 +4712,7 @@ dependencies = [ "ruffle_input_format", "ruffle_render", "ruffle_render_wgpu", + "ruffle_socket_format", "ruffle_video_software", "serde", "toml", diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 5936daa6e297..00598efa906d 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -13,6 +13,7 @@ ruffle_core = { path = "../core", features = ["deterministic", "timeline_debug", ruffle_render_wgpu = { path = "../render/wgpu" } ruffle_render = { path = "../render" } ruffle_input_format = { path = "input-format" } +ruffle_socket_format = { path = "socket-format" } ruffle_video_software = { path = "../video/software", optional = true } image = { version = "0.24.5", default-features = false, features = ["png"] } regex = "1.7.1" diff --git a/tests/socket-format/src/lib.rs b/tests/socket-format/src/lib.rs index 0cbdb3771610..736a3f9e2a19 100644 --- a/tests/socket-format/src/lib.rs +++ b/tests/socket-format/src/lib.rs @@ -1,19 +1,15 @@ -use std::{io, fs::File, path::Path}; +use std::{fs::File, io, path::Path}; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use serde_json::from_reader; -#[derive(Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] #[serde(tag = "type")] pub enum SocketEvent { /// Wait for input data that matches this. - Receive { - expected: Vec, - }, + Receive { expected: Vec }, /// Send data to client. - Send { - payload: Vec, - }, + Send { payload: Vec }, /// Expect client to disconnect. WaitForDisconnect, /// Disconnect the client. @@ -29,4 +25,4 @@ impl SocketEvent { Ok(from_reader(file)?) } -} \ No newline at end of file +} diff --git a/tests/tests/util/navigator.rs b/tests/tests/util/navigator.rs index 36fc73ebaea8..fc9d24d09a2c 100644 --- a/tests/tests/util/navigator.rs +++ b/tests/tests/util/navigator.rs @@ -7,8 +7,9 @@ use ruffle_core::backend::navigator::{ use ruffle_core::indexmap::IndexMap; use ruffle_core::loader::Error; use ruffle_core::socket::{ConnectionState, SocketAction, SocketHandle}; +use ruffle_socket_format::SocketEvent; use std::path::{Path, PathBuf}; -use std::sync::mpsc::{Receiver, Sender}; +use std::sync::mpsc::{Receiver, Sender, TryRecvError, RecvError}; use std::time::Duration; use url::{ParseError, Url}; @@ -18,6 +19,7 @@ use url::{ParseError, Url}; pub struct TestNavigatorBackend { spawner: NullSpawner, relative_base_path: PathBuf, + socket_events: Option>, log: Option, } @@ -25,11 +27,13 @@ impl TestNavigatorBackend { pub fn new( path: &Path, executor: &NullExecutor, + socket_events: Option>, log: Option, ) -> Result { Ok(Self { spawner: executor.spawner(), relative_base_path: path.canonicalize()?, + socket_events, log, }) } @@ -104,15 +108,63 @@ impl NavigatorBackend for TestNavigatorBackend { port: u16, _timeout: Duration, handle: SocketHandle, - _receiver: Receiver>, + receiver: Receiver>, sender: Sender, ) { if let Some(log) = &self.log { log.avm_trace("Navigator::connect_socket"); log.avm_trace(&format!(" Host: {}; Port: {}", host, port)); } - sender - .send(SocketAction::Connect(handle, ConnectionState::Failed)) - .expect("working channel send"); + + if let Some(events) = self.socket_events.clone() { + std::thread::spawn(move || { + sender + .send(SocketAction::Connect(handle, ConnectionState::Connected)) + .expect("working channel send"); + + for event in events { + match event { + SocketEvent::Disconnect => { + sender + .send(SocketAction::Close(handle)) + .expect("working channel send"); + + return; + }, + SocketEvent::WaitForDisconnect => { + loop { + match receiver.recv() { + Err(_) => return, + Ok(_) => panic!("Expected client to disconnect, data was sent instead"), + } + + //NOTE: We need to yield to executor. + //Timer::after(Duration::from_millis(30)).await; + } + }, + SocketEvent::Receive { expected } => { + loop { + match receiver.recv() { + Ok(val) => { + if expected != val { + panic!("Received data did not match expected data\nExpected: {:?}\nActual: {:?}", expected, val); + } + + break; + } + Err(_) => panic!("Expected client to send data, but connection was closed instead"), + } + + //NOTE: We need to yield to executor. + //Timer::after(Duration::from_millis(30)).await; + } + }, + SocketEvent::Send { payload } => { + sender.send(SocketAction::Data(handle, payload)).expect("working channel send"); + } + } + } + }); + } } } diff --git a/tests/tests/util/runner.rs b/tests/tests/util/runner.rs index c41226394e98..ed9340532872 100644 --- a/tests/tests/util/runner.rs +++ b/tests/tests/util/runner.rs @@ -17,6 +17,7 @@ use ruffle_input_format::{ AutomatedEvent, InputInjector, MouseButton as InputMouseButton, TextControlCode as InputTextControlCode, }; +use ruffle_socket_format::SocketEvent; use std::cell::RefCell; use std::path::Path; use std::rc::Rc; @@ -81,10 +82,11 @@ impl LogBackend for TestLogBackend { } /// Loads an SWF and runs it through the Ruffle core for a number of frames. -/// Tests that the trace output matches the given expected output. +/// Tests that the trace output matches the given expectedrun_swf output. pub fn run_swf( test: &Test, mut injector: InputInjector, + socket_events: Option>, before_start: impl FnOnce(Arc>) -> Result<()>, before_end: impl FnOnce(Arc>) -> Result<()>, ) -> Result { @@ -102,6 +104,7 @@ pub fn run_swf( let navigator = TestNavigatorBackend::new( base_path, &executor, + socket_events, test.options.log_fetch.then(|| log.clone()), )?; diff --git a/tests/tests/util/test.rs b/tests/tests/util/test.rs index 0a22be1e6a0d..b4b125891269 100644 --- a/tests/tests/util/test.rs +++ b/tests/tests/util/test.rs @@ -5,6 +5,7 @@ use crate::util::runner::run_swf; use anyhow::{Context, Result}; use ruffle_core::Player; use ruffle_input_format::InputInjector; +use ruffle_socket_format::SocketEvent; use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex}; @@ -12,6 +13,7 @@ pub struct Test { pub options: TestOptions, pub swf_path: PathBuf, pub input_path: PathBuf, + pub socket_path: PathBuf, pub output_path: PathBuf, pub name: String, } @@ -20,11 +22,13 @@ impl Test { pub fn from_options(options: TestOptions, test_dir: &Path, name: String) -> Result { let swf_path = test_dir.join("test.swf"); let input_path = test_dir.join("input.json"); + let socket_path = test_dir.join("socket.json"); let output_path = options.output_path(test_dir); Ok(Self { options, swf_path, input_path, + socket_path, output_path, name, }) @@ -51,7 +55,12 @@ impl Test { } else { InputInjector::empty() }; - let output = run_swf(&self, injector, before_start, before_end)?; + let socket_events = if self.socket_path.is_file() { + Some(SocketEvent::from_file(&self.socket_path)?) + } else { + None + }; + let output = run_swf(&self, injector, socket_events, before_start, before_end)?; self.compare_output(&output)?; Ok(()) } From a31c6ffe50141f5ab1015430ff186589cc1b5ffe Mon Sep 17 00:00:00 2001 From: sleepycatcoding <131554884+sleepycatcoding@users.noreply.github.com> Date: Sun, 23 Jul 2023 13:14:16 +0300 Subject: [PATCH 04/19] core: Run async tasks until stalled Previously it used run which tries to run until completion, but we can't do that if we are testing socket behavior. --- core/src/backend/navigator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/backend/navigator.rs b/core/src/backend/navigator.rs index 468803ccc787..60d1304e69a8 100644 --- a/core/src/backend/navigator.rs +++ b/core/src/backend/navigator.rs @@ -289,7 +289,7 @@ impl NullExecutor { } pub fn run(&mut self) { - self.0.run(); + self.0.run_until_stalled(); } } From 5f1a42dfc3f29238b544b3a0a8aa93e6750cb994 Mon Sep 17 00:00:00 2001 From: sleepycatcoding <131554884+sleepycatcoding@users.noreply.github.com> Date: Sun, 23 Jul 2023 13:46:00 +0300 Subject: [PATCH 05/19] core: Send data directly to socket task This improves socket latency. Sometimes the ping is better in Ruffle than in Flash Player! --- core/src/socket.rs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/core/src/socket.rs b/core/src/socket.rs index 29de2d7a29c2..459c5aba152f 100644 --- a/core/src/socket.rs +++ b/core/src/socket.rs @@ -7,7 +7,6 @@ use gc_arena::Collect; use generational_arena::{Arena, Index}; use std::{ cell::RefCell, - collections::VecDeque, sync::mpsc::{channel, Receiver, Sender}, time::Duration, }; @@ -19,7 +18,6 @@ pub type SocketHandle = Index; struct Socket<'gc> { target: SocketObject<'gc>, sender: RefCell>>, - send_buffer: VecDeque>, } impl<'gc> Socket<'gc> { @@ -27,7 +25,6 @@ impl<'gc> Socket<'gc> { Self { target, sender: RefCell::new(sender), - send_buffer: Default::default(), } } } @@ -107,8 +104,8 @@ impl<'gc> Sockets<'gc> { } pub fn send(&mut self, handle: SocketHandle, data: Vec) { - if let Some(Socket { send_buffer, .. }) = self.sockets.get_mut(handle) { - send_buffer.push_back(data); + if let Some(Socket { sender, .. }) = self.sockets.get_mut(handle) { + let _ = sender.borrow().send(data); } } @@ -210,17 +207,5 @@ impl<'gc> Sockets<'gc> { } } } - - for (_handle, socket) in context.sockets.sockets.iter_mut() { - let Socket { - sender, - send_buffer, - .. - } = socket; - - if let Some(to_send) = send_buffer.pop_front() { - let _ = sender.borrow().send(to_send); - } - } } } From 0d9b3b4e28b078aaeb2751d6d1056007579042a7 Mon Sep 17 00:00:00 2001 From: sleepycatcoding <131554884+sleepycatcoding@users.noreply.github.com> Date: Sun, 23 Jul 2023 16:32:14 +0300 Subject: [PATCH 06/19] tests: Improve socket testing backend --- Cargo.lock | 1 + tests/Cargo.toml | 1 + tests/tests/util/navigator.rs | 31 +++++++++++++++++-------------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 99cbad2b374d..45f34f0df545 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4702,6 +4702,7 @@ version = "0.1.0" dependencies = [ "anyhow", "approx", + "async-io", "env_logger", "futures", "image", diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 00598efa906d..ccd0dc725934 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -36,6 +36,7 @@ toml = "0.7.4" libtest-mimic = "0.6.0" walkdir = "2.3.2" anyhow = "1.0" +async-io = "1.13.0" [[test]] name = "tests" diff --git a/tests/tests/util/navigator.rs b/tests/tests/util/navigator.rs index fc9d24d09a2c..74a8fba00312 100644 --- a/tests/tests/util/navigator.rs +++ b/tests/tests/util/navigator.rs @@ -1,4 +1,5 @@ use crate::util::runner::TestLogBackend; +use async_io::Timer; use ruffle_core::backend::log::LogBackend; use ruffle_core::backend::navigator::{ fetch_path, resolve_url_with_relative_base_path, ErrorResponse, NavigationMethod, @@ -9,7 +10,7 @@ use ruffle_core::loader::Error; use ruffle_core::socket::{ConnectionState, SocketAction, SocketHandle}; use ruffle_socket_format::SocketEvent; use std::path::{Path, PathBuf}; -use std::sync::mpsc::{Receiver, Sender, TryRecvError, RecvError}; +use std::sync::mpsc::{Receiver, Sender, TryRecvError}; use std::time::Duration; use url::{ParseError, Url}; @@ -117,7 +118,7 @@ impl NavigatorBackend for TestNavigatorBackend { } if let Some(events) = self.socket_events.clone() { - std::thread::spawn(move || { + self.spawn_future(Box::pin(async move { sender .send(SocketAction::Connect(handle, ConnectionState::Connected)) .expect("working channel send"); @@ -128,23 +129,22 @@ impl NavigatorBackend for TestNavigatorBackend { sender .send(SocketAction::Close(handle)) .expect("working channel send"); - - return; }, SocketEvent::WaitForDisconnect => { loop { - match receiver.recv() { - Err(_) => return, + match receiver.try_recv() { + Err(TryRecvError::Empty) => { + //NOTE: We need to yield to executor. + Timer::after(Duration::from_millis(30)).await; + } + Err(_) => break, Ok(_) => panic!("Expected client to disconnect, data was sent instead"), } - - //NOTE: We need to yield to executor. - //Timer::after(Duration::from_millis(30)).await; } }, SocketEvent::Receive { expected } => { loop { - match receiver.recv() { + match receiver.try_recv() { Ok(val) => { if expected != val { panic!("Received data did not match expected data\nExpected: {:?}\nActual: {:?}", expected, val); @@ -152,11 +152,12 @@ impl NavigatorBackend for TestNavigatorBackend { break; } + Err(TryRecvError::Empty) => { + //NOTE: We need to yield to executor. + Timer::after(Duration::from_millis(30)).await; + } Err(_) => panic!("Expected client to send data, but connection was closed instead"), } - - //NOTE: We need to yield to executor. - //Timer::after(Duration::from_millis(30)).await; } }, SocketEvent::Send { payload } => { @@ -164,7 +165,9 @@ impl NavigatorBackend for TestNavigatorBackend { } } } - }); + + Ok(()) + })); } } } From 725c9fc3a26d2fd57cf959ef3d7ad585960dcf30 Mon Sep 17 00:00:00 2001 From: sleepycatcoding <131554884+sleepycatcoding@users.noreply.github.com> Date: Sun, 23 Jul 2023 16:33:35 +0300 Subject: [PATCH 07/19] chore: fmt --- tests/socket-mock/src/main.rs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/tests/socket-mock/src/main.rs b/tests/socket-mock/src/main.rs index 1461921b43c1..dec2c082b5d2 100644 --- a/tests/socket-mock/src/main.rs +++ b/tests/socket-mock/src/main.rs @@ -1,5 +1,8 @@ -use std::{net::TcpListener, io::{Read, Write}}; use ruffle_socket_format::SocketEvent; +use std::{ + io::{Read, Write}, + net::TcpListener, +}; use tracing_subscriber::filter::{EnvFilter, LevelFilter}; static POLICY: &'static [u8] = &*b" @@ -8,10 +11,13 @@ static POLICY: &'static [u8] = &*b" \0"; - fn main() { let subscriber = tracing_subscriber::fmt::Subscriber::builder() - .with_env_filter(EnvFilter::builder().with_default_directive(LevelFilter::INFO.into()).from_env_lossy()) + .with_env_filter( + EnvFilter::builder() + .with_default_directive(LevelFilter::INFO.into()) + .from_env_lossy(), + ) .finish(); // Ignore error if it's already been set let _ = tracing::subscriber::set_global_default(subscriber); @@ -62,9 +68,13 @@ fn main() { } if output != expected { - tracing::error!("Received data did not match expected data\nExpected: {:?}\nActual: {:?}", expected, output); + tracing::error!( + "Received data did not match expected data\nExpected: {:?}\nActual: {:?}", + expected, + output + ); } - }, + } SocketEvent::Send { mut payload } => { while !payload.is_empty() { match stream.write(&payload) { @@ -77,7 +87,7 @@ fn main() { } } } - }, + } SocketEvent::WaitForDisconnect => { let mut buffer = [0; 4096]; @@ -87,10 +97,12 @@ fn main() { return; } Ok(_) => { - tracing::error!("Expected client to close connection, but data was sent instead."); + tracing::error!( + "Expected client to close connection, but data was sent instead." + ); } } - }, + } SocketEvent::Disconnect => { tracing::info!("Disconnecting client."); drop(stream); From d6db10401e4386595da0240a2acc56b04c528d56 Mon Sep 17 00:00:00 2001 From: sleepycatcoding <131554884+sleepycatcoding@users.noreply.github.com> Date: Sun, 23 Jul 2023 16:44:27 +0300 Subject: [PATCH 08/19] chore: Fix clippy warning --- tests/socket-mock/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/socket-mock/src/main.rs b/tests/socket-mock/src/main.rs index dec2c082b5d2..17d9193ac814 100644 --- a/tests/socket-mock/src/main.rs +++ b/tests/socket-mock/src/main.rs @@ -5,7 +5,7 @@ use std::{ }; use tracing_subscriber::filter::{EnvFilter, LevelFilter}; -static POLICY: &'static [u8] = &*b" +static POLICY: &[u8] = b" From 5f3600e1584b3326f18e703aabc38e8b0afbd632 Mon Sep 17 00:00:00 2001 From: sleepycatcoding <131554884+sleepycatcoding@users.noreply.github.com> Date: Sun, 23 Jul 2023 18:57:01 +0300 Subject: [PATCH 09/19] tests: Rename socket-mock utility to mocket --- Cargo.lock | 18 +++++++++--------- Cargo.toml | 2 +- tests/{socket-mock => mocket}/Cargo.toml | 2 +- tests/{socket-mock => mocket}/src/main.rs | 0 4 files changed, 11 insertions(+), 11 deletions(-) rename tests/{socket-mock => mocket}/Cargo.toml (91%) rename tests/{socket-mock => mocket}/src/main.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 45f34f0df545..014c9c89d283 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2845,6 +2845,15 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "mocket" +version = "0.1.0" +dependencies = [ + "ruffle_socket_format", + "tracing", + "tracing-subscriber", +] + [[package]] name = "naga" version = "0.12.3" @@ -4055,15 +4064,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "ruffle_socket_mock" -version = "0.1.0" -dependencies = [ - "ruffle_socket_format", - "tracing", - "tracing-subscriber", -] - [[package]] name = "ruffle_video" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index e81aafce50ab..d1423f2bb050 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ members = [ "tests", "tests/input-format", "tests/socket-format", - "tests/socket-mock", + "tests/mocket", ] default-members = ["desktop"] resolver = "2" diff --git a/tests/socket-mock/Cargo.toml b/tests/mocket/Cargo.toml similarity index 91% rename from tests/socket-mock/Cargo.toml rename to tests/mocket/Cargo.toml index 2bce02ff47ef..e5f7ca296f21 100644 --- a/tests/socket-mock/Cargo.toml +++ b/tests/mocket/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "ruffle_socket_mock" +name = "mocket" authors.workspace = true edition.workspace = true homepage.workspace = true diff --git a/tests/socket-mock/src/main.rs b/tests/mocket/src/main.rs similarity index 100% rename from tests/socket-mock/src/main.rs rename to tests/mocket/src/main.rs From 0ba2804c15c4fc1d0a4374e9e341d645c0d28059 Mon Sep 17 00:00:00 2001 From: sleepycatcoding <131554884+sleepycatcoding@users.noreply.github.com> Date: Sun, 23 Jul 2023 19:12:00 +0300 Subject: [PATCH 10/19] tests: Allow passing path to mocket utility Also use anyhow to remove some unwraps. --- Cargo.lock | 2 ++ tests/mocket/Cargo.toml | 2 ++ tests/mocket/src/main.rs | 34 ++++++++++++++++++++++++---------- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 014c9c89d283..5a3c2fbd87bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2849,6 +2849,8 @@ dependencies = [ name = "mocket" version = "0.1.0" dependencies = [ + "anyhow", + "clap", "ruffle_socket_format", "tracing", "tracing-subscriber", diff --git a/tests/mocket/Cargo.toml b/tests/mocket/Cargo.toml index e5f7ca296f21..b7c232aa8570 100644 --- a/tests/mocket/Cargo.toml +++ b/tests/mocket/Cargo.toml @@ -8,6 +8,8 @@ repository.workspace = true version.workspace = true [dependencies] +anyhow = "1.0" +clap = { version = "4.3.12", features = ["derive"] } tracing = { workspace = true} tracing-subscriber = { workspace = true } ruffle_socket_format = { path = "../socket-format" } \ No newline at end of file diff --git a/tests/mocket/src/main.rs b/tests/mocket/src/main.rs index 17d9193ac814..d09d53263872 100644 --- a/tests/mocket/src/main.rs +++ b/tests/mocket/src/main.rs @@ -1,7 +1,10 @@ +use anyhow::Error; +use clap::Parser; use ruffle_socket_format::SocketEvent; use std::{ io::{Read, Write}, net::TcpListener, + path::PathBuf, }; use tracing_subscriber::filter::{EnvFilter, LevelFilter}; @@ -11,7 +14,16 @@ static POLICY: &[u8] = b" \0"; -fn main() { +#[derive(Parser, Debug)] +struct Opt { + /// Path to a `socket.json` file. + #[clap(name = "FILE")] + file_path: PathBuf, +} + +fn main() -> Result<(), Error> { + let opt = Opt::parse(); + let subscriber = tracing_subscriber::fmt::Subscriber::builder() .with_env_filter( EnvFilter::builder() @@ -22,22 +34,22 @@ fn main() { // Ignore error if it's already been set let _ = tracing::subscriber::set_global_default(subscriber); - let events = SocketEvent::from_file("socket.json").unwrap(); + let events = SocketEvent::from_file(opt.file_path)?; let event_count = events.len(); - let listener = TcpListener::bind("0.0.0.0:8001").unwrap(); - tracing::info!("Listening on {}", listener.local_addr().unwrap()); - let (mut stream, addr) = listener.accept().unwrap(); + let listener = TcpListener::bind("0.0.0.0:8001")?; + tracing::info!("Listening on {}", listener.local_addr()?); + let (mut stream, addr) = listener.accept()?; tracing::info!("Incoming connection from {}", addr); // Handle socket policy stuff. (Required as Flash Player wont want to connect otherwise.) let mut buffer = [0; 4096]; let _ = stream.read(&mut buffer); - stream.write_all(POLICY).unwrap(); + stream.write_all(POLICY)?; tracing::info!("Policy sent successfully!"); // Now we listen again as flash reopens socket connection. - let (mut stream, addr) = listener.accept().unwrap(); + let (mut stream, addr) = listener.accept()?; tracing::info!("Incoming connection from {}", addr); for (index, event) in events.into_iter().enumerate() { @@ -53,7 +65,7 @@ fn main() { match stream.read(&mut buffer) { Err(_) | Ok(0) => { tracing::error!("Expected data, but socket was closed."); - return; + return Ok(()); } Ok(read) => { if read == 4096 { @@ -80,7 +92,7 @@ fn main() { match stream.write(&payload) { Err(_) | Ok(0) => { tracing::error!("Socket was closed in middle of writing."); - return; + return Ok(()); } Ok(written) => { let _ = payload.drain(..written); @@ -94,7 +106,7 @@ fn main() { match stream.read(&mut buffer) { Err(_) | Ok(0) => { tracing::info!("Client has closed the connection!"); - return; + return Ok(()); } Ok(_) => { tracing::error!( @@ -110,4 +122,6 @@ fn main() { } } } + + Ok(()) } From 38f44ce4d7105776416fdb3f4d4f511e887d4cca Mon Sep 17 00:00:00 2001 From: sleepycatcoding <131554884+sleepycatcoding@users.noreply.github.com> Date: Sun, 23 Jul 2023 19:15:30 +0300 Subject: [PATCH 11/19] chore: Remove accidental doc change For some reason my IDE keeps adding random stuff :( --- tests/tests/util/runner.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests/util/runner.rs b/tests/tests/util/runner.rs index ed9340532872..9df68241f56c 100644 --- a/tests/tests/util/runner.rs +++ b/tests/tests/util/runner.rs @@ -82,7 +82,7 @@ impl LogBackend for TestLogBackend { } /// Loads an SWF and runs it through the Ruffle core for a number of frames. -/// Tests that the trace output matches the given expectedrun_swf output. +/// Tests that the trace output matches the given expected output. pub fn run_swf( test: &Test, mut injector: InputInjector, From f98ae905ecc4387b69063eadb4b88387fcf8ea27 Mon Sep 17 00:00:00 2001 From: sleepycatcoding <131554884+sleepycatcoding@users.noreply.github.com> Date: Sun, 23 Jul 2023 20:44:15 +0300 Subject: [PATCH 12/19] tests: Add socket_connect test --- tests/tests/swfs/avm2/socket_connect/Test.as | 24 ++++++++++++++++++ .../tests/swfs/avm2/socket_connect/output.txt | 1 + .../swfs/avm2/socket_connect/socket.json | 18 +++++++++++++ tests/tests/swfs/avm2/socket_connect/test.swf | Bin 0 -> 910 bytes .../tests/swfs/avm2/socket_connect/test.toml | 1 + 5 files changed, 44 insertions(+) create mode 100644 tests/tests/swfs/avm2/socket_connect/Test.as create mode 100644 tests/tests/swfs/avm2/socket_connect/output.txt create mode 100644 tests/tests/swfs/avm2/socket_connect/socket.json create mode 100644 tests/tests/swfs/avm2/socket_connect/test.swf create mode 100644 tests/tests/swfs/avm2/socket_connect/test.toml diff --git a/tests/tests/swfs/avm2/socket_connect/Test.as b/tests/tests/swfs/avm2/socket_connect/Test.as new file mode 100644 index 000000000000..38ba07fe78b8 --- /dev/null +++ b/tests/tests/swfs/avm2/socket_connect/Test.as @@ -0,0 +1,24 @@ +package +{ + import flash.display.Sprite; + + public class Test extends Sprite + { + } +} + +import flash.events.Event; +import flash.net.Socket; + +var socket:Socket = new Socket(); + +socket.addEventListener(Event.CONNECT, function(event:Event):void +{ + trace("connected"); + socket.writeUTF("Hello!"); + socket.flush(); + socket.close(); +}); + +socket.connect("localhost", 8001); + diff --git a/tests/tests/swfs/avm2/socket_connect/output.txt b/tests/tests/swfs/avm2/socket_connect/output.txt new file mode 100644 index 000000000000..da707dffac31 --- /dev/null +++ b/tests/tests/swfs/avm2/socket_connect/output.txt @@ -0,0 +1 @@ +connected diff --git a/tests/tests/swfs/avm2/socket_connect/socket.json b/tests/tests/swfs/avm2/socket_connect/socket.json new file mode 100644 index 000000000000..032cef223303 --- /dev/null +++ b/tests/tests/swfs/avm2/socket_connect/socket.json @@ -0,0 +1,18 @@ +[ + { + "type": "Receive", + "expected": [ + 0, + 6, + 72, + 101, + 108, + 108, + 111, + 33 + ] + }, + { + "type": "WaitForDisconnect" + } +] \ No newline at end of file diff --git a/tests/tests/swfs/avm2/socket_connect/test.swf b/tests/tests/swfs/avm2/socket_connect/test.swf new file mode 100644 index 0000000000000000000000000000000000000000..c269b7175e619ea7b4cdb75cf1e089457133ff3e GIT binary patch literal 910 zcmV;919ALAS5qb$1poke0fkb{ZX-ny?w-H)IPqVcbrN8~*#%h)JHfzk< zjW8Y=&Hep-!)zI?Rvi%axmm$moqwLb;qZPduZGO1&4dw zXPx7SS}v>hd^WEh-_ld?3L&ueZJwR$Dji@nXv$9WN*S-?1TUIg_+H|&_*I;K=@?GqcncIXD`u33|4VuW6BM5YqX`|c4hx3Q`>E#5Rayb%tkY^YsxKxJ->bIF zR(qAPxIZ++l^5A2jz>Cozt`W=g0m27iZ79Xi!^;K2| zmj+8IUjEjGK|yGD`O|mbgY|3noFyFny!oSqknp6(B5DZGJ(W$Nr!~V3$IO^A?=mzv zz`bBJOxrh1T#r9|C^!w8s63_?L%J0P0kb%>wI|H?!`;j*_BeZf-cucalDMknhY3@r zp=YnBDvdNsqCOVE6d|UI%@A8|g|NLO^65*h9|)ac|02Hl&uObDElasU4)5j<0MQYn=h|j!)GeGKoXi?t{ z6Hcyc+!_u?;gE+zn>k+Ki6I}l%#Y+KOr(#S>Epu7yx-c_k~E6k{HUF&D3vueS1D}g zDqHG%s7$a-Fd;ZYuugE6Nb3aWh*BiDM5GO(l!>xQlsiPL5WG$B4#95|QdO|3Dc?ZP z6lhf*mV%^r@ZEP|?P8MARU|=2u`H1;{Lsdclt&l?NW!@J55}nQue2-;@B_7n@!oR7 z_N50}PXe;DnkR^ z(ak~D$(n;TXU!a}JL~2k=j6;m#>u4Hm*{T#xda%wLH^S`vOgS4%K}6kXpZI-j!>^C k?SXeoB=*(^zjS&f>Dxbkf0BWc_43WE9zo^*0pmJ!FfQf48UO$Q literal 0 HcmV?d00001 diff --git a/tests/tests/swfs/avm2/socket_connect/test.toml b/tests/tests/swfs/avm2/socket_connect/test.toml new file mode 100644 index 000000000000..0d5c2c67fa6d --- /dev/null +++ b/tests/tests/swfs/avm2/socket_connect/test.toml @@ -0,0 +1 @@ +num_ticks = 10 From ac66864168af337f19a307978f74ad0c89aecc51 Mon Sep 17 00:00:00 2001 From: sleepycatcoding <131554884+sleepycatcoding@users.noreply.github.com> Date: Sun, 23 Jul 2023 21:05:10 +0300 Subject: [PATCH 13/19] tests: Add test for socket write (Big Endian) --- .../tests/swfs/avm2/socket_write_big/Test.as | 78 ++++++++++++++++++ .../swfs/avm2/socket_write_big/output.txt | 16 ++++ .../swfs/avm2/socket_write_big/socket.json | 9 ++ .../tests/swfs/avm2/socket_write_big/test.swf | Bin 0 -> 1473 bytes .../swfs/avm2/socket_write_big/test.toml | 1 + 5 files changed, 104 insertions(+) create mode 100644 tests/tests/swfs/avm2/socket_write_big/Test.as create mode 100644 tests/tests/swfs/avm2/socket_write_big/output.txt create mode 100644 tests/tests/swfs/avm2/socket_write_big/socket.json create mode 100644 tests/tests/swfs/avm2/socket_write_big/test.swf create mode 100644 tests/tests/swfs/avm2/socket_write_big/test.toml diff --git a/tests/tests/swfs/avm2/socket_write_big/Test.as b/tests/tests/swfs/avm2/socket_write_big/Test.as new file mode 100644 index 000000000000..4259d4537372 --- /dev/null +++ b/tests/tests/swfs/avm2/socket_write_big/Test.as @@ -0,0 +1,78 @@ +package +{ + import flash.display.Sprite; + + public class Test extends Sprite + { + } +} + +import flash.net.Socket; +import flash.net.ObjectEncoding; +import flash.events.Event; +import flash.utils.ByteArray; +import flash.utils.Endian; + +var socket:Socket = new Socket(); + +socket.endian = Endian.BIG_ENDIAN; + +socket.addEventListener(Event.CONNECT, function(evt:Event):void +{ + trace("connected"); + + trace("writeBoolean()"); + socket.writeBoolean(true); + + trace("writeByte()"); + socket.writeByte(67); + socket.writeByte(255); + + trace("writeBytes()"); + var byteArray:ByteArray = new ByteArray(); + byteArray.writeByte(10); + byteArray.writeByte(20); + byteArray.writeByte(65); + socket.writeBytes(byteArray, 0, 0); + + trace("writeDouble()"); + socket.writeDouble(8090.76); + + trace("writeFloat()"); + socket.writeFloat(76.6555); + + trace("writeInt()"); + socket.writeInt(-2376553554); + + trace("writeMultiByte()"); + socket.writeMultiByte("Hello!", "utf-8"); + + trace("writeObject() (AMF3)"); + socket.objectEncoding = ObjectEncoding.AMF3; + socket.writeObject(new Object()); + + trace("writeObject() (AMF0)"); + socket.objectEncoding = ObjectEncoding.AMF0; + socket.writeObject(new Object()); + + trace("writeShort()"); + socket.writeShort(65535); + + trace("writeUnsignedInt()"); + socket.writeUnsignedInt(4000565000); + + trace("writeUTF()"); + socket.writeUTF("Hello from Ruffle Socket!"); + + trace("writeUTFBytes()"); + socket.writeUTFBytes("Raw UTF is cool"); + + trace("flush()"); + socket.flush(); + + trace("close()"); + socket.close(); + +}); + +socket.connect("localhost", 8001); diff --git a/tests/tests/swfs/avm2/socket_write_big/output.txt b/tests/tests/swfs/avm2/socket_write_big/output.txt new file mode 100644 index 000000000000..6d8d3ea3cbe1 --- /dev/null +++ b/tests/tests/swfs/avm2/socket_write_big/output.txt @@ -0,0 +1,16 @@ +connected +writeBoolean() +writeByte() +writeBytes() +writeDouble() +writeFloat() +writeInt() +writeMultiByte() +writeObject() (AMF3) +writeObject() (AMF0) +writeShort() +writeUnsignedInt() +writeUTF() +writeUTFBytes() +flush() +close() diff --git a/tests/tests/swfs/avm2/socket_write_big/socket.json b/tests/tests/swfs/avm2/socket_write_big/socket.json new file mode 100644 index 000000000000..0ed238184344 --- /dev/null +++ b/tests/tests/swfs/avm2/socket_write_big/socket.json @@ -0,0 +1,9 @@ +[ + { + "type": "Receive", + "expected": [ 1, 67, 255, 10, 20, 65, 64, 191, 154, 194, 143, 92, 40, 246, 66, 153, 79, 158, 114, 88, 171, 174, 72, 101, 108, 108, 111, 33, 10, 11, 1, 1, 3, 0, 0, 9, 255, 255, 238, 115, 199, 8, 0, 25, 72, 101, 108, 108, 111, 32, 102, 114, 111, 109, 32, 82, 117, 102, 102, 108, 101, 32, 83, 111, 99, 107, 101, 116, 33, 82, 97, 119, 32, 85, 84, 70, 32, 105, 115, 32, 99, 111, 111, 108 ] + }, + { + "type": "WaitForDisconnect" + } +] diff --git a/tests/tests/swfs/avm2/socket_write_big/test.swf b/tests/tests/swfs/avm2/socket_write_big/test.swf new file mode 100644 index 0000000000000000000000000000000000000000..fa50d9222a207e48d443106b320408f07c82395a GIT binary patch literal 1473 zcmV;y1wQ&iS5qeB2mk2NgasgFBHA3PV-p=M% zB_u5E?t7p4zBlvcmk*KeH-tLBMraVDLQfPS^g-WCjLLUqS( zvc>7?v#eV6B5A$ZFnLO?DpQm0QHwe9Y-$z~Y1Mh%ZtSTnr`GGHQB~b^@?p}c+0~~9 z>OM{Crs~ud+OXDNuftNxztlFR|v;Q~fT;_(Ds`wlb#W*9dzB$y{-HdK*Cg0ANO7CoL70_`P zY=YN*h3-GZ1+*fZo}RuJ5}_#okFWdb4_VkK2z?&<{o_x-`aZNx9fqFuGiY~PxZ90V z2qHz~|0nVOXWxDCZ0W}@i{Jh&m6i}%`t;>DFP?+)#ox=<4Yf*9uxeWttum^09yAO_mu=gms+EvB zuDb1>1AQc<;DvoA0qOu=J|96l?=972hUtVZ#7>x-1sm2LvUnLi&jw#pKc7r`CR zT(f|-@nA5!x$&rJGQ;gKAq7^cY1-rdCexGmyc#ZA`?+{?=Lr;;kYb7aBPAO8qna^$Rw7L4cHQ=q3K=VZNj>@jBSQ;$SmYhSV9)-x>H2zb>6ik4=mR%m(c zVWqfHSj%q&C?{lPb7P~pvfZs}8t?Hf!(kKxgQi_o&6@2na<+>HDwSQk!t9Dhb;B~; z8?REMW?ih?j&M86Pa5p~cxEo(@F^8DnLELVKN5}%MP~ik$nC+bUqMp@`v`6$I7EaF zf;$QBCb*a2eu4*yc%9&3f=37*C3uYBae^lZo+LOy@J)h~1j_`ci7!KNmIUq)-(3>8 zM*?#sFi*t$L|7nrk>DJ`4+vf&c$u_4^x?>W|3f(YemK;(;PE421s96&tm46FkRSnW z1}qAL1^A%JC1Dg{>_a{ga9jfL0&E)sAsn zP&`h9DPSB7g^tt5YY3L?O(3Eu;5K%g2G>VXIjo1%%El*mS|Zi+`OZ*n9s1)Q*`yxc${M literal 0 HcmV?d00001 diff --git a/tests/tests/swfs/avm2/socket_write_big/test.toml b/tests/tests/swfs/avm2/socket_write_big/test.toml new file mode 100644 index 000000000000..0d5c2c67fa6d --- /dev/null +++ b/tests/tests/swfs/avm2/socket_write_big/test.toml @@ -0,0 +1 @@ +num_ticks = 10 From 645a578443deea97a424ceb331c8310ccdaaa2cd Mon Sep 17 00:00:00 2001 From: sleepycatcoding <131554884+sleepycatcoding@users.noreply.github.com> Date: Sun, 23 Jul 2023 21:10:06 +0300 Subject: [PATCH 14/19] tests: Add test for socket write (Little Endian) --- .../swfs/avm2/socket_write_little/Test.as | 78 ++++++++++++++++++ .../swfs/avm2/socket_write_little/output.txt | 16 ++++ .../swfs/avm2/socket_write_little/socket.json | 9 ++ .../swfs/avm2/socket_write_little/test.swf | Bin 0 -> 1475 bytes .../swfs/avm2/socket_write_little/test.toml | 1 + 5 files changed, 104 insertions(+) create mode 100644 tests/tests/swfs/avm2/socket_write_little/Test.as create mode 100644 tests/tests/swfs/avm2/socket_write_little/output.txt create mode 100644 tests/tests/swfs/avm2/socket_write_little/socket.json create mode 100644 tests/tests/swfs/avm2/socket_write_little/test.swf create mode 100644 tests/tests/swfs/avm2/socket_write_little/test.toml diff --git a/tests/tests/swfs/avm2/socket_write_little/Test.as b/tests/tests/swfs/avm2/socket_write_little/Test.as new file mode 100644 index 000000000000..4d0ee2e5a259 --- /dev/null +++ b/tests/tests/swfs/avm2/socket_write_little/Test.as @@ -0,0 +1,78 @@ +package +{ + import flash.display.Sprite; + + public class Test extends Sprite + { + } +} + +import flash.net.Socket; +import flash.net.ObjectEncoding; +import flash.events.Event; +import flash.utils.ByteArray; +import flash.utils.Endian; + +var socket:Socket = new Socket(); + +socket.endian = Endian.LITTLE_ENDIAN; + +socket.addEventListener(Event.CONNECT, function(evt:Event):void +{ + trace("connected"); + + trace("writeBoolean()"); + socket.writeBoolean(true); + + trace("writeByte()"); + socket.writeByte(67); + socket.writeByte(255); + + trace("writeBytes()"); + var byteArray:ByteArray = new ByteArray(); + byteArray.writeByte(10); + byteArray.writeByte(20); + byteArray.writeByte(65); + socket.writeBytes(byteArray, 0, 0); + + trace("writeDouble()"); + socket.writeDouble(8090.76); + + trace("writeFloat()"); + socket.writeFloat(76.6555); + + trace("writeInt()"); + socket.writeInt(-2376553554); + + trace("writeMultiByte()"); + socket.writeMultiByte("Hello!", "utf-8"); + + trace("writeObject() (AMF3)"); + socket.objectEncoding = ObjectEncoding.AMF3; + socket.writeObject(new Object()); + + trace("writeObject() (AMF0)"); + socket.objectEncoding = ObjectEncoding.AMF0; + socket.writeObject(new Object()); + + trace("writeShort()"); + socket.writeShort(65535); + + trace("writeUnsignedInt()"); + socket.writeUnsignedInt(4000565000); + + trace("writeUTF()"); + socket.writeUTF("Hello from Ruffle Socket!"); + + trace("writeUTFBytes()"); + socket.writeUTFBytes("Raw UTF is cool"); + + trace("flush()"); + socket.flush(); + + trace("close()"); + socket.close(); + +}); + +socket.connect("localhost", 8001); diff --git a/tests/tests/swfs/avm2/socket_write_little/output.txt b/tests/tests/swfs/avm2/socket_write_little/output.txt new file mode 100644 index 000000000000..6d8d3ea3cbe1 --- /dev/null +++ b/tests/tests/swfs/avm2/socket_write_little/output.txt @@ -0,0 +1,16 @@ +connected +writeBoolean() +writeByte() +writeBytes() +writeDouble() +writeFloat() +writeInt() +writeMultiByte() +writeObject() (AMF3) +writeObject() (AMF0) +writeShort() +writeUnsignedInt() +writeUTF() +writeUTFBytes() +flush() +close() diff --git a/tests/tests/swfs/avm2/socket_write_little/socket.json b/tests/tests/swfs/avm2/socket_write_little/socket.json new file mode 100644 index 000000000000..35ae352399af --- /dev/null +++ b/tests/tests/swfs/avm2/socket_write_little/socket.json @@ -0,0 +1,9 @@ +[ + { + "type": "Receive", + "expected": [ 1, 67, 255, 10, 20, 65, 246, 40, 92, 143, 194, 154, 191, 64, 158, 79, 153, 66, 174, 171, 88, 114, 72, 101, 108, 108, 111, 33, 10, 11, 1, 1, 3, 0, 0, 9, 255, 255, 8, 199, 115, 238, 25, 0, 72, 101, 108, 108, 111, 32, 102, 114, 111, 109, 32, 82, 117, 102, 102, 108, 101, 32, 83, 111, 99, 107, 101, 116, 33, 82, 97, 119, 32, 85, 84, 70, 32, 105, 115, 32, 99, 111, 111, 108 ] + }, + { + "type": "WaitForDisconnect" + } +] diff --git a/tests/tests/swfs/avm2/socket_write_little/test.swf b/tests/tests/swfs/avm2/socket_write_little/test.swf new file mode 100644 index 0000000000000000000000000000000000000000..9de87898203e2637d05881d0824dd238e021f989 GIT binary patch literal 1475 zcmV;!1w8sgS5qeE2mkD%)u>&yo9-)h(M9_gRNY3Y)J0XPqDbvNT~(2)xT@4GJ#&Xw zq)N3kGv|Ewch0@%zI=#$za!NB4MIa06?`=2CNzNUbhtR%2gra!S2!=vBo{Cmkm3npJ() zQVwWRGZeeFBwY&K7)N&unk&?mYK;oAK@Ww(WjGUi3RkOMjx%>wr3Mixg+;S*v52cW zH?H2?HFUd18|VF$EX`>t4d~EnnkpM93%nG%Vbumz9P59B&Sh?hp_qG3Wsl~lS$R@o zIWG{aKyhd;lT8Uvn@vL(GU-g#8?nomBzN+!EXEmu_06H~NHey%m3+5QD!sS0T|~z{ zunFG!6(fJ}OK62VJw5#(#6wd69$)0yk6G9#2z`0y%_pCN^+RZf+75a#(1Lcig}D)w zLJ-L#|38TjKmY!V7x|yQTK(>Cv6M$B|JmzrU%dq7tHYoFEUfYLzzOaiIkeDdC`U6= z&Dy8Z0o9*bk^`A_bFacyx? zuB&dR=Rh9`F?eC0Nr2jbADoY%ll7KrI=W$pF2r`2nMDiM9OlUtv$7>UP~w zjsm5+yH|RcvItCZ;I?RlT@#wUdFq8iDeN&vKcF6ozSX{B!L6s8v=Q*C3#^)|u9)GC zwVj=f)ynE-ajmc!pbV0gt4-h;=`0E6Z5Ijoo7{TKNPY^sw@D#xbf^QL=Bv>LiO?(-Gvm|hr z`0kOweG-@_fd#@Z5^jm$WrA}Aze8}I;0L7Rp$|s~{m2(x0U!A;8? zuwh_9#zug}S7aXGD40{HnAzhX=wt$+>|6Jt=f21yA0o$z`X$=wip7eoRR-8&ccfav~Pq6HA$V4_9fNi0Voav5Np z!5l!zC-(x(1Ds~C0C09j?gO|2P-L*^!kcnGKpEgHgAW1914wMI0ZK8n?xJgeHXg$5 zj&VnjKTd3$2$pOM2+wo4!#Pfa>!+w3*23xXb?th(Jgg0;%Ol!Ix;(0l zrpqxc#$NBEQTD41K}4iHwmyc`Tl-wQ4|*(*YvY=rOtc4FXHXl|Zsd_X$%!D{1T Date: Sun, 23 Jul 2023 21:33:15 +0300 Subject: [PATCH 15/19] tests: Write a signed short too --- .../tests/swfs/avm2/socket_write_big/Test.as | 1 + .../swfs/avm2/socket_write_big/socket.json | 2 +- .../tests/swfs/avm2/socket_write_big/test.swf | Bin 1473 -> 1488 bytes .../swfs/avm2/socket_write_little/Test.as | 1 + .../swfs/avm2/socket_write_little/socket.json | 2 +- .../swfs/avm2/socket_write_little/test.swf | Bin 1475 -> 1492 bytes 6 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/tests/swfs/avm2/socket_write_big/Test.as b/tests/tests/swfs/avm2/socket_write_big/Test.as index 4259d4537372..808b7e4f9383 100644 --- a/tests/tests/swfs/avm2/socket_write_big/Test.as +++ b/tests/tests/swfs/avm2/socket_write_big/Test.as @@ -57,6 +57,7 @@ socket.addEventListener(Event.CONNECT, function(evt:Event):void trace("writeShort()"); socket.writeShort(65535); + socket.writeShort(-30562); trace("writeUnsignedInt()"); socket.writeUnsignedInt(4000565000); diff --git a/tests/tests/swfs/avm2/socket_write_big/socket.json b/tests/tests/swfs/avm2/socket_write_big/socket.json index 0ed238184344..49fa409456c4 100644 --- a/tests/tests/swfs/avm2/socket_write_big/socket.json +++ b/tests/tests/swfs/avm2/socket_write_big/socket.json @@ -1,7 +1,7 @@ [ { "type": "Receive", - "expected": [ 1, 67, 255, 10, 20, 65, 64, 191, 154, 194, 143, 92, 40, 246, 66, 153, 79, 158, 114, 88, 171, 174, 72, 101, 108, 108, 111, 33, 10, 11, 1, 1, 3, 0, 0, 9, 255, 255, 238, 115, 199, 8, 0, 25, 72, 101, 108, 108, 111, 32, 102, 114, 111, 109, 32, 82, 117, 102, 102, 108, 101, 32, 83, 111, 99, 107, 101, 116, 33, 82, 97, 119, 32, 85, 84, 70, 32, 105, 115, 32, 99, 111, 111, 108 ] + "expected": [ 1, 67, 255, 10, 20, 65, 64, 191, 154, 194, 143, 92, 40, 246, 66, 153, 79, 158, 114, 88, 171, 174, 72, 101, 108, 108, 111, 33, 10, 11, 1, 1, 3, 0, 0, 9, 255, 255, 136, 158, 238, 115, 199, 8, 0, 25, 72, 101, 108, 108, 111, 32, 102, 114, 111, 109, 32, 82, 117, 102, 102, 108, 101, 32, 83, 111, 99, 107, 101, 116, 33, 82, 97, 119, 32, 85, 84, 70, 32, 105, 115, 32, 99, 111, 111, 108 ] }, { "type": "WaitForDisconnect" diff --git a/tests/tests/swfs/avm2/socket_write_big/test.swf b/tests/tests/swfs/avm2/socket_write_big/test.swf index fa50d9222a207e48d443106b320408f07c82395a..b41cb90d3735116b9c27abb1c2c3546a756cd685 100644 GIT binary patch literal 1488 zcmV;>1uyzTS5qeQ2mkdU-$~;00a~uRI{}!e21)It_^jgoH{Zcppz_5?T-vkCdN} zdz*wrB-_8==X`&^bAIQR0~GiTp^k45>c^Y%w|y*4t5RGnE~(K zM9p>UGm^Bwzn|XEr7e3$nwp-TmNHo>n@xcta*#5e(TO}uP^3=P*6XfrnSz&4 z*|r+)y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asgFBHA3PV-p=M% zB_u5E?t7p4zBlvcmk*KeH-tLBMraVDLQfPS^g-WCjLLUqS( zvc>7?v#eV6B5A$ZFnLO?DpQm0QHwe9Y-$z~Y1Mh%ZtSTnr`GGHQB~b^@?p}c+0~~9 z>OM{Crs~ud+OXDNuftNxztlFR|v;Q~fT;_(Ds`wlb#W*9dzB$y{-HdK*Cg0ANO7CoL70_`P zY=YN*h3-GZ1+*fZo}RuJ5}_#okFWdb4_VkK2z?&<{o_x-`aZNx9fqFuGiY~PxZ90V z2qHz~|0nVOXWxDCZ0W}@i{Jh&m6i}%`t;>DFP?+)#ox=<4Yf*9uxeWttum^09yAO_mu=gms+EvB zuDb1>1AQc<;DvoA0qOu=J|96l?=972hUtVZ#7>x-1sm2LvUnLi&jw#pKc7r`CR zT(f|-@nA5!x$&rJGQ;gKAq7^cY1-rdCexGmyc#ZA`?+{?=Lr;;kYb7aBPAO8qna^$Rw7L4cHQ=q3K=VZNj>@jBSQ;$SmYhSV9)-x>H2zb>6ik4=mR%m(c zVWqfHSj%q&C?{lPb7P~pvfZs}8t?Hf!(kKxgQi_o&6@2na<+>HDwSQk!t9Dhb;B~; z8?REMW?ih?j&M86Pa5p~cxEo(@F^8DnLELVKN5}%MP~ik$nC+bUqMp@`v`6$I7EaF zf;$QBCb*a2eu4*yc%9&3f=37*C3uYBae^lZo+LOy@J)h~1j_`ci7!KNmIUq)-(3>8 zM*?#sFi*t$L|7nrk>DJ`4+vf&c$u_4^x?>W|3f(YemK;(;PE421s96&tm46FkRSnW z1}qAL1^A%JC1Dg{>_a{ga9jfL0&E)sAsn zP&`h9DPSB7g^tt5YY3L?O(3Eu;5K%g2G>VXIjo1%%El*mS|Zi+`OZ*n9s1)Q*`yxc${M diff --git a/tests/tests/swfs/avm2/socket_write_little/Test.as b/tests/tests/swfs/avm2/socket_write_little/Test.as index 4d0ee2e5a259..27f8e6db5c84 100644 --- a/tests/tests/swfs/avm2/socket_write_little/Test.as +++ b/tests/tests/swfs/avm2/socket_write_little/Test.as @@ -57,6 +57,7 @@ socket.addEventListener(Event.CONNECT, function(evt:Event):void trace("writeShort()"); socket.writeShort(65535); + socket.writeShort(-30562); trace("writeUnsignedInt()"); socket.writeUnsignedInt(4000565000); diff --git a/tests/tests/swfs/avm2/socket_write_little/socket.json b/tests/tests/swfs/avm2/socket_write_little/socket.json index 35ae352399af..5ab72ee673db 100644 --- a/tests/tests/swfs/avm2/socket_write_little/socket.json +++ b/tests/tests/swfs/avm2/socket_write_little/socket.json @@ -1,7 +1,7 @@ [ { "type": "Receive", - "expected": [ 1, 67, 255, 10, 20, 65, 246, 40, 92, 143, 194, 154, 191, 64, 158, 79, 153, 66, 174, 171, 88, 114, 72, 101, 108, 108, 111, 33, 10, 11, 1, 1, 3, 0, 0, 9, 255, 255, 8, 199, 115, 238, 25, 0, 72, 101, 108, 108, 111, 32, 102, 114, 111, 109, 32, 82, 117, 102, 102, 108, 101, 32, 83, 111, 99, 107, 101, 116, 33, 82, 97, 119, 32, 85, 84, 70, 32, 105, 115, 32, 99, 111, 111, 108 ] + "expected": [ 1, 67, 255, 10, 20, 65, 246, 40, 92, 143, 194, 154, 191, 64, 158, 79, 153, 66, 174, 171, 88, 114, 72, 101, 108, 108, 111, 33, 10, 11, 1, 1, 3, 0, 0, 9, 255, 255, 158, 136, 8, 199, 115, 238, 25, 0, 72, 101, 108, 108, 111, 32, 102, 114, 111, 109, 32, 82, 117, 102, 102, 108, 101, 32, 83, 111, 99, 107, 101, 116, 33, 82, 97, 119, 32, 85, 84, 70, 32, 105, 115, 32, 99, 111, 111, 108 ] }, { "type": "WaitForDisconnect" diff --git a/tests/tests/swfs/avm2/socket_write_little/test.swf b/tests/tests/swfs/avm2/socket_write_little/test.swf index 9de87898203e2637d05881d0824dd238e021f989..9f27291e8467171e71100c12c17d262a5ac08412 100644 GIT binary patch literal 1492 zcmV;_1uObPS5qeT2mklOgM+^iAOEBO~u-DjW5uH{{0IJK&(O6{fUwTDW*^x8|*Ym`boRFx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i3RkOMjx%>wr3Mixg+;S*v52cW zH?H2?HFUd18|VF$EX`>t4d~EnnkpM93%nG%Vbumz9P59B&Sh?hp_qG3Wsl~lS$R@o zIWG{aKyhd;lT8Uvn@vL(GU-g#8?nomBzN+!EXEmu_06H~NHey%m3+5QD!sS0T|~z{ zunFG!6(fJ}OK62VJw5#(#6wd69$)0yk6G9#2z`0y%_pCN^+RZf+75a#(1Lcig}D)w zLJ-L#|38TjKmY!V7x|yQTK(>Cv6M$B|JmzrU%dq7tHYoFEUfYLzzOaiIkeDdC`U6= z&Dy8Z0o9*bk^`A_bFacyx? zuB&dR=Rh9`F?eC0Nr2jbADoY%ll7KrI=W$pF2r`2nMDiM9OlUtv$7>UP~w zjsm5+yH|RcvItCZ;I?RlT@#wUdFq8iDeN&vKcF6ozSX{B!L6s8v=Q*C3#^)|u9)GC zwVj=f)ynE-ajmc!pbV0gt4-h;=`0E6Z5Ijoo7{TKNPY^sw@D#xbf^QL=Bv>LiO?(-Gvm|hr z`0kOweG-@_fd#@Z5^jm$WrA}Aze8}I;0L7Rp$|s~{m2(x0U!A;8? zuwh_9#zug}S7aXGD40{HnAzhX=wt$+>|6Jt=f21yA0o$z`X$=wip7eoRR-8&ccfav~Pq6HA$V4_9fNi0Voav5Np z!5l!zC-(x(1Ds~C0C09j?gO|2P-L*^!kcnGKpEgHgAW1914wMI0ZK8n?xJgeHXg$5 zj&VnjKTd3$2$pOM2+wo4!#Pfa>!+w3*23xXb?th(Jgg0;%Ol!Ix;(0l zrpqxc#$NBEQTD41K}4iHwmyc`Tl-wQ4|*(*YvY=rOtc4FXHXl|Zsd_X$%!D{1T Date: Sun, 23 Jul 2023 22:04:07 +0300 Subject: [PATCH 16/19] tests: Fix some number ranges Also reduce float precision. --- .../tests/swfs/avm2/socket_write_big/Test.as | 4 ++-- .../swfs/avm2/socket_write_big/socket.json | 2 +- .../tests/swfs/avm2/socket_write_big/test.swf | Bin 1488 -> 1482 bytes .../swfs/avm2/socket_write_little/Test.as | 4 ++-- .../swfs/avm2/socket_write_little/socket.json | 2 +- .../swfs/avm2/socket_write_little/test.swf | Bin 1492 -> 1487 bytes 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/tests/swfs/avm2/socket_write_big/Test.as b/tests/tests/swfs/avm2/socket_write_big/Test.as index 808b7e4f9383..0d0ed58ade87 100644 --- a/tests/tests/swfs/avm2/socket_write_big/Test.as +++ b/tests/tests/swfs/avm2/socket_write_big/Test.as @@ -39,10 +39,10 @@ socket.addEventListener(Event.CONNECT, function(evt:Event):void socket.writeDouble(8090.76); trace("writeFloat()"); - socket.writeFloat(76.6555); + socket.writeFloat(76.65); trace("writeInt()"); - socket.writeInt(-2376553554); + socket.writeInt(-2076553554); trace("writeMultiByte()"); socket.writeMultiByte("Hello!", "utf-8"); diff --git a/tests/tests/swfs/avm2/socket_write_big/socket.json b/tests/tests/swfs/avm2/socket_write_big/socket.json index 49fa409456c4..1c71f37424b4 100644 --- a/tests/tests/swfs/avm2/socket_write_big/socket.json +++ b/tests/tests/swfs/avm2/socket_write_big/socket.json @@ -1,7 +1,7 @@ [ { "type": "Receive", - "expected": [ 1, 67, 255, 10, 20, 65, 64, 191, 154, 194, 143, 92, 40, 246, 66, 153, 79, 158, 114, 88, 171, 174, 72, 101, 108, 108, 111, 33, 10, 11, 1, 1, 3, 0, 0, 9, 255, 255, 136, 158, 238, 115, 199, 8, 0, 25, 72, 101, 108, 108, 111, 32, 102, 114, 111, 109, 32, 82, 117, 102, 102, 108, 101, 32, 83, 111, 99, 107, 101, 116, 33, 82, 97, 119, 32, 85, 84, 70, 32, 105, 115, 32, 99, 111, 111, 108 ] + "expected": [ 1, 67, 255, 10, 20, 65, 64, 191, 154, 194, 143, 92, 40, 246, 66, 153, 76, 205, 132, 58, 78, 174, 72, 101, 108, 108, 111, 33, 10, 11, 1, 1, 3, 0, 0, 9, 255, 255, 136, 158, 238, 115, 199, 8, 0, 25, 72, 101, 108, 108, 111, 32, 102, 114, 111, 109, 32, 82, 117, 102, 102, 108, 101, 32, 83, 111, 99, 107, 101, 116, 33, 82, 97, 119, 32, 85, 84, 70, 32, 105, 115, 32, 99, 111, 111, 108 ] }, { "type": "WaitForDisconnect" diff --git a/tests/tests/swfs/avm2/socket_write_big/test.swf b/tests/tests/swfs/avm2/socket_write_big/test.swf index b41cb90d3735116b9c27abb1c2c3546a756cd685..a6ebc59d09d39132d09a72212735a12fe428d09c 100644 GIT binary patch literal 1482 zcmV;*1vUCZS5qeN2mkX^HC>ml4jF5iMNftj$PX3qi&oy zn-6GG#i>9D%i4Hn<83#)mUkT|Co05+6XFOGNL)B_;$DHofeQ+e=p9agglaAv32$ff zRSAie*8ARX{_oAa`SKz1{fbc6R|pMaRP2c(gx>G_10%H1P_?=3qAVQl8>T%6-h-){ z7>JyU9+ms zTFL=UX@+9g7Nkp|8{_DXLGy*WQms)zHt3;HxD01vPvL6S%W>w5WyM}JpXyd$}lBGE}#Aievq6(7DVFF%)yJsqE1_H7id_ zEawGc6(|nPXLD)cX|rkQLN=4lc_ViDg5*yAmBlzCu)cZJ6>Y{hw^EM_rPAA5+eLKT z4V&P#rx^W>UqH*;>FMdaVIGQk4nI^3|RPAatbcZfkmO&LWDRy3U zJ3I&aNQ$8g`%D7V2E24Wf)3VOy6NbK9lj9T5oQ)GSa`_dW%N8Rk8D_qlN7xO=6L41 z2{g!p!HhEFQPXgAx5K0uSfhqvjrp67mb&lNaM9Y O;hp}?dlBnyw^oY>|0D`wSF zVQxa+Xie()+~zKesn1&jp4c0$Xa7gijOfN@ygEuXt8q~Wb9&h@o|v}2XHu2bOn&#a(h`6Rx-C>;1--cj zz}kssH0@ea^s_Ii8kP+c=VxEvfu*aR-W<>a_wMkoxF4UpO+xOEh50YX38Qk#eu7$5phju_U5Sv3Z<~e9Q}ZLB=%bSvISS3Zqi1;t1hr&s=8u^m)2J+ zE1Sjj!e)RnLYB8SH&>Q-qKc}r9^cY!heBY;u&RntvuuZ)?c#w-WzVWORz;&etuQyF0^<8SMQ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socket_read_big/output.txt | 54 +++++++++ .../swfs/avm2/socket_read_big/socket.json | 9 ++ .../tests/swfs/avm2/socket_read_big/test.swf | Bin 0 -> 1549 bytes .../tests/swfs/avm2/socket_read_big/test.toml | 1 + 5 files changed, 167 insertions(+) create mode 100644 tests/tests/swfs/avm2/socket_read_big/Test.as create mode 100644 tests/tests/swfs/avm2/socket_read_big/output.txt create mode 100644 tests/tests/swfs/avm2/socket_read_big/socket.json create mode 100644 tests/tests/swfs/avm2/socket_read_big/test.swf create mode 100644 tests/tests/swfs/avm2/socket_read_big/test.toml diff --git a/tests/tests/swfs/avm2/socket_read_big/Test.as b/tests/tests/swfs/avm2/socket_read_big/Test.as new file mode 100644 index 000000000000..2a747adb2bfc --- /dev/null +++ b/tests/tests/swfs/avm2/socket_read_big/Test.as @@ -0,0 +1,103 @@ +package +{ + import flash.display.Sprite; + + public class Test extends Sprite + { + } +} + +import flash.net.Socket; +import flash.net.ObjectEncoding; +import flash.events.Event; +import flash.events.ProgressEvent; +import flash.utils.ByteArray; +import flash.utils.Endian; + +var socket:Socket = new Socket(); + +socket.endian = Endian.BIG_ENDIAN; + +socket.addEventListener(Event.CONNECT, function(evt:Event):void { + trace("connected"); +}); + +socket.addEventListener(ProgressEvent.SOCKET_DATA, function(evt:ProgressEvent):void +{ + trace("data received"); + trace(evt); + trace("Bytes available:"); + trace(socket.bytesAvailable); + trace("--------") + + trace("readBoolean()"); + trace(socket.readBoolean()); + + trace(""); + trace("readByte()"); + trace(socket.readByte()); + + trace(""); + trace("readUnsignedByte()"); + trace(socket.readUnsignedByte()); + + trace(""); + trace("readBytes()"); + var byteArray:ByteArray = new ByteArray(); + socket.readBytes(byteArray, 0, 3); + trace(byteArray.readByte()); + trace(byteArray.readByte()); + trace(byteArray.readByte()); + + trace(""); + trace("readDouble()"); + trace(socket.readDouble()); + + trace(""); + trace("readFloat()"); + trace(socket.readFloat()); + + trace(""); + trace("readInt()"); + trace(socket.readInt()); + + trace(""); + trace("readMultiByte()"); + trace(socket.readMultiByte(6, "utf-8")); + + trace(""); + trace("readObject() (AMF3)"); + socket.objectEncoding = ObjectEncoding.AMF3; + trace(socket.readObject()); + + trace(""); + trace("readObject() (AMF0)"); + socket.objectEncoding = ObjectEncoding.AMF0; + trace(socket.readObject()); + + trace(""); + trace("readUnsignedShort()"); + trace(socket.readUnsignedShort()); + + trace(""); + trace("readShort()"); + trace(socket.readShort()); + + trace(""); + trace("readUnsignedInt()"); + trace(socket.readUnsignedInt()); + + trace(""); + trace("readUTF()"); + trace(socket.readUTF()); + + trace(""); + trace("readUTFBytes()"); + trace(socket.readUTFBytes(15)); + + trace(""); + trace("close()"); + socket.close(); +}); + +socket.connect("localhost", 8001); diff --git a/tests/tests/swfs/avm2/socket_read_big/output.txt b/tests/tests/swfs/avm2/socket_read_big/output.txt new file mode 100644 index 000000000000..d080ad7be46b --- /dev/null +++ b/tests/tests/swfs/avm2/socket_read_big/output.txt @@ -0,0 +1,54 @@ +connected +data received +[ProgressEvent type="socketData" bubbles=false cancelable=false eventPhase=2 bytesLoaded=86 bytesTotal=0] +Bytes available: +86 +-------- +readBoolean() +true + +readByte() +67 + +readUnsignedByte() +255 + +readBytes() +10 +20 +65 + +readDouble() +8090.76 + +readFloat() +76.6500015258789 + +readInt() +-2076553554 + +readMultiByte() +Hello! + +readObject() (AMF3) +[object Object] + +readObject() (AMF0) +[object Object] + +readUnsignedShort() +65535 + +readShort() +-30562 + +readUnsignedInt() +4000565000 + +readUTF() +Hello from Ruffle Socket! + +readUTFBytes() +Raw UTF is cool + +close() diff --git a/tests/tests/swfs/avm2/socket_read_big/socket.json b/tests/tests/swfs/avm2/socket_read_big/socket.json new file mode 100644 index 000000000000..cafba6337750 --- /dev/null +++ b/tests/tests/swfs/avm2/socket_read_big/socket.json @@ -0,0 +1,9 @@ +[ + { + "type": "Send", + "payload": [ 1, 67, 255, 10, 20, 65, 64, 191, 154, 194, 143, 92, 40, 246, 66, 153, 76, 205, 132, 58, 78, 174, 72, 101, 108, 108, 111, 33, 10, 11, 1, 1, 3, 0, 0, 9, 255, 255, 136, 158, 238, 115, 199, 8, 0, 25, 72, 101, 108, 108, 111, 32, 102, 114, 111, 109, 32, 82, 117, 102, 102, 108, 101, 32, 83, 111, 99, 107, 101, 116, 33, 82, 97, 119, 32, 85, 84, 70, 32, 105, 115, 32, 99, 111, 111, 108 ] + }, + { + "type": "WaitForDisconnect" + } +] diff --git a/tests/tests/swfs/avm2/socket_read_big/test.swf b/tests/tests/swfs/avm2/socket_read_big/test.swf new file mode 100644 index 0000000000000000000000000000000000000000..34bc545c179d9033c08643e9917f6e09b56049c0 GIT binary patch literal 1549 zcmV+o2J-nsS5qcK3IG6j0fm)YQ`<%q$9Lt+VlKvn#6Sqa5E5{LFPMY`LR<_+3AsQf zCQT-->k4ayl?cfr$v~dk>2#*kuhEBojZPo>&^MA!`vLmYX&*vAL3;MAtw8%w%}D;A zv%hn8&(UgqNW#Ap691l%VM@vaBZQDI2LGglEW5g~^rWn&4)-kETLSCObi?h^5)PEp3+ekn_HR3rAp=5){`W58m>MAGx z2rZK}<^B8jFS52oWP_CP-F5n<2jM z$97)(yyUvt>*-v>+2gr=ZoYDIK7^U}ZVg{!&1;zc?b{+Yt9cRM)#{w|K`XVC%j?|S z=Xzol(s(ItUo$Oj$Kp$Ik=HAA?5<4v>VrP(tBzxF&7Mj3oUpo4L)1*Vt0T_{@znOr zU7PD-ikWoc-!7R$%r=vb2?nd_!IfuQzG-=}PCBnwsImiF1Tx`-(!d<5re6QA;7S?y6Q2K6Zp%fqrdk>El0>9*P~ z98?^0Z>yqg=ri^a+-S18<#^D~2>yom9aHa>1@e7yX7oLFon4oE-nuYjb;q`$H(ZaP z9o~j*6%&t~c=X9g-SnE4_BvW=x~9*gvK##vP=+DRhZDr@6A~ynIsgmjur+)W+*X}c7&oVsQ;9M5O%f`)3fU8m+dHJux#ZHg1I*5Fn%)O0*$VGh4U_B7@c5rlF=zfuP{2pCna*uA@hx-vdKN@2sL=-~9 z%K0*dLnXbUOb|*VBpjmjyU06A$;dmZ(Cpu#PvqNM)h)alT65s_o2kCv@S2z8>Ve0qQK~TaYt$$r*12#3HC95=)YZ zNn$x5?tmIbq9}=ONvs4!3DkKcR*{&B&W@@*vV-M-S_d_TlnND9dyQVBPm3Sll}Y<$ z(v1MW59$))4?1`P@Q0`H%>ds5bs6!;k{FN)p9Dk&)HD*?k~kxYj|1Wvs5BDKB{3+8 z7Xk4JsB1`kDv7g__$(l5pfX5&j>J^IdXA#K6EJm9IrQmJnwli(V}2L@2^EFXvtp;7 zgH4(Q=sH3}Fa{%CvCvT-B<$x{clS~LXoCRO08coi(5`RjQ6B6FC)Eqag?x3)7|T~L z8W;1`abrARO&O_tb<`Ne$8$1 Date: Sun, 23 Jul 2023 22:06:08 +0300 Subject: [PATCH 18/19] tests: Add read socket test (Little Endian) --- .../swfs/avm2/socket_read_little/Test.as | 103 ++++++++++++++++++ .../swfs/avm2/socket_read_little/output.txt | 54 +++++++++ .../swfs/avm2/socket_read_little/socket.json | 9 ++ .../swfs/avm2/socket_read_little/test.swf | Bin 0 -> 1552 bytes .../swfs/avm2/socket_read_little/test.toml | 1 + 5 files changed, 167 insertions(+) create mode 100644 tests/tests/swfs/avm2/socket_read_little/Test.as create mode 100644 tests/tests/swfs/avm2/socket_read_little/output.txt create mode 100644 tests/tests/swfs/avm2/socket_read_little/socket.json create mode 100644 tests/tests/swfs/avm2/socket_read_little/test.swf create mode 100644 tests/tests/swfs/avm2/socket_read_little/test.toml diff --git a/tests/tests/swfs/avm2/socket_read_little/Test.as b/tests/tests/swfs/avm2/socket_read_little/Test.as new file mode 100644 index 000000000000..26fac45c7584 --- /dev/null +++ b/tests/tests/swfs/avm2/socket_read_little/Test.as @@ -0,0 +1,103 @@ +package +{ + import flash.display.Sprite; + + public class Test extends Sprite + { + } +} + +import flash.net.Socket; +import flash.net.ObjectEncoding; +import flash.events.Event; +import flash.events.ProgressEvent; +import flash.utils.ByteArray; +import flash.utils.Endian; + +var socket:Socket = new Socket(); + +socket.endian = Endian.LITTLE_ENDIAN; + +socket.addEventListener(Event.CONNECT, function(evt:Event):void { + trace("connected"); +}); + +socket.addEventListener(ProgressEvent.SOCKET_DATA, function(evt:ProgressEvent):void +{ + trace("data received"); + trace(evt); + trace("Bytes available:"); + trace(socket.bytesAvailable); + trace("--------") + + trace("readBoolean()"); + trace(socket.readBoolean()); + + trace(""); + trace("readByte()"); + trace(socket.readByte()); + + trace(""); + trace("readUnsignedByte()"); + trace(socket.readUnsignedByte()); + + trace(""); + trace("readBytes()"); + var byteArray:ByteArray = new ByteArray(); + socket.readBytes(byteArray, 0, 3); + trace(byteArray.readByte()); + trace(byteArray.readByte()); + trace(byteArray.readByte()); + + trace(""); + trace("readDouble()"); + trace(socket.readDouble()); + + trace(""); + trace("readFloat()"); + trace(socket.readFloat()); + + trace(""); + trace("readInt()"); + trace(socket.readInt()); + + trace(""); + trace("readMultiByte()"); + trace(socket.readMultiByte(6, "utf-8")); + + trace(""); + trace("readObject() (AMF3)"); + socket.objectEncoding = ObjectEncoding.AMF3; + trace(socket.readObject()); + + trace(""); + trace("readObject() (AMF0)"); + socket.objectEncoding = ObjectEncoding.AMF0; + trace(socket.readObject()); + + trace(""); + trace("readUnsignedShort()"); + trace(socket.readUnsignedShort()); + + trace(""); + trace("readShort()"); + trace(socket.readShort()); + + trace(""); + trace("readUnsignedInt()"); + trace(socket.readUnsignedInt()); + + trace(""); + trace("readUTF()"); + trace(socket.readUTF()); + + trace(""); + trace("readUTFBytes()"); + trace(socket.readUTFBytes(15)); + + trace(""); + trace("close()"); + socket.close(); +}); + +socket.connect("localhost", 8001); diff --git a/tests/tests/swfs/avm2/socket_read_little/output.txt b/tests/tests/swfs/avm2/socket_read_little/output.txt new file mode 100644 index 000000000000..d080ad7be46b --- /dev/null +++ b/tests/tests/swfs/avm2/socket_read_little/output.txt @@ -0,0 +1,54 @@ +connected +data received +[ProgressEvent type="socketData" bubbles=false cancelable=false eventPhase=2 bytesLoaded=86 bytesTotal=0] +Bytes available: +86 +-------- +readBoolean() +true + +readByte() +67 + +readUnsignedByte() +255 + +readBytes() +10 +20 +65 + +readDouble() +8090.76 + +readFloat() +76.6500015258789 + +readInt() +-2076553554 + +readMultiByte() +Hello! + +readObject() (AMF3) +[object Object] + +readObject() (AMF0) +[object Object] + +readUnsignedShort() +65535 + +readShort() +-30562 + +readUnsignedInt() +4000565000 + +readUTF() +Hello from Ruffle Socket! + +readUTFBytes() +Raw UTF is cool + +close() diff --git a/tests/tests/swfs/avm2/socket_read_little/socket.json b/tests/tests/swfs/avm2/socket_read_little/socket.json new file mode 100644 index 000000000000..461a49c1584e --- /dev/null +++ b/tests/tests/swfs/avm2/socket_read_little/socket.json @@ -0,0 +1,9 @@ +[ + { + "type": "Send", + "payload": [ 1, 67, 255, 10, 20, 65, 246, 40, 92, 143, 194, 154, 191, 64, 205, 76, 153, 66, 174, 78, 58, 132, 72, 101, 108, 108, 111, 33, 10, 11, 1, 1, 3, 0, 0, 9, 255, 255, 158, 136, 8, 199, 115, 238, 25, 0, 72, 101, 108, 108, 111, 32, 102, 114, 111, 109, 32, 82, 117, 102, 102, 108, 101, 32, 83, 111, 99, 107, 101, 116, 33, 82, 97, 119, 32, 85, 84, 70, 32, 105, 115, 32, 99, 111, 111, 108 ] + }, + { + "type": "WaitForDisconnect" + } +] diff --git a/tests/tests/swfs/avm2/socket_read_little/test.swf b/tests/tests/swfs/avm2/socket_read_little/test.swf new file mode 100644 index 0000000000000000000000000000000000000000..cd9c6e77e3d6819a3b68e07d472492cb8f9c9d88 GIT binary patch literal 1552 zcmV+r2JiVpS5qcN3IG6j0fm*_a??f>$9LtAjq~Xca1uhmfk0x2KjJ_jA-FNI1%Z$- z*c67=browB3lzyC$w|0sr_-5EU!xbDzD1`Oz35$FraVBeI=vx%0($nWEt2-4nvwiJ zXMgAHo}<*wg^c6wWapQbma@5gHlI%ek@jBOzIKqdy-PC%OiDWn;P}_Fe{+*eb zPFB4UByF`_3sdTiEVuYBw|y@=pP7e5dSlse++EEtXswoIHZ+kgdyw{;PUF?Sw#U_=+c1gn2sXQ5N20TCGuqj6mrahwxzt@gHM zdQI+j=czb`zpuG4q0_c?Tqy>A1VvcG<(lvOZ%`K#A(m$Ew6z^x;CB6K1#<>2tU&X5 zA-|AGzHGNGGnvoj7vzeCeR zk8Qv9dC_&X*E89sv&*x4+!$Pig(^9)MIaMSC=JY^T8`#J4#A*C zwQhrt2_L8-@%yN4`KDYpNXU4!|*V%Eo=aq#SYdE$Iz2SNU z?Qj*gRZKjx;xQm2b<=BE+Usbg<(fW^%5Dr{KnaF4A5IW=KuDnE=rAmt!`Ad+KT1#H z#Q2&6C!uL`H(G&1iu=*Bt(%%Xu(4jPZj|fg&C+^tGs@A)*0we`%WKuRrt3KAhUxhn zV*4svYY)rSdZ}0~#w@3ySxv|DS*NDadVR;K`%YcwhH0DPP^>q()e5y7Pg$JDj}gA0 z>HJdE!!?BRH*dufk;JLQg+xBGn7B2z7fMYYV-|?NpLY#=WA5A z6hlGd0=Q$Sra<+gx`==pB4|y6KZ5EqsD4yeBoUUxY(S(y4I*(>5)nzv1w}lh0@bv zr=EdLngHlJLZdJSBR#RuVGbnh=U8v=VeW990M-OgIHb^?@91F;> Date: Sun, 23 Jul 2023 22:35:49 +0300 Subject: [PATCH 19/19] tests: Add test for close event --- tests/tests/swfs/avm2/socket_close/Test.as | 25 ++++++++++++++++++ tests/tests/swfs/avm2/socket_close/output.txt | 2 ++ .../tests/swfs/avm2/socket_close/socket.json | 5 ++++ tests/tests/swfs/avm2/socket_close/test.swf | Bin 0 -> 896 bytes tests/tests/swfs/avm2/socket_close/test.toml | 1 + 5 files changed, 33 insertions(+) create mode 100644 tests/tests/swfs/avm2/socket_close/Test.as create mode 100644 tests/tests/swfs/avm2/socket_close/output.txt create mode 100644 tests/tests/swfs/avm2/socket_close/socket.json create mode 100644 tests/tests/swfs/avm2/socket_close/test.swf create mode 100644 tests/tests/swfs/avm2/socket_close/test.toml diff --git a/tests/tests/swfs/avm2/socket_close/Test.as b/tests/tests/swfs/avm2/socket_close/Test.as new file mode 100644 index 000000000000..cbd6a991f445 --- /dev/null +++ b/tests/tests/swfs/avm2/socket_close/Test.as @@ -0,0 +1,25 @@ +package +{ + import flash.display.Sprite; + + public class Test extends Sprite + { + } +} + +import flash.net.Socket; +import flash.events.Event; + +var socket:Socket = new Socket(); + +socket.addEventListener(Event.CONNECT, function(evt:Event):void +{ + trace("connected"); +}); + +socket.addEventListener(Event.CLOSE, function(evt:Event):void +{ + trace("closed"); +}); + +socket.connect("localhost", 8001); diff --git a/tests/tests/swfs/avm2/socket_close/output.txt b/tests/tests/swfs/avm2/socket_close/output.txt new file mode 100644 index 000000000000..916d26dd549b --- /dev/null +++ b/tests/tests/swfs/avm2/socket_close/output.txt @@ -0,0 +1,2 @@ +connected +closed diff --git a/tests/tests/swfs/avm2/socket_close/socket.json b/tests/tests/swfs/avm2/socket_close/socket.json new file mode 100644 index 000000000000..f271f53d57be --- /dev/null +++ b/tests/tests/swfs/avm2/socket_close/socket.json @@ -0,0 +1,5 @@ +[ + { + "type": "Disconnect" + } +] diff --git a/tests/tests/swfs/avm2/socket_close/test.swf b/tests/tests/swfs/avm2/socket_close/test.swf new file mode 100644 index 0000000000000000000000000000000000000000..7d9b3af485a2c422bc24ecca493fffa12153b026 GIT binary patch literal 896 zcmV-`1AqKOS5qb%1poke0fkaeZ{tK1pYgwm)22zbA#E2HA_0n4G_jKiq;}h=Rnow& zRt?%L0wG1w)E>v)I<{p`{wx;|;=+Ni!G#ZjIB?(=4txPlhzsQtl;=s>?w%NF#xw8t z`@Q%4-diB$PlUF9L}(YIZgCGG^!4`N7@?!sb`GC)dzHn+50XQ89amk>qeH`(&*$}d zs~*NV3#-Z9NE^P6UGzD+cb)N&!VY2V^K@o(7K${8LK%yP23~nj+kn= z$9>j5ji}|aO3!DD%ITe4kXMY9Yv1MBUjL;7iaHf)k(W@s%1d?8^uqTNm&G@62BE{} zG=_lTG_XacLU>0^Wme265C2zmLrWz-4aQSCW^ERXJ{t(1ww@)RC^QufNR7 z0BNw5!sTx*7!-u|e>nc`d$|3Yea;e&elGnaA(SHGSwQuaRFTEDnrRr>BRJ z9=R3Q_L9h_FSS7wdz@+gix)u73uzZ1%3(0#TzUo83N1bkID^>So3WLp{2JZ~VZgnB z#o7R7k8yn!DPWv*`se3oo#zE=+aknMFX0TBYUgQxaHjjAMSV9+I9X@CGa8M<5f4W; zbG*PyXL{r^Ka!&`kv?jOT0$w_YaVEch$S~ZY-P$ynW)+F=5DrJQXilq!7{-bkun5l ziIO9Di%5B*6o^tJ$~~fO6Z{6jWrBAI-Xr8~6-%=64PKqlMCi;0Yz0a8@tbeKeg`Y6 zt|A#p2rH7(#n8#ZiL`+*R*@uOT>1xNRQgxCDi86#+Qaza)y~Jz?^`SnSP?K?VD|t6 zRYsSWCR}BV^=x)&E*~SH-3N;zOE~k@(uAkV&`@(Ub4VOw4l_>19O{m44zo_y9IB2g zjxW#yv0Mcdx#7l>4P<{Xk*@N#FAZf!b~aCNFDE?&v~*+IIzemG9+>ub-~XlE%S+$> W@%twkm{WcGc34lK7XJZCoNxvySGg?! literal 0 HcmV?d00001 diff --git a/tests/tests/swfs/avm2/socket_close/test.toml b/tests/tests/swfs/avm2/socket_close/test.toml new file mode 100644 index 000000000000..0d5c2c67fa6d --- /dev/null +++ b/tests/tests/swfs/avm2/socket_close/test.toml @@ -0,0 +1 @@ +num_ticks = 10