PageRenderTime 49ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/jruby-1.7.3/test/externals/ruby1.8/soap/test_basetype.rb

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