Address issue #50.
[stompngo.git] / sendbytes_test.go
blob01fc66614aeb020df2fadff22aab2687094fa05d
1 //
2 // Copyright © 2014-2019 Guy M. Allard
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this 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.
17 package stompngo
19 import (
20 "testing"
24 Test Send Basiconn, one message.
26 func TestSendBytesBasic(t *testing.T) {
27 for _, sp := range Protocols() {
28 n, _ = openConn(t)
29 ch := login_headers
30 ch = headersProtocol(ch, sp)
31 conn, e = Connect(n, ch)
32 if e != nil {
33 t.Fatalf("TestSendBytesBasic CONNECT expected no error, got [%v]\n", e)
37 mb := []byte("A message-" + sp)
38 d := tdest("/queue/send.basiconn.01.bytes." + sp)
39 sh := Headers{HK_DESTINATION, d}
40 e = conn.SendBytes(sh, mb)
41 if e != nil {
42 t.Fatalf("TestSendBytesBasic Expected nil error, got [%v]\n", e)
45 e = conn.SendBytes(empty_headers, mb)
46 if e == nil {
47 t.Fatalf("TestSendBytesBasic Expected error, got [nil]\n")
49 if e != EREQDSTSND {
50 t.Fatalf("TestSendBytesBasic Expected [%v], got [%v]\n", EREQDSTSND, e)
52 checkReceived(t, conn, false)
53 e = conn.Disconnect(empty_headers)
54 checkDisconnectError(t, e)
55 _ = closeConn(t, n)
60 Test Send Multiple, multiple messages, 5 to be exact.
62 func TestSendBytesMultiple(t *testing.T) {
63 for _, sp := range Protocols() {
64 n, _ = openConn(t)
65 ch := login_headers
66 ch = headersProtocol(ch, sp)
67 conn, e = Connect(n, ch)
68 if e != nil {
69 t.Fatalf("TestSendBytesMultiple CONNECT expected no error, got [%v]\n", e)
72 mdb := multi_send_data{conn: conn,
73 dest: tdest("/queue/sendmultiple.01.bytes." + sp + "."),
74 mpref: "sendmultiple.01.message.prefix.bytes ",
75 count: 5}
76 e = sendMultipleBytes(mdb)
77 if e != nil {
78 t.Fatalf("TestSendBytesMultiple Expected nil error, got [%v]\n", e)
81 checkReceived(t, conn, false)
82 e = conn.Disconnect(empty_headers)
83 checkDisconnectError(t, e)
84 _ = closeConn(t, n)