@@ -19,6 +19,273 @@ import (
1919 "testing"
2020)
2121
22- func TestIBMMQ (t * testing.T ) {
23- // TODO
22+ // Tests for mqistr.go
23+ func TestMqstrerror (t * testing.T ) {
24+ output := mqstrerror ("test" , 0 , 0 )
25+ expected := "test: MQCC = MQCC_OK [0] MQRC = MQRC_NONE [0]"
26+ if output != expected {
27+ t .Logf ("Gave 0, 0. Expected: %s, Got: %s" , expected , output )
28+ t .Fail ()
29+ }
30+
31+ output = mqstrerror ("test" , 1 , 2393 )
32+ expected = "test: MQCC = MQCC_WARNING [1] MQRC = MQRC_SSL_INITIALIZATION_ERROR [2393]"
33+ if output != expected {
34+ t .Logf ("Gave 1, 2393. Expected: %s, Got: %s" , expected , output )
35+ t .Fail ()
36+ }
37+
38+ output = mqstrerror ("test" , 2 , 2035 )
39+ expected = "test: MQCC = MQCC_FAILED [2] MQRC = MQRC_NOT_AUTHORIZED [2035]"
40+ if output != expected {
41+ t .Logf ("Gave 2, 2035. Expected: %s, Got: %s" , expected , output )
42+ t .Fail ()
43+ }
44+ }
45+
46+ func TestMQItoString (t * testing.T ) {
47+ output := MQItoString ("BACF" , 7019 )
48+ expected := "MQBACF_ALTERNATE_SECURITYID"
49+ if output != expected {
50+ t .Logf ("Gave BACF, 7019. Expected: %s, Got: %s" , expected , output )
51+ t .Fail ()
52+ }
53+
54+ output = MQItoString ("CA" , 2030 )
55+ expected = "MQCA_CLUSTER_NAMELIST"
56+ if output != expected {
57+ t .Logf ("Gave CA, 2030. Expected: %s, Got: %s" , expected , output )
58+ t .Fail ()
59+ }
60+
61+ output = MQItoString ("CA" , 3134 )
62+ expected = "MQCACF_ACTIVITY_DESC"
63+ if output != expected {
64+ t .Logf ("Gave CA, 3134. Expected: %s, Got: %s" , expected , output )
65+ t .Fail ()
66+ }
67+
68+ output = MQItoString ("CA" , 3529 )
69+ expected = "MQCACH_CHANNEL_START_DATE"
70+ if output != expected {
71+ t .Logf ("Gave CA, 3529. Expected: %s, Got: %s" , expected , output )
72+ t .Fail ()
73+ }
74+
75+ output = MQItoString ("CA" , 2708 )
76+ expected = "MQCAMO_END_TIME"
77+ if output != expected {
78+ t .Logf ("Gave CA, 2708. Expected: %s, Got: %s" , expected , output )
79+ t .Fail ()
80+ }
81+
82+ output = MQItoString ("CC" , - 1 )
83+ expected = "MQCC_UNKNOWN"
84+ if output != expected {
85+ t .Logf ("Gave CC, -1. Expected: %s, Got: %s" , expected , output )
86+ t .Fail ()
87+ }
88+
89+ output = MQItoString ("CMD" , 208 )
90+ expected = "MQCMD_CHANGE_PROT_POLICY"
91+ if output != expected {
92+ t .Logf ("Gave CMD, 208. Expected: %s, Got: %s" , expected , output )
93+ t .Fail ()
94+ }
95+
96+ output = MQItoString ("IA" , 102 )
97+ expected = "MQIA_ADOPTNEWMCA_CHECK"
98+ if output != expected {
99+ t .Logf ("Gave IA, 102. Expected: %s, Got: %s" , expected , output )
100+ t .Fail ()
101+ }
102+
103+ output = MQItoString ("IA" , 1019 )
104+ expected = "MQIACF_AUTH_INFO_ATTRS"
105+ if output != expected {
106+ t .Logf ("Gave IA, 1019. Expected: %s, Got: %s" , expected , output )
107+ t .Fail ()
108+ }
109+
110+ output = MQItoString ("IA" , 1584 )
111+ expected = "MQIACH_ADAPS_MAX"
112+ if output != expected {
113+ t .Logf ("Gave IA, 1584. Expected: %s, Got: %s" , expected , output )
114+ t .Fail ()
115+ }
116+
117+ output = MQItoString ("IA" , 770 )
118+ expected = "MQIAMO_CBS_FAILED"
119+ if output != expected {
120+ t .Logf ("Gave IA, 770. Expected: %s, Got: %s" , expected , output )
121+ t .Fail ()
122+ }
123+
124+ output = MQItoString ("IA" , 745 )
125+ expected = "MQIAMO64_BROWSE_BYTES"
126+ if output != expected {
127+ t .Logf ("Gave IA, 745. Expected: %s, Got: %s" , expected , output )
128+ t .Fail ()
129+ }
130+
131+ output = MQItoString ("OT" , 1008 )
132+ expected = "MQOT_SERVER_CHANNEL"
133+ if output != expected {
134+ t .Logf ("Gave OT, 1008. Expected: %s, Got: %s" , expected , output )
135+ t .Fail ()
136+ }
137+
138+ output = MQItoString ("RC" , 2277 )
139+ expected = "MQRC_CD_ERROR"
140+ if output != expected {
141+ t .Logf ("Gave RC, 2277. Expected: %s, Got: %s" , expected , output )
142+ t .Fail ()
143+ }
144+
145+ output = MQItoString ("RC" , 3049 )
146+ expected = "MQRCCF_CCSID_ERROR"
147+ if output != expected {
148+ t .Logf ("Gave RC, 3049. Expected: %s, Got: %s" , expected , output )
149+ t .Fail ()
150+ }
151+
152+ output = MQItoString ("BADVALUE" , 0 )
153+ expected = ""
154+ if output != expected {
155+ t .Logf ("Gave BADVALUE, 0. Expected: %s, Got: %s" , expected , output )
156+ t .Fail ()
157+ }
158+
159+ output = MQItoString ("IA" , 0123123123123 )
160+ expected = ""
161+ if output != expected {
162+ t .Logf ("Gave IA, 0123123123123. Expected: %s, Got: %s" , expected , output )
163+ t .Fail ()
164+ }
165+ }
166+
167+ // Tests for mqiPCF.go
168+ func TestReadPCFHeader (t * testing.T ) {
169+ testHeader := NewMQCFH ()
170+ returned , offset := ReadPCFHeader (testHeader .Bytes ())
171+ if returned .Type != testHeader .Type {
172+ t .Logf ("Returned 'Type' does not match Initial: Expected: %d Got: %d" , testHeader .Type , returned .Type )
173+ t .Fail ()
174+ }
175+ if returned .StrucLength != testHeader .StrucLength {
176+ t .Logf ("Returned 'StrucLength' does not match Initial: Expected: %d Got: %d" , testHeader .StrucLength , returned .StrucLength )
177+ t .Fail ()
178+ }
179+ if returned .Version != testHeader .Version {
180+ t .Logf ("Returned 'Version' does not match Initial: Expected: %d Got: %d" , testHeader .Version , returned .Version )
181+ t .Fail ()
182+ }
183+ if returned .Command != testHeader .Command {
184+ t .Logf ("Returned 'Command' does not match Initial: Expected: %d Got: %d" , testHeader .Command , returned .Command )
185+ t .Fail ()
186+ }
187+ if returned .MsgSeqNumber != testHeader .MsgSeqNumber {
188+ t .Logf ("Returned 'MsgSeqNumber' does not match Initial: Expected: %d Got: %d" , testHeader .MsgSeqNumber , returned .MsgSeqNumber )
189+ t .Fail ()
190+ }
191+ if returned .Control != testHeader .Control {
192+ t .Logf ("Returned 'Control' does not match Initial: Expected: %d Got: %d" , testHeader .Control , returned .Control )
193+ t .Fail ()
194+ }
195+ if returned .CompCode != testHeader .CompCode {
196+ t .Logf ("Returned 'CompCode' does not match Initial: Expected: %d Got: %d" , testHeader .CompCode , returned .CompCode )
197+ t .Fail ()
198+ }
199+ if returned .Reason != testHeader .Reason {
200+ t .Logf ("Returned 'Reason' does not match Initial: Expected: %d Got: %d" , testHeader .Reason , returned .Reason )
201+ t .Fail ()
202+ }
203+ if returned .ParameterCount != testHeader .ParameterCount {
204+ t .Logf ("Returned 'ParameterCount' does not match Initial: Expected: %d Got: %d" , testHeader .ParameterCount , returned .ParameterCount )
205+ t .Fail ()
206+ }
207+ if offset != 36 {
208+ t .Logf ("Expected offset to be 36 but was %d" , offset )
209+ t .Fail ()
210+ }
211+ }
212+
213+ func TestReadPCFParameter (t * testing.T ) {
214+ start := PCFParameter {
215+ Parameter : MQCACF_APPL_NAME ,
216+ Int64Value : []int64 {100 },
217+ String : []string {"HELLOTEST" },
218+ ParameterCount : 1 ,
219+ }
220+
221+ t .Log ("-MQCFT_INTEGER-" )
222+ start .Type = MQCFT_INTEGER
223+ back , _ := ReadPCFParameter (start .Bytes ())
224+ verifyParam (t , & start , back )
225+
226+ t .Log ("-MQCFT_STRING-" )
227+ start .Type = MQCFT_STRING
228+ back , _ = ReadPCFParameter (start .Bytes ())
229+ verifyParam (t , & start , back )
230+
231+ // The rest of the types are not implemented in the Bytes()
232+ // function so cannot be tested.
233+ }
234+
235+ func verifyParam (t * testing.T , given , returned * PCFParameter ) {
236+ t .Log ("Testing Type" )
237+ if given .Type != returned .Type {
238+ t .Logf ("Returned 'Type' does not match Initial: Expected: %d Got: %d" , given .Type , returned .Type )
239+ t .Fail ()
240+ }
241+ t .Log ("Testing Parameter" )
242+ if given .Parameter != returned .Parameter {
243+ t .Logf ("Returned 'Parameter' does not match Initial: Expected: %d Got: %d" , given .Parameter , returned .Parameter )
244+ t .Fail ()
245+ }
246+ if given .Type == MQCFT_INTEGER || given .Type == MQCFT_INTEGER64 || given .Type == MQCFT_INTEGER_LIST || given .Type == MQCFT_INTEGER64_LIST {
247+ t .Log ("Testing Length" )
248+ if len (given .Int64Value ) != len (returned .Int64Value ) {
249+ t .Logf ("Length of Returned 'Int64Value' does not match Initial: Expected: %d Got: %d" , len (given .Int64Value ), len (returned .Int64Value ))
250+ t .Fail ()
251+ } else if given .Int64Value [0 ] != returned .Int64Value [0 ] {
252+ t .Logf ("Returned parameter 'Int64Value' did not match. Expected: %d, Got: %d" , given .Int64Value [0 ], returned .Int64Value [0 ])
253+ t .Fail ()
254+ }
255+ }
256+
257+ if given .Type == MQCFT_STRING || given .Type == MQCFT_STRING_LIST {
258+ if len (given .String ) != len (returned .String ) {
259+ t .Logf ("Length of Returned 'String' does not match Initial: Expected: %d Got: %d" , len (given .String ), len (returned .String ))
260+ t .Fail ()
261+ } else if given .String [0 ] != returned .String [0 ] {
262+ t .Logf ("Returned parameter 'String' did not match. Expected: %s, Got: %s" , given .String [0 ], returned .String [0 ])
263+ t .Fail ()
264+ }
265+ }
266+
267+ if given .Type == MQCFT_GROUP {
268+ if given .ParameterCount != returned .ParameterCount {
269+ t .Logf ("Returned 'ParameterCount' does not match Initial: Expected: %d Got: %d" , given .ParameterCount , returned .ParameterCount )
270+ t .Fail ()
271+ }
272+ }
273+
274+ if len (given .GroupList ) != len (returned .GroupList ) {
275+ t .Logf ("Length of Returned 'GroupList' does not match Initial: Expected: %d Got: %d" , len (given .GroupList ), len (returned .GroupList ))
276+ t .Fail ()
277+ } // Should be nil
278+ }
279+
280+ func TestRoundTo4 (t * testing.T ) {
281+ start := []int32 {12 , 13 , 14 , 15 , 16 , 17 }
282+ expected := []int32 {12 , 16 , 16 , 16 , 16 , 20 }
283+
284+ for i , e := range start {
285+ back := roundTo4 (e )
286+ if back != expected [i ] {
287+ t .Logf ("Passed: %d. Expected: %d. Got: %d" , e , expected [i ], back )
288+ t .Fail ()
289+ }
290+ }
24291}
0 commit comments