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

root/tags/RELEASE_1_4_7/test/xsd_ut.rb

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