15804
|
1 |
use proptest::{
|
|
2 |
arbitrary::any,
|
|
3 |
proptest,
|
|
4 |
strategy::{BoxedStrategy, Just, Strategy},
|
|
5 |
};
|
|
6 |
|
|
7 |
use hedgewars_network_protocol::messages::{HwProtocolMessage, HwProtocolMessage::*};
|
|
8 |
use hedgewars_network_protocol::parser::message;
|
|
9 |
use hedgewars_network_protocol::types::{GameCfg, ServerVar, TeamInfo, VoteType};
|
|
10 |
|
|
11 |
use hedgewars_network_protocol::types::testing::*;
|
|
12 |
use hedgewars_network_protocol::{proto_msg_case, proto_msg_match};
|
|
13 |
|
|
14 |
pub fn gen_proto_msg() -> BoxedStrategy<HwProtocolMessage> where {
|
|
15 |
let res = (0..=55).no_shrink().prop_flat_map(|i| {
|
|
16 |
proto_msg_match!(i, def = Ping,
|
|
17 |
0 => Ping(),
|
|
18 |
1 => Pong(),
|
|
19 |
2 => Quit(Option<Ascii>),
|
|
20 |
4 => Global(Ascii),
|
|
21 |
5 => Watch(u32),
|
|
22 |
6 => ToggleServerRegisteredOnly(),
|
|
23 |
7 => SuperPower(),
|
|
24 |
8 => Info(Ascii),
|
|
25 |
9 => Nick(Ascii),
|
|
26 |
10 => Proto(u16),
|
|
27 |
11 => Password(Ascii, Ascii),
|
|
28 |
12 => Checker(u16, Ascii, Ascii),
|
|
29 |
13 => List(),
|
|
30 |
14 => Chat(Ascii),
|
|
31 |
15 => CreateRoom(Ascii, Option<Ascii>),
|
|
32 |
16 => JoinRoom(Ascii, Option<Ascii>),
|
|
33 |
17 => Follow(Ascii),
|
|
34 |
18 => Rnd(Vec<Ascii>),
|
|
35 |
19 => Kick(Ascii),
|
|
36 |
20 => Ban(Ascii, Ascii, u32),
|
|
37 |
21 => BanIp(Ascii, Ascii, u32),
|
|
38 |
22 => BanNick(Ascii, Ascii, u32),
|
|
39 |
23 => BanList(),
|
|
40 |
24 => Unban(Ascii),
|
|
41 |
25 => SetServerVar(ServerVar),
|
|
42 |
26 => GetServerVar(),
|
|
43 |
27 => RestartServer(),
|
|
44 |
28 => Stats(),
|
|
45 |
29 => Part(Option<Ascii>),
|
|
46 |
30 => Cfg(GameCfg),
|
|
47 |
31 => AddTeam(Box<TeamInfo>),
|
|
48 |
32 => RemoveTeam(Ascii),
|
|
49 |
33 => SetHedgehogsNumber(Ascii, u8),
|
|
50 |
34 => SetTeamColor(Ascii, u8),
|
|
51 |
35 => ToggleReady(),
|
|
52 |
36 => StartGame(),
|
|
53 |
37 => EngineMessage(Ascii),
|
|
54 |
38 => RoundFinished(),
|
|
55 |
39 => ToggleRestrictJoin(),
|
|
56 |
40 => ToggleRestrictTeams(),
|
|
57 |
41 => ToggleRegisteredOnly(),
|
|
58 |
42 => RoomName(Ascii),
|
|
59 |
43 => Delegate(Ascii),
|
|
60 |
44 => TeamChat(Ascii),
|
|
61 |
45 => MaxTeams(u8),
|
|
62 |
46 => Fix(),
|
|
63 |
47 => Unfix(),
|
|
64 |
48 => Greeting(Option<Ascii>),
|
|
65 |
49 => CallVote(Option<VoteType>),
|
|
66 |
50 => Vote(bool),
|
|
67 |
51 => ForceVote(bool),
|
|
68 |
52 => Save(Ascii, Ascii),
|
|
69 |
53 => Delete(Ascii),
|
|
70 |
54 => SaveRoom(Ascii),
|
|
71 |
55 => LoadRoom(Ascii)
|
|
72 |
)
|
|
73 |
});
|
|
74 |
res.boxed()
|
|
75 |
}
|
|
76 |
|
|
77 |
proptest! {
|
|
78 |
#[test]
|
|
79 |
fn is_parser_composition_idempotent(ref msg in gen_proto_msg()) {
|
|
80 |
println!("!! Msg: {:?}, Bytes: {:?} !!", msg, msg.to_raw_protocol().as_bytes());
|
|
81 |
assert_eq!(message(msg.to_raw_protocol().as_bytes()), Ok((&b""[..], msg.clone())))
|
|
82 |
}
|
|
83 |
}
|