PageRenderTime 27ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/library/xslt/test/unit/xm_xslt_test_fragments.e

http://github.com/gobo-eiffel/gobo
Specman e | 400 lines | 349 code | 32 blank | 19 comment | 0 complexity | 833608834a60ef7424d69e3c3da35632 MD5 | raw file
  1. note
  2. description:
  3. "[
  4. Test use of fragment identifiers on source and stylesheet URIs.
  5. Also, stylesheet chaining and xml-stylesheet PI
  6. ]"
  7. library: "Gobo Eiffel XSLT test suite"
  8. copyright: "Copyright (c) 2005-2018, Colin Adams and others"
  9. license: "MIT License"
  10. date: "$Date$"
  11. revision: "$Revision$"
  12. class XM_XSLT_TEST_FRAGMENTS
  13. inherit
  14. TS_TEST_CASE
  15. KL_IMPORTED_STRING_ROUTINES
  16. XM_XPATH_SHARED_CONFORMANCE
  17. XM_XPATH_SHARED_NAME_POOL
  18. XM_RESOLVER_FACTORY
  19. XM_XSLT_CONFIGURATION_CONSTANTS
  20. create
  21. make_default
  22. feature -- Test
  23. test_shorthand_pointer
  24. -- Transform books3.xml with books1.xsl.
  25. local
  26. l_transformer_factory: XM_XSLT_TRANSFORMER_FACTORY
  27. l_configuration: XM_XSLT_CONFIGURATION
  28. l_error_listener: XM_XSLT_TESTING_ERROR_LISTENER
  29. l_transformer: detachable XM_XSLT_TRANSFORMER
  30. l_uri_source, l_second_uri_source: XM_XSLT_URI_SOURCE
  31. l_output: XM_OUTPUT
  32. l_result: XM_XSLT_TRANSFORMATION_RESULT
  33. l_last_output: detachable STRING
  34. do
  35. conformance.set_basic_xslt_processor
  36. create l_configuration.make_with_defaults
  37. create l_error_listener.make (l_configuration.recovery_policy)
  38. l_configuration.set_error_listener (l_error_listener)
  39. l_configuration.set_string_mode_ascii -- make_with_defaults sets to mixed
  40. l_configuration.use_tiny_tree_model (False)
  41. create l_transformer_factory.make (l_configuration)
  42. create l_uri_source.make (books1_xsl_uri.full_reference)
  43. l_transformer_factory.create_new_transformer (l_uri_source, dummy_uri)
  44. assert ("Stylesheet compiled without errors", not l_transformer_factory.was_error)
  45. l_transformer := l_transformer_factory.created_transformer
  46. assert ("transformer", l_transformer /= Void)
  47. check asserted_above: l_transformer /= Void then end
  48. create l_second_uri_source.make (books3_xml_uri.full_reference + "#S")
  49. create l_output
  50. l_output.set_output_to_string
  51. create l_result.make (l_output, "string:")
  52. l_transformer.transform (l_second_uri_source, l_result)
  53. assert ("Transform successful", not l_transformer.is_error)
  54. l_last_output := l_output.last_output
  55. assert ("set_output_to_string", l_last_output /= Void)
  56. check asserted_above: l_last_output /= Void then end
  57. assert ("Correct output", STRING_.same_string (l_last_output, expected_output_1))
  58. end
  59. test_element_scheme_pointer
  60. -- Transform books3.xml with books1.xsl.
  61. local
  62. l_transformer_factory: XM_XSLT_TRANSFORMER_FACTORY
  63. l_configuration: XM_XSLT_CONFIGURATION
  64. l_error_listener: XM_XSLT_TESTING_ERROR_LISTENER
  65. l_transformer: detachable XM_XSLT_TRANSFORMER
  66. l_uri_source, l_second_uri_source: XM_XSLT_URI_SOURCE
  67. l_output: XM_OUTPUT
  68. l_result: XM_XSLT_TRANSFORMATION_RESULT
  69. l_last_output: detachable STRING
  70. do
  71. conformance.set_basic_xslt_processor
  72. create l_configuration.make_with_defaults
  73. create l_error_listener.make (l_configuration.recovery_policy)
  74. l_configuration.set_error_listener (l_error_listener)
  75. l_configuration.set_string_mode_ascii -- make_with_defaults sets to mixed
  76. l_configuration.use_tiny_tree_model (False)
  77. create l_transformer_factory.make (l_configuration)
  78. create l_uri_source.make (books1_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. create l_second_uri_source.make (books3_xml_uri.full_reference + "#element(/1/1/1/1)")
  85. create l_output
  86. l_output.set_output_to_string
  87. create l_result.make (l_output, "string:")
  88. l_transformer.transform (l_second_uri_source, l_result)
  89. assert ("Transform successful", not l_transformer.is_error)
  90. l_last_output := l_output.last_output
  91. assert ("set_output_to_string", l_last_output /= Void)
  92. check asserted_above: l_last_output /= Void then end
  93. assert ("Correct output", STRING_.same_string (l_last_output, expected_output_1))
  94. end
  95. test_gexslt_xpath_scheme_pointer
  96. -- Transform books3.xml with books1.xsl.
  97. local
  98. l_transformer_factory: XM_XSLT_TRANSFORMER_FACTORY
  99. l_configuration: XM_XSLT_CONFIGURATION
  100. l_error_listener: XM_XSLT_TESTING_ERROR_LISTENER
  101. l_transformer: detachable XM_XSLT_TRANSFORMER
  102. l_uri_source, l_second_uri_source: XM_XSLT_URI_SOURCE
  103. l_output: XM_OUTPUT
  104. l_result: XM_XSLT_TRANSFORMATION_RESULT
  105. l_last_output: detachable STRING
  106. do
  107. conformance.set_basic_xslt_processor
  108. create l_configuration.make_with_defaults
  109. create l_error_listener.make (l_configuration.recovery_policy)
  110. l_configuration.set_error_listener (l_error_listener)
  111. l_configuration.set_string_mode_ascii -- make_with_defaults sets to mixed
  112. l_configuration.use_tiny_tree_model (False)
  113. l_configuration.set_recovery_policy (Do_not_recover)
  114. create l_transformer_factory.make (l_configuration)
  115. create l_uri_source.make (books1_xsl_uri.full_reference)
  116. l_transformer_factory.create_new_transformer (l_uri_source, dummy_uri)
  117. assert ("Stylesheet compiled without errors", not l_transformer_factory.was_error)
  118. l_transformer := l_transformer_factory.created_transformer
  119. assert ("transformer", l_transformer /= Void)
  120. check asserted_above: l_transformer /= Void then end
  121. create l_second_uri_source.make (books3_xml_uri.full_reference + "#xmlns(gexslt=http://www.gobosoft.com/eiffel/gobo/gexslt/extension)gexslt:xpath(/descendant::AUTHOR%%5B1%%5D)")
  122. create l_output
  123. l_output.set_output_to_string
  124. create l_result.make (l_output, "string:")
  125. l_transformer.transform (l_second_uri_source, l_result)
  126. assert ("Transform successful", not l_transformer.is_error)
  127. l_last_output := l_output.last_output
  128. assert ("set_output_to_string", l_last_output /= Void)
  129. check asserted_above: l_last_output /= Void then end
  130. assert ("Correct output", STRING_.same_string (l_last_output, expected_output_2))
  131. end
  132. test_embedded_stylesheet
  133. -- Transform embedded.xml by itself, without using xml-stylesheet-pi
  134. local
  135. l_transformer_factory: XM_XSLT_TRANSFORMER_FACTORY
  136. l_configuration: XM_XSLT_CONFIGURATION
  137. l_error_listener: XM_XSLT_TESTING_ERROR_LISTENER
  138. l_transformer: detachable XM_XSLT_TRANSFORMER
  139. l_uri_source, l_second_uri_source: XM_XSLT_URI_SOURCE
  140. l_output: XM_OUTPUT
  141. l_result: XM_XSLT_TRANSFORMATION_RESULT
  142. l_last_output: detachable STRING
  143. do
  144. conformance.set_basic_xslt_processor
  145. create l_configuration.make_with_defaults
  146. create l_error_listener.make (l_configuration.recovery_policy)
  147. l_configuration.set_error_listener (l_error_listener)
  148. l_configuration.set_string_mode_ascii
  149. l_configuration.use_tiny_tree_model (False)
  150. create l_transformer_factory.make (l_configuration)
  151. create l_uri_source.make (embedded_xml_uri.full_reference + "#style1")
  152. l_transformer_factory.create_new_transformer (l_uri_source, dummy_uri)
  153. assert ("Stylesheet compiled without errors", not l_transformer_factory.was_error)
  154. l_transformer := l_transformer_factory.created_transformer
  155. assert ("transformer", l_transformer /= Void)
  156. check asserted_above: l_transformer /= Void then end
  157. create l_second_uri_source.make (embedded_xml_uri.full_reference)
  158. create l_output
  159. l_output.set_output_to_string
  160. create l_result.make (l_output, "string:")
  161. l_transformer.transform (l_second_uri_source, l_result)
  162. assert ("Transform successful", not l_transformer.is_error)
  163. l_last_output := l_output.last_output
  164. assert ("set_output_to_string", l_last_output /= Void)
  165. check asserted_above: l_last_output /= Void then end
  166. assert ("Correct output", l_last_output.count = 173)
  167. end
  168. test_xml_stylesheet_pi_one
  169. -- Transform processing_instructions.xml via PIs.
  170. -- For "print" medium, preferred style
  171. local
  172. l_transformer_factory: XM_XSLT_TRANSFORMER_FACTORY
  173. l_configuration: XM_XSLT_CONFIGURATION
  174. l_error_listener: XM_XSLT_TESTING_ERROR_LISTENER
  175. l_transformer: detachable XM_XSLT_TRANSFORMER
  176. l_stylesheet_source: detachable XM_XSLT_SOURCE
  177. l_uri_source: XM_XSLT_URI_SOURCE
  178. l_output: XM_OUTPUT
  179. l_result: XM_XSLT_TRANSFORMATION_RESULT
  180. l_chooser: XM_XSLT_PREFERRED_PI_CHOOSER
  181. l_last_output: detachable STRING
  182. do
  183. conformance.set_basic_xslt_processor
  184. create l_configuration.make_with_defaults
  185. create l_error_listener.make (l_configuration.recovery_policy)
  186. l_configuration.set_error_listener (l_error_listener)
  187. l_configuration.set_string_mode_ascii
  188. l_configuration.use_tiny_tree_model (False)
  189. create l_transformer_factory.make (l_configuration)
  190. create l_uri_source.make (processing_instructions_xml_uri.full_reference)
  191. create l_chooser.make
  192. l_stylesheet_source := l_transformer_factory.associated_stylesheet (l_uri_source.system_id, "print", l_chooser)
  193. assert ("Stylesheet found", l_stylesheet_source /= Void)
  194. check asserted_above: l_stylesheet_source /= Void then end
  195. l_transformer_factory.create_new_transformer (l_stylesheet_source, dummy_uri)
  196. assert ("Stylesheet compiled without errors", not l_transformer_factory.was_error)
  197. l_transformer := l_transformer_factory.created_transformer
  198. assert ("Transformer not void", l_transformer /= Void)
  199. check asserted_above: l_transformer /= Void then end
  200. create l_output
  201. l_output.set_output_to_string
  202. create l_result.make (l_output, "string:")
  203. l_transformer.transform (l_uri_source, l_result)
  204. assert ("Transform successful", not l_transformer.is_error)
  205. l_last_output := l_output.last_output
  206. assert ("set_output_to_string", l_last_output /= Void)
  207. check asserted_above: l_last_output /= Void then end
  208. assert ("Correct output", l_last_output.count = 309)
  209. end
  210. test_xml_stylesheet_pi_two
  211. -- Transform processing_instructions.xml via PIs.
  212. -- For "screen" and alternate style "Alternate"
  213. local
  214. l_transformer_factory: XM_XSLT_TRANSFORMER_FACTORY
  215. l_configuration: XM_XSLT_CONFIGURATION
  216. l_error_listener: XM_XSLT_TESTING_ERROR_LISTENER
  217. l_transformer: detachable XM_XSLT_TRANSFORMER
  218. l_stylesheet_source: detachable XM_XSLT_SOURCE
  219. l_uri_source: XM_XSLT_URI_SOURCE
  220. l_output: XM_OUTPUT
  221. l_result: XM_XSLT_TRANSFORMATION_RESULT
  222. l_chooser: XM_XSLT_PI_CHOOSER_BY_NAME
  223. l_last_output: detachable STRING
  224. do
  225. conformance.set_basic_xslt_processor
  226. create l_configuration.make_with_defaults
  227. create l_error_listener.make (l_configuration.recovery_policy)
  228. l_configuration.set_error_listener (l_error_listener)
  229. l_configuration.set_string_mode_ascii
  230. l_configuration.use_tiny_tree_model (False)
  231. create l_transformer_factory.make (l_configuration)
  232. create l_uri_source.make (processing_instructions_xml_uri.full_reference)
  233. create l_chooser.make ("Alternate")
  234. l_stylesheet_source := l_transformer_factory.associated_stylesheet (l_uri_source.system_id, "screen", l_chooser)
  235. assert ("Stylesheet found", l_stylesheet_source /= Void)
  236. check asserted_above: l_stylesheet_source /= Void then end
  237. l_transformer_factory.create_new_transformer (l_stylesheet_source, dummy_uri)
  238. assert ("Stylesheet compiled without errors", not l_transformer_factory.was_error)
  239. l_transformer := l_transformer_factory.created_transformer
  240. assert ("Transformer not void", l_transformer /= Void)
  241. check asserted_above: l_transformer /= Void then end
  242. create l_output
  243. l_output.set_output_to_string
  244. create l_result.make (l_output, "string:")
  245. l_transformer.transform (l_uri_source, l_result)
  246. assert ("Transform successful", not l_transformer.is_error)
  247. l_last_output := l_output.last_output
  248. assert ("set_output_to_string", l_last_output /= Void)
  249. check asserted_above: l_last_output /= Void then end
  250. assert ("Correct output", l_last_output.count = 295)
  251. end
  252. test_next_in_chain
  253. -- Test gexslt:next-in-chain
  254. local
  255. l_transformer_factory: XM_XSLT_TRANSFORMER_FACTORY
  256. l_configuration: XM_XSLT_CONFIGURATION
  257. l_error_listener: XM_XSLT_TESTING_ERROR_LISTENER
  258. l_transformer: detachable XM_XSLT_TRANSFORMER
  259. l_uri_source: XM_XSLT_URI_SOURCE
  260. l_output: XM_OUTPUT
  261. l_result: XM_XSLT_TRANSFORMATION_RESULT
  262. l_last_output: detachable STRING
  263. do
  264. conformance.set_basic_xslt_processor
  265. create l_configuration.make_with_defaults
  266. create l_error_listener.make (l_configuration.recovery_policy)
  267. l_configuration.set_error_listener (l_error_listener)
  268. l_configuration.set_string_mode_ascii -- make_with_defaults sets to mixed
  269. l_configuration.use_tiny_tree_model (False)
  270. create l_transformer_factory.make (l_configuration)
  271. create l_uri_source.make (example0_xsl_uri.full_reference)
  272. l_transformer_factory.create_new_transformer (l_uri_source, dummy_uri)
  273. assert ("Stylesheet compiled without errors", not l_transformer_factory.was_error)
  274. l_transformer := l_transformer_factory.created_transformer
  275. assert ("transformer", l_transformer /= Void)
  276. check asserted_above: l_transformer /= Void then end
  277. create l_output
  278. l_output.set_output_to_string
  279. create l_result.make (l_output, "string:")
  280. l_transformer.set_initial_template ("initial")
  281. l_transformer.transform (Void, l_result)
  282. assert ("Transform successful", not l_transformer.is_error)
  283. l_last_output := l_output.last_output
  284. assert ("set_output_to_string", l_last_output /= Void)
  285. check asserted_above: l_last_output /= Void then end
  286. assert ("Correct output", l_last_output.count = 81)
  287. end
  288. feature {NONE} -- Implementation
  289. data_dirname: STRING
  290. -- Name of directory containing schematron data files
  291. once
  292. Result := file_system.nested_pathname ("${GOBO}", <<"library", "xslt", "test", "unit", "data">>)
  293. Result := Execution_environment.interpreted_string (Result)
  294. ensure
  295. data_dirname_not_void: Result /= Void
  296. data_dirname_not_empty: not Result.is_empty
  297. end
  298. dummy_uri: UT_URI
  299. -- Dummy URI
  300. once
  301. create Result.make ("dummy:")
  302. ensure
  303. dummy_uri_is_absolute: Result /= Void and then Result.is_absolute
  304. end
  305. books1_xsl_uri: UT_URI
  306. -- URI of file 'books1.xsl'
  307. local
  308. l_path: STRING
  309. once
  310. l_path := file_system.pathname (data_dirname, "books1.xsl")
  311. Result := File_uri.filename_to_uri (l_path)
  312. ensure
  313. books1_xsl_uri_not_void: Result /= Void
  314. end
  315. xpath_data_dirname: STRING
  316. -- Name of directory containing XPath data files
  317. once
  318. Result := file_system.nested_pathname ("${GOBO}", <<"library", "xpath", "test", "unit", "data">>)
  319. Result := Execution_environment.interpreted_string (Result)
  320. ensure
  321. xpath_data_dirname_not_void: Result /= Void
  322. xpath_data_dirname_not_empty: not Result.is_empty
  323. end
  324. books3_xml_uri: UT_URI
  325. -- URI of file 'books3.xml'
  326. local
  327. l_path: STRING
  328. once
  329. l_path := file_system.pathname (xpath_data_dirname, "books3.xml")
  330. Result := File_uri.filename_to_uri (l_path)
  331. ensure
  332. books3_xml_uri_not_void: Result /= Void
  333. end
  334. embedded_xml_uri: UT_URI
  335. -- URI of file 'embedded.xml'
  336. local
  337. l_path: STRING
  338. once
  339. l_path := file_system.pathname (data_dirname, "embedded.xml")
  340. Result := File_uri.filename_to_uri (l_path)
  341. ensure
  342. embedded_xml_uri_not_void: Result /= Void
  343. end
  344. processing_instructions_xml_uri: UT_URI
  345. -- URI of file 'processing_instructions.xml'
  346. local
  347. l_path: STRING
  348. once
  349. l_path := file_system.pathname (data_dirname, "processing_instructions.xml")
  350. Result := File_uri.filename_to_uri (l_path)
  351. ensure
  352. processing_instructions_xml_uri_not_void: Result /= Void
  353. end
  354. example0_xsl_uri: UT_URI
  355. -- URI of file 'example0.xsl'
  356. local
  357. l_path: STRING
  358. once
  359. l_path := file_system.pathname (data_dirname, "example0.xsl")
  360. Result := File_uri.filename_to_uri (l_path)
  361. ensure
  362. example0_xsl_uri_not_void: Result /= Void
  363. end
  364. expected_output_1: STRING = "<?xml version=%"1.0%" encoding=%"UTF-8%"?><output>Number, the Language of Science</output>"
  365. -- An expected output
  366. expected_output_2: STRING = "<?xml version=%"1.0%" encoding=%"UTF-8%"?><output>Danzig</output>"
  367. -- An expected output
  368. end