react-native-nitro-xlsx 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (449) hide show
  1. package/NitroXlsx.podspec +26 -27
  2. package/Package.swift +31 -10
  3. package/README.md +21 -9
  4. package/android/CMakeLists.txt +20 -27
  5. package/cpp/HybridNitroXlsx.cpp +25 -1
  6. package/cpp/HybridXlsxCellFormat.cpp +46 -146
  7. package/cpp/HybridXlsxCellFormat.hpp +9 -41
  8. package/cpp/HybridXlsxConditionalFormat.cpp +4 -1
  9. package/cpp/HybridXlsxConditionalFormats.cpp +5 -1
  10. package/cpp/HybridXlsxWorkbook.cpp +38 -8
  11. package/cpp/HybridXlsxWorkbook.hpp +10 -1
  12. package/cpp/HybridXlsxWorksheet.cpp +422 -141
  13. package/cpp/HybridXlsxWorksheet.hpp +4 -1
  14. package/cpp/XlsxCacheDir.cpp +25 -2
  15. package/cpp/XlsxCacheDir.hpp +3 -1
  16. package/cpp/XlsxCellStyle.hpp +360 -0
  17. package/cpp/XlsxJson.cpp +29 -8
  18. package/package.json +2 -2
  19. package/scripts/run-cpp-tests.sh +1 -1
  20. package/scripts/sync-openxlsx-headers.sh +34 -0
  21. package/src/__mocks__/react-native-nitro-modules.ts +523 -20
  22. package/src/__tests__/index.test.ts +124 -16
  23. package/src/index.ts +13 -13
  24. package/thirdparty/OpenXLSX/.clang-format +118 -0
  25. package/thirdparty/OpenXLSX/.clang-tidy +28 -0
  26. package/thirdparty/OpenXLSX/.gitignore +130 -0
  27. package/thirdparty/OpenXLSX/Benchmarks/2024-07-29-benchmarks_before_XMLNode_wrappers +46 -0
  28. package/thirdparty/OpenXLSX/Benchmarks/2024-07-29-benchmarks_with_XMLNode_wrappers_and_namespace_and_stripping +49 -0
  29. package/thirdparty/OpenXLSX/Benchmarks/2024-07-29-benchmarks_with_XMLNode_wrappers_and_namespace_char_support +49 -0
  30. package/thirdparty/OpenXLSX/Benchmarks/2024-07-29-benchmarks_with_XMLNode_wrappers_and_namespace_support +49 -0
  31. package/thirdparty/OpenXLSX/Benchmarks/2024-07-29-benchmarks_with_XMLNode_wrappers_and_namespaced_name_disabled +49 -0
  32. package/thirdparty/OpenXLSX/Benchmarks/2024-08-11-benchmarks_post-XLCellIterator-Rework +46 -0
  33. package/thirdparty/OpenXLSX/Benchmarks/2024-08-14-benchmarks_post-default-row-column-style-support +46 -0
  34. package/thirdparty/OpenXLSX/Benchmarks/2024-09-02-benchmarks +46 -0
  35. package/thirdparty/OpenXLSX/Benchmarks/2024-12-19-benchmarks +46 -0
  36. package/thirdparty/OpenXLSX/Benchmarks/2024-12-30-benchmarks-post-XLSharedStrings-by-ref +46 -0
  37. package/thirdparty/OpenXLSX/Benchmarks/2025-01-09-benchmarks-post-conditionalFormatsAndSheetProtection +46 -0
  38. package/thirdparty/OpenXLSX/Benchmarks/2025-01-10-benchmarks-post-XLCellValue-bugfix +46 -0
  39. package/thirdparty/OpenXLSX/Benchmarks/2025-01-31-benchmarks-post-XLComments-implementation +46 -0
  40. package/thirdparty/OpenXLSX/Benchmarks/2025-02-02-benchmarks-post-XLRowIterator-Rework +46 -0
  41. package/thirdparty/OpenXLSX/Benchmarks/2025-07-20-benchmarks-after-hiding-pugixml-internals +46 -0
  42. package/thirdparty/OpenXLSX/Benchmarks/2025-08-29-benchmarks-after-code-review-with-libzip +46 -0
  43. package/thirdparty/OpenXLSX/Benchmarks/Benchmark.cpp +249 -0
  44. package/thirdparty/OpenXLSX/Benchmarks/CMakeLists.txt +19 -0
  45. package/thirdparty/OpenXLSX/CMakeLists.txt +466 -0
  46. package/thirdparty/OpenXLSX/Documentation/CMakeLists.txt +31 -0
  47. package/thirdparty/OpenXLSX/Documentation/Doxyfile.in +2471 -0
  48. package/thirdparty/OpenXLSX/Documentation/DoxygenLayout.xml +194 -0
  49. package/thirdparty/OpenXLSX/Documentation/customdoxygen.css +1355 -0
  50. package/thirdparty/OpenXLSX/Examples/CMakeLists.txt +103 -0
  51. package/thirdparty/OpenXLSX/Examples/Demo1.cpp +279 -0
  52. package/thirdparty/OpenXLSX/Examples/Demo10.cpp +545 -0
  53. package/thirdparty/OpenXLSX/Examples/Demo1A.cpp +137 -0
  54. package/thirdparty/OpenXLSX/Examples/Demo2.cpp +65 -0
  55. package/thirdparty/OpenXLSX/Examples/Demo3.cpp +89 -0
  56. package/thirdparty/OpenXLSX/Examples/Demo4.cpp +86 -0
  57. package/thirdparty/OpenXLSX/Examples/Demo5.cpp +77 -0
  58. package/thirdparty/OpenXLSX/Examples/Demo6.cpp +103 -0
  59. package/thirdparty/OpenXLSX/Examples/Demo7.cpp +79 -0
  60. package/thirdparty/OpenXLSX/Examples/Demo8.cpp +117 -0
  61. package/thirdparty/OpenXLSX/Examples/Demo9.cpp +363 -0
  62. package/thirdparty/OpenXLSX/Examples/cmake/FindLIBZIP.cmake +61 -0
  63. package/thirdparty/OpenXLSX/Examples/external/CustomZip/CustomZip.hpp +256 -0
  64. package/thirdparty/OpenXLSX/LICENSE.md +29 -0
  65. package/thirdparty/OpenXLSX/Makefile.GNU +530 -0
  66. package/thirdparty/OpenXLSX/Notes/TBDs.txt +16 -0
  67. package/thirdparty/OpenXLSX/Notes/confirmed-TBCs.txt +8 -0
  68. package/thirdparty/OpenXLSX/Notes/styles-missing-support.xml +12 -0
  69. package/thirdparty/OpenXLSX/Notes/todo-list.txt +108 -0
  70. package/thirdparty/OpenXLSX/OpenXLSX/CMakeLists.txt +631 -0
  71. package/thirdparty/OpenXLSX/OpenXLSX/OpenXLSX.hpp +63 -0
  72. package/thirdparty/OpenXLSX/OpenXLSX/OpenXLSXConfig.cmake +11 -0
  73. package/thirdparty/OpenXLSX/OpenXLSX/cmake/bundle_static_library.cmake +198 -0
  74. package/thirdparty/OpenXLSX/OpenXLSX/cmake/patch_pkg_config.cmake +69 -0
  75. package/thirdparty/OpenXLSX/OpenXLSX/headers/IZipArchive.hpp +361 -0
  76. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/IZipArchive.hpp +361 -0
  77. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/OpenXLSX-Exports.hpp +12 -0
  78. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLCell.hpp +367 -0
  79. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLCellIterator.hpp +252 -0
  80. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLCellRange.hpp +223 -0
  81. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLCellReference.hpp +317 -0
  82. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLCellValue.hpp +793 -0
  83. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLColor.hpp +232 -0
  84. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLColumn.hpp +159 -0
  85. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLCommandQuery.hpp +228 -0
  86. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLComments.hpp +270 -0
  87. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLConstants.hpp +18 -0
  88. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLContentTypes.hpp +264 -0
  89. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLDateTime.hpp +175 -0
  90. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLDocument.hpp +505 -0
  91. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLDrawing.hpp +452 -0
  92. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLException.hpp +161 -0
  93. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLFormula.hpp +375 -0
  94. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLIterator.hpp +40 -0
  95. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLMergeCells.hpp +216 -0
  96. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLProperties.hpp +348 -0
  97. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLRelationships.hpp +348 -0
  98. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLRow.hpp +721 -0
  99. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLRowData.hpp +488 -0
  100. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLSharedStrings.hpp +204 -0
  101. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLSheet.hpp +1640 -0
  102. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLStyles.hpp +2390 -0
  103. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLTables.hpp +132 -0
  104. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLWorkbook.hpp +404 -0
  105. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLXmlData.hpp +283 -0
  106. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLXmlFile.hpp +194 -0
  107. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLXmlParser.hpp +282 -0
  108. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLXmlParserForwardDeclarations.hpp +85 -0
  109. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLZipArchive.hpp +232 -0
  110. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/detail/LibZip.hpp +447 -0
  111. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/detail/OpenXLSXFileSystemTools.hpp +207 -0
  112. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/detail/Zippy.hpp +1375 -0
  113. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX-Exports.hpp +12 -0
  114. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLCell.hpp +367 -0
  115. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLCellIterator.hpp +252 -0
  116. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLCellRange.hpp +223 -0
  117. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLCellReference.hpp +317 -0
  118. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLCellValue.hpp +793 -0
  119. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLColor.hpp +232 -0
  120. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLColumn.hpp +159 -0
  121. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLCommandQuery.hpp +228 -0
  122. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLComments.hpp +270 -0
  123. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLConstants.hpp +18 -0
  124. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLContentTypes.hpp +264 -0
  125. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLDateTime.hpp +175 -0
  126. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLDocument.hpp +505 -0
  127. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLDrawing.hpp +452 -0
  128. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLException.hpp +161 -0
  129. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLFormula.hpp +375 -0
  130. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLIterator.hpp +40 -0
  131. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLMergeCells.hpp +216 -0
  132. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLProperties.hpp +348 -0
  133. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLRelationships.hpp +348 -0
  134. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLRow.hpp +721 -0
  135. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLRowData.hpp +488 -0
  136. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLSharedStrings.hpp +204 -0
  137. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLSheet.hpp +1640 -0
  138. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLStyles.hpp +2390 -0
  139. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLTables.hpp +132 -0
  140. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLWorkbook.hpp +404 -0
  141. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLXmlData.hpp +283 -0
  142. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLXmlFile.hpp +194 -0
  143. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLXmlParser.hpp +282 -0
  144. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLXmlParserForwardDeclarations.hpp +85 -0
  145. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLZipArchive.hpp +232 -0
  146. package/thirdparty/OpenXLSX/OpenXLSX/headers/detail/LibZip.hpp +447 -0
  147. package/thirdparty/OpenXLSX/OpenXLSX/headers/detail/OpenXLSXFileSystemTools.hpp +207 -0
  148. package/thirdparty/OpenXLSX/OpenXLSX/headers/detail/Zippy.hpp +1375 -0
  149. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLCell.cpp +340 -0
  150. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLCellIterator.cpp +427 -0
  151. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLCellRange.cpp +221 -0
  152. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLCellReference.cpp +408 -0
  153. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLCellValue.cpp +519 -0
  154. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLColor.cpp +202 -0
  155. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLColumn.cpp +141 -0
  156. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLComments.cpp +637 -0
  157. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLContentTypes.cpp +329 -0
  158. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLDateTime.cpp +269 -0
  159. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLDocument.cpp +1678 -0
  160. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLDrawing.cpp +784 -0
  161. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLFormula.cpp +201 -0
  162. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLMergeCells.cpp +357 -0
  163. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLProperties.cpp +810 -0
  164. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLRelationships.cpp +529 -0
  165. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLRow.cpp +918 -0
  166. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLRowData.cpp +508 -0
  167. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLSharedStrings.cpp +220 -0
  168. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLSheet.cpp +1970 -0
  169. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLStyles.cpp +3014 -0
  170. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLTables.cpp +125 -0
  171. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLWorkbook.cpp +784 -0
  172. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLXmlData.cpp +247 -0
  173. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLXmlFile.cpp +160 -0
  174. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLXmlParser.cpp +261 -0
  175. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLZipArchive.cpp +266 -0
  176. package/thirdparty/OpenXLSX/OpenXLSX/sources/utilities/XLUtilities.hpp +478 -0
  177. package/thirdparty/OpenXLSX/README.md +1279 -0
  178. package/thirdparty/OpenXLSX/Scripts/cmake-cleanup.sh +102 -0
  179. package/thirdparty/OpenXLSX/Scripts/compile.sh +23 -0
  180. package/thirdparty/OpenXLSX/Scripts/demos-cleanup.sh +25 -0
  181. package/thirdparty/OpenXLSX/Scripts/demos-run-all.sh +60 -0
  182. package/thirdparty/OpenXLSX/Scripts/guarded-xml-format.sh +47 -0
  183. package/thirdparty/OpenXLSX/Scripts/make-gnu.sh +11 -0
  184. package/thirdparty/OpenXLSX/Scripts/uninstall-manifest.sh +48 -0
  185. package/thirdparty/OpenXLSX/Scripts/xml-format-all.sh +19 -0
  186. package/thirdparty/OpenXLSX/Scripts/xml-format.sh +38 -0
  187. package/thirdparty/OpenXLSX/Tests/CMakeLists.txt +37 -0
  188. package/thirdparty/OpenXLSX/Tests/catch/catch.hpp +17799 -0
  189. package/thirdparty/OpenXLSX/Tests/catch/catch_reporter_automake.hpp +68 -0
  190. package/thirdparty/OpenXLSX/Tests/catch/catch_reporter_sonarqube.hpp +182 -0
  191. package/thirdparty/OpenXLSX/Tests/catch/catch_reporter_tap.hpp +278 -0
  192. package/thirdparty/OpenXLSX/Tests/catch/catch_reporter_teamcity.hpp +212 -0
  193. package/thirdparty/OpenXLSX/Tests/main.cpp +55 -0
  194. package/thirdparty/OpenXLSX/Tests/testXLCell.cpp +176 -0
  195. package/thirdparty/OpenXLSX/Tests/testXLCellRange.cpp +180 -0
  196. package/thirdparty/OpenXLSX/Tests/testXLCellReference.cpp +160 -0
  197. package/thirdparty/OpenXLSX/Tests/testXLCellValue.cpp +366 -0
  198. package/thirdparty/OpenXLSX/Tests/testXLCellValueProxy.cpp +255 -0
  199. package/thirdparty/OpenXLSX/Tests/testXLColor.cpp +75 -0
  200. package/thirdparty/OpenXLSX/Tests/testXLDateTime.cpp +229 -0
  201. package/thirdparty/OpenXLSX/Tests/testXLDocument.cpp +197 -0
  202. package/thirdparty/OpenXLSX/Tests/testXLFormula.cpp +131 -0
  203. package/thirdparty/OpenXLSX/Tests/testXLRow.cpp +597 -0
  204. package/thirdparty/OpenXLSX/Tests/testXLSheet.cpp +77 -0
  205. package/thirdparty/OpenXLSX/Tests/ziptest-with-libs.cpp +88 -0
  206. package/thirdparty/OpenXLSX/Tests/ziptest.cpp +735 -0
  207. package/thirdparty/OpenXLSX/cmake/get-git-HEAD-ID.cmake +45 -0
  208. package/thirdparty/OpenXLSX/cmake/libopenxlsxCPackOptions.cmake.in +20 -0
  209. package/thirdparty/OpenXLSX/cmake/manage_dependency.cmake +813 -0
  210. package/thirdparty/OpenXLSX/cmake/recursive_library_type_test.cmake +52 -0
  211. package/thirdparty/OpenXLSX/gnu-make-crutch/OpenXLSX-Exports-shared.hpp +42 -0
  212. package/thirdparty/OpenXLSX/gnu-make-crutch/OpenXLSX-Exports-static.hpp +42 -0
  213. package/thirdparty/OpenXLSX/vcpkg.json +24 -0
  214. package/thirdparty/README.md +46 -0
  215. package/thirdparty/miniz/.clang-format +47 -0
  216. package/thirdparty/miniz/.travis.yml +2 -0
  217. package/thirdparty/miniz/CMakeLists.txt +333 -0
  218. package/thirdparty/miniz/CMakePresets.json +31 -0
  219. package/thirdparty/miniz/ChangeLog.md +272 -0
  220. package/thirdparty/miniz/Config.cmake.in +1 -0
  221. package/thirdparty/miniz/LICENSE +22 -0
  222. package/thirdparty/miniz/amalgamate.sh +57 -0
  223. package/thirdparty/miniz/examples/example1.c +105 -0
  224. package/thirdparty/miniz/examples/example2.c +164 -0
  225. package/thirdparty/miniz/examples/example3.c +269 -0
  226. package/thirdparty/miniz/examples/example4.c +102 -0
  227. package/thirdparty/miniz/examples/example5.c +327 -0
  228. package/thirdparty/miniz/examples/example6.c +189 -0
  229. package/thirdparty/miniz/meson.build +21 -0
  230. package/thirdparty/miniz/miniz.c +646 -0
  231. package/thirdparty/miniz/miniz.h +615 -0
  232. package/thirdparty/miniz/miniz.pc.in +13 -0
  233. package/thirdparty/miniz/miniz_common.h +89 -0
  234. package/thirdparty/miniz/miniz_export.h +20 -0
  235. package/thirdparty/miniz/miniz_tdef.c +1602 -0
  236. package/thirdparty/miniz/miniz_tdef.h +199 -0
  237. package/thirdparty/miniz/miniz_tinfl.c +778 -0
  238. package/thirdparty/miniz/miniz_tinfl.h +150 -0
  239. package/thirdparty/miniz/miniz_zip.c +4895 -0
  240. package/thirdparty/miniz/miniz_zip.h +454 -0
  241. package/thirdparty/miniz/readme.md +46 -0
  242. package/thirdparty/miniz/test.sh +36 -0
  243. package/thirdparty/miniz/tests/add_in_place_fuzzer.c +87 -0
  244. package/thirdparty/miniz/tests/catch_amalgamated.cpp +10795 -0
  245. package/thirdparty/miniz/tests/catch_amalgamated.hpp +13143 -0
  246. package/thirdparty/miniz/tests/checksum_fuzzer.c +26 -0
  247. package/thirdparty/miniz/tests/compress_fuzzer.c +91 -0
  248. package/thirdparty/miniz/tests/flush_fuzzer.c +88 -0
  249. package/thirdparty/miniz/tests/fuzz_main.c +55 -0
  250. package/thirdparty/miniz/tests/large_fuzzer.c +133 -0
  251. package/thirdparty/miniz/tests/main.cpp +185 -0
  252. package/thirdparty/miniz/tests/miniz_tdefl_fuzzer.cc +115 -0
  253. package/thirdparty/miniz/tests/miniz_tester.cpp +1881 -0
  254. package/thirdparty/miniz/tests/miniz_zip_validate_fuzzer.cc +71 -0
  255. package/thirdparty/miniz/tests/miniz_zip_writer_fuzzer.cc +96 -0
  256. package/thirdparty/miniz/tests/ossfuzz.sh +48 -0
  257. package/thirdparty/miniz/tests/small_fuzzer.c +126 -0
  258. package/thirdparty/miniz/tests/timer.cpp +152 -0
  259. package/thirdparty/miniz/tests/timer.h +40 -0
  260. package/thirdparty/miniz/tests/uncompress2_fuzzer.c +21 -0
  261. package/thirdparty/miniz/tests/uncompress_fuzzer.c +30 -0
  262. package/thirdparty/miniz/tests/zip.dict +9 -0
  263. package/thirdparty/miniz/tests/zip_fuzzer.c +63 -0
  264. package/thirdparty/pugixml/.codecov.yml +7 -0
  265. package/thirdparty/pugixml/.gitattributes +1 -0
  266. package/thirdparty/pugixml/CMakeLists.txt +330 -0
  267. package/thirdparty/pugixml/LICENSE.md +24 -0
  268. package/thirdparty/pugixml/Makefile +98 -0
  269. package/thirdparty/pugixml/README.md +81 -0
  270. package/thirdparty/pugixml/SECURITY.md +9 -0
  271. package/thirdparty/pugixml/appveyor.yml +50 -0
  272. package/thirdparty/pugixml/docs/config.adoc +7 -0
  273. package/thirdparty/pugixml/docs/images/dom_tree.png +0 -0
  274. package/thirdparty/pugixml/docs/images/vs2005_link1.png +0 -0
  275. package/thirdparty/pugixml/docs/images/vs2005_link2.png +0 -0
  276. package/thirdparty/pugixml/docs/images/vs2005_pch1.png +0 -0
  277. package/thirdparty/pugixml/docs/images/vs2005_pch2.png +0 -0
  278. package/thirdparty/pugixml/docs/images/vs2005_pch3.png +0 -0
  279. package/thirdparty/pugixml/docs/images/vs2005_pch4.png +0 -0
  280. package/thirdparty/pugixml/docs/images/vs2010_link1.png +0 -0
  281. package/thirdparty/pugixml/docs/images/vs2010_link2.png +0 -0
  282. package/thirdparty/pugixml/docs/manual.adoc +3326 -0
  283. package/thirdparty/pugixml/docs/manual.html +6395 -0
  284. package/thirdparty/pugixml/docs/quickstart.adoc +287 -0
  285. package/thirdparty/pugixml/docs/quickstart.html +1107 -0
  286. package/thirdparty/pugixml/docs/samples/character.xml +8 -0
  287. package/thirdparty/pugixml/docs/samples/custom_memory_management.cpp +27 -0
  288. package/thirdparty/pugixml/docs/samples/include.cpp +64 -0
  289. package/thirdparty/pugixml/docs/samples/load_error_handling.cpp +33 -0
  290. package/thirdparty/pugixml/docs/samples/load_file.cpp +16 -0
  291. package/thirdparty/pugixml/docs/samples/load_memory.cpp +66 -0
  292. package/thirdparty/pugixml/docs/samples/load_options.cpp +30 -0
  293. package/thirdparty/pugixml/docs/samples/load_stream.cpp +97 -0
  294. package/thirdparty/pugixml/docs/samples/modify_add.cpp +29 -0
  295. package/thirdparty/pugixml/docs/samples/modify_base.cpp +43 -0
  296. package/thirdparty/pugixml/docs/samples/modify_remove.cpp +27 -0
  297. package/thirdparty/pugixml/docs/samples/save_custom_writer.cpp +116 -0
  298. package/thirdparty/pugixml/docs/samples/save_declaration.cpp +27 -0
  299. package/thirdparty/pugixml/docs/samples/save_file.cpp +17 -0
  300. package/thirdparty/pugixml/docs/samples/save_options.cpp +48 -0
  301. package/thirdparty/pugixml/docs/samples/save_stream.cpp +18 -0
  302. package/thirdparty/pugixml/docs/samples/save_subtree.cpp +26 -0
  303. package/thirdparty/pugixml/docs/samples/text.cpp +35 -0
  304. package/thirdparty/pugixml/docs/samples/transitions.xml +7 -0
  305. package/thirdparty/pugixml/docs/samples/traverse_base.cpp +51 -0
  306. package/thirdparty/pugixml/docs/samples/traverse_iter.cpp +27 -0
  307. package/thirdparty/pugixml/docs/samples/traverse_predicate.cpp +48 -0
  308. package/thirdparty/pugixml/docs/samples/traverse_rangefor.cpp +32 -0
  309. package/thirdparty/pugixml/docs/samples/traverse_walker.cpp +35 -0
  310. package/thirdparty/pugixml/docs/samples/tree.xml +12 -0
  311. package/thirdparty/pugixml/docs/samples/weekly-shift_jis.xml +78 -0
  312. package/thirdparty/pugixml/docs/samples/weekly-utf-16.xml +0 -0
  313. package/thirdparty/pugixml/docs/samples/weekly-utf-8.xml +78 -0
  314. package/thirdparty/pugixml/docs/samples/xgconsole.xml +12 -0
  315. package/thirdparty/pugixml/docs/samples/xpath_error.cpp +43 -0
  316. package/thirdparty/pugixml/docs/samples/xpath_query.cpp +36 -0
  317. package/thirdparty/pugixml/docs/samples/xpath_select.cpp +28 -0
  318. package/thirdparty/pugixml/docs/samples/xpath_variables.cpp +38 -0
  319. package/thirdparty/pugixml/readme.txt +50 -0
  320. package/thirdparty/pugixml/scripts/archive.py +54 -0
  321. package/thirdparty/pugixml/scripts/cocoapods_push.sh +4 -0
  322. package/thirdparty/pugixml/scripts/natvis/pugixml.natvis +77 -0
  323. package/thirdparty/pugixml/scripts/natvis/pugixml_compact.natvis +506 -0
  324. package/thirdparty/pugixml/scripts/nuget/build/native/pugixml-propertiesui.xml +17 -0
  325. package/thirdparty/pugixml/scripts/nuget/build/native/pugixml.targets +28 -0
  326. package/thirdparty/pugixml/scripts/nuget/pugixml.nuspec +20 -0
  327. package/thirdparty/pugixml/scripts/nuget_build.ps1 +60 -0
  328. package/thirdparty/pugixml/scripts/premake4.lua +92 -0
  329. package/thirdparty/pugixml/scripts/pugixml-config.cmake.in +12 -0
  330. package/thirdparty/pugixml/scripts/pugixml.pc.in +11 -0
  331. package/thirdparty/pugixml/scripts/pugixml.podspec +14 -0
  332. package/thirdparty/pugixml/scripts/pugixml.xcodeproj/project.pbxproj +212 -0
  333. package/thirdparty/pugixml/scripts/pugixml_airplay.mkf +13 -0
  334. package/thirdparty/pugixml/scripts/pugixml_codeblocks.cbp +44 -0
  335. package/thirdparty/pugixml/scripts/pugixml_codelite.project +56 -0
  336. package/thirdparty/pugixml/scripts/pugixml_dll.rc +45 -0
  337. package/thirdparty/pugixml/scripts/pugixml_vs2005.vcproj +343 -0
  338. package/thirdparty/pugixml/scripts/pugixml_vs2005_static.vcproj +343 -0
  339. package/thirdparty/pugixml/scripts/pugixml_vs2008.vcproj +339 -0
  340. package/thirdparty/pugixml/scripts/pugixml_vs2008_static.vcproj +339 -0
  341. package/thirdparty/pugixml/scripts/pugixml_vs2010.vcxproj +191 -0
  342. package/thirdparty/pugixml/scripts/pugixml_vs2010_static.vcxproj +191 -0
  343. package/thirdparty/pugixml/scripts/pugixml_vs2013.vcxproj +199 -0
  344. package/thirdparty/pugixml/scripts/pugixml_vs2013_static.vcxproj +199 -0
  345. package/thirdparty/pugixml/scripts/pugixml_vs2015.vcxproj +172 -0
  346. package/thirdparty/pugixml/scripts/pugixml_vs2015_static.vcxproj +176 -0
  347. package/thirdparty/pugixml/scripts/pugixml_vs2017.vcxproj +172 -0
  348. package/thirdparty/pugixml/scripts/pugixml_vs2017_static.vcxproj +176 -0
  349. package/thirdparty/pugixml/scripts/pugixml_vs2019.vcxproj +176 -0
  350. package/thirdparty/pugixml/scripts/pugixml_vs2019_static.vcxproj +180 -0
  351. package/thirdparty/pugixml/scripts/pugixml_vs2022.vcxproj +176 -0
  352. package/thirdparty/pugixml/scripts/pugixml_vs2022_static.vcxproj +180 -0
  353. package/thirdparty/pugixml/scripts/pugixml_vs2026.vcxproj +176 -0
  354. package/thirdparty/pugixml/scripts/pugixml_vs2026_static.vcxproj +180 -0
  355. package/thirdparty/pugixml/scripts/sbom.cdx.json +47 -0
  356. package/thirdparty/pugixml/src/pugiconfig.hpp +81 -0
  357. package/thirdparty/pugixml/src/pugixml.cpp +13776 -0
  358. package/thirdparty/pugixml/src/pugixml.hpp +1604 -0
  359. package/thirdparty/pugixml/tests/allocator.cpp +175 -0
  360. package/thirdparty/pugixml/tests/allocator.hpp +10 -0
  361. package/thirdparty/pugixml/tests/autotest-appveyor.ps1 +93 -0
  362. package/thirdparty/pugixml/tests/cmake-appveyor.ps1 +57 -0
  363. package/thirdparty/pugixml/tests/data/empty.xml +0 -0
  364. package/thirdparty/pugixml/tests/data/large.xml +1 -0
  365. package/thirdparty/pugixml/tests/data/latintest_latin1.xml +1 -0
  366. package/thirdparty/pugixml/tests/data/latintest_utf8.xml +1 -0
  367. package/thirdparty/pugixml/tests/data/multiline.xml +3 -0
  368. package/thirdparty/pugixml/tests/data/small.xml +1 -0
  369. package/thirdparty/pugixml/tests/data/truncation.xml +19 -0
  370. package/thirdparty/pugixml/tests/data/utftest_utf16_be.xml +0 -0
  371. package/thirdparty/pugixml/tests/data/utftest_utf16_be_bom.xml +0 -0
  372. package/thirdparty/pugixml/tests/data/utftest_utf16_be_clean.xml +0 -0
  373. package/thirdparty/pugixml/tests/data/utftest_utf16_be_nodecl.xml +0 -0
  374. package/thirdparty/pugixml/tests/data/utftest_utf16_le.xml +0 -0
  375. package/thirdparty/pugixml/tests/data/utftest_utf16_le_bom.xml +0 -0
  376. package/thirdparty/pugixml/tests/data/utftest_utf16_le_clean.xml +0 -0
  377. package/thirdparty/pugixml/tests/data/utftest_utf16_le_nodecl.xml +0 -0
  378. package/thirdparty/pugixml/tests/data/utftest_utf32_be.xml +0 -0
  379. package/thirdparty/pugixml/tests/data/utftest_utf32_be_bom.xml +0 -0
  380. package/thirdparty/pugixml/tests/data/utftest_utf32_be_clean.xml +0 -0
  381. package/thirdparty/pugixml/tests/data/utftest_utf32_be_nodecl.xml +0 -0
  382. package/thirdparty/pugixml/tests/data/utftest_utf32_le.xml +0 -0
  383. package/thirdparty/pugixml/tests/data/utftest_utf32_le_bom.xml +0 -0
  384. package/thirdparty/pugixml/tests/data/utftest_utf32_le_clean.xml +0 -0
  385. package/thirdparty/pugixml/tests/data/utftest_utf32_le_nodecl.xml +0 -0
  386. package/thirdparty/pugixml/tests/data/utftest_utf8.xml +87 -0
  387. package/thirdparty/pugixml/tests/data/utftest_utf8_bom.xml +87 -0
  388. package/thirdparty/pugixml/tests/data/utftest_utf8_clean.xml +84 -0
  389. package/thirdparty/pugixml/tests/data/utftest_utf8_nodecl.xml +86 -0
  390. package/thirdparty/pugixml/tests/data//321/202/320/265/321/201/321/202.xml +1 -0
  391. package/thirdparty/pugixml/tests/data_fuzz_parse/basic.xml +1 -0
  392. package/thirdparty/pugixml/tests/data_fuzz_parse/doctype.xml +1 -0
  393. package/thirdparty/pugixml/tests/data_fuzz_parse/refs.xml +1 -0
  394. package/thirdparty/pugixml/tests/data_fuzz_parse/types.xml +1 -0
  395. package/thirdparty/pugixml/tests/data_fuzz_parse/utf16.xml +0 -0
  396. package/thirdparty/pugixml/tests/data_fuzz_parse/utf32.xml +0 -0
  397. package/thirdparty/pugixml/tests/data_fuzz_xpath/basic.xpath +1 -0
  398. package/thirdparty/pugixml/tests/data_fuzz_xpath/functions.xpath +1 -0
  399. package/thirdparty/pugixml/tests/data_fuzz_xpath/math.xpath +1 -0
  400. package/thirdparty/pugixml/tests/data_fuzz_xpath/path.xpath +1 -0
  401. package/thirdparty/pugixml/tests/data_fuzz_xpath/predicate.xpath +1 -0
  402. package/thirdparty/pugixml/tests/fuzz_parse.cpp +14 -0
  403. package/thirdparty/pugixml/tests/fuzz_parse.dict +72 -0
  404. package/thirdparty/pugixml/tests/fuzz_setup.sh +11 -0
  405. package/thirdparty/pugixml/tests/fuzz_xpath.cpp +46 -0
  406. package/thirdparty/pugixml/tests/fuzz_xpath.dict +72 -0
  407. package/thirdparty/pugixml/tests/helpers.hpp +114 -0
  408. package/thirdparty/pugixml/tests/main.cpp +218 -0
  409. package/thirdparty/pugixml/tests/test.cpp +220 -0
  410. package/thirdparty/pugixml/tests/test.hpp +175 -0
  411. package/thirdparty/pugixml/tests/test_compact.cpp +150 -0
  412. package/thirdparty/pugixml/tests/test_deprecated.cpp +25 -0
  413. package/thirdparty/pugixml/tests/test_document.cpp +1910 -0
  414. package/thirdparty/pugixml/tests/test_dom_modify.cpp +2122 -0
  415. package/thirdparty/pugixml/tests/test_dom_text.cpp +601 -0
  416. package/thirdparty/pugixml/tests/test_dom_traverse.cpp +1481 -0
  417. package/thirdparty/pugixml/tests/test_header_guard.cpp +3 -0
  418. package/thirdparty/pugixml/tests/test_header_iosfwd_1.cpp +3 -0
  419. package/thirdparty/pugixml/tests/test_header_iosfwd_2.cpp +3 -0
  420. package/thirdparty/pugixml/tests/test_header_iostream_1.cpp +3 -0
  421. package/thirdparty/pugixml/tests/test_header_iostream_2.cpp +3 -0
  422. package/thirdparty/pugixml/tests/test_header_only_1.cpp +21 -0
  423. package/thirdparty/pugixml/tests/test_header_only_2.cpp +21 -0
  424. package/thirdparty/pugixml/tests/test_header_string_1.cpp +3 -0
  425. package/thirdparty/pugixml/tests/test_header_string_2.cpp +3 -0
  426. package/thirdparty/pugixml/tests/test_header_string_iostream.cpp +5 -0
  427. package/thirdparty/pugixml/tests/test_memory.cpp +303 -0
  428. package/thirdparty/pugixml/tests/test_parse.cpp +1463 -0
  429. package/thirdparty/pugixml/tests/test_parse_doctype.cpp +366 -0
  430. package/thirdparty/pugixml/tests/test_unicode.cpp +152 -0
  431. package/thirdparty/pugixml/tests/test_version.cpp +5 -0
  432. package/thirdparty/pugixml/tests/test_write.cpp +757 -0
  433. package/thirdparty/pugixml/tests/test_xpath.cpp +833 -0
  434. package/thirdparty/pugixml/tests/test_xpath_api.cpp +646 -0
  435. package/thirdparty/pugixml/tests/test_xpath_functions.cpp +844 -0
  436. package/thirdparty/pugixml/tests/test_xpath_operators.cpp +566 -0
  437. package/thirdparty/pugixml/tests/test_xpath_parse.cpp +428 -0
  438. package/thirdparty/pugixml/tests/test_xpath_paths.cpp +787 -0
  439. package/thirdparty/pugixml/tests/test_xpath_paths_abbrev_w3c.cpp +219 -0
  440. package/thirdparty/pugixml/tests/test_xpath_paths_w3c.cpp +312 -0
  441. package/thirdparty/pugixml/tests/test_xpath_variables.cpp +683 -0
  442. package/thirdparty/pugixml/tests/test_xpath_xalan_1.cpp +411 -0
  443. package/thirdparty/pugixml/tests/test_xpath_xalan_2.cpp +417 -0
  444. package/thirdparty/pugixml/tests/test_xpath_xalan_3.cpp +321 -0
  445. package/thirdparty/pugixml/tests/test_xpath_xalan_4.cpp +300 -0
  446. package/thirdparty/pugixml/tests/test_xpath_xalan_5.cpp +295 -0
  447. package/thirdparty/pugixml/tests/writer_string.cpp +79 -0
  448. package/thirdparty/pugixml/tests/writer_string.hpp +27 -0
  449. package/scripts/prepare-openxlsx.js +0 -126
