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

root/tags/RELEASE_1_4_5/test/baseType_ut.rb

Revision 532, 26.8 kB (checked in by nahi, 7 years ago)

Added some 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 '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       "-19999-12-31T23:59:59Z",
356       "-2002-12-31T23:59:59+00:01",
357       "-0001-12-31T23:59:59.00000000000000000001+13:30",
358     ]
359     targets.each do | str |
360       assertParsedResult( SOAP::SOAPDateTime, str )
361     end
362
363     targets = [
364       [ "2002-12-31T23:59:59.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:00",
369         "2002-12-31T23:59:59Z" ],
370       [ "-2002-12-31T23:59:59.00",
371         "-2002-12-31T23:59:59Z" ],
372       [ "-2002-12-31T23:59:59+00:00",
373         "-2002-12-31T23:59:59Z" ],
374       [ "-2002-12-31T23:59:59-00:00",
375         "-2002-12-31T23:59:59Z" ],
376     ]
377     targets.each do | data, expected |
378       assert_equal( expected, SOAP::SOAPDateTime.new( data ).to_s )
379     end
380
381     targets = [
382       "0000-05-18T16:52:20Z",
383       "05-18T16:52:20Z",
384       "2002-05T16:52:20Z",
385       "2002-05-18T16:52Z",
386       "",
387     ]
388     targets.each do | d |
389       assert_exception( XSD::ValueSpaceError, d.to_s ) do
390         SOAP::SOAPDateTime.new( d )
391       end
392     end
393   end
394
395   def test_SOAPTime
396     o = SOAP::SOAPTime.new
397     assert_equal( XSD::Namespace, o.typeNamespace )
398     assert_equal( XSD::TimeLiteral, o.typeName )
399     assert_equal( nil, o.data )
400     assert_equal( true, o.isNil )
401
402     targets = [
403       "16:52:20Z",
404       "00:00:00Z",
405       "23:59:59Z",
406       "23:59:59.999Z",
407       "23:59:59.001Z",
408       "23:59:59.99999999999999999999Z",
409       "23:59:59.00000000000000000001Z",
410       "23:59:59+09:00",
411       "23:59:59+00:01",
412       "23:59:59-00:01",
413       "23:59:59-23:59",
414       "23:59:59.00000000000000000001+13:30",
415       "23:59:59+00:01",
416     ]
417     targets.each do | str |
418       assertParsedResult( SOAP::SOAPTime, str )
419     end
420
421     targets = [
422       [ "23:59:59.00",
423         "23:59:59Z" ],
424       [ "23:59:59+00:00",
425         "23:59:59Z" ],
426       [ "23:59:59-00:00",
427         "23:59:59Z" ],
428     ]
429     targets.each do | data, expected |
430       assert_equal( expected, SOAP::SOAPTime.new( data ).to_s )
431     end
432   end
433
434   def test_SOAPDate
435     o = SOAP::SOAPDate.new
436     assert_equal( XSD::Namespace, o.typeNamespace )
437     assert_equal( XSD::DateLiteral, o.typeName )
438     assert_equal( nil, o.data )
439     assert_equal( true, o.isNil )
440
441     targets = [
442       "2002-05-18Z",
443       "0000-01-01Z",
444       "9999-12-31Z",
445       "19999-12-31Z",
446       "2002-12-31+09:00",
447       "2002-12-31+00:01",
448       "2002-12-31-00:01",
449       "2002-12-31-23:59",
450       "2002-12-31+13:30",
451       "-2002-05-18Z",
452       "-19999-12-31Z",
453       "-2002-12-31+00:01",
454       "-0001-12-31+13:30",
455     ]
456     targets.each do | str |
457       assertParsedResult( SOAP::SOAPDate, str )
458     end
459
460     targets = [
461       [ "2002-12-31",
462         "2002-12-31Z" ],
463       [ "2002-12-31+00:00",
464         "2002-12-31Z" ],
465       [ "2002-12-31-00:00",
466         "2002-12-31Z" ],
467       [ "-2002-12-31",
468         "-2002-12-31Z" ],
469       [ "-2002-12-31+00:00",
470         "-2002-12-31Z" ],
471       [ "-2002-12-31-00:00",
472         "-2002-12-31Z" ],
473     ]
474     targets.each do | data, expected |
475       assert_equal( expected, SOAP::SOAPDate.new( data ).to_s )
476     end
477   end
478
479   def test_SOAPGYearMonth
480     o = SOAP::SOAPGYearMonth.new
481     assert_equal( XSD::Namespace, o.typeNamespace )
482     assert_equal( XSD::GYearMonthLiteral, o.typeName )
483     assert_equal( nil, o.data )
484     assert_equal( true, o.isNil )
485
486     targets = [
487       "2002-05Z",
488       "0000-01Z",
489       "9999-12Z",
490       "19999-12Z",
491       "2002-12+09:00",
492       "2002-12+00:01",
493       "2002-12-00:01",
494       "2002-12-23:59",
495       "2002-12+13:30",
496       "-2002-05Z",
497       "-19999-12Z",
498       "-2002-12+00:01",
499       "-0001-12+13:30",
500     ]
501     targets.each do | str |
502       assertParsedResult( SOAP::SOAPGYearMonth, str )
503     end
504
505     targets = [
506       [ "2002-12",
507         "2002-12Z" ],
508       [ "2002-12+00:00",
509         "2002-12Z" ],
510       [ "2002-12-00:00",
511         "2002-12Z" ],
512       [ "-2002-12",
513         "-2002-12Z" ],
514       [ "-2002-12+00:00",
515         "-2002-12Z" ],
516       [ "-2002-12-00:00",
517         "-2002-12Z" ],
518     ]
519     targets.each do | data, expected |
520       assert_equal( expected, SOAP::SOAPGYearMonth.new( data ).to_s )
521     end
522   end
523
524   def test_SOAPGYear
525     o = SOAP::SOAPGYear.new
526     assert_equal( XSD::Namespace, o.typeNamespace )
527     assert_equal( XSD::GYearLiteral, o.typeName )
528     assert_equal( nil, o.data )
529     assert_equal( true, o.isNil )
530
531     targets = [
532       "2002Z",
533       "0000Z",
534       "9999Z",
535       "19999Z",
536       "2002+09:00",
537       "2002+00:01",
538       "2002-00:01",
539       "2002-23:59",
540       "2002+13:30",
541       "-2002Z",
542       "-19999Z",
543       "-2002+00:01",
544       "-0001+13:30",
545     ]
546     targets.each do | str |
547       assertParsedResult( SOAP::SOAPGYear, str )
548     end
549
550     targets = [
551       [ "2002",
552         "2002Z" ],
553       [ "2002+00:00",
554         "2002Z" ],
555       [ "2002-00:00",
556         "2002Z" ],
557       [ "-2002",
558         "-2002Z" ],
559       [ "-2002+00:00",
560         "-2002Z" ],
561       [ "-2002-00:00",
562         "-2002Z" ],
563     ]
564     targets.each do | data, expected |
565       assert_equal( expected, SOAP::SOAPGYear.new( data ).to_s )
566     end
567   end
568
569   def test_SOAPGMonthDay
570     o = SOAP::SOAPGMonthDay.new
571     assert_equal( XSD::Namespace, o.typeNamespace )
572     assert_equal( XSD::GMonthDayLiteral, o.typeName )
573     assert_equal( nil, o.data )
574     assert_equal( true, o.isNil )
575
576     targets = [
577       "05-18Z",
578       "01-01Z",
579       "12-31Z",
580       "12-31+09:00",
581       "12-31+00:01",
582       "12-31-00:01",
583       "12-31-23:59",
584       "12-31+13:30",
585     ]
586     targets.each do | str |
587       assertParsedResult( SOAP::SOAPGMonthDay, str )
588     end
589
590     targets = [
591       [ "12-31",
592         "12-31Z" ],
593       [ "12-31+00:00",
594         "12-31Z" ],
595       [ "12-31-00:00",
596         "12-31Z" ],
597     ]
598     targets.each do | data, expected |
599       assert_equal( expected, SOAP::SOAPGMonthDay.new( data ).to_s )
600     end
601   end
602
603   def test_SOAPGDay
604     o = SOAP::SOAPGDay.new
605     assert_equal( XSD::Namespace, o.typeNamespace )
606     assert_equal( XSD::GDayLiteral, o.typeName )
607     assert_equal( nil, o.data )
608     assert_equal( true, o.isNil )
609
610     targets = [
611       "18Z",
612       "01Z",
613       "31Z",
614       "31+09:00",
615       "31+00:01",
616       "31-00:01",
617       "31-23:59",
618       "31+13:30",
619     ]
620     targets.each do | str |
621       assertParsedResult( SOAP::SOAPGDay, str )
622     end
623
624     targets = [
625       [ "31",
626         "31Z" ],
627       [ "31+00:00",
628         "31Z" ],
629       [ "31-00:00",
630         "31Z" ],
631     ]
632     targets.each do | data, expected |
633       assert_equal( expected, SOAP::SOAPGDay.new( data ).to_s )
634     end
635   end
636
637   def test_SOAPGMonth
638     o = SOAP::SOAPGMonth.new
639     assert_equal( XSD::Namespace, o.typeNamespace )
640     assert_equal( XSD::GMonthLiteral, o.typeName )
641     assert_equal( nil, o.data )
642     assert_equal( true, o.isNil )
643
644     targets = [
645       "05Z",
646       "01Z",
647       "12Z",
648       "12+09:00",
649       "12+00:01",
650       "12-00:01",
651       "12-23:59",
652       "12+13:30",
653     ]
654     targets.each do | str |
655       assertParsedResult( SOAP::SOAPGMonth, str )
656     end
657
658     targets = [
659       [ "12",
660         "12Z" ],
661       [ "12+00:00",
662         "12Z" ],
663       [ "12-00:00",
664         "12Z" ],
665     ]
666     targets.each do | data, expected |
667       assert_equal( expected, SOAP::SOAPGMonth.new( data ).to_s )
668     end
669   end
670
671   def test_SOAPHexBinary
672     o = SOAP::SOAPHexBinary.new
673     assert_equal( XSD::Namespace, o.typeNamespace )
674     assert_equal( XSD::HexBinaryLiteral, o.typeName )
675     assert_equal( nil, o.data )
676     assert_equal( true, o.isNil )
677
678     targets = [
679       "abcdef",
680       "�Ȃ�,
681       "\0",
682       "",
683     ]
684     targets.each do | str |
685       assert_equal( str, SOAP::SOAPHexBinary.new( str ).toString )
686       assert_equal( str.unpack( "H*" )[ 0 ].tr( 'a-f', 'A-F' ),
687         SOAP::SOAPHexBinary.new( str ).data )
688       o = SOAP::SOAPHexBinary.new
689       o.setEncoded( str.unpack( "H*" )[ 0 ].tr( 'a-f', 'A-F' ))
690       assert_equal( str, o.toString )
691       o.setEncoded( str.unpack( "H*" )[ 0 ].tr( 'A-F', 'a-f' ))
692       assert_equal( str, o.toString )
693     end
694
695     targets = [
696       "0FG7",
697       "0fg7",
698     ]
699     targets.each do | d |
700       assert_exception( XSD::ValueSpaceError, d.to_s ) do
701         o = SOAP::SOAPHexBinary.new
702         o.setEncoded( d )
703         p o.toString
704       end
705     end
706   end
707
708   def test_SOAPBase64Binary
709     o = SOAP::SOAPBase64.new
710     assert_equal( SOAP::EncodingNamespace, o.typeNamespace )
711     assert_equal( SOAP::Base64Literal, o.typeName )
712     assert_equal( nil, o.data )
713     assert_equal( true, o.isNil )
714
715     targets = [
716       "abcdef",
717       "�Ȃ�,
718       "\0",
719       "",
720     ]
721     targets.each do | str |
722       assert_equal( str, SOAP::SOAPBase64.new( str ).toString )
723       assert_equal( [ str ].pack( "m" ).chomp, SOAP::SOAPBase64.new( str ).data )
724       o = SOAP::SOAPBase64.new
725       o.setEncoded( [ str ].pack( "m" ).chomp )
726       assert_equal( str, o.toString )
727     end
728
729     targets = [
730       "-",
731       "*",
732     ]
733     targets.each do | d |
734       assert_exception( XSD::ValueSpaceError, d.to_s ) do
735         o = SOAP::SOAPBase64.new
736         o.setEncoded( d )
737         p o.toString
738       end
739     end
740   end
741
742   def test_SOAPAnyURI
743     o = SOAP::SOAPAnyURI.new
744     assert_equal( XSD::Namespace, o.typeNamespace )
745     assert_equal( XSD::AnyURILiteral, o.typeName )
746     assert_equal( nil, o.data )
747     assert_equal( true, o.isNil )
748
749     # Too few tests here I know.  Believe uri module. :)
750     targets = [
751       "foo",
752       "http://foo",
753       "http://foo/bar/baz",
754       "http://foo/bar#baz",
755       "http://foo/bar%20%20?a+b",
756       "HTTP://FOO/BAR%20%20?A+B",
757     ]
758     targets.each do | str |
759       assertParsedResult( SOAP::SOAPAnyURI, str )
760     end
761   end
762
763   def test_SOAPQName
764     o = SOAP::SOAPQName.new
765     assert_equal( XSD::Namespace, o.typeNamespace )
766     assert_equal( XSD::QNameLiteral, o.typeName )
767     assert_equal( nil, o.data )
768     assert_equal( true, o.isNil )
769
770     # More strict test is needed but current implementation allows all non-':'
771     # chars like ' ', C0 or C1...
772     targets = [
773       "foo",
774       "foo:bar",
775       "a:b",
776     ]
777     targets.each do | str |
778       assertParsedResult( SOAP::SOAPQName, str )
779     end
780   end
781
782
783   ###
784   ## Derived types
785   #
786
787   def test_SOAPInteger
788     o = SOAP::SOAPInteger.new
789     assert_equal( XSD::Namespace, o.typeNamespace )
790     assert_equal( XSD::IntegerLiteral, o.typeName )
791     assert_equal( nil, o.data )
792     assert_equal( true, o.isNil )
793
794     targets = [
795       0,
796       1000000000,
797       -9999999999,
798       12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,
799       12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,
800       -1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789,
801     ]
802     targets.each do | int |
803       assert_equal( int, SOAP::SOAPInteger.new( int ).data )
804     end
805
806     targets = [
807       "0",
808       "1000000000",
809       "-9999999999",
810       "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
811       "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
812       "-1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
813     ]
814     targets.each do | str |
815       assert_equal( str, SOAP::SOAPInteger.new( str ).to_s )
816     end
817
818     targets = [
819       [ "-0", "0" ],
820       [ "+0", "0" ],
821       [ "000123", "123" ],
822       [ "-000123", "-123" ],
823       [
824         "+12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
825         "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
826       ],
827     ]
828     targets.each do | data, expected |
829       assert_equal( expected, SOAP::SOAPInteger.new( data ).to_s )
830     end
831
832     targets = [
833       "0.0",
834       "-5.2",
835       "0.000000000000a",
836       "+-5",
837       "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890."
838     ]
839     targets.each do | d |
840       assert_exception( XSD::ValueSpaceError ) do
841         SOAP::SOAPInteger.new( d )
842       end
843     end
844   end
845
846   def test_SOAPLong
847     o = SOAP::SOAPLong.new
848     assert_equal( XSD::Namespace, o.typeNamespace )
849     assert_equal( XSD::LongLiteral, o.typeName )
850     assert_equal( nil, o.data )
851     assert_equal( true, o.isNil )
852
853     targets = [
854       0,
855       123,
856       -123,
857       9223372036854775807,
858       -9223372036854775808,
859     ]
860     targets.each do | lng |
861       assert_equal( lng, SOAP::SOAPLong.new( lng ).data )
862     end
863
864     targets = [
865       "0",
866       "123",
867       "-123",
868       "9223372036854775807",
869       "-9223372036854775808",
870     ]
871     targets.each do | str |
872       assert_equal( str, SOAP::SOAPLong.new( str ).to_s )
873     end
874
875     targets = [
876       [ "-0", "0" ],
877       [ "+0", "0" ],
878       [ "000123", "123" ],
879       [ "-000123", "-123" ],
880     ]
881     targets.each do | data, expected |
882       assert_equal( expected, SOAP::SOAPLong.new( data ).to_s )
883     end
884
885     targets = [
886       9223372036854775808,
887       -9223372036854775809,
888       "0.0",
889       "-5.2",
890       "0.000000000000a",
891       "+-5",
892     ]
893     targets.each do | d |
894       assert_exception( XSD::ValueSpaceError ) do
895         SOAP::SOAPLong.new( d )
896       end
897     end
898   end
899
900   def test_SOAPInt
901     o = SOAP::SOAPInt.new
902     assert_equal( XSD::Namespace, o.typeNamespace )
903     assert_equal( XSD::IntLiteral, o.typeName )
904     assert_equal( nil, o.data )
905     assert_equal( true, o.isNil )
906
907     targets = [
908       0,
909       123,
910       -123,
911       2147483647,
912       -2147483648,
913     ]
914     targets.each do | lng |
915       assert_equal( lng, SOAP::SOAPInt.new( lng ).data )
916     end
917
918     targets = [
919       "0",
920       "123",
921       "-123",
922       "2147483647",
923       "-2147483648",
924     ]
925     targets.each do | str |
926       assert_equal( str, SOAP::SOAPInt.new( str ).to_s )
927     end
928
929     targets = [
930       [ "-0", "0" ],
931       [ "+0", "0" ],
932       [ "000123", "123" ],
933       [ "-000123", "-123" ],
934     ]
935     targets.each do | data, expected |
936       assert_equal( expected, SOAP::SOAPInt.new( data ).to_s )
937     end
938
939     targets = [
940       2147483648,
941       -2147483649,
942       "0.0",
943       "-5.2",
944       "0.000000000000a",
945       "+-5",
946     ]
947     targets.each do | d |
948       assert_exception( XSD::ValueSpaceError ) do
949         SOAP::SOAPInt.new( d )
950       end
951     end
952   end
953 end
954
955 if $0 == __FILE__
956   testrunner = RUNIT::CUI::TestRunner.new
957   if ARGV.size == 0
958     suite = TestSOAP.suite
959   else
960     suite = RUNIT::TestSuite.new
961     ARGV.each do | testmethod |
962       suite.add_test( TestSOAP.new( testmethod ))
963     end
964   end
965   testrunner.run(suite)
966 end
Note: See TracBrowser for help on using the browser.