MCPcopy Create free account
hub / github.com/OpenPrinting/goipp / TestEncodeErrors

Function TestEncodeErrors

encdec_test.go:185–290  ·  view source on GitHub ↗

Test encode errors

(t *testing.T)

Source from the content-addressed store, hash-verified

183
184// Test encode errors
185func TestEncodeErrors(t *testing.T) {
186 // Attribute without name
187 m := NewRequest(DefaultVersion, OpGetPrinterAttributes, 0x12345678)
188 a := MakeAttribute("attr", TagInteger, Integer(123))
189 a.Name = ""
190 m.Operation.Add(a)
191 err := m.Encode(ioutil.Discard)
192 assertErrorIs(t, err, "Attribute without name")
193
194 // Attribute without value
195 m = NewRequest(DefaultVersion, OpGetPrinterAttributes, 0x12345678)
196 a = MakeAttribute("attr", TagInteger, Integer(123))
197 a.Values = nil
198 m.Operation.Add(a)
199 err = m.Encode(ioutil.Discard)
200 assertErrorIs(t, err, "Attribute without value")
201
202 // Attribute name exceeds...
203 m = NewRequest(DefaultVersion, OpGetPrinterAttributes, 0x12345678)
204 a = MakeAttribute("attr", TagInteger, Integer(123))
205 a.Name = strings.Repeat("x", 32767)
206 m.Operation.Add(a)
207 err = m.Encode(ioutil.Discard)
208 assertNoError(t, err)
209
210 m = NewRequest(DefaultVersion, OpGetPrinterAttributes, 0x12345678)
211 a = MakeAttribute("attr", TagInteger, Integer(123))
212 a.Name = strings.Repeat("x", 32767+1)
213 m.Operation.Add(a)
214 err = m.Encode(ioutil.Discard)
215 assertErrorIs(t, err, "Attribute name exceeds 32767 bytes")
216
217 // Attribute value exceeds...
218 m = NewRequest(DefaultVersion, OpGetPrinterAttributes, 0x12345678)
219 a = MakeAttribute("attr", TagText, String(strings.Repeat("x", 32767)))
220 m.Operation.Add(a)
221 err = m.Encode(ioutil.Discard)
222 assertNoError(t, err)
223
224 m = NewRequest(DefaultVersion, OpGetPrinterAttributes, 0x12345678)
225 a = MakeAttribute("attr", TagText, String(strings.Repeat("x", 32767+1)))
226 m.Operation.Add(a)
227 err = m.Encode(ioutil.Discard)
228 assertErrorIs(t, err, "Attribute value exceeds 32767 bytes")
229
230 // Tag XXX cannot be used with value
231 m = NewRequest(DefaultVersion, OpGetPrinterAttributes, 0x12345678)
232 a = MakeAttribute("attr", TagJobGroup, Integer(123))
233 m.Operation.Add(a)
234 err = m.Encode(ioutil.Discard)
235 assertErrorIs(t, err, "Tag job-attributes-tag cannot be used with value")
236
237 m = NewRequest(DefaultVersion, OpGetPrinterAttributes, 0x12345678)
238 a = MakeAttribute("attr", TagMemberName, Integer(123))
239 m.Operation.Add(a)
240 err = m.Encode(ioutil.Discard)
241 assertErrorIs(t, err, "Tag memberAttrName cannot be used with value")
242

Callers

nothing calls this directly

Calls 10

NewRequestFunction · 0.85
MakeAttributeFunction · 0.85
IntegerTypeAlias · 0.85
assertErrorIsFunction · 0.85
assertNoErrorFunction · 0.85
StringTypeAlias · 0.85
testEncodeDecodeMessageFunction · 0.85
EncodeMethod · 0.80
EncodeBytesMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected