PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/library/xslt/test/unit/xm_xslt_test_character_map.e

http://github.com/gobo-eiffel/gobo
Specman e | 398 lines | 344 code | 35 blank | 19 comment | 0 complexity | 41f5f15bbb715fd466bb5f1dbadbb31e MD5 | raw file
  1. note
  2. description:
  3. "[
  4. Test character maps and other serialization features.
  5. This class tests various aspects of serialization.
  6. Principally, use of character maps, but also CDATA sections
  7. and user-written QName output methods.
  8. ]"
  9. library: "Gobo Eiffel XSLT test suite"
  10. copyright: "Copyright (c) 2004-2018, Colin Adams and others"
  11. license: "MIT License"
  12. date: "$Date$"
  13. revision: "$Revision$"
  14. class XM_XSLT_TEST_CHARACTER_MAP
  15. inherit
  16. XM_XSLT_TEST_ROUTINES
  17. XM_XPATH_SHARED_CONFORMANCE
  18. XM_XPATH_SHARED_NAME_POOL
  19. XM_XPATH_STANDARD_NAMESPACES
  20. XM_XSLT_SHARED_EMITTER_FACTORY
  21. create
  22. make_default
  23. feature -- Access
  24. expected_result: STRING = "<?xml version=%"1.0%" encoding=%"UTF-8%"?><setProperty name=%"user%" property=%"id%" value='<%%= %"id%" + idValue %%>'/>"
  25. -- Expected result for `test_character_map'
  26. feature -- Test
  27. test_xml_character_map
  28. -- Test use-character-maps with method=xml
  29. local
  30. l_transformer_factory: XM_XSLT_TRANSFORMER_FACTORY
  31. l_configuration: XM_XSLT_CONFIGURATION
  32. l_error_listener: XM_XSLT_TESTING_ERROR_LISTENER
  33. l_transformer: detachable XM_XSLT_TRANSFORMER
  34. l_uri_source: XM_XSLT_URI_SOURCE
  35. l_output: XM_OUTPUT
  36. l_result: XM_XSLT_TRANSFORMATION_RESULT
  37. l_last_output: detachable STRING
  38. do
  39. conformance.set_basic_xslt_processor
  40. create l_configuration.make_with_defaults
  41. create l_error_listener.make (l_configuration.recovery_policy)
  42. l_configuration.set_error_listener (l_error_listener)
  43. create l_transformer_factory.make (l_configuration)
  44. create l_uri_source.make (character_map_xsl_uri.full_reference)
  45. l_transformer_factory.create_new_transformer (l_uri_source, dummy_uri)
  46. assert ("Stylesheet compiled without errors", not l_transformer_factory.was_error)
  47. l_transformer := l_transformer_factory.created_transformer
  48. assert ("transformer", l_transformer /= Void)
  49. check asserted_above: l_transformer /= Void then end
  50. l_transformer.set_initial_template ("first")
  51. assert ("Initial template set", l_transformer.initial_template /= Void)
  52. create l_output
  53. l_output.set_output_to_string
  54. create l_result.make (l_output, "string:")
  55. l_transformer.transform (Void, l_result)
  56. assert ("Transform successful", not l_transformer.is_error)
  57. l_last_output := l_output.last_output
  58. assert ("set_output_to_string", l_last_output /= Void)
  59. check asserted_above: l_last_output /= Void then end
  60. assert ("Correct result", STRING_.same_string (l_last_output, expected_result))
  61. end
  62. test_html_character_map
  63. -- Test use-character-maps with method=html
  64. local
  65. l_transformer_factory: XM_XSLT_TRANSFORMER_FACTORY
  66. l_configuration: XM_XSLT_CONFIGURATION
  67. l_transformer: detachable XM_XSLT_TRANSFORMER
  68. l_uri_source: XM_XSLT_URI_SOURCE
  69. l_output: XM_OUTPUT
  70. l_result: XM_XSLT_TRANSFORMATION_RESULT
  71. l_last_output: detachable STRING
  72. l_last_utf8_string: like last_utf8_string
  73. do
  74. conformance.set_basic_xslt_processor
  75. create l_configuration.make_with_defaults
  76. l_configuration.set_line_numbering (True)
  77. create l_transformer_factory.make (l_configuration)
  78. create l_uri_source.make (character_map2_xsl_uri.full_reference)
  79. l_transformer_factory.create_new_transformer (l_uri_source, dummy_uri)
  80. assert ("Stylesheet compiled without errors", not l_transformer_factory.was_error)
  81. l_transformer := l_transformer_factory.created_transformer
  82. assert ("transformer", l_transformer /= Void)
  83. check asserted_above: l_transformer /= Void then end
  84. l_transformer.set_initial_template ("first")
  85. assert ("Initial template set", l_transformer.initial_template /= Void)
  86. create l_output
  87. l_output.set_output_to_string
  88. create l_result.make (l_output, "string:")
  89. l_transformer.transform (Void, l_result)
  90. assert ("Transform successful", not l_transformer.is_error)
  91. read_utf8_results_file (character_map2_results_filename)
  92. l_last_utf8_string := last_utf8_string
  93. assert ("postcondition_of_read_utf8_results_file", l_last_utf8_string /= Void)
  94. check asserted_above: l_last_utf8_string /= Void then end
  95. l_last_output := l_output.last_output
  96. assert ("set_output_to_string", l_last_output /= Void)
  97. check asserted_above: l_last_output /= Void then end
  98. assert ("Correct result", STRING_.same_string (l_last_output, l_last_utf8_string))
  99. end
  100. test_xhtml_character_map
  101. -- Test use-character-maps with method=xhtml
  102. local
  103. l_transformer_factory: XM_XSLT_TRANSFORMER_FACTORY
  104. l_configuration: XM_XSLT_CONFIGURATION
  105. l_transformer: detachable XM_XSLT_TRANSFORMER
  106. l_uri_source: XM_XSLT_URI_SOURCE
  107. l_output: XM_OUTPUT
  108. l_result: XM_XSLT_TRANSFORMATION_RESULT
  109. l_last_output: detachable STRING
  110. l_last_utf8_string: like last_utf8_string
  111. do
  112. conformance.set_basic_xslt_processor
  113. create l_configuration.make_with_defaults
  114. l_configuration.set_line_numbering (True)
  115. create l_transformer_factory.make (l_configuration)
  116. create l_uri_source.make (character_map4_xsl_uri.full_reference)
  117. l_transformer_factory.create_new_transformer (l_uri_source, dummy_uri)
  118. assert ("Stylesheet compiled without errors", not l_transformer_factory.was_error)
  119. l_transformer := l_transformer_factory.created_transformer
  120. assert ("transformer", l_transformer /= Void)
  121. check asserted_above: l_transformer /= Void then end
  122. l_transformer.set_initial_template ("first")
  123. assert ("Initial template set", l_transformer.initial_template /= Void)
  124. create l_output
  125. l_output.set_output_to_string
  126. create l_result.make (l_output, "string:")
  127. l_transformer.transform (Void, l_result)
  128. assert ("Transform successful", not l_transformer.is_error)
  129. read_utf8_results_file (character_map4_results_filename)
  130. l_last_utf8_string := last_utf8_string
  131. assert ("postcondition_of_read_utf8_results_file", l_last_utf8_string /= Void)
  132. check asserted_above: l_last_utf8_string /= Void then end
  133. l_last_output := l_output.last_output
  134. assert ("set_output_to_string", l_last_output /= Void)
  135. check asserted_above: l_last_output /= Void then end
  136. assert ("Correct result", STRING_.same_string (l_last_output, l_last_utf8_string))
  137. end
  138. test_text_character_map
  139. -- Test use-character-maps with method=text
  140. local
  141. l_transformer_factory: XM_XSLT_TRANSFORMER_FACTORY
  142. l_configuration: XM_XSLT_CONFIGURATION
  143. l_transformer: detachable XM_XSLT_TRANSFORMER
  144. l_uri_source: XM_XSLT_URI_SOURCE
  145. l_output: XM_OUTPUT
  146. l_result: XM_XSLT_TRANSFORMATION_RESULT
  147. l_last_output: detachable STRING
  148. l_last_utf8_string: like last_utf8_string
  149. do
  150. conformance.set_basic_xslt_processor
  151. create l_configuration.make_with_defaults
  152. l_configuration.set_line_numbering (True)
  153. create l_transformer_factory.make (l_configuration)
  154. create l_uri_source.make (character_map5_xsl_uri.full_reference)
  155. l_transformer_factory.create_new_transformer (l_uri_source, dummy_uri)
  156. assert ("Stylesheet compiled without errors", not l_transformer_factory.was_error)
  157. l_transformer := l_transformer_factory.created_transformer
  158. assert ("transformer", l_transformer /= Void)
  159. check asserted_above: l_transformer /= Void then end
  160. l_transformer.set_initial_template ("first")
  161. assert ("Initial template set", l_transformer.initial_template /= Void)
  162. create l_output
  163. l_output.set_output_to_string
  164. create l_result.make (l_output, "string:")
  165. l_transformer.transform (Void, l_result)
  166. assert ("Transform successful", not l_transformer.is_error)
  167. read_utf8_results_file (character_map5_results_filename)
  168. l_last_utf8_string := last_utf8_string
  169. assert ("postcondition_of_read_utf8_results_file", l_last_utf8_string /= Void)
  170. check asserted_above: l_last_utf8_string /= Void then end
  171. l_last_output := l_output.last_output
  172. assert ("set_output_to_string", l_last_output /= Void)
  173. check asserted_above: l_last_output /= Void then end
  174. assert ("Correct result", STRING_.same_string (l_last_output, l_last_utf8_string))
  175. end
  176. test_xhtml_character_map_with_cdata
  177. -- Test use-character-maps with method=xhtml
  178. local
  179. l_transformer_factory: XM_XSLT_TRANSFORMER_FACTORY
  180. l_configuration: XM_XSLT_CONFIGURATION
  181. l_transformer: detachable XM_XSLT_TRANSFORMER
  182. l_uri_source: XM_XSLT_URI_SOURCE
  183. l_output: XM_OUTPUT
  184. l_result: XM_XSLT_TRANSFORMATION_RESULT
  185. l_last_output: detachable STRING
  186. l_last_utf8_string: like last_utf8_string
  187. do
  188. conformance.set_basic_xslt_processor
  189. create l_configuration.make_with_defaults
  190. l_configuration.set_line_numbering (True)
  191. create l_transformer_factory.make (l_configuration)
  192. create l_uri_source.make (character_map6_xsl_uri.full_reference)
  193. l_transformer_factory.create_new_transformer (l_uri_source, dummy_uri)
  194. assert ("Stylesheet compiled without errors", not l_transformer_factory.was_error)
  195. l_transformer := l_transformer_factory.created_transformer
  196. assert ("transformer", l_transformer /= Void)
  197. check asserted_above: l_transformer /= Void then end
  198. l_transformer.set_initial_template ("first")
  199. assert ("Initial template set", l_transformer.initial_template /= Void)
  200. create l_output
  201. l_output.set_output_to_string
  202. create l_result.make (l_output, "string:")
  203. l_transformer.transform (Void, l_result)
  204. assert ("Transform successful", not l_transformer.is_error)
  205. read_utf8_results_file (character_map6_results_filename)
  206. l_last_utf8_string := last_utf8_string
  207. assert ("postcondition_of_read_utf8_results_file", l_last_utf8_string /= Void)
  208. check asserted_above: l_last_utf8_string /= Void then end
  209. l_last_output := l_output.last_output
  210. assert ("set_output_to_string", l_last_output /= Void)
  211. check asserted_above: l_last_output /= Void then end
  212. assert ("Correct result", STRING_.same_string (l_last_output, l_last_utf8_string))
  213. end
  214. test_qname_method
  215. -- Test use of a QName output method.
  216. local
  217. l_transformer_factory: XM_XSLT_TRANSFORMER_FACTORY
  218. l_configuration: XM_XSLT_CONFIGURATION
  219. l_transformer: detachable XM_XSLT_TRANSFORMER
  220. l_uri_source: XM_XSLT_URI_SOURCE
  221. l_output: XM_OUTPUT
  222. l_result: XM_XSLT_TRANSFORMATION_RESULT
  223. l_emitter_factory: XM_XSLT_GEXSLT_EXAMPLES_EMITTER_FACTORY
  224. l_last_output: detachable STRING
  225. l_last_utf8_string: like last_utf8_string
  226. do
  227. conformance.set_basic_xslt_processor
  228. create l_configuration.make_with_defaults
  229. l_configuration.set_line_numbering (True)
  230. create l_emitter_factory.make
  231. emitter_factory.register_extension_emitter_factory (l_emitter_factory)
  232. create l_transformer_factory.make (l_configuration)
  233. create l_uri_source.make (qname_output_xsl_uri.full_reference)
  234. l_transformer_factory.create_new_transformer (l_uri_source, dummy_uri)
  235. assert ("Stylesheet compiled without errors", not l_transformer_factory.was_error)
  236. l_transformer := l_transformer_factory.created_transformer
  237. assert ("transformer", l_transformer /= Void)
  238. check asserted_above: l_transformer /= Void then end
  239. l_transformer.set_initial_template ("first")
  240. assert ("Initial template set", l_transformer.initial_template /= Void)
  241. create l_output
  242. l_output.set_output_to_string
  243. create l_result.make (l_output, "string:")
  244. l_transformer.transform (Void, l_result)
  245. assert ("Transform successful", not l_transformer.is_error)
  246. read_utf8_results_file (qname_output_results_filename)
  247. l_last_utf8_string := last_utf8_string
  248. assert ("postcondition_of_read_utf8_results_file", l_last_utf8_string /= Void)
  249. check asserted_above: l_last_utf8_string /= Void then end
  250. l_last_output := l_output.last_output
  251. assert ("set_output_to_string", l_last_output /= Void)
  252. check asserted_above: l_last_output /= Void then end
  253. assert ("Correct result", STRING_.same_string (l_last_output, l_last_utf8_string))
  254. end
  255. feature {NONE} -- Implementation
  256. character_map6_results_filename: STRING
  257. -- Name of file containing expected results for `test_xhtml_character_map_with_cdata'
  258. once
  259. Result := "character_map6.out"
  260. ensure
  261. character_map6_results_filename_not_void: Result /= Void
  262. character_map6_results_filename_not_empty: not Result.is_empty
  263. end
  264. character_map2_results_filename: STRING
  265. -- Name of file containing expected results for `test_html_character_map'
  266. once
  267. Result := "character_map2.out"
  268. ensure
  269. character_map2_results_filename_not_void: Result /= Void
  270. character_map2_results_filename_not_empty: not Result.is_empty
  271. end
  272. character_map5_results_filename: STRING
  273. -- Name of file containing expected results for `test_test_character_map'
  274. once
  275. Result := "character_map5.out"
  276. ensure
  277. character_map5_results_filename_not_void: Result /= Void
  278. character_map5_results_filename_not_empty: not Result.is_empty
  279. end
  280. character_map4_results_filename: STRING
  281. -- Name of file containing expected results for `test_xhtml_character_map'
  282. once
  283. Result := "character_map4.out"
  284. ensure
  285. character_map4_results_filename_not_void: Result /= Void
  286. character_map4_results_filename_not_empty: not Result.is_empty
  287. end
  288. qname_output_results_filename: STRING
  289. -- Name of file containing expected results for `test_qname_method'
  290. once
  291. Result := "qname_output.out"
  292. ensure
  293. qname_output_results_filename_not_void: Result /= Void
  294. qname_output_results_filename_not_empty: not Result.is_empty
  295. end
  296. dummy_uri: UT_URI
  297. -- Dummy URI
  298. once
  299. create Result.make ("dummy:")
  300. ensure
  301. dummy_uri_is_absolute: Result /= Void and then Result.is_absolute
  302. end
  303. character_map_xsl_uri: UT_URI
  304. -- URI of file 'character_map.xsl'
  305. local
  306. l_path: STRING
  307. once
  308. l_path := file_system.pathname (data_dirname, "character_map.xsl")
  309. Result := File_uri.filename_to_uri (l_path)
  310. ensure
  311. character_map_uri_not_void: Result /= Void
  312. end
  313. character_map2_xsl_uri: UT_URI
  314. -- URI of file 'character_map2.xsl'
  315. local
  316. l_path: STRING
  317. once
  318. l_path := file_system.pathname (data_dirname, "character_map2.xsl")
  319. Result := File_uri.filename_to_uri (l_path)
  320. ensure
  321. character_map2_uri_not_void: Result /= Void
  322. end
  323. character_map4_xsl_uri: UT_URI
  324. -- URI of file 'character_map4.xsl'
  325. local
  326. l_path: STRING
  327. once
  328. l_path := file_system.pathname (data_dirname, "character_map4.xsl")
  329. Result := File_uri.filename_to_uri (l_path)
  330. ensure
  331. character_map4_uri_not_void: Result /= Void
  332. end
  333. character_map5_xsl_uri: UT_URI
  334. -- URI of file 'character_map5.xsl'
  335. local
  336. l_path: STRING
  337. once
  338. l_path := file_system.pathname (data_dirname, "character_map5.xsl")
  339. Result := File_uri.filename_to_uri (l_path)
  340. ensure
  341. character_map5_uri_not_void: Result /= Void
  342. end
  343. character_map6_xsl_uri: UT_URI
  344. -- URI of file 'character_map6.xsl'
  345. local
  346. l_path: STRING
  347. once
  348. l_path := file_system.pathname (data_dirname, "character_map6.xsl")
  349. Result := File_uri.filename_to_uri (l_path)
  350. ensure
  351. character_map6_uri_not_void: Result /= Void
  352. end
  353. qname_output_xsl_uri: UT_URI
  354. -- URI of file 'qname_output.xsl'
  355. local
  356. l_path: STRING
  357. once
  358. l_path := file_system.pathname (data_dirname, "qname_output.xsl")
  359. Result := File_uri.filename_to_uri (l_path)
  360. ensure
  361. qname_output_uri_not_void: Result /= Void
  362. end
  363. end