Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

root/tags/RELEASE_1_5_0/test/test_basetype.rb

Revision 930, 25.8 kB (checked in by nahi, 5 years ago)

Add tests.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to author date id revision
Line 
1 require 'test/unit'
2 require 'soap/baseData'
3
4 class TestSOAP < Test::Unit::TestCase
5   def setup
6     # Nothing to do.
7   end
8
9   def teardown
10     # Nothing to do.
11   end
12
13   def assert_parsed_result(klass, str)
14     o = klass.new(str)
15     assert_equal(str, o.to_s)
16   end
17
18   def test_SOAPNil
19     o = SOAP::SOAPNil.new
20     assert_equal(XSD::Namespace, o.type.namespace)
21     assert_equal(XSD::NilLiteral, o.type.name)
22     assert_equal(nil, o.data)
23     assert_equal(true, o.is_nil)
24
25     o = SOAP::SOAPNil.new(nil)
26     assert_equal(true, o.is_nil)
27     assert_equal(nil, o.data)
28     assert_equal("", o.to_s)
29     o = SOAP::SOAPNil.new('var')
30     assert_equal(false, o.is_nil)
31     assert_equal('var', o.data)
32     assert_equal('var', o.to_s)
33   end
34
35   def test_SOAPString
36     o = SOAP::SOAPString.new
37     assert_equal(XSD::Namespace, o.type.namespace)
38     assert_equal(XSD::StringLiteral, o.type.name)
39     assert_equal(nil, o.data)
40     assert_equal(true, o.is_nil)
41
42     str = "abc"
43     assert_equal(str, SOAP::SOAPString.new(str).data)
44     assert_equal(str, SOAP::SOAPString.new(str).to_s)
45     assert_raises(XSD::ValueSpaceError) do
46       SOAP::SOAPString.new("\0")
47     end
48     assert_raises(XSD::ValueSpaceError) do
49       p SOAP::SOAPString.new("\xC0\xC0").to_s
50     end
51   end
52
53   def test_SOAPBoolean
54     o = SOAP::SOAPBoolean.new
55     assert_equal(XSD::Namespace, o.type.namespace)
56     assert_equal(XSD::BooleanLiteral, o.type.name)
57     assert_equal(nil, o.data)
58     assert_equal(true, o.is_nil)
59
60     targets = [
61       ["true", true],
62       ["1", true],
63       ["false", false],
64       ["0", false],
65     ]
66     targets.each do |data, expected|
67       assert_equal(expected, SOAP::SOAPBoolean.new(data).data)
68       assert_equal(expected.to_s, SOAP::SOAPBoolean.new(data).to_s)
69     end
70
71     assert_raises(XSD::ValueSpaceError) do
72       SOAP::SOAPBoolean.new("nil").to_s
73     end
74   end
75
76   def test_SOAPDecimal
77     o = SOAP::SOAPDecimal.new
78     assert_equal(XSD::Namespace, o.type.namespace)
79     assert_equal(XSD::DecimalLiteral, o.type.name)
80     assert_equal(nil, o.data)
81     assert_equal(true, o.is_nil)
82
83     targets = [
84       0,
85       1000000000,
86       -9999999999,
87       12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,
88       12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,
89       -1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789,
90     ]
91     targets.each do |dec|
92       assert_equal(dec.to_s, SOAP::SOAPDecimal.new(dec).data)
93     end
94
95     targets = [
96       "0",
97       "0.00000001",
98       "1000000000",
99       "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
100       "-12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123.45678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
101     ]
102     targets.each do |str|
103       assert_equal(str, SOAP::SOAPDecimal.new(str).to_s)
104     end
105
106     targets = [
107       ["-0", "0"],
108       ["+0", "0"],
109       ["0.0", "0"],
110       ["-0.0", "0"],
111       ["+0.0", "0"],
112       ["0.", "0"],
113       [".0", "0"],
114       [
115         "+0.12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
116         "0.1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
117       ],
118       [
119         ".0000012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
120         "0.000001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
121       ],
122       [
123         "-12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.",
124         "-12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
125       ],
126     ]
127     targets.each do |data, expected|
128       assert_equal(expected, SOAP::SOAPDecimal.new(data).to_s)
129     end
130
131     targets = [
132       "0.000000000000a",
133       "00a.0000000000001",
134       "+-5",
135     ]
136     targets.each do |d|
137       assert_raises(XSD::ValueSpaceError) do
138         SOAP::SOAPDecimal.new(d)
139       end
140     end
141   end
142
143   def test_SOAPFloat
144     o = SOAP::SOAPFloat.new
145     assert_equal(XSD::Namespace, o.type.namespace)
146     assert_equal(XSD::FloatLiteral, o.type.name)
147     assert_equal(nil, o.data)
148     assert_equal(true, o.is_nil)
149
150     targets = [
151       3.14159265358979,
152       12.34e36,
153       1.4e-45,
154       -1.4e-45,
155     ]
156     targets.each do |f|
157       assert_equal(f, SOAP::SOAPFloat.new(f).data)
158     end
159
160     targets = [
161       "3.141592654",
162       "1.234e+37",
163       "1.4e-45",
164       "-1.4e-45",
165     ]
166     targets.each do |f|
167       assert_equal(f, SOAP::SOAPFloat.new(f).to_s)
168     end
169
170     targets = [
171       [3, "3"],         # should be 3.0?
172       [-2, "-2"],       # ditto
173       [3.14159265358979, "3.141592654"],
174       [12.34e36, "1.234e+37"],
175       [1.4e-45, "1.4e-45"],
176       [-1.4e-45, "-1.4e-45"],
177       ["1.4e", "1.4"],
178       ["12.34E36", "1.234e+37"],
179       ["1.4E-45", "1.4e-45"],
180       ["-1.4E-45", "-1.4e-45"],
181       ["1.4E", "1.4"],
182     ]
183     targets.each do |f, str|
184       assert_equal(str, SOAP::SOAPFloat.new(f).to_s)
185     end
186
187     assert_equal("0", SOAP::SOAPFloat.new(+0.0).to_s)
188     assert_equal("-0", SOAP::SOAPFloat.new(-0.0).to_s)
189     assert(SOAP::SOAPFloat.new(0.0/0.0).data.nan?)
190     assert_equal("INF", SOAP::SOAPFloat.new(1.0/0.0).to_s)
191     assert_equal(1, SOAP::SOAPFloat.new(1.0/0.0).data.infinite?)
192     assert_equal("-INF", SOAP::SOAPFloat.new(-1.0/0.0).to_s)
193     assert_equal(-1, SOAP::SOAPFloat.new(-1.0/0.0).data.infinite?)
194
195     targets = [
196       "0.000000000000a",
197       "00a.0000000000001",
198       "+-5",
199       "5_0",
200     ]
201     targets.each do |d|
202       assert_raises(XSD::ValueSpaceError) do
203         SOAP::SOAPFloat.new(d)
204       end
205     end
206   end
207
208   def test_SOAPDouble
209     o = SOAP::SOAPDouble.new
210     assert_equal(XSD::Namespace, o.type.namespace)
211     assert_equal(XSD::DoubleLiteral, o.type.name)
212     assert_equal(nil, o.data)
213     assert_equal(true, o.is_nil)
214
215     targets = [
216       3.14159265358979,
217       12.34e36,
218       1.4e-45,
219       -1.4e-45,
220     ]
221     targets.each do |f|
222       assert_equal(f, SOAP::SOAPDouble.new(f).data)
223     end
224
225     targets = [
226       "3.14159265358979",
227       "1.234e+37",
228       "1.4e-45",
229       "-1.4e-45",
230     ]
231     targets.each do |f|
232       assert_equal(f, SOAP::SOAPDouble.new(f).to_s)
233     end
234
235     targets = [
236       [3, "3"], # should be 3.0?
237       [-2, "-2"],       # ditto.
238       [3.14159265358979, "3.14159265358979"],
239       [12.34e36, "1.234e+37"],
240       [1.4e-45, "1.4e-45"],
241       [-1.4e-45, "-1.4e-45"],
242       ["1.4e", "1.4"],
243       ["12.34E36", "1.234e+37"],
244       ["1.4E-45", "1.4e-45"],
245       ["-1.4E-45", "-1.4e-45"],
246       ["1.4E", "1.4"],
247     ]
248     targets.each do |f, str|
249       assert_equal(str, SOAP::SOAPDouble.new(f).to_s)
250     end
251
252     assert_equal("0", SOAP::SOAPFloat.new(+0.0).to_s)
253     assert_equal("-0", SOAP::SOAPFloat.new(-0.0).to_s)
254     assert_equal("NaN", SOAP::SOAPDouble.new(0.0/0.0).to_s)
255     assert(SOAP::SOAPDouble.new(0.0/0.0).data.nan?)
256     assert_equal("INF", SOAP::SOAPDouble.new(1.0/0.0).to_s)
257     assert_equal(1, SOAP::SOAPDouble.new(1.0/0.0).data.infinite?)
258     assert_equal("-INF", SOAP::SOAPDouble.new(-1.0/0.0).to_s)
259     assert_equal(-1, SOAP::SOAPDouble.new(-1.0/0.0).data.infinite?)
260
261     targets = [
262       "0.000000000000a",
263       "00a.0000000000001",
264       "+-5",
265     ]
266     targets.each do |d|
267       assert_raises(XSD::ValueSpaceError) do
268         SOAP::SOAPDouble.new(d)
269       end
270     end
271   end
272
273   def test_SOAPDuration
274     o = SOAP::SOAPDuration.new
275     assert_equal(XSD::Namespace, o.type.namespace)
276     assert_equal(XSD::DurationLiteral, o.type.name)
277     assert_equal(nil, o.data)
278     assert_equal(true, o.is_nil)
279
280     targets = [
281       "P1Y2M3DT4H5M6S",
282       "P1234Y5678M9012DT3456H7890M1234.5678S",
283       "P0DT3456H7890M1234.5678S",
284       "P1234Y5678M9012D",
285       "-P1234Y5678M9012DT3456H7890M1234.5678S",
286       "P5678M9012DT3456H7890M1234.5678S",
287       "-P1234Y9012DT3456H7890M1234.5678S",
288       "+P1234Y5678MT3456H7890M1234.5678S",
289       "P1234Y5678M9012DT7890M1234.5678S",
290       "-P1234Y5678M9012DT3456H1234.5678S",
291       "+P1234Y5678M9012DT3456H7890M",
292       "P123400000000000Y",
293       "-P567800000000000M",
294       "+P901200000000000D",
295       "P0DT345600000000000H",
296       "-P0DT789000000000000M",
297       "+P0DT123400000000000.000000000005678S",
298       "P1234YT1234.5678S",
299       "-P5678MT7890M",
300       "+P9012DT3456H",
301     ]
302     targets.each do |str|
303       assert_parsed_result(SOAP::SOAPDuration, str)
304     end
305
306     targets = [
307       ["P0Y0M0DT0H0M0S",
308         "P0D"],
309       ["-P0DT0S",
310         "-P0D"],
311       ["P01234Y5678M9012DT3456H7890M1234.5678S",
312         "P1234Y5678M9012DT3456H7890M1234.5678S"],
313       ["P1234Y005678M9012DT3456H7890M1234.5678S",
314         "P1234Y5678M9012DT3456H7890M1234.5678S"],
315       ["P1234Y5678M0009012DT3456H7890M1234.5678S",
316         "P1234Y5678M9012DT3456H7890M1234.5678S"],
317       ["P1234Y5678M9012DT00003456H7890M1234.5678S",
318         "P1234Y5678M9012DT3456H7890M1234.5678S"],
319       ["P1234Y5678M9012DT3456H000007890M1234.5678S",
320         "P1234Y5678M9012DT3456H7890M1234.5678S"],
321       ["P1234Y5678M9012DT3456H7890M0000001234.5678S",
322         "P1234Y5678M9012DT3456H7890M1234.5678S"],
323     ]
324     targets.each do |data, expected|
325       assert_equal(expected, SOAP::SOAPDuration.new(data).to_s)
326     end
327   end
328
329   def test_SOAPDateTime
330     o = SOAP::SOAPDateTime.new
331     assert_equal(XSD::Namespace, o.type.namespace)
332     assert_equal(XSD::DateTimeLiteral, o.type.name)
333     assert_equal(nil, o.data)
334     assert_equal(true, o.is_nil)
335
336     targets = [
337       "2002-05-18T16:52:20Z",
338       "0001-01-01T00:00:00Z",
339       "9999-12-31T23:59:59Z",
340       "19999-12-31T23:59:59Z",
341       "2002-12-31T23:59:59.999Z",
342       "2002-12-31T23:59:59.001Z",
343       "2002-12-31T23:59:59.99999999999999999999Z",
344       "2002-12-31T23:59:59.00000000000000000001Z",
345       "2002-12-31T23:59:59+09:00",
346       "2002-12-31T23:59:59+00:01",
347       "2002-12-31T23:59:59-00:01",
348       "2002-12-31T23:59:59-23:59",
349       "2002-12-31T23:59:59.00000000000000000001+13:30",
350       "-2002-05-18T16:52:20Z",
351       "-4711-12-31T23:59:59Z",
352       "-4713-01-01T12:00:00Z",
353       "-19999-12-31T23:59:59Z",
354       "-2002-12-31T23:59:59+00:01",
355       "-0001-12-31T23:59:59.00000000000000000001+13:30",
356     ]
357     targets.each do |str|
358       assert_parsed_result(SOAP::SOAPDateTime, str)
359     end
360
361     targets = [
362       ["2002-12-31T23:59:59.00",
363         "2002-12-31T23:59:59Z"],
364       ["2002-12-31T23:59:59+00:00",
365         "2002-12-31T23:59:59Z"],
366       ["2002-12-31T23:59:59-00:00",
367         "2002-12-31T23:59:59Z"],
368       ["-2002-12-31T23:59:59.00",
369         "-2002-12-31T23:59:59Z"],
370       ["-2002-12-31T23:59:59+00:00",
371         "-2002-12-31T23:59:59Z"],
372       ["-2002-12-31T23:59:59-00:00",
373         "-2002-12-31T23:59:59Z"],
374     ]
375     targets.each do |data, expected|
376       assert_equal(expected, SOAP::SOAPDateTime.new(data).to_s)
377     end
378
379     targets = [
380       "1-05-18T16:52:20Z",
381       "05-18T16:52:20Z",
382       "2002-05T16:52:20Z",
383       "2002-05-18T16:52Z",
384       "",
385     ]
386     targets.each do |d|
387       assert_raises(XSD::ValueSpaceError, d.to_s) do
388         SOAP::SOAPDateTime.new(d)
389       end
390     end
391   end
392
393   def test_SOAPTime
394     o = SOAP::SOAPTime.new
395     assert_equal(XSD::Namespace, o.type.namespace)
396     assert_equal(XSD::TimeLiteral, o.type.name)
397     assert_equal(nil, o.data)
398     assert_equal(true, o.is_nil)
399
400     targets = [
401       "16:52:20Z",
402       "00:00:00Z",
403       "23:59:59Z",
404       "23:59:59.999Z",
405       "23:59:59.001Z",
406       "23:59:59.99999999999999999999Z",
407       "23:59:59.00000000000000000001Z",
408       "23:59:59+09:00",
409       "23:59:59+00:01",
410       "23:59:59-00:01",
411       "23:59:59-23:59",
412       "23:59:59.00000000000000000001+13:30",
413       "23:59:59+00:01",
414     ]
415     targets.each do |str|
416       assert_parsed_result(SOAP::SOAPTime, str)
417     end
418
419     targets = [
420       ["23:59:59.00",
421         "23:59:59Z"],
422       ["23:59:59+00:00",
423         "23:59:59Z"],
424       ["23:59:59-00:00",
425         "23:59:59Z"],
426     ]
427     targets.each do |data, expected|
428       assert_equal(expected, SOAP::SOAPTime.new(data).to_s)
429     end
430   end
431
432   def test_SOAPDate
433     o = SOAP::SOAPDate.new
434     assert_equal(XSD::Namespace, o.type.namespace)
435     assert_equal(XSD::DateLiteral, o.type.name)
436     assert_equal(nil, o.data)
437     assert_equal(true, o.is_nil)
438
439     targets = [
440       "2002-05-18Z",
441       "0001-01-01Z",
442       "9999-12-31Z",
443       "19999-12-31Z",
444       "2002-12-31+09:00",
445       "2002-12-31+00:01",
446       "2002-12-31-00:01",
447       "2002-12-31-23:59",
448       "2002-12-31+13:30",
449       "-2002-05-18Z",
450       "-19999-12-31Z",
451       "-2002-12-31+00:01",
452       "-0001-12-31+13:30",
453     ]
454     targets.each do |str|
455       assert_parsed_result(SOAP::SOAPDate, str)
456     end
457
458     targets = [
459       ["2002-12-31",
460         "2002-12-31Z"],
461       ["2002-12-31+00:00",
462         "2002-12-31Z"],
463       ["2002-12-31-00:00",
464         "2002-12-31Z"],
465       ["-2002-12-31",
466         "-2002-12-31Z"],
467       ["-2002-12-31+00:00",
468         "-2002-12-31Z"],
469       ["-2002-12-31-00:00",
470         "-2002-12-31Z"],
471     ]
472     targets.each do |data, expected|
473       assert_equal(expected, SOAP::SOAPDate.new(data).to_s)
474     end
475   end
476
477   def test_SOAPGYearMonth
478     o = SOAP::SOAPGYearMonth.new
479     assert_equal(XSD::Namespace, o.type.namespace)
480     assert_equal(XSD::GYearMonthLiteral, o.type.name)
481     assert_equal(nil, o.data)
482     assert_equal(true, o.is_nil)
483
484     targets = [
485       "2002-05Z",
486       "0001-01Z",
487       "9999-12Z",
488       "19999-12Z",
489       "2002-12+09:00",
490       "2002-12+00:01",
491       "2002-12-00:01",
492       "2002-12-23:59",
493       "2002-12+13:30",
494       "-2002-05Z",
495       "-19999-12Z",
496       "-2002-12+00:01",
497       "-0001-12+13:30",
498     ]
499     targets.each do |str|
500       assert_parsed_result(SOAP::SOAPGYearMonth, str)
501     end
502
503     targets = [
504       ["2002-12",
505         "2002-12Z"],
506       ["2002-12+00:00",
507         "2002-12Z"],
508       ["2002-12-00:00",
509         "2002-12Z"],
510       ["-2002-12",
511         "-2002-12Z"],
512       ["-2002-12+00:00",
513         "-2002-12Z"],
514       ["-2002-12-00:00",
515         "-2002-12Z"],
516     ]
517     targets.each do |data, expected|
518       assert_equal(expected, SOAP::SOAPGYearMonth.new(data).to_s)
519     end
520   end
521
522   def test_SOAPGYear
523     o = SOAP::SOAPGYear.new
524     assert_equal(XSD::Namespace, o.type.namespace)
525     assert_equal(XSD::GYearLiteral, o.type.name)
526     assert_equal(nil, o.data)
527     assert_equal(true, o.is_nil)
528
529     targets = [
530       "2002Z",
531       "0001Z",
532       "9999Z",
533       "19999Z",
534       "2002+09:00",
535       "2002+00:01",
536       "2002-00:01",
537       "2002-23:59",
538       "2002+13:30",
539       "-2002Z",
540       "-19999Z",
541       "-2002+00:01",
542       "-0001+13:30",
543     ]
544     targets.each do |str|
545       assert_parsed_result(SOAP::SOAPGYear, str)
546     end
547
548     targets = [
549       ["2002",
550         "2002Z"],
551       ["2002+00:00",
552         "2002Z"],
553       ["2002-00:00",
554         "2002Z"],
555       ["-2002",
556         "-2002Z"],
557       ["-2002+00:00",
558         "-2002Z"],
559       ["-2002-00:00",
560         "-2002Z"],
561     ]
562     targets.each do |data, expected|
563       assert_equal(expected, SOAP::SOAPGYear.new(data).to_s)
564     end
565   end
566
567   def test_SOAPGMonthDay
568     o = SOAP::SOAPGMonthDay.new
569     assert_equal(XSD::Namespace, o.type.namespace)
570     assert_equal(XSD::GMonthDayLiteral, o.type.name)
571     assert_equal(nil, o.data)
572     assert_equal(true, o.is_nil)
573
574     targets = [
575       "05-18Z",
576       "01-01Z",
577       "12-31Z",
578       "12-31+09:00",
579       "12-31+00:01",
580       "12-31-00:01",
581       "12-31-23:59",
582       "12-31+13:30",
583     ]
584     targets.each do |str|
585       assert_parsed_result(SOAP::SOAPGMonthDay, str)
586     end
587
588     targets = [
589       ["12-31",
590         "12-31Z"],
591       ["12-31+00:00",
592         "12-31Z"],
593       ["12-31-00:00",
594         "12-31Z"],
595     ]
596     targets.each do |data, expected|
597       assert_equal(expected, SOAP::SOAPGMonthDay.new(data).to_s)
598     end
599   end
600
601   def test_SOAPGDay
602     o = SOAP::SOAPGDay.new
603     assert_equal(XSD::Namespace, o.type.namespace)
604     assert_equal(XSD::GDayLiteral, o.type.name)
605     assert_equal(nil, o.data)
606     assert_equal(true, o.is_nil)
607
608     targets = [
609       "18Z",
610       "01Z",
611       "31Z",
612       "31+09:00",
613       "31+00:01",
614       "31-00:01",
615       "31-23:59",
616       "31+13:30",
617     ]
618     targets.each do |str|
619       assert_parsed_result(SOAP::SOAPGDay, str)
620     end
621
622     targets = [
623       ["31",
624         "31Z"],
625       ["31+00:00",
626         "31Z"],
627       ["31-00:00",
628         "31Z"],
629     ]
630     targets.each do |data, expected|
631       assert_equal(expected, SOAP::SOAPGDay.new(data).to_s)
632     end
633   end
634
635   def test_SOAPGMonth
636     o = SOAP::SOAPGMonth.new
637     assert_equal(XSD::Namespace, o.type.namespace)
638     assert_equal(XSD::GMonthLiteral, o.type.name)
639     assert_equal(nil, o.data)
640     assert_equal(true, o.is_nil)
641
642     targets = [
643       "05Z",
644       "01Z",
645       "12Z",
646       "12+09:00",
647       "12+00:01",
648       "12-00:01",
649       "12-23:59",
650       "12+13:30",
651     ]
652     targets.each do |str|
653       assert_parsed_result(SOAP::SOAPGMonth, str)
654     end
655
656     targets = [
657       ["12",
658         "12Z"],
659       ["12+00:00",
660         "12Z"],
661       ["12-00:00",
662         "12Z"],
663     ]
664     targets.each do |data, expected|
665       assert_equal(expected, SOAP::SOAPGMonth.new(data).to_s)
666     end
667   end
668
669   def test_SOAPHexBinary
670     o = SOAP::SOAPHexBinary.new
671     assert_equal(XSD::Namespace, o.type.namespace)
672     assert_equal(XSD::HexBinaryLiteral, o.type.name)
673     assert_equal(nil, o.data)
674     assert_equal(true, o.is_nil)
675
676     targets = [
677       "abcdef",
678       "\xe3\x81\xaa\xe3\x81\xb2",
679       "\0",
680       "",
681     ]
682     targets.each do |str|
683       assert_equal(str, SOAP::SOAPHexBinary.new(str).string)
684       assert_equal(str.unpack("H*")[0].tr('a-f', 'A-F'),
685         SOAP::SOAPHexBinary.new(str).data)
686       o = SOAP::SOAPHexBinary.new
687       o.set_encoded(str.unpack("H*")[0].tr('a-f', 'A-F'))
688       assert_equal(str, o.string)
689       o.set_encoded(str.unpack("H*")[0].tr('A-F', 'a-f'))
690       assert_equal(str, o.string)
691     end
692
693     targets = [
694       "0FG7",
695       "0fg7",
696     ]
697     targets.each do |d|
698       assert_raises(XSD::ValueSpaceError, d.to_s) do
699         o = SOAP::SOAPHexBinary.new
700         o.set_encoded(d)
701         p o.string
702       end
703     end
704   end
705
706   def test_SOAPBase64Binary
707     o = SOAP::SOAPBase64.new
708     assert_equal(SOAP::EncodingNamespace, o.type.namespace)
709     assert_equal(SOAP::Base64Literal, o.type.name)
710     assert_equal(nil, o.data)
711     assert_equal(true, o.is_nil)
712
713     targets = [
714       "abcdef",
715       "\xe3\x81\xaa\xe3\x81\xb2",
716       "\0",
717       "",
718     ]
719     targets.each do |str|
720       assert_equal(str, SOAP::SOAPBase64.new(str).string)
721       assert_equal([str].pack("m").chomp, SOAP::SOAPBase64.new(str).data)
722       o = SOAP::SOAPBase64.new
723       o.set_encoded([str].pack("m").chomp)
724       assert_equal(str, o.string)
725     end
726
727     targets = [
728       "-",
729       "*",
730     ]
731     targets.each do |d|
732       assert_raises(XSD::ValueSpaceError, d.to_s) do
733         o = SOAP::SOAPBase64.new
734         o.set_encoded(d)
735         p o.string
736       end
737     end
738   end
739
740   def test_SOAPAnyURI
741     o = SOAP::SOAPAnyURI.new
742     assert_equal(XSD::Namespace, o.type.namespace)
743     assert_equal(XSD::AnyURILiteral, o.type.name)
744     assert_equal(nil, o.data)
745     assert_equal(true, o.is_nil)
746
747     # Too few tests here I know.  Believe uri module. :)
748     targets = [
749       "foo",
750       "http://foo",
751       "http://foo/bar/baz",
752       "http://foo/bar#baz",
753       "http://foo/bar%20%20?a+b",
754       "HTTP://FOO/BAR%20%20?A+B",
755     ]
756     targets.each do |str|
757       assert_parsed_result(SOAP::SOAPAnyURI, str)
758     end
759   end
760
761   def test_SOAPQName
762     o = SOAP::SOAPQName.new
763     assert_equal(XSD::Namespace, o.type.namespace)
764     assert_equal(XSD::QNameLiteral, o.type.name)
765     assert_equal(nil, o.data)
766     assert_equal(true, o.is_nil)
767
768     # More strict test is needed but current implementation allows all non-':'
769     # chars like ' ', C0 or C1...
770     targets = [
771       "foo",
772       "foo:bar",
773       "a:b",
774     ]
775     targets.each do |str|
776       assert_parsed_result(SOAP::SOAPQName, str)
777     end
778   end
779
780
781   ###
782   ## Derived types
783   #
784
785   def test_SOAPInteger
786     o = SOAP::SOAPInteger.new
787     assert_equal(XSD::Namespace, o.type.namespace)
788     assert_equal(XSD::IntegerLiteral, o.type.name)
789     assert_equal(nil, o.data)
790     assert_equal(true, o.is_nil)
791
792     targets = [
793       0,
794       1000000000,
795       -9999999999,
796       12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,
797       12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,
798       -1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789,
799     ]
800     targets.each do |int|
801       assert_equal(int, SOAP::SOAPInteger.new(int).data)
802     end
803
804     targets = [
805       "0",
806       "1000000000",
807       "-9999999999",
808       "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
809       "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
810       "-1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
811     ]
812     targets.each do |str|
813       assert_equal(str, SOAP::SOAPInteger.new(str).to_s)
814     end
815
816     targets = [
817       ["-0", "0"],
818       ["+0", "0"],
819       ["000123", "123"],
820       ["-000123", "-123"],
821       [
822         "+12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
823         "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
824       ],
825    ]
826     targets.each do |data, expected|
827       assert_equal(expected, SOAP::SOAPInteger.new(data).to_s)
828     end
829
830     targets = [
831       "0.0",
832       "-5.2",
833       "0.000000000000a",
834       "+-5",
835       "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890."
836     ]
837     targets.each do |d|
838       assert_raises(XSD::ValueSpaceError) do
839         SOAP::SOAPInteger.new(d)
840       end
841     end
842   end
843
844   def test_SOAPLong
845     o = SOAP::SOAPLong.new
846     assert_equal(XSD::Namespace, o.type.namespace)
847     assert_equal(XSD::LongLiteral, o.type.name)
848     assert_equal(nil, o.data)
849     assert_equal(true, o.is_nil)
850
851     targets = [
852       0,
853       123,
854       -123,
855       9223372036854775807,
856       -9223372036854775808,
857     ]
858     targets.each do |lng|
859       assert_equal(lng, SOAP::SOAPLong.new(lng).data)
860     end
861
862     targets = [
863       "0",
864       "123",
865       "-123",
866       "9223372036854775807",
867       "-9223372036854775808",
868     ]
869     targets.each do |str|
870       assert_equal(str, SOAP::SOAPLong.new(str).to_s)
871     end
872
873     targets = [
874       ["-0", "0"],
875       ["+0", "0"],
876       ["000123", "123"],
877       ["-000123", "-123"],
878     ]
879     targets.each do |data, expected|
880       assert_equal(expected, SOAP::SOAPLong.new(data).to_s)
881     end
882
883     targets = [
884       9223372036854775808,
885       -9223372036854775809,
886       "0.0",
887       "-5.2",
888       "0.000000000000a",
889       "+-5",
890     ]
891     targets.each do |d|
892       assert_raises(XSD::ValueSpaceError) do
893         SOAP::SOAPLong.new(d)
894       end
895     end
896   end
897
898   def test_SOAPInt
899     o = SOAP::SOAPInt.new
900     assert_equal(XSD::Namespace, o.type.namespace)
901     assert_equal(XSD::IntLiteral, o.type.name)
902     assert_equal(nil, o.data)
903     assert_equal(true, o.is_nil)
904
905     targets = [
906       0,
907       123,
908       -123,
909       2147483647,
910       -2147483648,
911     ]
912     targets.each do |lng|
913       assert_equal(lng, SOAP::SOAPInt.new(lng).data)
914     end
915
916     targets = [
917       "0",
918       "123",
919       "-123",
920       "2147483647",
921       "-2147483648",
922     ]
923     targets.each do |str|
924       assert_equal(str, SOAP::SOAPInt.new(str).to_s)
925     end
926
927     targets = [
928       ["-0", "0"],
929       ["+0", "0"],
930       ["000123", "123"],
931       ["-000123", "-123"],
932     ]
933     targets.each do |data, expected|
934       assert_equal(expected, SOAP::SOAPInt.new(data).to_s)
935     end
936
937     targets = [
938       2147483648,
939       -2147483649,
940       "0.0",
941       "-5.2",
942       "0.000000000000a",
943       "+-5",
944     ]
945     targets.each do |d|
946       assert_raises(XSD::ValueSpaceError) do
947         SOAP::SOAPInt.new(d)
948       end
949     end
950   end
951 end
Note: See TracBrowser for help on using the browser.