@@ -0,0 +1,2122 @@
1
+ #include "test.hpp"
2
+
3
+ #include <limits>
4
+ #include <string>
5
+
6
+ #include <math.h>
7
+ #include <string.h>
8
+ #include <limits.h>
9
+
10
+ using namespace pugi;
11
+
12
+ TEST_XML(dom_attr_assign, "<node/>")
13
+ {
14
+ xml_node node = doc.child(STR("node"));
15
+
16
+ node.append_attribute(STR("attr1")) = STR("v1");
17
+ xml_attribute() = STR("v1");
18
+
19
+ node.append_attribute(STR("attr2")) = -2147483647;
20
+ node.append_attribute(STR("attr3")) = -2147483647 - 1;
21
+ xml_attribute() = -2147483647 - 1;
22
+
23
+ node.append_attribute(STR("attr4")) = 4294967295u;
24
+ node.append_attribute(STR("attr5")) = 4294967294u;
25
+ xml_attribute() = 4294967295u;
26
+
27
+ node.append_attribute(STR("attr6")) = 0.5;
28
+ xml_attribute() = 0.5;
29
+
30
+ node.append_attribute(STR("attr7")) = 0.25f;
31
+ xml_attribute() = 0.25f;
32
+
33
+ node.append_attribute(STR("attr8")) = true;
34
+ xml_attribute() = true;
35
+
36
+ #ifdef PUGIXML_HAS_STRING_VIEW
37
+ node.append_attribute(string_view_t(STR("attr9"))) = string_view_t(STR("v2"));
38
+ #else
39
+ node.append_attribute(STR("attr9")) = STR("v2");
40
+ #endif
41
+
42
+ CHECK_NODE(node, STR("<node attr1=\"v1\" attr2=\"-2147483647\" attr3=\"-2147483648\" attr4=\"4294967295\" attr5=\"4294967294\" attr6=\"0.5\" attr7=\"0.25\" attr8=\"true\" attr9=\"v2\"/>"));
43
+ }
44
+
45
+ TEST_XML(dom_attr_set_name, "<node attr='value' />")
46
+ {
47
+ xml_attribute attr = doc.child(STR("node")).attribute(STR("attr"));
48
+
49
+ CHECK(attr.set_name(STR("n")));
50
+ CHECK(!xml_attribute().set_name(STR("n")));
51
+
52
+ CHECK_NODE(doc, STR("<node n=\"value\"/>"));
53
+ }
54
+
55
+ TEST_XML(dom_attr_set_name_with_size, "<node attr='value' />")
56
+ {
57
+ xml_attribute attr = doc.child(STR("node")).attribute(STR("attr"));
58
+
59
+ CHECK(attr.set_name(STR("n1234"), 1));
60
+ CHECK(!xml_attribute().set_name(STR("nfail"), 1));
61
+
62
+ CHECK_NODE(doc, STR("<node n=\"value\"/>"));
63
+ }
64
+
65
+ #ifdef PUGIXML_HAS_STRING_VIEW
66
+ TEST_XML(dom_attr_set_name_with_string_view, "<node attr='value' />")
67
+ {
68
+ xml_attribute attr = doc.child(STR("node")).attribute(STR("attr"));
69
+
70
+ CHECK(attr.set_name(string_view_t()));
71
+ CHECK(!xml_attribute().set_name(string_view_t()));
72
+
73
+ CHECK_NODE(doc, STR("<node :anonymous=\"value\"/>"));
74
+
75
+ CHECK(attr.set_name(string_view_t(STR("n1234"), 1)));
76
+ CHECK(!xml_attribute().set_name(string_view_t(STR("nfail"), 1)));
77
+
78
+ CHECK_NODE(doc, STR("<node n=\"value\"/>"));
79
+ }
80
+ #endif
81
+
82
+ TEST_XML(dom_attr_set_value, "<node/>")
83
+ {
84
+ xml_node node = doc.child(STR("node"));
85
+
86
+ CHECK(node.append_attribute(STR("attr1")).set_value(STR("v1")));
87
+ CHECK(!xml_attribute().set_value(STR("v1")));
88
+
89
+ CHECK(node.append_attribute(STR("attr2")).set_value(-2147483647));
90
+ CHECK(node.append_attribute(STR("attr3")).set_value(-2147483647 - 1));
91
+ CHECK(!xml_attribute().set_value(-2147483647));
92
+
93
+ CHECK(node.append_attribute(STR("attr4")).set_value(4294967295u));
94
+ CHECK(node.append_attribute(STR("attr5")).set_value(4294967294u));
95
+ CHECK(!xml_attribute().set_value(4294967295u));
96
+
97
+ CHECK(node.append_attribute(STR("attr6")).set_value(0.5));
98
+ CHECK(!xml_attribute().set_value(0.5));
99
+
100
+ CHECK(node.append_attribute(STR("attr7")).set_value(0.25f));
101
+ CHECK(!xml_attribute().set_value(0.25f));
102
+
103
+ CHECK(node.append_attribute(STR("attr8")).set_value(true));
104
+ CHECK(!xml_attribute().set_value(true));
105
+
106
+ CHECK(node.append_attribute(STR("attr9")).set_value(STR("v2"), 2));
107
+ CHECK(!xml_attribute().set_value(STR("v2")));
108
+
109
+ CHECK(node.append_attribute(STR("attr10")).set_value(STR("v3foobar"), 2));
110
+ CHECK(!xml_attribute().set_value(STR("v3")));
111
+
112
+ #ifdef PUGIXML_HAS_STRING_VIEW
113
+ CHECK(node.append_attribute(string_view_t(STR("attr11"))).set_value(string_view_t(STR("v4"))));
114
+ CHECK(!xml_attribute().set_value(string_view_t(STR("v4"))));
115
+ #else
116
+ CHECK(node.append_attribute(STR("attr11")).set_value(STR("v4")));
117
+ #endif
118
+
119
+ CHECK_NODE(node, STR("<node attr1=\"v1\" attr2=\"-2147483647\" attr3=\"-2147483648\" attr4=\"4294967295\" attr5=\"4294967294\" attr6=\"0.5\" attr7=\"0.25\" attr8=\"true\" attr9=\"v2\" attr10=\"v3\" attr11=\"v4\"/>"));
120
+ }
121
+
122
+ #if LONG_MAX > 2147483647
123
+ TEST_XML(dom_attr_assign_long, "<node/>")
124
+ {
125
+ xml_node node = doc.child(STR("node"));
126
+
127
+ node.append_attribute(STR("attr1")) = -9223372036854775807l;
128
+ node.append_attribute(STR("attr2")) = -9223372036854775807l - 1;
129
+ xml_attribute() = -9223372036854775807l - 1;
130
+
131
+ node.append_attribute(STR("attr3")) = 18446744073709551615ul;
132
+ node.append_attribute(STR("attr4")) = 18446744073709551614ul;
133
+ xml_attribute() = 18446744073709551615ul;
134
+
135
+ CHECK_NODE(node, STR("<node attr1=\"-9223372036854775807\" attr2=\"-9223372036854775808\" attr3=\"18446744073709551615\" attr4=\"18446744073709551614\"/>"));
136
+ }
137
+
138
+ TEST_XML(dom_attr_set_value_long, "<node/>")
139
+ {
140
+ xml_node node = doc.child(STR("node"));
141
+
142
+ CHECK(node.append_attribute(STR("attr1")).set_value(-9223372036854775807l));
143
+ CHECK(node.append_attribute(STR("attr2")).set_value(-9223372036854775807l - 1));
144
+ CHECK(!xml_attribute().set_value(-9223372036854775807l - 1));
145
+
146
+ CHECK(node.append_attribute(STR("attr3")).set_value(18446744073709551615ul));
147
+ CHECK(node.append_attribute(STR("attr4")).set_value(18446744073709551614ul));
148
+ CHECK(!xml_attribute().set_value(18446744073709551615ul));
149
+
150
+ CHECK_NODE(node, STR("<node attr1=\"-9223372036854775807\" attr2=\"-9223372036854775808\" attr3=\"18446744073709551615\" attr4=\"18446744073709551614\"/>"));
151
+ }
152
+ #else
153
+ TEST_XML(dom_attr_assign_long, "<node/>")
154
+ {
155
+ xml_node node = doc.child(STR("node"));
156
+
157
+ node.append_attribute(STR("attr1")) = -2147483647l;
158
+ node.append_attribute(STR("attr2")) = -2147483647l - 1;
159
+ xml_attribute() = -2147483647l - 1;
160
+
161
+ node.append_attribute(STR("attr3")) = 4294967295ul;
162
+ node.append_attribute(STR("attr4")) = 4294967294ul;
163
+ xml_attribute() = 4294967295ul;
164
+
165
+ CHECK_NODE(node, STR("<node attr1=\"-2147483647\" attr2=\"-2147483648\" attr3=\"4294967295\" attr4=\"4294967294\"/>"));
166
+ }
167
+
168
+ TEST_XML(dom_attr_set_value_long, "<node/>")
169
+ {
170
+ xml_node node = doc.child(STR("node"));
171
+
172
+ CHECK(node.append_attribute(STR("attr1")).set_value(-2147483647l));
173
+ CHECK(node.append_attribute(STR("attr2")).set_value(-2147483647l - 1));
174
+ CHECK(!xml_attribute().set_value(-2147483647l - 1));
175
+
176
+ CHECK(node.append_attribute(STR("attr3")).set_value(4294967295ul));
177
+ CHECK(node.append_attribute(STR("attr4")).set_value(4294967294ul));
178
+ CHECK(!xml_attribute().set_value(4294967295ul));
179
+
180
+ CHECK_NODE(node, STR("<node attr1=\"-2147483647\" attr2=\"-2147483648\" attr3=\"4294967295\" attr4=\"4294967294\"/>"));
181
+ }
182
+ #endif
183
+
184
+ #ifdef PUGIXML_HAS_LONG_LONG
185
+ TEST_XML(dom_attr_assign_llong, "<node/>")
186
+ {
187
+ xml_node node = doc.child(STR("node"));
188
+
189
+ node.append_attribute(STR("attr1")) = -9223372036854775807ll;
190
+ node.append_attribute(STR("attr2")) = -9223372036854775807ll - 1;
191
+ xml_attribute() = -9223372036854775807ll - 1;
192
+
193
+ node.append_attribute(STR("attr3")) = 18446744073709551615ull;
194
+ node.append_attribute(STR("attr4")) = 18446744073709551614ull;
195
+ xml_attribute() = 18446744073709551615ull;
196
+
197
+ CHECK_NODE(node, STR("<node attr1=\"-9223372036854775807\" attr2=\"-9223372036854775808\" attr3=\"18446744073709551615\" attr4=\"18446744073709551614\"/>"));
198
+ }
199
+
200
+ TEST_XML(dom_attr_set_value_llong, "<node/>")
201
+ {
202
+ xml_node node = doc.child(STR("node"));
203
+
204
+ CHECK(node.append_attribute(STR("attr1")).set_value(-9223372036854775807ll));
205
+ CHECK(node.append_attribute(STR("attr2")).set_value(-9223372036854775807ll - 1));
206
+ CHECK(!xml_attribute().set_value(-9223372036854775807ll - 1));
207
+
208
+ CHECK(node.append_attribute(STR("attr3")).set_value(18446744073709551615ull));
209
+ CHECK(node.append_attribute(STR("attr4")).set_value(18446744073709551614ull));
210
+ CHECK(!xml_attribute().set_value(18446744073709551615ull));
211
+
212
+ CHECK_NODE(node, STR("<node attr1=\"-9223372036854775807\" attr2=\"-9223372036854775808\" attr3=\"18446744073709551615\" attr4=\"18446744073709551614\"/>"));
213
+ }
214
+ #endif
215
+
216
+ TEST_XML(dom_attr_assign_large_number_float, "<node attr='' />")
217
+ {
218
+ xml_node node = doc.child(STR("node"));
219
+
220
+ node.attribute(STR("attr")) = std::numeric_limits<float>::max();
221
+
222
+ CHECK(test_node(node, STR("<node attr=\"3.40282347e+038\"/>"), STR(""), format_raw) ||
223
+ test_node(node, STR("<node attr=\"3.40282347e+38\"/>"), STR(""), format_raw));
224
+ }
225
+
226
+ TEST_XML(dom_attr_assign_large_number_double, "<node attr='' />")
227
+ {
228
+ xml_node node = doc.child(STR("node"));
229
+
230
+ node.attribute(STR("attr")) = std::numeric_limits<double>::max();
231
+
232
+ // Borland C does not print double values with enough precision
233
+ #ifdef __BORLANDC__
234
+ CHECK_NODE(node, STR("<node attr=\"1.7976931348623156e+308\"/>"));
235
+ #else
236
+ CHECK_NODE(node, STR("<node attr=\"1.7976931348623157e+308\"/>"));
237
+ #endif
238
+ }
239
+
240
+ TEST_XML(dom_node_set_name, "<node>text</node>")
241
+ {
242
+ CHECK(doc.child(STR("node")).set_name(STR("n")));
243
+ CHECK(!doc.child(STR("node")).first_child().set_name(STR("n")));
244
+ CHECK(!xml_node().set_name(STR("n")));
245
+
246
+ CHECK_NODE(doc, STR("<n>text</n>"));
247
+ }
248
+
249
+ TEST_XML(dom_node_set_name_with_size, "<node>text</node>")
250
+ {
251
+ CHECK(doc.child(STR("node")).set_name(STR("nlongname"), 1));
252
+ CHECK(!doc.child(STR("node")).first_child().set_name(STR("n42"), 1));
253
+ CHECK(!xml_node().set_name(STR("nanothername"), 1));
254
+
255
+ CHECK_NODE(doc, STR("<n>text</n>"));
256
+ }
257
+
258
+ #ifdef PUGIXML_HAS_STRING_VIEW
259
+ TEST_XML(dom_node_set_name_with_string_view, "<node>text</node>")
260
+ {
261
+ xml_node node = doc.child(STR("node"));
262
+
263
+ CHECK(node.set_name(string_view_t()));
264
+ CHECK(!node.first_child().set_name(string_view_t(STR("n42"), 1)));
265
+ CHECK(!xml_node().set_name(string_view_t(STR("nanothername"), 1)));
266
+
267
+ CHECK_NODE(doc, STR("<:anonymous>text</:anonymous>"));
268
+
269
+ CHECK(node.set_name(string_view_t(STR("nlongname"), 1)));
270
+ CHECK(!doc.child(STR("node")).first_child().set_name(string_view_t(STR("n42"), 1)));
271
+ CHECK(!xml_node().set_name(string_view_t(STR("nanothername"), 1)));
272
+
273
+ CHECK_NODE(doc, STR("<n>text</n>"));
274
+ }
275
+ #endif
276
+
277
+ TEST_XML(dom_node_set_value, "<node>text</node>")
278
+ {
279
+ CHECK(doc.child(STR("node")).first_child().set_value(STR("no text")));
280
+ CHECK(!doc.child(STR("node")).set_value(STR("no text")));
281
+ CHECK(!xml_node().set_value(STR("no text")));
282
+
283
+ CHECK_NODE(doc, STR("<node>no text</node>"));
284
+ }
285
+
286
+ TEST_XML(dom_node_set_value_partially_with_size, "<node>text</node>")
287
+ {
288
+ CHECK(doc.child(STR("node")).first_child().set_value(STR("no text"), 2));
289
+ CHECK(!doc.child(STR("node")).set_value(STR("no text"), 2));
290
+ CHECK(!xml_node().set_value(STR("no text"), 2));
291
+
292
+ CHECK_NODE(doc, STR("<node>no</node>"));
293
+ }
294
+
295
+ TEST_XML(dom_node_set_value_with_size, "<node>text</node>")
296
+ {
297
+ CHECK(doc.child(STR("node")).first_child().set_value(STR("no text"), 7));
298
+ CHECK(!doc.child(STR("node")).set_value(STR("no text"), 7));
299
+ CHECK(!xml_node().set_value(STR("no text"), 7));
300
+
301
+ CHECK_NODE(doc, STR("<node>no text</node>"));
302
+ }
303
+
304
+ #ifdef PUGIXML_HAS_STRING_VIEW
305
+ TEST_XML(dom_node_set_value_partially_with_string_view, "<node>text</node>")
306
+ {
307
+ CHECK(doc.child(STR("node")).first_child().set_value(string_view_t(STR("no text"), 2)));
308
+ CHECK(!doc.child(STR("node")).set_value(string_view_t(STR("no text"), 2)));
309
+ CHECK(!xml_node().set_value(string_view_t(STR("no text"), 2)));
310
+
311
+ CHECK_NODE(doc, STR("<node>no</node>"));
312
+ }
313
+
314
+ TEST_XML(dom_node_set_value_with_string_view, "<node>text</node>")
315
+ {
316
+ CHECK(doc.child(STR("node")).first_child().set_value(string_view_t(STR("no text"), 7)));
317
+ CHECK(!doc.child(STR("node")).set_value(string_view_t(STR("no text"), 7)));
318
+ CHECK(!xml_node().set_value(string_view_t(STR("no text"), 7)));
319
+
320
+ CHECK_NODE(doc, STR("<node>no text</node>"));
321
+ }
322
+ #endif
323
+
324
+ TEST_XML(dom_node_set_value_allocated, "<node>text</node>")
325
+ {
326
+ CHECK(doc.child(STR("node")).first_child().set_value(STR("no text")));
327
+ CHECK(!doc.child(STR("node")).set_value(STR("no text")));
328
+ CHECK(!xml_node().set_value(STR("no text")));
329
+ CHECK(doc.child(STR("node")).first_child().set_value(STR("no text at all")));
330
+
331
+ CHECK_NODE(doc, STR("<node>no text at all</node>"));
332
+ }
333
+
334
+ TEST_XML(dom_node_prepend_attribute, "<node><child/></node>")
335
+ {
336
+ CHECK(xml_node().prepend_attribute(STR("a")) == xml_attribute());
337
+ CHECK(doc.prepend_attribute(STR("a")) == xml_attribute());
338
+
339
+ xml_attribute a1 = doc.child(STR("node")).prepend_attribute(STR("a1"));
340
+ CHECK(a1);
341
+ a1 = STR("v1");
342
+
343
+ xml_attribute a2 = doc.child(STR("node")).prepend_attribute(STR("a2"));
344
+ CHECK(a2 && a1 != a2);
345
+ a2 = STR("v2");
346
+
347
+ xml_attribute a3 = doc.child(STR("node")).child(STR("child")).prepend_attribute(STR("a3"));
348
+ CHECK(a3 && a1 != a3 && a2 != a3);
349
+ a3 = STR("v3");
350
+
351
+ #ifdef PUGIXML_HAS_STRING_VIEW
352
+ xml_attribute a4 = doc.child(STR("node")).child(STR("child")).prepend_attribute(string_view_t(STR("a4")));
353
+ #else
354
+ xml_attribute a4 = doc.child(STR("node")).child(STR("child")).prepend_attribute(STR("a4"));
355
+ #endif
356
+ CHECK(a4 && a1 != a4 && a2 != a4 && a3 != a4);
357
+ a4 = STR("v4");
358
+
359
+ CHECK_NODE(doc, STR("<node a2=\"v2\" a1=\"v1\"><child a4=\"v4\" a3=\"v3\"/></node>"));
360
+ }
361
+
362
+ TEST_XML(dom_node_append_attribute, "<node><child/></node>")
363
+ {
364
+ CHECK(xml_node().append_attribute(STR("a")) == xml_attribute());
365
+ CHECK(doc.append_attribute(STR("a")) == xml_attribute());
366
+
367
+ xml_attribute a1 = doc.child(STR("node")).append_attribute(STR("a1"));
368
+ CHECK(a1);
369
+ a1 = STR("v1");
370
+
371
+ xml_attribute a2 = doc.child(STR("node")).append_attribute(STR("a2"));
372
+ CHECK(a2 && a1 != a2);
373
+ a2 = STR("v2");
374
+
375
+ xml_attribute a3 = doc.child(STR("node")).child(STR("child")).append_attribute(STR("a3"));
376
+ CHECK(a3 && a1 != a3 && a2 != a3);
377
+ a3 = STR("v3");
378
+
379
+ CHECK_NODE(doc, STR("<node a1=\"v1\" a2=\"v2\"><child a3=\"v3\"/></node>"));
380
+ }
381
+
382
+ TEST_XML(dom_node_ensure_attribute, "<node a1='v1'><child/></node>")
383
+ {
384
+ CHECK(xml_node().ensure_attribute(STR("a")) == xml_attribute());
385
+ CHECK(doc.ensure_attribute(STR("a")) == xml_attribute());
386
+
387
+ xml_node node = doc.child(STR("node"));
388
+
389
+ // existing attribute is returned as is
390
+ xml_attribute a1 = node.ensure_attribute(STR("a1"));
391
+ CHECK(a1 && a1 == node.attribute(STR("a1")));
392
+ CHECK_STRING(a1.value(), STR("v1"));
393
+
394
+ // missing attribute is appended
395
+ xml_attribute a2 = node.ensure_attribute(STR("a2"));
396
+ CHECK(a2 && a2 != a1);
397
+ a2 = STR("v2");
398
+
399
+ // ensuring an existing attribute does not add a duplicate
400
+ CHECK(node.ensure_attribute(STR("a2")) == a2);
401
+
402
+ #ifdef PUGIXML_HAS_STRING_VIEW
403
+ xml_attribute a3 = node.child(STR("child")).ensure_attribute(string_view_t(STR("a3")));
404
+ #else
405
+ xml_attribute a3 = node.child(STR("child")).ensure_attribute(STR("a3"));
406
+ #endif
407
+ CHECK(a3 && a3 != a1 && a3 != a2);
408
+ a3 = STR("v3");
409
+
410
+ CHECK_NODE(doc, STR("<node a1=\"v1\" a2=\"v2\"><child a3=\"v3\"/></node>"));
411
+ }
412
+
413
+ TEST_XML(dom_node_insert_attribute_after, "<node a1='v1'><child a2='v2'/></node>")
414
+ {
415
+ CHECK(xml_node().insert_attribute_after(STR("a"), xml_attribute()) == xml_attribute());
416
+
417
+ xml_node node = doc.child(STR("node"));
418
+ xml_node child = node.child(STR("child"));
419
+
420
+ xml_attribute a1 = node.attribute(STR("a1"));
421
+ xml_attribute a2 = child.attribute(STR("a2"));
422
+
423
+ CHECK(node.insert_attribute_after(STR("a"), xml_attribute()) == xml_attribute());
424
+ CHECK(node.insert_attribute_after(STR("a"), a2) == xml_attribute());
425
+
426
+ xml_attribute a3 = node.insert_attribute_after(STR("a3"), a1);
427
+ CHECK(a3 && a3 != a2 && a3 != a1);
428
+ a3 = STR("v3");
429
+
430
+ xml_attribute a4 = node.insert_attribute_after(STR("a4"), a1);
431
+ CHECK(a4 && a4 != a3 && a4 != a2 && a4 != a1);
432
+ a4 = STR("v4");
433
+
434
+ xml_attribute a5 = node.insert_attribute_after(STR("a5"), a3);
435
+ CHECK(a5 && a5 != a4 && a5 != a3 && a5 != a2 && a5 != a1);
436
+ a5 = STR("v5");
437
+
438
+ CHECK(child.insert_attribute_after(STR("a"), a4) == xml_attribute());
439
+
440
+ #ifdef PUGIXML_HAS_STRING_VIEW
441
+ xml_attribute a6 = node.insert_attribute_after(string_view_t(STR("a6")), a5);
442
+ CHECK(child.insert_attribute_after(string_view_t(STR("a")), a5) == xml_attribute());
443
+ #else
444
+ xml_attribute a6 = node.insert_attribute_after(STR("a6"), a5);
445
+ CHECK(child.insert_attribute_after(STR("a"), a5) == xml_attribute());
446
+ #endif
447
+ CHECK(a6 && a6 != a5 && a6 != a4 && a6 != a3 && a6 != a2 && a6 != a1);
448
+ a6 = STR("v6");
449
+
450
+ CHECK_NODE(doc, STR("<node a1=\"v1\" a4=\"v4\" a3=\"v3\" a5=\"v5\" a6=\"v6\"><child a2=\"v2\"/></node>"));
451
+ }
452
+
453
+ TEST_XML(dom_node_insert_attribute_before, "<node a1='v1'><child a2='v2'/></node>")
454
+ {
455
+ CHECK(xml_node().insert_attribute_before(STR("a"), xml_attribute()) == xml_attribute());
456
+
457
+ xml_node node = doc.child(STR("node"));
458
+ xml_node child = node.child(STR("child"));
459
+
460
+ xml_attribute a1 = node.attribute(STR("a1"));
461
+ xml_attribute a2 = child.attribute(STR("a2"));
462
+
463
+ CHECK(node.insert_attribute_before(STR("a"), xml_attribute()) == xml_attribute());
464
+ CHECK(node.insert_attribute_before(STR("a"), a2) == xml_attribute());
465
+
466
+ xml_attribute a3 = node.insert_attribute_before(STR("a3"), a1);
467
+ CHECK(a3 && a3 != a2 && a3 != a1);
468
+ a3 = STR("v3");
469
+
470
+ xml_attribute a4 = node.insert_attribute_before(STR("a4"), a1);
471
+ CHECK(a4 && a4 != a3 && a4 != a2 && a4 != a1);
472
+ a4 = STR("v4");
473
+
474
+ xml_attribute a5 = node.insert_attribute_before(STR("a5"), a3);
475
+ CHECK(a5 && a5 != a4 && a5 != a3 && a5 != a2 && a5 != a1);
476
+ a5 = STR("v5");
477
+
478
+ CHECK(child.insert_attribute_before(STR("a"), a4) == xml_attribute());
479
+
480
+ #ifdef PUGIXML_HAS_STRING_VIEW
481
+ xml_attribute a6 = node.insert_attribute_before(string_view_t(STR("a6")), a1);
482
+ CHECK(child.insert_attribute_before(string_view_t(STR("a")), a4) == xml_attribute());
483
+ #else
484
+ xml_attribute a6 = node.insert_attribute_before(STR("a6"), a1);
485
+ CHECK(child.insert_attribute_before(STR("a"), a4) == xml_attribute());
486
+ #endif
487
+ CHECK(a6 && a6 != a5 && a6 != a4 && a6 != a3 && a6 != a2 && a6 != a1);
488
+ a6 = STR("v6");
489
+
490
+ CHECK_NODE(doc, STR("<node a5=\"v5\" a3=\"v3\" a4=\"v4\" a6=\"v6\" a1=\"v1\"><child a2=\"v2\"/></node>"));
491
+ }
492
+
493
+ TEST_XML(dom_node_prepend_copy_attribute, "<node a1='v1'><child a2='v2'/><child/></node>")
494
+ {
495
+ CHECK(xml_node().prepend_copy(xml_attribute()) == xml_attribute());
496
+ CHECK(xml_node().prepend_copy(doc.child(STR("node")).attribute(STR("a1"))) == xml_attribute());
497
+ CHECK(doc.prepend_copy(doc.child(STR("node")).attribute(STR("a1"))) == xml_attribute());
498
+ CHECK(doc.child(STR("node")).prepend_copy(xml_attribute()) == xml_attribute());
499
+
500
+ xml_node node = doc.child(STR("node"));
501
+ xml_node child = node.child(STR("child"));
502
+
503
+ xml_attribute a1 = node.attribute(STR("a1"));
504
+ xml_attribute a2 = child.attribute(STR("a2"));
505
+
506
+ xml_attribute a3 = node.prepend_copy(a1);
507
+ CHECK(a3 && a3 != a2 && a3 != a1);
508
+
509
+ xml_attribute a4 = node.prepend_copy(a2);
510
+ CHECK(a4 && a4 != a3 && a4 != a2 && a4 != a1);
511
+
512
+ xml_attribute a5 = node.last_child().prepend_copy(a1);
513
+ CHECK(a5 && a5 != a4 && a5 != a3 && a5 != a2 && a5 != a1);
514
+
515
+ CHECK_NODE(doc, STR("<node a2=\"v2\" a1=\"v1\" a1=\"v1\"><child a2=\"v2\"/><child a1=\"v1\"/></node>"));
516
+
517
+ a3.set_name(STR("a3"));
518
+ a3 = STR("v3");
519
+
520
+ a4.set_name(STR("a4"));
521
+ a4 = STR("v4");
522
+
523
+ a5.set_name(STR("a5"));
524
+ a5 = STR("v5");
525
+
526
+ CHECK_NODE(doc, STR("<node a4=\"v4\" a3=\"v3\" a1=\"v1\"><child a2=\"v2\"/><child a5=\"v5\"/></node>"));
527
+ }
528
+
529
+ TEST_XML(dom_node_append_copy_attribute, "<node a1='v1'><child a2='v2'/><child/></node>")
530
+ {
531
+ CHECK(xml_node().append_copy(xml_attribute()) == xml_attribute());
532
+ CHECK(xml_node().append_copy(doc.child(STR("node")).attribute(STR("a1"))) == xml_attribute());
533
+ CHECK(doc.append_copy(doc.child(STR("node")).attribute(STR("a1"))) == xml_attribute());
534
+ CHECK(doc.child(STR("node")).append_copy(xml_attribute()) == xml_attribute());
535
+
536
+ xml_node node = doc.child(STR("node"));
537
+ xml_node child = node.child(STR("child"));
538
+
539
+ xml_attribute a1 = node.attribute(STR("a1"));
540
+ xml_attribute a2 = child.attribute(STR("a2"));
541
+
542
+ xml_attribute a3 = node.append_copy(a1);
543
+ CHECK(a3 && a3 != a2 && a3 != a1);
544
+
545
+ xml_attribute a4 = node.append_copy(a2);
546
+ CHECK(a4 && a4 != a3 && a4 != a2 && a4 != a1);
547
+
548
+ xml_attribute a5 = node.last_child().append_copy(a1);
549
+ CHECK(a5 && a5 != a4 && a5 != a3 && a5 != a2 && a5 != a1);
550
+
551
+ CHECK_NODE(doc, STR("<node a1=\"v1\" a1=\"v1\" a2=\"v2\"><child a2=\"v2\"/><child a1=\"v1\"/></node>"));
552
+
553
+ a3.set_name(STR("a3"));
554
+ a3 = STR("v3");
555
+
556
+ a4.set_name(STR("a4"));
557
+ a4 = STR("v4");
558
+
559
+ a5.set_name(STR("a5"));
560
+ a5 = STR("v5");
561
+
562
+ CHECK_NODE(doc, STR("<node a1=\"v1\" a3=\"v3\" a4=\"v4\"><child a2=\"v2\"/><child a5=\"v5\"/></node>"));
563
+ }
564
+
565
+ TEST_XML(dom_node_insert_copy_after_attribute, "<node a1='v1'><child a2='v2'/>text</node>")
566
+ {
567
+ CHECK(xml_node().insert_copy_after(xml_attribute(), xml_attribute()) == xml_attribute());
568
+
569
+ xml_node node = doc.child(STR("node"));
570
+ xml_node child = node.child(STR("child"));
571
+
572
+ xml_attribute a1 = node.attribute(STR("a1"));
573
+ xml_attribute a2 = child.attribute(STR("a2"));
574
+
575
+ CHECK(node.insert_copy_after(a1, xml_attribute()) == xml_attribute());
576
+ CHECK(node.insert_copy_after(xml_attribute(), a1) == xml_attribute());
577
+ CHECK(node.insert_copy_after(a2, a2) == xml_attribute());
578
+ CHECK(node.last_child().insert_copy_after(a2, a2) == xml_attribute());
579
+
580
+ xml_attribute a3 = node.insert_copy_after(a1, a1);
581
+ CHECK(a3 && a3 != a2 && a3 != a1);
582
+
583
+ xml_attribute a4 = node.insert_copy_after(a2, a1);
584
+ CHECK(a4 && a4 != a3 && a4 != a2 && a4 != a1);
585
+
586
+ xml_attribute a5 = node.insert_copy_after(a4, a1);
587
+ CHECK(a5 && a5 != a4 && a5 != a3 && a5 != a2 && a5 != a1);
588
+
589
+ CHECK(child.insert_copy_after(a4, a4) == xml_attribute());
590
+
591
+ CHECK_NODE(doc, STR("<node a1=\"v1\" a2=\"v2\" a2=\"v2\" a1=\"v1\"><child a2=\"v2\"/>text</node>"));
592
+
593
+ a3.set_name(STR("a3"));
594
+ a3 = STR("v3");
595
+
596
+ a4.set_name(STR("a4"));
597
+ a4 = STR("v4");
598
+
599
+ a5.set_name(STR("a5"));
600
+ a5 = STR("v5");
601
+
602
+ CHECK_NODE(doc, STR("<node a1=\"v1\" a5=\"v5\" a4=\"v4\" a3=\"v3\"><child a2=\"v2\"/>text</node>"));
603
+ }
604
+
605
+ TEST_XML(dom_node_insert_copy_before_attribute, "<node a1='v1'><child a2='v2'/>text</node>")
606
+ {
607
+ CHECK(xml_node().insert_copy_before(xml_attribute(), xml_attribute()) == xml_attribute());
608
+
609
+ xml_node node = doc.child(STR("node"));
610
+ xml_node child = node.child(STR("child"));
611
+
612
+ xml_attribute a1 = node.attribute(STR("a1"));
613
+ xml_attribute a2 = child.attribute(STR("a2"));
614
+
615
+ CHECK(node.insert_copy_before(a1, xml_attribute()) == xml_attribute());
616
+ CHECK(node.insert_copy_before(xml_attribute(), a1) == xml_attribute());
617
+ CHECK(node.insert_copy_before(a2, a2) == xml_attribute());
618
+ CHECK(node.last_child().insert_copy_before(a2, a2) == xml_attribute());
619
+
620
+ xml_attribute a3 = node.insert_copy_before(a1, a1);
621
+ CHECK(a3 && a3 != a2 && a3 != a1);
622
+
623
+ xml_attribute a4 = node.insert_copy_before(a2, a1);
624
+ CHECK(a4 && a4 != a3 && a4 != a2 && a4 != a1);
625
+
626
+ xml_attribute a5 = node.insert_copy_before(a4, a1);
627
+ CHECK(a5 && a5 != a4 && a5 != a3 && a5 != a2 && a5 != a1);
628
+
629
+ CHECK(child.insert_copy_before(a4, a4) == xml_attribute());
630
+
631
+ CHECK_NODE(doc, STR("<node a1=\"v1\" a2=\"v2\" a2=\"v2\" a1=\"v1\"><child a2=\"v2\"/>text</node>"));
632
+
633
+ a3.set_name(STR("a3"));
634
+ a3 = STR("v3");
635
+
636
+ a4.set_name(STR("a4"));
637
+ a4 = STR("v4");
638
+
639
+ a5.set_name(STR("a5"));
640
+ a5 = STR("v5");
641
+
642
+ CHECK_NODE(doc, STR("<node a3=\"v3\" a4=\"v4\" a5=\"v5\" a1=\"v1\"><child a2=\"v2\"/>text</node>"));
643
+ }
644
+
645
+ TEST_XML(dom_node_remove_attribute, "<node a1='v1' a2='v2' a3='v3'><child a4='v4'/></node>")
646
+ {
647
+ CHECK(!xml_node().remove_attribute(STR("a")));
648
+ CHECK(!xml_node().remove_attribute(xml_attribute()));
649
+
650
+ xml_node node = doc.child(STR("node"));
651
+ xml_node child = node.child(STR("child"));
652
+
653
+ CHECK(!node.remove_attribute(STR("a")));
654
+ CHECK(!node.remove_attribute(xml_attribute()));
655
+ CHECK(!node.remove_attribute(child.attribute(STR("a4"))));
656
+
657
+ CHECK_NODE(doc, STR("<node a1=\"v1\" a2=\"v2\" a3=\"v3\"><child a4=\"v4\"/></node>"));
658
+
659
+ CHECK(node.remove_attribute(STR("a1")));
660
+ CHECK(node.remove_attribute(node.attribute(STR("a3"))));
661
+ CHECK(child.remove_attribute(STR("a4")));
662
+
663
+ CHECK_NODE(doc, STR("<node a2=\"v2\"><child/></node>"));
664
+
665
+ #ifdef PUGIXML_HAS_STRING_VIEW
666
+ CHECK(!node.remove_attribute(string_view_t()));
667
+ CHECK(!node.remove_attribute(string_view_t(STR("a2"), 1)));
668
+ CHECK(node.remove_attribute(string_view_t(STR("a2extra"), 2)));
669
+
670
+ CHECK_NODE(doc, STR("<node><child/></node>"));
671
+ #endif
672
+ }
673
+
674
+ TEST_XML(dom_node_remove_attributes, "<node a1='v1' a2='v2' a3='v3'><child a4='v4'/></node>")
675
+ {
676
+ CHECK(!xml_node().remove_attributes());
677
+ xml_node node = doc.child(STR("node"));
678
+ xml_node child = node.child(STR("child"));
679
+
680
+ CHECK(child.remove_attributes());
681
+ CHECK_NODE(child, STR("<child/>"));
682
+
683
+ CHECK(node.remove_attributes());
684
+ CHECK_NODE(node, STR("<node><child/></node>"));
685
+ }
686
+
687
+ TEST_XML(dom_node_remove_attributes_lots, "<node/>")
688
+ {
689
+ xml_node node = doc.child(STR("node"));
690
+
691
+ // this test makes sure we generate at least 2 pages (64K) worth of attribute data
692
+ // so that we can trigger page deallocation to make sure code is memory safe
693
+ for (size_t i = 0; i < 10000; ++i)
694
+ node.append_attribute(STR("a")) = STR("v");
695
+
696
+ CHECK_STRING(node.attribute(STR("a")).value(), STR("v"));
697
+
698
+ CHECK(node.remove_attributes());
699
+
700
+ CHECK_STRING(node.attribute(STR("a")).value(), STR(""));
701
+ CHECK_NODE(node, STR("<node/>"));
702
+ }
703
+
704
+ TEST_XML(dom_node_prepend_child, "<node>foo<child/></node>")
705
+ {
706
+ CHECK(xml_node().prepend_child() == xml_node());
707
+ CHECK(doc.child(STR("node")).first_child().prepend_child() == xml_node());
708
+ CHECK(doc.prepend_child(node_document) == xml_node());
709
+ CHECK(doc.prepend_child(node_null) == xml_node());
710
+
711
+ xml_node n1 = doc.child(STR("node")).prepend_child();
712
+ CHECK(n1);
713
+ CHECK(n1.set_name(STR("n1")));
714
+
715
+ xml_node n2 = doc.child(STR("node")).prepend_child();
716
+ CHECK(n2 && n1 != n2);
717
+ CHECK(n2.set_name(STR("n2")));
718
+
719
+ xml_node n3 = doc.child(STR("node")).child(STR("child")).prepend_child(node_pcdata);
720
+ CHECK(n3 && n1 != n3 && n2 != n3);
721
+ CHECK(n3.set_value(STR("n3")));
722
+
723
+ xml_node n4 = doc.prepend_child(node_comment);
724
+ CHECK(n4 && n1 != n4 && n2 != n4 && n3 != n4);
725
+ CHECK(n4.set_value(STR("n4")));
726
+
727
+ CHECK_NODE(doc, STR("<!--n4--><node><n2/><n1/>foo<child>n3</child></node>"));
728
+ }
729
+
730
+ TEST_XML(dom_node_append_child, "<node>foo<child/></node>")
731
+ {
732
+ CHECK(xml_node().append_child() == xml_node());
733
+ CHECK(doc.child(STR("node")).first_child().append_child() == xml_node());
734
+ CHECK(doc.append_child(node_document) == xml_node());
735
+ CHECK(doc.append_child(node_null) == xml_node());
736
+
737
+ xml_node n1 = doc.child(STR("node")).append_child();
738
+ CHECK(n1);
739
+ CHECK(n1.set_name(STR("n1")));
740
+
741
+ xml_node n2 = doc.child(STR("node")).append_child();
742
+ CHECK(n2 && n1 != n2);
743
+ CHECK(n2.set_name(STR("n2")));
744
+
745
+ xml_node n3 = doc.child(STR("node")).child(STR("child")).append_child(node_pcdata);
746
+ CHECK(n3 && n1 != n3 && n2 != n3);
747
+ CHECK(n3.set_value(STR("n3")));
748
+
749
+ xml_node n4 = doc.append_child(node_comment);
750
+ CHECK(n4 && n1 != n4 && n2 != n4 && n3 != n4);
751
+ CHECK(n4.set_value(STR("n4")));
752
+
753
+ CHECK_NODE(doc, STR("<node>foo<child>n3</child><n1/><n2/></node><!--n4-->"));
754
+ }
755
+
756
+ TEST_XML(dom_node_insert_child_after, "<node>foo<child/></node>")
757
+ {
758
+ CHECK(xml_node().insert_child_after(node_element, xml_node()) == xml_node());
759
+ CHECK(doc.child(STR("node")).first_child().insert_child_after(node_element, xml_node()) == xml_node());
760
+ CHECK(doc.insert_child_after(node_document, xml_node()) == xml_node());
761
+ CHECK(doc.insert_child_after(node_null, xml_node()) == xml_node());
762
+
763
+ xml_node node = doc.child(STR("node"));
764
+ xml_node child = node.child(STR("child"));
765
+
766
+ CHECK(node.insert_child_after(node_element, xml_node()) == xml_node());
767
+ CHECK(node.insert_child_after(node_element, node) == xml_node());
768
+ CHECK(child.insert_child_after(node_element, node) == xml_node());
769
+
770
+ xml_node n1 = node.insert_child_after(node_element, child);
771
+ CHECK(n1 && n1 != node && n1 != child);
772
+ CHECK(n1.set_name(STR("n1")));
773
+
774
+ xml_node n2 = node.insert_child_after(node_element, child);
775
+ CHECK(n2 && n2 != node && n2 != child && n2 != n1);
776
+ CHECK(n2.set_name(STR("n2")));
777
+
778
+ xml_node n3 = node.insert_child_after(node_pcdata, n2);
779
+ CHECK(n3 && n3 != node && n3 != child && n3 != n1 && n3 != n2);
780
+ CHECK(n3.set_value(STR("n3")));
781
+
782
+ xml_node n4 = node.insert_child_after(node_pi, node.first_child());
783
+ CHECK(n4 && n4 != node && n4 != child && n4 != n1 && n4 != n2 && n4 != n3);
784
+ CHECK(n4.set_name(STR("n4")));
785
+
786
+ CHECK(child.insert_child_after(node_element, n3) == xml_node());
787
+
788
+ CHECK_NODE(doc, STR("<node>foo<?n4?><child/><n2/>n3<n1/></node>"));
789
+ }
790
+
791
+ TEST_XML(dom_node_insert_child_before, "<node>foo<child/></node>")
792
+ {
793
+ CHECK(xml_node().insert_child_before(node_element, xml_node()) == xml_node());
794
+ CHECK(doc.child(STR("node")).first_child().insert_child_before(node_element, xml_node()) == xml_node());
795
+ CHECK(doc.insert_child_before(node_document, xml_node()) == xml_node());
796
+ CHECK(doc.insert_child_before(node_null, xml_node()) == xml_node());
797
+
798
+ xml_node node = doc.child(STR("node"));
799
+ xml_node child = node.child(STR("child"));
800
+
801
+ CHECK(node.insert_child_before(node_element, xml_node()) == xml_node());
802
+ CHECK(node.insert_child_before(node_element, node) == xml_node());
803
+ CHECK(child.insert_child_before(node_element, node) == xml_node());
804
+
805
+ xml_node n1 = node.insert_child_before(node_element, child);
806
+ CHECK(n1 && n1 != node && n1 != child);
807
+ CHECK(n1.set_name(STR("n1")));
808
+
809
+ xml_node n2 = node.insert_child_before(node_element, child);
810
+ CHECK(n2 && n2 != node && n2 != child && n2 != n1);
811
+ CHECK(n2.set_name(STR("n2")));
812
+
813
+ xml_node n3 = node.insert_child_before(node_pcdata, n2);
814
+ CHECK(n3 && n3 != node && n3 != child && n3 != n1 && n3 != n2);
815
+ CHECK(n3.set_value(STR("n3")));
816
+
817
+ xml_node n4 = node.insert_child_before(node_pi, node.first_child());
818
+ CHECK(n4 && n4 != node && n4 != child && n4 != n1 && n4 != n2 && n4 != n3);
819
+ CHECK(n4.set_name(STR("n4")));
820
+
821
+ CHECK(child.insert_child_before(node_element, n3) == xml_node());
822
+
823
+ CHECK_NODE(doc, STR("<node><?n4?>foo<n1/>n3<n2/><child/></node>"));
824
+ }
825
+
826
+ TEST_XML(dom_node_prepend_child_name, "<node>foo<child/></node>")
827
+ {
828
+ CHECK(xml_node().prepend_child(STR("")) == xml_node());
829
+ CHECK(doc.child(STR("node")).first_child().prepend_child(STR("")) == xml_node());
830
+ #ifdef PUGIXML_HAS_STRING_VIEW
831
+ CHECK(xml_node().prepend_child(string_view_t()) == xml_node());
832
+ CHECK(doc.child(STR("node")).first_child().prepend_child(string_view_t()) == xml_node());
833
+ #endif
834
+
835
+ xml_node n1 = doc.child(STR("node")).prepend_child(STR("n1"));
836
+ CHECK(n1);
837
+
838
+ xml_node n2 = doc.child(STR("node")).prepend_child(STR("n2"));
839
+ CHECK(n2 && n1 != n2);
840
+
841
+ #ifdef PUGIXML_HAS_STRING_VIEW
842
+ xml_node n3 = doc.prepend_child(string_view_t(STR("n3")));
843
+ #else
844
+ xml_node n3 = doc.prepend_child(STR("n3"));
845
+ #endif
846
+ CHECK(n3 && n1 != n3 && n2 != n3);
847
+
848
+ CHECK_NODE(doc, STR("<n3/><node><n2/><n1/>foo<child/></node>"));
849
+ }
850
+
851
+ TEST_XML(dom_node_append_child_name, "<node>foo<child/></node>")
852
+ {
853
+ CHECK(xml_node().append_child(STR("")) == xml_node());
854
+ CHECK(doc.child(STR("node")).first_child().append_child(STR("")) == xml_node());
855
+
856
+ xml_node n1 = doc.child(STR("node")).append_child(STR("n1"));
857
+ CHECK(n1);
858
+
859
+ xml_node n2 = doc.child(STR("node")).append_child(STR("n2"));
860
+ CHECK(n2 && n1 != n2);
861
+
862
+ #ifdef PUGIXML_HAS_STRING_VIEW
863
+ xml_node n3 = doc.append_child(string_view_t(STR("n3")));
864
+ #else
865
+ xml_node n3 = doc.append_child(STR("n3"));
866
+ #endif
867
+ CHECK(n3 && n3 != n2 && n3 != n1);
868
+
869
+ CHECK_NODE(doc, STR("<node>foo<child/><n1/><n2/></node><n3/>"));
870
+ }
871
+
872
+ TEST_XML(dom_node_ensure_child, "<node>foo<child/></node>")
873
+ {
874
+ CHECK(xml_node().ensure_child(STR("")) == xml_node());
875
+ CHECK(doc.child(STR("node")).first_child().ensure_child(STR("n")) == xml_node());
876
+
877
+ xml_node node = doc.child(STR("node"));
878
+
879
+ // existing child is returned as is
880
+ xml_node child = node.ensure_child(STR("child"));
881
+ CHECK(child && child == node.child(STR("child")));
882
+
883
+ // missing child is appended
884
+ xml_node n1 = node.ensure_child(STR("n1"));
885
+ CHECK(n1 && n1 != child);
886
+
887
+ // ensuring an existing child does not add a duplicate
888
+ CHECK(node.ensure_child(STR("child")) == child);
889
+
890
+ #ifdef PUGIXML_HAS_STRING_VIEW
891
+ xml_node n2 = doc.ensure_child(string_view_t(STR("n2")));
892
+ #else
893
+ xml_node n2 = doc.ensure_child(STR("n2"));
894
+ #endif
895
+ CHECK(n2 && n2 != child && n2 != n1);
896
+
897
+ CHECK_NODE(doc, STR("<node>foo<child/><n1/></node><n2/>"));
898
+ }
899
+
900
+ TEST_XML(dom_node_insert_child_after_name, "<node>foo<child/></node>")
901
+ {
902
+ CHECK(xml_node().insert_child_after(STR(""), xml_node()) == xml_node());
903
+ CHECK(doc.child(STR("node")).first_child().insert_child_after(STR(""), xml_node()) == xml_node());
904
+
905
+ xml_node node = doc.child(STR("node"));
906
+ xml_node child = node.child(STR("child"));
907
+
908
+ CHECK(node.insert_child_after(STR(""), node) == xml_node());
909
+ CHECK(child.insert_child_after(STR(""), node) == xml_node());
910
+
911
+ xml_node n1 = node.insert_child_after(STR("n1"), child);
912
+ CHECK(n1 && n1 != node && n1 != child);
913
+
914
+ xml_node n2 = node.insert_child_after(STR("n2"), child);
915
+ CHECK(n2 && n2 != node && n2 != child && n2 != n1);
916
+
917
+ CHECK(child.insert_child_after(STR(""), n2) == xml_node());
918
+
919
+ #ifdef PUGIXML_HAS_STRING_VIEW
920
+ xml_node n3 = node.insert_child_after(string_view_t(STR("n3")), n1);
921
+ #else
922
+ xml_node n3 = node.insert_child_after(STR("n3"), n1);
923
+ #endif
924
+ CHECK(n3 && n3 != node && n3 != child && n3 != n2 && n3 != n1);
925
+
926
+ CHECK_NODE(doc, STR("<node>foo<child/><n2/><n1/><n3/></node>"));
927
+ }
928
+
929
+ TEST_XML(dom_node_insert_child_before_name, "<node>foo<child/></node>")
930
+ {
931
+ CHECK(xml_node().insert_child_before(STR(""), xml_node()) == xml_node());
932
+ CHECK(doc.child(STR("node")).first_child().insert_child_before(STR(""), xml_node()) == xml_node());
933
+
934
+ xml_node node = doc.child(STR("node"));
935
+ xml_node child = node.child(STR("child"));
936
+
937
+ CHECK(node.insert_child_before(STR(""), node) == xml_node());
938
+ CHECK(child.insert_child_before(STR(""), node) == xml_node());
939
+
940
+ xml_node n1 = node.insert_child_before(STR("n1"), child);
941
+ CHECK(n1 && n1 != node && n1 != child);
942
+
943
+ xml_node n2 = node.insert_child_before(STR("n2"), child);
944
+ CHECK(n2 && n2 != node && n2 != child && n2 != n1);
945
+
946
+ CHECK(child.insert_child_before(STR(""), n2) == xml_node());
947
+
948
+ #ifdef PUGIXML_HAS_STRING_VIEW
949
+ xml_node n3 = node.insert_child_before(string_view_t(STR("n3")), child);
950
+ #else
951
+ xml_node n3 = node.insert_child_before(STR("n3"), child);
952
+ #endif
953
+ CHECK(n3 && n3 != node && n3 != child && n3 != n2 && n3 != n1);
954
+
955
+ CHECK_NODE(doc, STR("<node>foo<n1/><n2/><n3/><child/></node>"));
956
+ }
957
+
958
+ TEST_XML(dom_node_remove_child, "<node><n1/><n2/><n3/><child><n4/></child></node>")
959
+ {
960
+ CHECK(!xml_node().remove_child(STR("a")));
961
+ CHECK(!xml_node().remove_child(xml_node()));
962
+
963
+ xml_node node = doc.child(STR("node"));
964
+ xml_node child = node.child(STR("child"));
965
+
966
+ CHECK(!node.remove_child(STR("a")));
967
+ CHECK(!node.remove_child(xml_node()));
968
+ CHECK(!node.remove_child(child.child(STR("n4"))));
969
+
970
+ CHECK_NODE(doc, STR("<node><n1/><n2/><n3/><child><n4/></child></node>"));
971
+
972
+ CHECK(node.remove_child(STR("n1")));
973
+ CHECK(node.remove_child(node.child(STR("n3"))));
974
+ CHECK(child.remove_child(STR("n4")));
975
+
976
+ CHECK_NODE(doc, STR("<node><n2/><child/></node>"));
977
+
978
+ #ifdef PUGIXML_HAS_STRING_VIEW
979
+ CHECK(!node.remove_child(string_view_t()));
980
+ CHECK(!node.remove_child(string_view_t(STR("child"), 3)));
981
+ CHECK(!node.remove_child(string_view_t(STR("n2"), 1)));
982
+
983
+ CHECK_NODE(doc, STR("<node><n2/><child/></node>"));
984
+
985
+ CHECK(node.remove_child(string_view_t(STR("child"))));
986
+ CHECK_NODE(doc, STR("<node><n2/></node>"));
987
+
988
+ CHECK(node.remove_child(string_view_t(STR("n2_notinview"), 2)));
989
+ CHECK_NODE(doc, STR("<node/>"));
990
+ #endif
991
+ }
992
+
993
+ TEST_XML(dom_node_remove_children, "<node><n1/><n2/><n3/><child><n4/></child></node>")
994
+ {
995
+ CHECK(!xml_node().remove_children());
996
+ xml_node node = doc.child(STR("node"));
997
+ xml_node child = node.child(STR("child"));
998
+
999
+ CHECK(child.remove_children());
1000
+ CHECK_NODE(child, STR("<child/>"));
1001
+
1002
+ CHECK(node.remove_children());
1003
+ CHECK_NODE(node, STR("<node/>"));
1004
+ }
1005
+
1006
+ TEST_XML(dom_node_remove_children_lots, "<node/>")
1007
+ {
1008
+ xml_node node = doc.child(STR("node"));
1009
+
1010
+ // this test makes sure we generate at least 2 pages (64K) worth of node data
1011
+ // so that we can trigger page deallocation to make sure code is memory safe
1012
+ for (size_t i = 0; i < 10000; ++i)
1013
+ node.append_child().set_name(STR("n"));
1014
+
1015
+ CHECK(node.child(STR("n")));
1016
+
1017
+ CHECK(node.remove_children());
1018
+
1019
+ CHECK(!node.child(STR("n")));
1020
+ CHECK_NODE(node, STR("<node/>"));
1021
+ }
1022
+
1023
+ TEST_XML(dom_node_remove_child_complex, "<node id='1'><n1 id1='1' id2='2'/><n2/><n3/><child><n4/></child></node>")
1024
+ {
1025
+ CHECK(doc.child(STR("node")).remove_child(STR("n1")));
1026
+
1027
+ CHECK_NODE(doc, STR("<node id=\"1\"><n2/><n3/><child><n4/></child></node>"));
1028
+
1029
+ CHECK(doc.remove_child(STR("node")));
1030
+
1031
+ CHECK_NODE(doc, STR(""));
1032
+ }
1033
+
1034
+ TEST_XML(dom_node_remove_child_complex_allocated, "<node id='1'><n1 id1='1' id2='2'/><n2/><n3/><child><n4/></child></node>")
1035
+ {
1036
+ doc.append_copy(doc.child(STR("node")));
1037
+
1038
+ CHECK(doc.remove_child(STR("node")));
1039
+ CHECK(doc.remove_child(STR("node")));
1040
+
1041
+ CHECK_NODE(doc, STR(""));
1042
+ }
1043
+
1044
+ TEST_XML(dom_node_prepend_copy, "<node>foo<child/></node>")
1045
+ {
1046
+ CHECK(xml_node().prepend_copy(xml_node()) == xml_node());
1047
+ CHECK(doc.child(STR("node")).first_child().prepend_copy(doc.child(STR("node"))) == xml_node());
1048
+ CHECK(doc.prepend_copy(doc) == xml_node());
1049
+ CHECK(doc.prepend_copy(xml_node()) == xml_node());
1050
+
1051
+ xml_node n1 = doc.child(STR("node")).prepend_copy(doc.child(STR("node")).first_child());
1052
+ CHECK(n1);
1053
+ CHECK_STRING(n1.value(), STR("foo"));
1054
+ CHECK_NODE(doc, STR("<node>foofoo<child/></node>"));
1055
+
1056
+ xml_node n2 = doc.child(STR("node")).prepend_copy(doc.child(STR("node")).child(STR("child")));
1057
+ CHECK(n2 && n2 != n1);
1058
+ CHECK_STRING(n2.name(), STR("child"));
1059
+ CHECK_NODE(doc, STR("<node><child/>foofoo<child/></node>"));
1060
+
1061
+ xml_node n3 = doc.child(STR("node")).child(STR("child")).prepend_copy(doc.child(STR("node")).first_child().next_sibling());
1062
+ CHECK(n3 && n3 != n1 && n3 != n2);
1063
+ CHECK_STRING(n3.value(), STR("foo"));
1064
+ CHECK_NODE(doc, STR("<node><child>foo</child>foofoo<child/></node>"));
1065
+ }
1066
+
1067
+ TEST_XML(dom_node_append_copy, "<node>foo<child/></node>")
1068
+ {
1069
+ CHECK(xml_node().append_copy(xml_node()) == xml_node());
1070
+ CHECK(doc.child(STR("node")).first_child().append_copy(doc.child(STR("node"))) == xml_node());
1071
+ CHECK(doc.append_copy(doc) == xml_node());
1072
+ CHECK(doc.append_copy(xml_node()) == xml_node());
1073
+
1074
+ xml_node n1 = doc.child(STR("node")).append_copy(doc.child(STR("node")).first_child());
1075
+ CHECK(n1);
1076
+ CHECK_STRING(n1.value(), STR("foo"));
1077
+ CHECK_NODE(doc, STR("<node>foo<child/>foo</node>"));
1078
+
1079
+ xml_node n2 = doc.child(STR("node")).append_copy(doc.child(STR("node")).child(STR("child")));
1080
+ CHECK(n2 && n2 != n1);
1081
+ CHECK_STRING(n2.name(), STR("child"));
1082
+ CHECK_NODE(doc, STR("<node>foo<child/>foo<child/></node>"));
1083
+
1084
+ xml_node n3 = doc.child(STR("node")).child(STR("child")).append_copy(doc.child(STR("node")).first_child());
1085
+ CHECK(n3 && n3 != n1 && n3 != n2);
1086
+ CHECK_STRING(n3.value(), STR("foo"));
1087
+ CHECK_NODE(doc, STR("<node>foo<child>foo</child>foo<child/></node>"));
1088
+ }
1089
+
1090
+ TEST_XML(dom_node_insert_copy_after, "<node>foo<child/></node>")
1091
+ {
1092
+ xml_node child = doc.child(STR("node")).child(STR("child"));
1093
+
1094
+ CHECK(xml_node().insert_copy_after(xml_node(), xml_node()) == xml_node());
1095
+ CHECK(doc.child(STR("node")).first_child().insert_copy_after(doc.child(STR("node")), doc.child(STR("node"))) == xml_node());
1096
+ CHECK(doc.insert_copy_after(doc, doc) == xml_node());
1097
+ CHECK(doc.insert_copy_after(xml_node(), doc.child(STR("node"))) == xml_node());
1098
+ CHECK(doc.insert_copy_after(doc.child(STR("node")), xml_node()) == xml_node());
1099
+ CHECK(doc.insert_copy_after(doc.child(STR("node")), child) == xml_node());
1100
+
1101
+ xml_node n1 = doc.child(STR("node")).insert_copy_after(child, doc.child(STR("node")).first_child());
1102
+ CHECK(n1);
1103
+ CHECK_STRING(n1.name(), STR("child"));
1104
+ CHECK_NODE(doc, STR("<node>foo<child/><child/></node>"));
1105
+
1106
+ xml_node n2 = doc.child(STR("node")).insert_copy_after(doc.child(STR("node")).first_child(), doc.child(STR("node")).last_child());
1107
+ CHECK(n2 && n2 != n1);
1108
+ CHECK_STRING(n2.value(), STR("foo"));
1109
+ CHECK_NODE(doc, STR("<node>foo<child/><child/>foo</node>"));
1110
+
1111
+ xml_node n3 = doc.child(STR("node")).insert_copy_after(doc.child(STR("node")).first_child(), doc.child(STR("node")).first_child());
1112
+ CHECK(n3 && n3 != n1 && n3 != n2);
1113
+ CHECK_STRING(n3.value(), STR("foo"));
1114
+ CHECK_NODE(doc, STR("<node>foofoo<child/><child/>foo</node>"));
1115
+ }
1116
+
1117
+ TEST_XML(dom_node_insert_copy_before, "<node>foo<child/></node>")
1118
+ {
1119
+ xml_node child = doc.child(STR("node")).child(STR("child"));
1120
+
1121
+ CHECK(xml_node().insert_copy_before(xml_node(), xml_node()) == xml_node());
1122
+ CHECK(doc.child(STR("node")).first_child().insert_copy_before(doc.child(STR("node")), doc.child(STR("node"))) == xml_node());
1123
+ CHECK(doc.insert_copy_before(doc, doc) == xml_node());
1124
+ CHECK(doc.insert_copy_before(xml_node(), doc.child(STR("node"))) == xml_node());
1125
+ CHECK(doc.insert_copy_before(doc.child(STR("node")), xml_node()) == xml_node());
1126
+ CHECK(doc.insert_copy_before(doc.child(STR("node")), child) == xml_node());
1127
+
1128
+ xml_node n1 = doc.child(STR("node")).insert_copy_before(child, doc.child(STR("node")).first_child());
1129
+ CHECK(n1);
1130
+ CHECK_STRING(n1.name(), STR("child"));
1131
+ CHECK_NODE(doc, STR("<node><child/>foo<child/></node>"));
1132
+
1133
+ xml_node n2 = doc.child(STR("node")).insert_copy_before(doc.child(STR("node")).first_child(), doc.child(STR("node")).last_child());
1134
+ CHECK(n2 && n2 != n1);
1135
+ CHECK_STRING(n2.name(), STR("child"));
1136
+ CHECK_NODE(doc, STR("<node><child/>foo<child/><child/></node>"));
1137
+
1138
+ xml_node n3 = doc.child(STR("node")).insert_copy_before(doc.child(STR("node")).first_child().next_sibling(), doc.child(STR("node")).first_child());
1139
+ CHECK(n3 && n3 != n1 && n3 != n2);
1140
+ CHECK_STRING(n3.value(), STR("foo"));
1141
+ CHECK_NODE(doc, STR("<node>foo<child/>foo<child/><child/></node>"));
1142
+ }
1143
+
1144
+ TEST_XML(dom_node_copy_recursive, "<node>foo<child/></node>")
1145
+ {
1146
+ doc.child(STR("node")).append_copy(doc.child(STR("node")));
1147
+ CHECK_NODE(doc, STR("<node>foo<child/><node>foo<child/></node></node>"));
1148
+ }
1149
+
1150
+ TEST_XML(dom_node_copy_crossdoc, "<node/>")
1151
+ {
1152
+ xml_document newdoc;
1153
+ newdoc.append_copy(doc.child(STR("node")));
1154
+ CHECK_NODE(doc, STR("<node/>"));
1155
+ CHECK_NODE(newdoc, STR("<node/>"));
1156
+ }
1157
+
1158
+ TEST_XML(dom_node_copy_crossdoc_attribute, "<node attr='value'/>")
1159
+ {
1160
+ xml_document newdoc;
1161
+ newdoc.append_child(STR("copy")).append_copy(doc.child(STR("node")).attribute(STR("attr")));
1162
+ CHECK_NODE(doc, STR("<node attr=\"value\"/>"));
1163
+ CHECK_NODE(newdoc, STR("<copy attr=\"value\"/>"));
1164
+ }
1165
+
1166
+ TEST_XML_FLAGS(dom_node_copy_types, "<?xml version='1.0'?><!DOCTYPE id><root><?pi value?><!--comment--><node id='1'>pcdata<![CDATA[cdata]]></node></root>", parse_full)
1167
+ {
1168
+ doc.append_copy(doc.child(STR("root")));
1169
+ CHECK_NODE(doc, STR("<?xml version=\"1.0\"?><!DOCTYPE id><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root>"));
1170
+
1171
+ doc.insert_copy_before(doc.first_child(), doc.first_child());
1172
+ CHECK_NODE(doc, STR("<?xml version=\"1.0\"?><?xml version=\"1.0\"?><!DOCTYPE id><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root>"));
1173
+
1174
+ doc.insert_copy_after(doc.first_child().next_sibling().next_sibling(), doc.first_child());
1175
+ CHECK_NODE(doc, STR("<?xml version=\"1.0\"?><!DOCTYPE id><?xml version=\"1.0\"?><!DOCTYPE id><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root>"));
1176
+ }
1177
+
1178
+ TEST(dom_node_declaration_name)
1179
+ {
1180
+ xml_document doc;
1181
+ doc.append_child(node_declaration);
1182
+
1183
+ // name 'xml' is auto-assigned
1184
+ CHECK(doc.first_child().type() == node_declaration);
1185
+ CHECK_STRING(doc.first_child().name(), STR("xml"));
1186
+
1187
+ doc.insert_child_after(node_declaration, doc.first_child());
1188
+ doc.insert_child_before(node_declaration, doc.first_child());
1189
+ doc.prepend_child(node_declaration);
1190
+
1191
+ CHECK_NODE(doc, STR("<?xml?><?xml?><?xml?><?xml?>"));
1192
+ }
1193
+
1194
+ TEST(dom_node_declaration_attributes)
1195
+ {
1196
+ xml_document doc;
1197
+ xml_node node = doc.append_child(node_declaration);
1198
+ node.append_attribute(STR("version")) = STR("1.0");
1199
+ node.append_attribute(STR("encoding")) = STR("utf-8");
1200
+
1201
+ CHECK_NODE(doc, STR("<?xml version=\"1.0\" encoding=\"utf-8\"?>"));
1202
+ }
1203
+
1204
+ TEST(dom_node_declaration_top_level)
1205
+ {
1206
+ xml_document doc;
1207
+ doc.append_child().set_name(STR("node"));
1208
+
1209
+ xml_node node = doc.first_child();
1210
+ node.append_child(node_pcdata).set_value(STR("text"));
1211
+
1212
+ CHECK(node.insert_child_before(node_declaration, node.first_child()) == xml_node());
1213
+ CHECK(node.insert_child_after(node_declaration, node.first_child()) == xml_node());
1214
+ CHECK(node.append_child(node_declaration) == xml_node());
1215
+
1216
+ CHECK_NODE(doc, STR("<node>text</node>"));
1217
+
1218
+ CHECK(doc.insert_child_before(node_declaration, node));
1219
+ CHECK(doc.insert_child_after(node_declaration, node));
1220
+ CHECK(doc.append_child(node_declaration));
1221
+
1222
+ CHECK_NODE(doc, STR("<?xml?><node>text</node><?xml?><?xml?>"));
1223
+ }
1224
+
1225
+ TEST(dom_node_declaration_copy)
1226
+ {
1227
+ xml_document doc;
1228
+ doc.append_child(node_declaration);
1229
+
1230
+ doc.append_child().set_name(STR("node"));
1231
+
1232
+ doc.last_child().append_copy(doc.first_child());
1233
+
1234
+ CHECK_NODE(doc, STR("<?xml?><node/>"));
1235
+ }
1236
+
1237
+ TEST(dom_string_out_of_memory)
1238
+ {
1239
+ const unsigned int length = 65536;
1240
+ static char_t string[length + 1];
1241
+
1242
+ for (unsigned int i = 0; i < length; ++i) string[i] = 'a';
1243
+ string[length] = 0;
1244
+
1245
+ xml_document doc;
1246
+ xml_node node = doc.append_child();
1247
+ xml_attribute attr = node.append_attribute(STR("a"));
1248
+ xml_node text = node.append_child(node_pcdata);
1249
+
1250
+ // no value => long value
1251
+ test_runner::_memory_fail_threshold = 32;
1252
+
1253
+ CHECK_ALLOC_FAIL(CHECK(!node.set_name(string)));
1254
+ CHECK_ALLOC_FAIL(CHECK(!text.set_value(string)));
1255
+ CHECK_ALLOC_FAIL(CHECK(!attr.set_name(string)));
1256
+ CHECK_ALLOC_FAIL(CHECK(!attr.set_value(string)));
1257
+
1258
+ // set some names/values
1259
+ test_runner::_memory_fail_threshold = 0;
1260
+
1261
+ node.set_name(STR("n"));
1262
+ attr.set_value(STR("v"));
1263
+ text.set_value(STR("t"));
1264
+
1265
+ // some value => long value
1266
+ test_runner::_memory_fail_threshold = 32;
1267
+
1268
+ CHECK_ALLOC_FAIL(CHECK(!node.set_name(string)));
1269
+ CHECK_ALLOC_FAIL(CHECK(!text.set_value(string)));
1270
+ CHECK_ALLOC_FAIL(CHECK(!attr.set_name(string)));
1271
+ CHECK_ALLOC_FAIL(CHECK(!attr.set_value(string)));
1272
+
1273
+ // check that original state was preserved
1274
+ test_runner::_memory_fail_threshold = 0;
1275
+
1276
+ CHECK_NODE(doc, STR("<n a=\"v\">t</n>"));
1277
+ }
1278
+
1279
+ TEST(dom_node_out_of_memory)
1280
+ {
1281
+ test_runner::_memory_fail_threshold = 65536;
1282
+
1283
+ // exhaust memory limit
1284
+ xml_document doc;
1285
+
1286
+ xml_node n = doc.append_child();
1287
+ CHECK(n.set_name(STR("n")));
1288
+
1289
+ xml_attribute a = n.append_attribute(STR("a"));
1290
+ CHECK(a);
1291
+
1292
+ CHECK_ALLOC_FAIL(while (n.append_child(node_comment)) { /* nop */ });
1293
+ CHECK_ALLOC_FAIL(while (n.append_attribute(STR("b"))) { /* nop */ });
1294
+
1295
+ // verify all node modification operations
1296
+ CHECK_ALLOC_FAIL(CHECK(!n.append_child()));
1297
+ CHECK_ALLOC_FAIL(CHECK(!n.prepend_child()));
1298
+ CHECK_ALLOC_FAIL(CHECK(!n.insert_child_after(node_element, n.first_child())));
1299
+ CHECK_ALLOC_FAIL(CHECK(!n.insert_child_before(node_element, n.first_child())));
1300
+ CHECK_ALLOC_FAIL(CHECK(!n.append_attribute(STR(""))));
1301
+ CHECK_ALLOC_FAIL(CHECK(!n.prepend_attribute(STR(""))));
1302
+ CHECK_ALLOC_FAIL(CHECK(!n.insert_attribute_after(STR(""), a)));
1303
+ CHECK_ALLOC_FAIL(CHECK(!n.insert_attribute_before(STR(""), a)));
1304
+
1305
+ // verify node copy operations
1306
+ CHECK_ALLOC_FAIL(CHECK(!n.append_copy(n.first_child())));
1307
+ CHECK_ALLOC_FAIL(CHECK(!n.prepend_copy(n.first_child())));
1308
+ CHECK_ALLOC_FAIL(CHECK(!n.insert_copy_after(n.first_child(), n.first_child())));
1309
+ CHECK_ALLOC_FAIL(CHECK(!n.insert_copy_before(n.first_child(), n.first_child())));
1310
+ CHECK_ALLOC_FAIL(CHECK(!n.append_copy(a)));
1311
+ CHECK_ALLOC_FAIL(CHECK(!n.prepend_copy(a)));
1312
+ CHECK_ALLOC_FAIL(CHECK(!n.insert_copy_after(a, a)));
1313
+ CHECK_ALLOC_FAIL(CHECK(!n.insert_copy_before(a, a)));
1314
+ }
1315
+
1316
+ TEST(dom_node_memory_limit)
1317
+ {
1318
+ const unsigned int length = 65536;
1319
+ static char_t string[length + 1];
1320
+
1321
+ for (unsigned int i = 0; i < length; ++i) string[i] = 'a';
1322
+ string[length] = 0;
1323
+
1324
+ test_runner::_memory_fail_threshold = 32768 * 2 + sizeof(string);
1325
+
1326
+ xml_document doc;
1327
+
1328
+ for (int j = 0; j < 32; ++j)
1329
+ {
1330
+ CHECK(doc.append_child().set_name(string));
1331
+ CHECK(doc.remove_child(doc.first_child()));
1332
+ }
1333
+ }
1334
+
1335
+ TEST(dom_node_memory_limit_pi)
1336
+ {
1337
+ const unsigned int length = 65536;
1338
+ static char_t string[length + 1];
1339
+
1340
+ for (unsigned int i = 0; i < length; ++i) string[i] = 'a';
1341
+ string[length] = 0;
1342
+
1343
+ test_runner::_memory_fail_threshold = 32768 * 2 + sizeof(string);
1344
+
1345
+ xml_document doc;
1346
+
1347
+ for (int j = 0; j < 32; ++j)
1348
+ {
1349
+ CHECK(doc.append_child(node_pi).set_value(string));
1350
+ CHECK(doc.remove_child(doc.first_child()));
1351
+ }
1352
+ }
1353
+
1354
+ TEST(dom_node_doctype_top_level)
1355
+ {
1356
+ xml_document doc;
1357
+ doc.append_child().set_name(STR("node"));
1358
+
1359
+ xml_node node = doc.first_child();
1360
+ node.append_child(node_pcdata).set_value(STR("text"));
1361
+
1362
+ CHECK(node.insert_child_before(node_doctype, node.first_child()) == xml_node());
1363
+ CHECK(node.insert_child_after(node_doctype, node.first_child()) == xml_node());
1364
+ CHECK(node.append_child(node_doctype) == xml_node());
1365
+
1366
+ CHECK_NODE(doc, STR("<node>text</node>"));
1367
+
1368
+ CHECK(doc.insert_child_before(node_doctype, node));
1369
+ CHECK(doc.insert_child_after(node_doctype, node));
1370
+ CHECK(doc.append_child(node_doctype));
1371
+
1372
+ CHECK_NODE(doc, STR("<!DOCTYPE><node>text</node><!DOCTYPE><!DOCTYPE>"));
1373
+ }
1374
+
1375
+ TEST(dom_node_doctype_copy)
1376
+ {
1377
+ xml_document doc;
1378
+ doc.append_child(node_doctype);
1379
+
1380
+ doc.append_child().set_name(STR("node"));
1381
+
1382
+ doc.last_child().append_copy(doc.first_child());
1383
+
1384
+ CHECK_NODE(doc, STR("<!DOCTYPE><node/>"));
1385
+ }
1386
+
1387
+ TEST(dom_node_doctype_value)
1388
+ {
1389
+ xml_document doc;
1390
+ xml_node node = doc.append_child(node_doctype);
1391
+
1392
+ CHECK(node.type() == node_doctype);
1393
+ CHECK_STRING(node.value(), STR(""));
1394
+ CHECK_NODE(node, STR("<!DOCTYPE>"));
1395
+
1396
+ CHECK(node.set_value(STR("id [ foo ]")));
1397
+ CHECK_NODE(node, STR("<!DOCTYPE id [ foo ]>"));
1398
+ }
1399
+
1400
+ TEST_XML(dom_node_append_buffer_native, "<node>test</node>")
1401
+ {
1402
+ xml_node node = doc.child(STR("node"));
1403
+
1404
+ const char_t data1[] = STR("<child1 id='1' /><child2>text</child2>");
1405
+ const char_t data2[] = STR("<child3 />");
1406
+
1407
+ CHECK(node.append_buffer(data1, sizeof(data1)));
1408
+ CHECK(node.append_buffer(data2, sizeof(data2)));
1409
+ CHECK(node.append_buffer(data1, sizeof(data1)));
1410
+ CHECK(node.append_buffer(data2, sizeof(data2)));
1411
+ CHECK(node.append_buffer(data2, sizeof(data2)));
1412
+
1413
+ CHECK_NODE(doc, STR("<node>test<child1 id=\"1\"/><child2>text</child2><child3/><child1 id=\"1\"/><child2>text</child2><child3/><child3/></node>"));
1414
+ }
1415
+
1416
+ TEST_XML(dom_node_append_buffer_convert, "<node>test</node>")
1417
+ {
1418
+ xml_node node = doc.child(STR("node"));
1419
+
1420
+ const char data[] = {0, 0, 0, '<', 0, 0, 0, 'n', 0, 0, 0, '/', 0, 0, 0, '>'};
1421
+
1422
+ CHECK(node.append_buffer(data, sizeof(data)));
1423
+ CHECK(node.append_buffer(data, sizeof(data), parse_default, encoding_utf32_be));
1424
+
1425
+ CHECK_NODE(doc, STR("<node>test<n/><n/></node>"));
1426
+ }
1427
+
1428
+
1429
+ TEST_XML(dom_node_append_buffer_remove, "<node>test</node>")
1430
+ {
1431
+ xml_node node = doc.child(STR("node"));
1432
+
1433
+ const char data1[] = "<child1 id='1' /><child2>text</child2>";
1434
+ const char data2[] = "<child3 />";
1435
+
1436
+ CHECK(node.append_buffer(data1, sizeof(data1)));
1437
+ CHECK(node.append_buffer(data2, sizeof(data2)));
1438
+ CHECK(node.append_buffer(data1, sizeof(data1)));
1439
+ CHECK(node.append_buffer(data2, sizeof(data2)));
1440
+
1441
+ CHECK_NODE(doc, STR("<node>test<child1 id=\"1\"/><child2>text</child2><child3/><child1 id=\"1\"/><child2>text</child2><child3/></node>"));
1442
+
1443
+ while (node.remove_child(STR("child2"))) {}
1444
+
1445
+ CHECK_NODE(doc, STR("<node>test<child1 id=\"1\"/><child3/><child1 id=\"1\"/><child3/></node>"));
1446
+
1447
+ while (node.remove_child(STR("child1"))) {}
1448
+
1449
+ CHECK_NODE(doc, STR("<node>test<child3/><child3/></node>"));
1450
+
1451
+ while (node.remove_child(STR("child3"))) {}
1452
+
1453
+ CHECK_NODE(doc, STR("<node>test</node>"));
1454
+
1455
+ CHECK(doc.remove_child(STR("node")));
1456
+
1457
+ CHECK(!doc.first_child());
1458
+ }
1459
+
1460
+ TEST(dom_node_append_buffer_empty_document)
1461
+ {
1462
+ xml_document doc;
1463
+
1464
+ const char data[] = "<child1 id='1' /><child2>text</child2>";
1465
+
1466
+ doc.append_buffer(data, sizeof(data));
1467
+
1468
+ CHECK_NODE(doc, STR("<child1 id=\"1\"/><child2>text</child2>"));
1469
+ }
1470
+
1471
+ TEST_XML(dom_node_append_buffer_invalid_type, "<node>test</node>")
1472
+ {
1473
+ const char data[] = "<child1 id='1' /><child2>text</child2>";
1474
+
1475
+ CHECK(xml_node().append_buffer(data, sizeof(data)).status == status_append_invalid_root);
1476
+ CHECK(doc.first_child().first_child().append_buffer(data, sizeof(data)).status == status_append_invalid_root);
1477
+ }
1478
+
1479
+ TEST_XML(dom_node_append_buffer_close_external, "<node />")
1480
+ {
1481
+ xml_node node = doc.child(STR("node"));
1482
+
1483
+ const char data[] = "<child1 /></node><child2 />";
1484
+
1485
+ CHECK(node.append_buffer(data, sizeof(data)).status == status_end_element_mismatch);
1486
+ CHECK_NODE(doc, STR("<node><child1/></node>"));
1487
+
1488
+ CHECK(node.append_buffer(data, sizeof(data)).status == status_end_element_mismatch);
1489
+ CHECK_NODE(doc, STR("<node><child1/><child1/></node>"));
1490
+ }
1491
+
1492
+ TEST(dom_node_append_buffer_out_of_memory_extra)
1493
+ {
1494
+ test_runner::_memory_fail_threshold = 1;
1495
+
1496
+ xml_document doc;
1497
+ CHECK_ALLOC_FAIL(CHECK(doc.append_buffer("<n/>", 4).status == status_out_of_memory));
1498
+ CHECK(!doc.first_child());
1499
+ }
1500
+
1501
+ TEST(dom_node_append_buffer_out_of_memory_buffer)
1502
+ {
1503
+ test_runner::_memory_fail_threshold = 32768 + 128;
1504
+
1505
+ char data[128] = {0};
1506
+
1507
+ xml_document doc;
1508
+ CHECK_ALLOC_FAIL(CHECK(doc.append_buffer(data, sizeof(data)).status == status_out_of_memory));
1509
+ CHECK(!doc.first_child());
1510
+ }
1511
+
1512
+ TEST(dom_node_append_buffer_out_of_memory_nodes)
1513
+ {
1514
+ unsigned int count = 4000;
1515
+ std::basic_string<char_t> data;
1516
+
1517
+ for (unsigned int i = 0; i < count; ++i)
1518
+ data += STR("<a/>");
1519
+
1520
+ test_runner::_memory_fail_threshold = 32768 + 128 + data.length() * sizeof(char_t) + 32;
1521
+
1522
+ #ifdef PUGIXML_COMPACT
1523
+ // ... and some space for hash table
1524
+ test_runner::_memory_fail_threshold += 2048;
1525
+ #endif
1526
+
1527
+ xml_document doc;
1528
+ CHECK_ALLOC_FAIL(CHECK(doc.append_buffer(data.c_str(), data.length() * sizeof(char_t), parse_fragment).status == status_out_of_memory));
1529
+
1530
+ unsigned int valid = 0;
1531
+
1532
+ for (xml_node n = doc.first_child(); n; n = n.next_sibling())
1533
+ {
1534
+ CHECK_STRING(n.name(), STR("a"));
1535
+ valid++;
1536
+ }
1537
+
1538
+ CHECK(valid > 0 && valid < count);
1539
+ }
1540
+
1541
+ TEST(dom_node_append_buffer_out_of_memory_name)
1542
+ {
1543
+ test_runner::_memory_fail_threshold = 32768 + 4096;
1544
+
1545
+ char data[4096] = {0};
1546
+
1547
+ xml_document doc;
1548
+ CHECK(doc.append_child(STR("root")));
1549
+ CHECK_ALLOC_FAIL(CHECK(doc.first_child().append_buffer(data, sizeof(data)).status == status_out_of_memory));
1550
+ CHECK_STRING(doc.first_child().name(), STR("root"));
1551
+ }
1552
+
1553
+ TEST_XML(dom_node_append_buffer_fragment, "<node />")
1554
+ {
1555
+ xml_node node = doc.child(STR("node"));
1556
+
1557
+ CHECK(node.append_buffer("1", 1).status == status_no_document_element);
1558
+ CHECK_NODE(doc, STR("<node>1</node>"));
1559
+
1560
+ CHECK(node.append_buffer("2", 1, parse_fragment));
1561
+ CHECK_NODE(doc, STR("<node>12</node>"));
1562
+
1563
+ CHECK(node.append_buffer("3", 1).status == status_no_document_element);
1564
+ CHECK_NODE(doc, STR("<node>123</node>"));
1565
+
1566
+ CHECK(node.append_buffer("4", 1, parse_fragment));
1567
+ CHECK_NODE(doc, STR("<node>1234</node>"));
1568
+ }
1569
+
1570
+ TEST_XML(dom_node_append_buffer_empty, "<node />")
1571
+ {
1572
+ xml_node node = doc.child(STR("node"));
1573
+
1574
+ CHECK(node.append_buffer("", 0).status == status_no_document_element);
1575
+ CHECK(node.append_buffer("", 0, parse_fragment).status == status_ok);
1576
+
1577
+ CHECK(node.append_buffer(0, 0).status == status_no_document_element);
1578
+ CHECK(node.append_buffer(0, 0, parse_fragment).status == status_ok);
1579
+
1580
+ CHECK_NODE(doc, STR("<node/>"));
1581
+ }
1582
+
1583
+ TEST_XML(dom_node_prepend_move, "<node>foo<child/></node>")
1584
+ {
1585
+ xml_node child = doc.child(STR("node")).child(STR("child"));
1586
+
1587
+ CHECK(xml_node().prepend_move(xml_node()) == xml_node());
1588
+ CHECK(doc.child(STR("node")).first_child().prepend_move(child) == xml_node());
1589
+ CHECK(doc.prepend_move(doc) == xml_node());
1590
+ CHECK(doc.prepend_move(xml_node()) == xml_node());
1591
+
1592
+ xml_node n1 = doc.child(STR("node")).prepend_move(doc.child(STR("node")).first_child());
1593
+ CHECK(n1 && n1 == doc.child(STR("node")).first_child());
1594
+ CHECK_STRING(n1.value(), STR("foo"));
1595
+ CHECK_NODE(doc, STR("<node>foo<child/></node>"));
1596
+
1597
+ xml_node n2 = doc.child(STR("node")).prepend_move(doc.child(STR("node")).child(STR("child")));
1598
+ CHECK(n2 && n2 != n1 && n2 == child);
1599
+ CHECK_STRING(n2.name(), STR("child"));
1600
+ CHECK_NODE(doc, STR("<node><child/>foo</node>"));
1601
+
1602
+ xml_node n3 = doc.child(STR("node")).child(STR("child")).prepend_move(doc.child(STR("node")).first_child().next_sibling());
1603
+ CHECK(n3 && n3 == n1 && n3 != n2);
1604
+ CHECK_STRING(n3.value(), STR("foo"));
1605
+ CHECK_NODE(doc, STR("<node><child>foo</child></node>"));
1606
+ }
1607
+
1608
+ TEST_XML(dom_node_append_move, "<node>foo<child/></node>")
1609
+ {
1610
+ xml_node child = doc.child(STR("node")).child(STR("child"));
1611
+
1612
+ CHECK(xml_node().append_move(xml_node()) == xml_node());
1613
+ CHECK(doc.child(STR("node")).first_child().append_move(child) == xml_node());
1614
+ CHECK(doc.append_move(doc) == xml_node());
1615
+ CHECK(doc.append_move(xml_node()) == xml_node());
1616
+
1617
+ xml_node n1 = doc.child(STR("node")).append_move(doc.child(STR("node")).first_child());
1618
+ CHECK(n1 && n1 == doc.child(STR("node")).last_child());
1619
+ CHECK_STRING(n1.value(), STR("foo"));
1620
+ CHECK_NODE(doc, STR("<node><child/>foo</node>"));
1621
+
1622
+ xml_node n2 = doc.child(STR("node")).append_move(doc.child(STR("node")).last_child());
1623
+ CHECK(n2 && n2 == n1);
1624
+ CHECK_STRING(n2.value(), STR("foo"));
1625
+ CHECK_NODE(doc, STR("<node><child/>foo</node>"));
1626
+
1627
+ xml_node n3 = doc.child(STR("node")).child(STR("child")).append_move(doc.child(STR("node")).last_child());
1628
+ CHECK(n3 && n3 == n1 && n3 == n2);
1629
+ CHECK_STRING(n3.value(), STR("foo"));
1630
+ CHECK_NODE(doc, STR("<node><child>foo</child></node>"));
1631
+ }
1632
+
1633
+ TEST_XML(dom_node_insert_move_after, "<node>foo<child>bar</child></node>")
1634
+ {
1635
+ xml_node child = doc.child(STR("node")).child(STR("child"));
1636
+
1637
+ CHECK(xml_node().insert_move_after(xml_node(), xml_node()) == xml_node());
1638
+ CHECK(doc.child(STR("node")).first_child().insert_move_after(doc.child(STR("node")), doc.child(STR("node"))) == xml_node());
1639
+ CHECK(doc.insert_move_after(doc, doc) == xml_node());
1640
+ CHECK(doc.insert_move_after(xml_node(), doc.child(STR("node"))) == xml_node());
1641
+ CHECK(doc.insert_move_after(doc.child(STR("node")), xml_node()) == xml_node());
1642
+ CHECK(doc.insert_move_after(doc.child(STR("node")), child) == xml_node());
1643
+
1644
+ xml_node n1 = doc.child(STR("node")).insert_move_after(child, doc.child(STR("node")).first_child());
1645
+ CHECK(n1 && n1 == child);
1646
+ CHECK_STRING(n1.name(), STR("child"));
1647
+ CHECK_NODE(doc, STR("<node>foo<child>bar</child></node>"));
1648
+
1649
+ xml_node n2 = doc.child(STR("node")).insert_move_after(doc.child(STR("node")).first_child(), child);
1650
+ CHECK(n2 && n2 != n1);
1651
+ CHECK_STRING(n2.value(), STR("foo"));
1652
+ CHECK_NODE(doc, STR("<node><child>bar</child>foo</node>"));
1653
+
1654
+ xml_node n3 = child.insert_move_after(doc.child(STR("node")).last_child(), child.first_child());
1655
+ CHECK(n3 && n3 != n1 && n3 == n2);
1656
+ CHECK_STRING(n3.value(), STR("foo"));
1657
+ CHECK_NODE(doc, STR("<node><child>barfoo</child></node>"));
1658
+ }
1659
+
1660
+ TEST_XML(dom_node_insert_move_before, "<node>foo<child>bar</child></node>")
1661
+ {
1662
+ xml_node child = doc.child(STR("node")).child(STR("child"));
1663
+
1664
+ CHECK(xml_node().insert_move_before(xml_node(), xml_node()) == xml_node());
1665
+ CHECK(doc.child(STR("node")).first_child().insert_move_before(doc.child(STR("node")), doc.child(STR("node"))) == xml_node());
1666
+ CHECK(doc.insert_move_before(doc, doc) == xml_node());
1667
+ CHECK(doc.insert_move_before(xml_node(), doc.child(STR("node"))) == xml_node());
1668
+ CHECK(doc.insert_move_before(doc.child(STR("node")), xml_node()) == xml_node());
1669
+ CHECK(doc.insert_move_before(doc.child(STR("node")), child) == xml_node());
1670
+
1671
+ xml_node n1 = doc.child(STR("node")).insert_move_before(child, doc.child(STR("node")).first_child());
1672
+ CHECK(n1 && n1 == child);
1673
+ CHECK_STRING(n1.name(), STR("child"));
1674
+ CHECK_NODE(doc, STR("<node><child>bar</child>foo</node>"));
1675
+
1676
+ xml_node n2 = doc.child(STR("node")).insert_move_before(doc.child(STR("node")).last_child(), child);
1677
+ CHECK(n2 && n2 != n1);
1678
+ CHECK_STRING(n2.value(), STR("foo"));
1679
+ CHECK_NODE(doc, STR("<node>foo<child>bar</child></node>"));
1680
+
1681
+ xml_node n3 = child.insert_move_before(doc.child(STR("node")).first_child(), child.first_child());
1682
+ CHECK(n3 && n3 != n1 && n3 == n2);
1683
+ CHECK_STRING(n3.value(), STR("foo"));
1684
+ CHECK_NODE(doc, STR("<node><child>foobar</child></node>"));
1685
+ }
1686
+
1687
+ TEST_XML(dom_node_move_recursive, "<root><node>foo<child/></node></root>")
1688
+ {
1689
+ xml_node root = doc.child(STR("root"));
1690
+ xml_node node = root.child(STR("node"));
1691
+ xml_node foo = node.first_child();
1692
+ xml_node child = node.last_child();
1693
+
1694
+ CHECK(node.prepend_move(node) == xml_node());
1695
+ CHECK(node.prepend_move(root) == xml_node());
1696
+
1697
+ CHECK(node.append_move(node) == xml_node());
1698
+ CHECK(node.append_move(root) == xml_node());
1699
+
1700
+ CHECK(node.insert_move_before(node, foo) == xml_node());
1701
+ CHECK(node.insert_move_before(root, foo) == xml_node());
1702
+
1703
+ CHECK(node.insert_move_after(node, foo) == xml_node());
1704
+ CHECK(node.insert_move_after(root, foo) == xml_node());
1705
+
1706
+ CHECK(child.append_move(node) == xml_node());
1707
+
1708
+ CHECK_NODE(doc, STR("<root><node>foo<child/></node></root>"));
1709
+ }
1710
+
1711
+ TEST_XML(dom_node_move_marker, "<node />")
1712
+ {
1713
+ xml_node node = doc.child(STR("node"));
1714
+
1715
+ CHECK(doc.insert_move_before(node, node) == xml_node());
1716
+ CHECK(doc.insert_move_after(node, node) == xml_node());
1717
+
1718
+ CHECK_NODE(doc, STR("<node/>"));
1719
+ }
1720
+
1721
+ TEST_XML(dom_node_move_crossdoc, "<node/>")
1722
+ {
1723
+ xml_document newdoc;
1724
+ CHECK(newdoc.append_move(doc.child(STR("node"))) == xml_node());
1725
+ CHECK_NODE(newdoc, STR(""));
1726
+ }
1727
+
1728
+ TEST_XML(dom_node_move_tree, "<root><n1 a1='v1'><c1/>t1</n1><n2 a2='v2'><c2/>t2</n2><n3 a3='v3'><c3/>t3</n3><n4 a4='v4'><c4/>t4</n4></root>")
1729
+ {
1730
+ xml_node root = doc.child(STR("root"));
1731
+ xml_node n1 = root.child(STR("n1"));
1732
+ xml_node n2 = root.child(STR("n2"));
1733
+ xml_node n3 = root.child(STR("n3"));
1734
+ xml_node n4 = root.child(STR("n4"));
1735
+
1736
+ // n2 n1 n3 n4
1737
+ CHECK(n2 == root.prepend_move(n2));
1738
+
1739
+ // n2 n3 n4 n1
1740
+ CHECK(n1 == root.append_move(n1));
1741
+
1742
+ // n2 n4 n3 n1
1743
+ CHECK(n4 == root.insert_move_before(n4, n3));
1744
+
1745
+ // n2 n4 n1 + n3
1746
+ CHECK(n3 == doc.insert_move_after(n3, root));
1747
+
1748
+ CHECK_NODE(doc, STR("<root><n2 a2=\"v2\"><c2/>t2</n2><n4 a4=\"v4\"><c4/>t4</n4><n1 a1=\"v1\"><c1/>t1</n1></root><n3 a3=\"v3\"><c3/>t3</n3>"));
1749
+
1750
+ CHECK(n1 == root.child(STR("n1")));
1751
+ CHECK(n2 == root.child(STR("n2")));
1752
+ CHECK(n3 == doc.child(STR("n3")));
1753
+ CHECK(n4 == root.child(STR("n4")));
1754
+ }
1755
+
1756
+ TEST(dom_node_copy_stackless)
1757
+ {
1758
+ unsigned int count = 20000;
1759
+ std::basic_string<char_t> data;
1760
+
1761
+ for (unsigned int i = 0; i < count; ++i)
1762
+ data += STR("<a>");
1763
+
1764
+ data += STR("text");
1765
+
1766
+ for (unsigned int j = 0; j < count; ++j)
1767
+ data += STR("</a>");
1768
+
1769
+ xml_document doc;
1770
+ CHECK(doc.load_string(data.c_str()));
1771
+
1772
+ xml_document copy;
1773
+ CHECK(copy.append_copy(doc.first_child()));
1774
+
1775
+ CHECK_NODE(doc, data.c_str());
1776
+ }
1777
+
1778
+ TEST(dom_node_remove_child_stackless)
1779
+ {
1780
+ unsigned int count = 20000;
1781
+ std::basic_string<char_t> data = STR("<root>");
1782
+
1783
+ for (unsigned int i = 0; i < count; ++i)
1784
+ data += STR("<a>");
1785
+
1786
+ data += STR("text");
1787
+
1788
+ for (unsigned int j = 0; j < count; ++j)
1789
+ data += STR("</a>");
1790
+
1791
+ data += STR("<tail/></root>");
1792
+
1793
+ xml_document doc;
1794
+ CHECK(doc.load_string(data.c_str()));
1795
+
1796
+ xml_node root = doc.child(STR("root"));
1797
+ CHECK(root.remove_child(root.child(STR("a"))));
1798
+
1799
+ CHECK_NODE(doc, STR("<root><tail/></root>"));
1800
+ }
1801
+
1802
+ TEST(dom_node_copy_copyless)
1803
+ {
1804
+ std::basic_string<char_t> data;
1805
+ data += STR("<node>");
1806
+ for (int i = 0; i < 10000; ++i)
1807
+ data += STR("pcdata");
1808
+ data += STR("<?name value?><child attr1=\"\" attr2=\"value2\"/></node>");
1809
+
1810
+ std::basic_string<char_t> datacopy = data;
1811
+
1812
+ // the document is parsed in-place so there should only be 1 page worth of allocations
1813
+ test_runner::_memory_fail_threshold = 32768 + 128;
1814
+
1815
+ #ifdef PUGIXML_COMPACT
1816
+ // ... and some space for hash table
1817
+ test_runner::_memory_fail_threshold += 2048;
1818
+ #endif
1819
+
1820
+ xml_document doc;
1821
+ CHECK(doc.load_buffer_inplace(&datacopy[0], datacopy.size() * sizeof(char_t), parse_full));
1822
+
1823
+ // this copy should share all string storage; since there are not a lot of nodes we should not have *any* allocations here (everything will fit in the same page in the document)
1824
+ xml_node copy = doc.append_copy(doc.child(STR("node")));
1825
+ xml_node copy2 = doc.append_copy(copy);
1826
+
1827
+ CHECK_NODE(copy, data.c_str());
1828
+ CHECK_NODE(copy2, data.c_str());
1829
+ }
1830
+
1831
+ TEST(dom_node_copy_copyless_mix)
1832
+ {
1833
+ xml_document doc;
1834
+ CHECK(doc.load_string(STR("<node>pcdata<?name value?><child attr1=\"\" attr2=\"value2\" /></node>"), parse_full));
1835
+
1836
+ xml_node child = doc.child(STR("node")).child(STR("child"));
1837
+
1838
+ child.set_name(STR("copychild"));
1839
+ child.attribute(STR("attr2")).set_name(STR("copyattr2"));
1840
+ child.attribute(STR("attr1")).set_value(STR("copyvalue1"));
1841
+
1842
+ std::basic_string<char_t> data;
1843
+ for (int i = 0; i < 10000; ++i)
1844
+ data += STR("pcdata");
1845
+
1846
+ doc.child(STR("node")).text().set(data.c_str());
1847
+
1848
+ xml_node copy = doc.append_copy(doc.child(STR("node")));
1849
+ xml_node copy2 = doc.append_copy(copy);
1850
+
1851
+ std::basic_string<char_t> dataxml;
1852
+ dataxml += STR("<node>");
1853
+ dataxml += data;
1854
+ dataxml += STR("<?name value?><copychild attr1=\"copyvalue1\" copyattr2=\"value2\"/></node>");
1855
+
1856
+ CHECK_NODE(copy, dataxml.c_str());
1857
+ CHECK_NODE(copy2, dataxml.c_str());
1858
+ }
1859
+
1860
+ TEST_XML(dom_node_copy_copyless_taint, "<node attr=\"value\" />")
1861
+ {
1862
+ xml_node node = doc.child(STR("node"));
1863
+ xml_node copy = doc.append_copy(node);
1864
+
1865
+ CHECK_NODE(doc, STR("<node attr=\"value\"/><node attr=\"value\"/>"));
1866
+
1867
+ node.set_name(STR("nod1"));
1868
+
1869
+ CHECK_NODE(doc, STR("<nod1 attr=\"value\"/><node attr=\"value\"/>"));
1870
+
1871
+ xml_node copy2 = doc.append_copy(copy);
1872
+
1873
+ CHECK_NODE(doc, STR("<nod1 attr=\"value\"/><node attr=\"value\"/><node attr=\"value\"/>"));
1874
+
1875
+ copy.attribute(STR("attr")).set_value(STR("valu2"));
1876
+
1877
+ CHECK_NODE(doc, STR("<nod1 attr=\"value\"/><node attr=\"valu2\"/><node attr=\"value\"/>"));
1878
+
1879
+ copy2.attribute(STR("attr")).set_name(STR("att3"));
1880
+
1881
+ CHECK_NODE(doc, STR("<nod1 attr=\"value\"/><node attr=\"valu2\"/><node att3=\"value\"/>"));
1882
+ }
1883
+
1884
+ TEST(dom_node_copy_attribute_copyless)
1885
+ {
1886
+ std::basic_string<char_t> data;
1887
+ data += STR("<node attr=\"");
1888
+ for (int i = 0; i < 10000; ++i)
1889
+ data += STR("data");
1890
+ data += STR("\"/>");
1891
+
1892
+ std::basic_string<char_t> datacopy = data;
1893
+
1894
+ // the document is parsed in-place so there should only be 1 page worth of allocations
1895
+ test_runner::_memory_fail_threshold = 32768 + 128;
1896
+
1897
+ #ifdef PUGIXML_COMPACT
1898
+ // ... and some space for hash table
1899
+ test_runner::_memory_fail_threshold += 2048;
1900
+ #endif
1901
+
1902
+ xml_document doc;
1903
+ CHECK(doc.load_buffer_inplace(&datacopy[0], datacopy.size() * sizeof(char_t), parse_full));
1904
+
1905
+ // this copy should share all string storage; since there are not a lot of nodes we should not have *any* allocations here (everything will fit in the same page in the document)
1906
+ xml_node copy1 = doc.append_child(STR("node"));
1907
+ copy1.append_copy(doc.first_child().first_attribute());
1908
+
1909
+ xml_node copy2 = doc.append_child(STR("node"));
1910
+ copy2.append_copy(copy1.first_attribute());
1911
+
1912
+ CHECK_NODE(copy1, data.c_str());
1913
+ CHECK_NODE(copy2, data.c_str());
1914
+ }
1915
+
1916
+ TEST_XML(dom_node_copy_attribute_copyless_taint, "<node attr=\"value\" />")
1917
+ {
1918
+ xml_node node = doc.child(STR("node"));
1919
+ xml_attribute attr = node.first_attribute();
1920
+
1921
+ xml_node copy1 = doc.append_child(STR("copy1"));
1922
+ xml_node copy2 = doc.append_child(STR("copy2"));
1923
+ xml_node copy3 = doc.append_child(STR("copy3"));
1924
+
1925
+ CHECK_NODE(doc, STR("<node attr=\"value\"/><copy1/><copy2/><copy3/>"));
1926
+
1927
+ copy1.append_copy(attr);
1928
+
1929
+ CHECK_NODE(doc, STR("<node attr=\"value\"/><copy1 attr=\"value\"/><copy2/><copy3/>"));
1930
+
1931
+ attr.set_name(STR("att1"));
1932
+ copy2.append_copy(attr);
1933
+
1934
+ CHECK_NODE(doc, STR("<node att1=\"value\"/><copy1 attr=\"value\"/><copy2 att1=\"value\"/><copy3/>"));
1935
+
1936
+ copy1.first_attribute().set_value(STR("valu2"));
1937
+ copy3.append_copy(copy1.first_attribute());
1938
+
1939
+ CHECK_NODE(doc, STR("<node att1=\"value\"/><copy1 attr=\"valu2\"/><copy2 att1=\"value\"/><copy3 attr=\"valu2\"/>"));
1940
+ }
1941
+
1942
+ TEST_XML(dom_node_copy_out_of_memory_node, "<node><child1 /><child2 /><child3>text1<child4 />text2</child3></node>")
1943
+ {
1944
+ test_runner::_memory_fail_threshold = 32768 * 2 + 4096;
1945
+
1946
+ xml_document copy;
1947
+ CHECK_ALLOC_FAIL(for (int i = 0; i < 1000; ++i) copy.append_copy(doc.first_child()));
1948
+ }
1949
+
1950
+ TEST_XML(dom_node_copy_out_of_memory_attr, "<node attr1='' attr2='' attr3='' attr4='' attr5='' attr6='' attr7='' attr8='' attr9='' attr10='' attr11='' attr12='' attr13='' attr14='' attr15='' />")
1951
+ {
1952
+ test_runner::_memory_fail_threshold = 32768 * 2 + 4096;
1953
+
1954
+ xml_document copy;
1955
+ CHECK_ALLOC_FAIL(for (int i = 0; i < 1000; ++i) copy.append_copy(doc.first_child()));
1956
+ }
1957
+
1958
+ TEST_XML(dom_node_remove_deallocate, "<node attr='value'>text</node>")
1959
+ {
1960
+ xml_node node = doc.child(STR("node"));
1961
+
1962
+ xml_attribute attr = node.attribute(STR("attr"));
1963
+ attr.set_name(STR("longattr"));
1964
+ attr.set_value(STR("longvalue"));
1965
+
1966
+ node.set_name(STR("longnode"));
1967
+ node.text().set(STR("longtext"));
1968
+
1969
+ node.remove_attribute(attr);
1970
+ doc.remove_child(node);
1971
+
1972
+ CHECK_NODE(doc, STR(""));
1973
+ }
1974
+
1975
+ TEST_XML(dom_node_set_deallocate, "<node attr='value'>text</node>")
1976
+ {
1977
+ xml_node node = doc.child(STR("node"));
1978
+
1979
+ xml_attribute attr = node.attribute(STR("attr"));
1980
+
1981
+ attr.set_name(STR("longattr"));
1982
+ attr.set_value(STR("longvalue"));
1983
+ node.set_name(STR("longnode"));
1984
+
1985
+ attr.set_name(STR(""));
1986
+ attr.set_value(STR(""));
1987
+ node.set_name(STR(""));
1988
+ node.text().set(STR(""));
1989
+
1990
+ CHECK_NODE(doc, STR("<:anonymous :anonymous=\"\"/>"));
1991
+ }
1992
+
1993
+ TEST(dom_node_copy_declaration_empty_name)
1994
+ {
1995
+ xml_document doc1;
1996
+ xml_node decl1 = doc1.append_child(node_declaration);
1997
+ decl1.set_name(STR(""));
1998
+
1999
+ xml_document doc2;
2000
+ xml_node decl2 = doc2.append_copy(decl1);
2001
+
2002
+ CHECK_STRING(decl2.name(), STR(""));
2003
+ }
2004
+
2005
+ template <typename T> bool fp_equal(T lhs, T rhs)
2006
+ {
2007
+ // Several compilers compare float/double values on x87 stack without proper rounding
2008
+ // This causes roundtrip tests to fail, although they correctly preserve the data.
2009
+ #if (defined(_MSC_VER) && _MSC_VER < 1400) || defined(__MWERKS__)
2010
+ return memcmp(&lhs, &rhs, sizeof(T)) == 0;
2011
+ #else
2012
+ return lhs == rhs;
2013
+ #endif
2014
+ }
2015
+
2016
+ TEST(dom_fp_roundtrip_min_max_float)
2017
+ {
2018
+ xml_document doc;
2019
+ xml_node node = doc.append_child(STR("node"));
2020
+ xml_attribute attr = node.append_attribute(STR("attr"));
2021
+
2022
+ node.text().set(std::numeric_limits<float>::min());
2023
+ CHECK(fp_equal(node.text().as_float(), std::numeric_limits<float>::min()));
2024
+
2025
+ attr.set_value(std::numeric_limits<float>::max());
2026
+ CHECK(fp_equal(attr.as_float(), std::numeric_limits<float>::max()));
2027
+ }
2028
+
2029
+ TEST(dom_fp_roundtrip_min_max_double)
2030
+ {
2031
+ xml_document doc;
2032
+ xml_node node = doc.append_child(STR("node"));
2033
+ xml_attribute attr = node.append_attribute(STR("attr"));
2034
+
2035
+ attr.set_value(std::numeric_limits<double>::min());
2036
+ CHECK(fp_equal(attr.as_double(), std::numeric_limits<double>::min()));
2037
+
2038
+ node.text().set(std::numeric_limits<double>::max());
2039
+ CHECK(fp_equal(node.text().as_double(), std::numeric_limits<double>::max()));
2040
+ }
2041
+
2042
+ TEST(dom_fp_double_custom_precision)
2043
+ {
2044
+ xml_document doc;
2045
+ xml_node node = doc.append_child(STR("node"));
2046
+ xml_attribute attr = node.append_attribute(STR("attr"));
2047
+
2048
+ attr.set_value(std::numeric_limits<double>::min(), 20);
2049
+ CHECK(fp_equal(attr.as_double(), std::numeric_limits<double>::min()));
2050
+
2051
+ attr.set_value(1.0f, 5);
2052
+ CHECK(fp_equal(attr.as_double(), static_cast<double>(1.0f)));
2053
+
2054
+ attr.set_value(3.1415926f, 3);
2055
+ CHECK(!fp_equal(attr.as_double(), static_cast<double>(3.1415926f)));
2056
+
2057
+ node.text().set(1.0f, 5);
2058
+ CHECK(fp_equal(node.text().as_double(), static_cast<double>(1.0f)));
2059
+
2060
+ node.text().set(3.1415926f, 3);
2061
+ CHECK(!fp_equal(node.text().as_double(), static_cast<double>(3.1415926f)));
2062
+
2063
+ node.text().set(std::numeric_limits<double>::max(), 20);
2064
+ CHECK(fp_equal(node.text().as_double(), std::numeric_limits<double>::max()));
2065
+ }
2066
+
2067
+ const double fp_roundtrip_base[] =
2068
+ {
2069
+ 0.31830988618379067154,
2070
+ 0.43429448190325182765,
2071
+ 0.57721566490153286061,
2072
+ 0.69314718055994530942,
2073
+ 0.70710678118654752440,
2074
+ 0.78539816339744830962,
2075
+ };
2076
+
2077
+ TEST(dom_fp_roundtrip_float)
2078
+ {
2079
+ xml_document doc;
2080
+
2081
+ for (int e = -125; e <= 128; ++e)
2082
+ {
2083
+ for (size_t i = 0; i < sizeof(fp_roundtrip_base) / sizeof(fp_roundtrip_base[0]); ++i)
2084
+ {
2085
+ float value = static_cast<float>(ldexp(fp_roundtrip_base[i], e));
2086
+
2087
+ doc.text().set(value);
2088
+ CHECK(fp_equal(doc.text().as_float(), value));
2089
+ }
2090
+ }
2091
+ }
2092
+
2093
+ // Borland C does not print double values with enough precision
2094
+ #ifndef __BORLANDC__
2095
+ TEST(dom_fp_roundtrip_double)
2096
+ {
2097
+ xml_document doc;
2098
+
2099
+ for (int e = -1021; e <= 1024; ++e)
2100
+ {
2101
+ for (size_t i = 0; i < sizeof(fp_roundtrip_base) / sizeof(fp_roundtrip_base[0]); ++i)
2102
+ {
2103
+ #if (defined(_MSC_VER) && _MSC_VER < 1400) || defined(__MWERKS__)
2104
+ // Not all runtime libraries guarantee roundtripping for denormals
2105
+ if (e == -1021 && fp_roundtrip_base[i] < 0.5)
2106
+ continue;
2107
+ #endif
2108
+
2109
+ #ifdef __DMC__
2110
+ // Digital Mars C does not roundtrip on exactly one combination
2111
+ if (e == -12 && i == 1)
2112
+ continue;
2113
+ #endif
2114
+
2115
+ double value = ldexp(fp_roundtrip_base[i], e);
2116
+
2117
+ doc.text().set(value);
2118
+ CHECK(fp_equal(doc.text().as_double(), value));
2119
+ }
2120
+ }
2121
+ }
2122
+ #endif