go.nanomsg.org/mangos/v3@v3.4.3-0.20240217232803-46464076f1f5/protocol/pair1/pair1_test.go (about) 1 /* 2 * Copyright 2022 The Mangos Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use file except in compliance with the License. 6 * You may obtain a copy of the license at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18 package pair1 19 20 import ( 21 "testing" 22 23 "go.nanomsg.org/mangos/v3" 24 25 . "go.nanomsg.org/mangos/v3/internal/test" 26 _ "go.nanomsg.org/mangos/v3/transport/inproc" 27 ) 28 29 func TestPair1Identity(t *testing.T) { 30 s := GetSocket(t, NewSocket) 31 id := s.Info() 32 MustBeTrue(t, id.Self == mangos.ProtoPair1) 33 MustBeTrue(t, id.Peer == mangos.ProtoPair1) 34 MustBeTrue(t, id.SelfName == "pair1") 35 MustBeTrue(t, id.PeerName == "pair1") 36 MustClose(t, s) 37 } 38 39 func TestPairCooked(t *testing.T) { 40 VerifyCooked(t, NewSocket) 41 } 42 43 func TestPair1SendReceive(t *testing.T) { 44 self := GetSocket(t, NewSocket) 45 peer := GetSocket(t, NewSocket) 46 ConnectPair(t, self, peer) 47 MustSendString(t, self, "ping") 48 m := MustRecvMsg(t, peer) 49 MustBeTrue(t, len(m.Header) == 0) 50 MustClose(t, self) 51 MustClose(t, peer) 52 } 53 func TestPairClosed(t *testing.T) { 54 VerifyClosedSend(t, NewSocket) 55 VerifyClosedRecv(t, NewSocket) 56 VerifyClosedClose(t, NewSocket) 57 VerifyClosedDial(t, NewSocket) 58 VerifyClosedListen(t, NewSocket) 59 VerifyClosedAddPipe(t, NewSocket) 60 } 61 62 func TestPairOptions(t *testing.T) { 63 VerifyInvalidOption(t, NewSocket) 64 VerifyOptionDuration(t, NewSocket, mangos.OptionRecvDeadline) 65 VerifyOptionDuration(t, NewSocket, mangos.OptionSendDeadline) 66 VerifyOptionInt(t, NewSocket, mangos.OptionReadQLen) 67 VerifyOptionInt(t, NewSocket, mangos.OptionWriteQLen) 68 VerifyOptionBool(t, NewSocket, mangos.OptionBestEffort) 69 }