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

root/tags/RELEASE_1_4_7/test/baseType_ut.rb

Revision 561, 26.8 kB (checked in by nahi, 6 years ago)

Follow changes of XMLSchemaDatatypes.rb

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