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

root/trunk/test/soap/test_basetype.rb

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