use std::error::Error; use mpstthree::binary::struct_trait::{end::End, recv::Recv, send::Send, session::Session}; use mpstthree::functionmpst::close::close_mpst; use mpstthree::functionmpst::fork::fork_mpst; use mpstthree::meshedchannels::MeshedChannels; use mpstthree::checker_concat; use mpstthree::role::a::RoleA; use mpstthree::role::b::RoleB; use mpstthree::role::c::RoleC; use mpstthree::role::end::RoleEnd; use mpstthree::name::a::NameA; use mpstthree::name::b::NameB; use mpstthree::name::c::NameC; use mpstthree::functionmpst::recv::recv_mpst_a_from_c; use mpstthree::functionmpst::recv::recv_mpst_b_from_a; use mpstthree::functionmpst::recv::recv_mpst_c_from_b; use mpstthree::functionmpst::send::send_mpst_a_to_b; use mpstthree::functionmpst::send::send_mpst_b_to_c; use mpstthree::functionmpst::send::send_mpst_c_to_a; use petgraph::dot::Dot; // Creating the binary sessions type AtoB = Send; type AtoC = Recv; type BtoA = as Session>::Dual; type BtoC = Send; type CtoA = as Session>::Dual; type CtoB = as Session>::Dual; // Stacks type StackA = RoleB>; type StackB = RoleA>; type StackC = RoleA>; // Creating the MP sessions type EndpointA = MeshedChannels, AtoC, StackA, NameA>; type EndpointB = MeshedChannels, BtoC, StackB, NameB>; type EndpointC = MeshedChannels, CtoB, StackC, NameC>; // Single test for A fn endpoint_a(s: EndpointA) -> Result<(), Box> { let s = send_mpst_a_to_b(1, s); let (x, s) = recv_mpst_a_from_c(s)?; assert_eq!(x, 3); close_mpst(s) } // Single test for B fn endpoint_b(s: EndpointB) -> Result<(), Box> { let (x, s) = recv_mpst_b_from_a(s)?; let s = send_mpst_b_to_c(2, s); assert_eq!(x, 1); close_mpst(s) } // Single test for C fn endpoint_c(s: EndpointC) -> Result<(), Box> { let s = send_mpst_c_to_a(3, s); let (x, s) = recv_mpst_c_from_b(s)?; assert_eq!(x, 2); close_mpst(s) } ///////////////////////////////////////// pub fn simple_triple_endpoints() { let (thread_a, thread_b, thread_c) = fork_mpst(endpoint_a, endpoint_b, endpoint_c); assert!(thread_a.join().is_ok()); assert!(thread_b.join().is_ok()); assert!(thread_c.join().is_ok()); } pub fn simple_triple_endpoints_checker() { let (graphs, kmc) = checker_concat!("", EndpointB, EndpointC, EndpointA).unwrap(); ////////////// Test graph A let graph_a = &graphs["RoleA"]; assert_eq!( format!("{:?}", Dot::new(&graph_a)), "digraph {\n \ 0 [ label = \"\\\"0\\\"\" ]\n \ 1 [ label = \"\\\"1\\\"\" ]\n \ 2 [ label = \"\\\"2\\\"\" ]\n \ 3 [ label = \"\\\"3\\\"\" ]\n \ 0 -> 1 [ label = \"\\\"RoleA!RoleB: i32\\\"\" ]\n \ 1 -> 2 [ label = \"\\\"RoleA?RoleC: i32\\\"\" ]\n \ 2 -> 3 [ label = \"\\\"0\\\"\" ]\n\ }\n" ); ////////////// Test graph B let graph_b = &graphs["RoleB"]; assert_eq!( format!("{:?}", Dot::new(&graph_b)), "digraph {\n \ 0 [ label = \"\\\"0\\\"\" ]\n \ 1 [ label = \"\\\"1\\\"\" ]\n \ 2 [ label = \"\\\"2\\\"\" ]\n \ 3 [ label = \"\\\"3\\\"\" ]\n \ 0 -> 1 [ label = \"\\\"RoleB?RoleA: i32\\\"\" ]\n \ 1 -> 2 [ label = \"\\\"RoleB!RoleC: i32\\\"\" ]\n \ 2 -> 3 [ label = \"\\\"0\\\"\" ]\n\ }\n" ); ////////////// Test graph C let graph_c = &graphs["RoleC"]; assert_eq!( format!("{:?}", Dot::new(&graph_c)), "digraph {\n \ 0 [ label = \"\\\"0\\\"\" ]\n \ 1 [ label = \"\\\"1\\\"\" ]\n \ 2 [ label = \"\\\"2\\\"\" ]\n \ 3 [ label = \"\\\"3\\\"\" ]\n \ 0 -> 1 [ label = \"\\\"RoleC!RoleA: i32\\\"\" ]\n \ 1 -> 2 [ label = \"\\\"RoleC?RoleB: i32\\\"\" ]\n \ 2 -> 3 [ label = \"\\\"0\\\"\" ]\n\ }\n" ); ////////////// Test KMC output assert_eq!(kmc, None); }