2 // Copyright © 2011-2019 Guy M. Allard
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
24 Data Test: Frame Basic.
26 func TestDataFrameBasic(t
*testing
.T
) {
28 wh
:= Headers
{"keya", "valuea"}
29 ms
:= "The Message Body"
30 f
:= &Frame
{Command
: cm
, Headers
: wh
, Body
: []byte(ms
)}
33 t
.Fatalf("TestDataFrameBasic Command, expected: [%v], got [%v]\n",
36 if !wh
.Compare(f
.Headers
) {
37 t
.Fatalf("TestDataFrameBasic Headers, expected: [true], got [false], for [%v] [%v]\n",
40 if ms
!= string(f
.Body
) {
41 t
.Fatalf("TestDataFrameBasic Body string, expected: [%v], got [%v]\n",
47 Data Test: Message Basic.
49 func TestDataMessageBasic(t
*testing
.T
) {
51 wh
:= Headers
{"keya", "valuea"}
52 ms
:= "The Message Body"
53 m
:= &Message
{Command
: fc
, Headers
: wh
, Body
: []byte(ms
)}
56 t
.Fatalf("TestDataMessageBasic Command, expected: [%v], got [%v]\n",
59 if !wh
.Compare(m
.Headers
) {
60 t
.Fatalf("TestDataMessageBasic Headers, expected: [true], got [false], for [%v] [%v]\n",
63 if ms
!= m
.BodyString() {
64 t
.Fatalf("TestDataMessageBasic Body string, expected: [%v], got [%v]\n",
72 func TestDataprotocols(t
*testing
.T
) {
73 if !Supported(SPL_10
) {
74 t
.Fatalf("TestDataprotocolsExpected: [true], got: [false] for protocol level %v\n",
77 if !Supported(SPL_11
) {
78 t
.Fatalf("TestDataprotocols Expected: [true], got: [false] for protocol level %v\n",
81 if !Supported(SPL_12
) {
82 t
.Fatalf("TestDataprotocols Expected: [true], got: [false] for protocol level %v\n",
86 t
.Fatalf("TestDataprotocols Expected: [false], got: [true] for protocol level %v\n",
90 for _
, v
:= range suptests
{
93 t
.Fatalf("TestDataprotocols Expected: [%v] for protocol level [%v]\n",
100 Data test: Protocols.
102 func TestDataProtocols(t
*testing
.T
) {
103 for i
, p
:= range Protocols() {
104 if supported
[i
] != p
{
105 t
.Fatalf("TestDataProtocols Expected [%v], got [%v]\n",
114 func TestDataError(t
*testing
.T
) {
115 es
:= "An error string"
118 t
.Fatalf("TestDataError Expected [%v], got [%v]\n", es
, e
.Error())
123 Data Test: Message Size.
125 func TestDataMessageSize(t
*testing
.T
) {
127 wh
:= Headers
{"keya", "valuea"}
128 ms
:= "The Message Body"
129 m
:= &Message
{Command
: f
, Headers
: wh
, Body
: []byte(ms
)}
132 var w
int64 = int64(len(CONNECT
)) + 1 + wh
.Size(b
) + 1 + int64(len(ms
)) + 1
135 t
.Fatalf("TestDataMessageSize Message size, expected: [%d], got [%d]\n",
141 Data Test: Broker Command Validity.
143 func TestDataBrokerCmdVal(t
*testing
.T
) {
144 var tData
= map[string]bool{MESSAGE
: true, ERROR
: true, RECEIPT
: true,
145 CONNECT
: false, DISCONNECT
: false, SUBSCRIBE
: false, BEGIN
: false,
146 STOMP
: false, COMMIT
: false, ABORT
: false, UNSUBSCRIBE
: false,
147 SEND
: false, ACK
: false, NACK
: false, CONNECTED
: false,
149 for k
, v
:= range tData
{
150 if v
!= validCmds
[k
] {
151 t
.Fatalf("TestDataBrokerCmdVal Command Validity, expected: [%t], got [%t] for key [%s]\n",
158 func BenchmarkHeaderAdd(b
*testing
.B
) {
159 h
:= Headers
{"k1", "v1"}
160 for n
:= 0; n
< b
.N
; n
++ {
161 _
= h
.Add("akey", "avalue")
165 func BenchmarkHeaderAppend(b
*testing
.B
) {
166 h
:= []string{"k1", "v1"}
167 for n
:= 0; n
< b
.N
; n
++ {
168 _
= append(h
, "akey", "avalue")