tests: Move SocketEvent into ruffle_socket_format crate

This commit is contained in:
sleepycatcoding 2023-07-21 18:27:44 +03:00 committed by Nathan Adams
parent 88626b7212
commit 3e8ee00a67
6 changed files with 56 additions and 34 deletions

9
Cargo.lock generated
View File

@ -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",
]

View File

@ -25,6 +25,7 @@ members = [
"tests",
"tests/input-format",
"tests/socket-format",
"tests/socket-mock",
]
default-members = ["desktop"]

View File

@ -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"

View File

@ -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<u8>,
},
/// Send data to client.
Send {
payload: Vec<u8>,
},
/// Expect client to disconnect.
WaitForDisconnect,
/// Disconnect the client.
Disconnect,
}
impl SocketEvent {
pub fn from_file<P>(path: P) -> Result<Vec<Self>, io::Error>
where
P: AsRef<Path>,
{
let file = File::open(path)?;
Ok(from_reader(file)?)
}
}

View File

@ -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"
ruffle_socket_format = { path = "../socket-format" }

View File

@ -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<u8>,
},
/// Send data to client.
Send {
payload: Vec<u8>,
},
/// Expect client to disconnect.
WaitForDisconnect,
/// Disconnect the client.
Disconnect,
}
impl SocketEvent {
pub fn from_file<P>(path: P) -> Result<Vec<Self>, io::Error>
where
P: AsRef<Path>,
{
let file = File::open(path)?;
Ok(from_reader(file)?)
}
}
static POLICY: &'static [u8] = &*b"<?xml version=\"1.0\"?>
<!DOCTYPE cross-domain-policy SYSTEM \"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd\">
<cross-domain-policy>