react-native-nitro-xlsx 0.1.4 → 0.2.6

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 (428) hide show
  1. package/NitroXlsx.podspec +27 -27
  2. package/Package.swift +35 -10
  3. package/README.md +220 -58
  4. package/android/CMakeLists.txt +24 -27
  5. package/android/cpp-adapter.cpp +12 -0
  6. package/android/src/main/java/com/margelo/nitro/xlsx/NitroXlsxPackage.kt +9 -0
  7. package/cpp/HybridNitroXlsx.cpp +25 -179
  8. package/cpp/HybridNitroXlsx.hpp +2 -2
  9. package/cpp/HybridXlsxConditionalFormat.cpp +252 -0
  10. package/cpp/HybridXlsxConditionalFormat.hpp +62 -0
  11. package/cpp/HybridXlsxConditionalFormats.cpp +46 -0
  12. package/cpp/HybridXlsxConditionalFormats.hpp +28 -0
  13. package/cpp/HybridXlsxWorkbook.cpp +159 -196
  14. package/cpp/HybridXlsxWorkbook.hpp +7 -2
  15. package/cpp/HybridXlsxWorksheet.cpp +433 -62
  16. package/cpp/HybridXlsxWorksheet.hpp +73 -26
  17. package/cpp/XlsxCacheDir.cpp +76 -0
  18. package/cpp/XlsxCacheDir.hpp +27 -0
  19. package/cpp/XlsxError.hpp +68 -0
  20. package/cpp/XlsxJson.cpp +185 -0
  21. package/cpp/XlsxJson.hpp +36 -0
  22. package/ios/XlsxCacheDir.mm +60 -0
  23. package/nitrogen/generated/android/NitroXlsx+autolinking.cmake +2 -0
  24. package/nitrogen/generated/shared/c++/HybridNitroXlsxSpec.hpp +5 -3
  25. package/nitrogen/generated/shared/c++/HybridXlsxConditionalFormatSpec.cpp +54 -0
  26. package/nitrogen/generated/shared/c++/HybridXlsxConditionalFormatSpec.hpp +95 -0
  27. package/nitrogen/generated/shared/c++/HybridXlsxConditionalFormatsSpec.cpp +24 -0
  28. package/nitrogen/generated/shared/c++/HybridXlsxConditionalFormatsSpec.hpp +68 -0
  29. package/nitrogen/generated/shared/c++/HybridXlsxWorkbookSpec.cpp +3 -0
  30. package/nitrogen/generated/shared/c++/HybridXlsxWorkbookSpec.hpp +6 -1
  31. package/nitrogen/generated/shared/c++/HybridXlsxWorksheetSpec.cpp +47 -19
  32. package/nitrogen/generated/shared/c++/HybridXlsxWorksheetSpec.hpp +52 -20
  33. package/package.json +3 -3
  34. package/scripts/run-cpp-tests.sh +14 -0
  35. package/src/__mocks__/react-native-nitro-modules.ts +1 -0
  36. package/src/__tests__/index.test.ts +76 -7
  37. package/src/index.ts +107 -18
  38. package/src/specs/NitroXlsx.nitro.ts +141 -44
  39. package/thirdparty/OpenXLSX/.clang-format +118 -0
  40. package/thirdparty/OpenXLSX/.clang-tidy +28 -0
  41. package/thirdparty/OpenXLSX/.gitignore +130 -0
  42. package/thirdparty/OpenXLSX/Benchmarks/2024-07-29-benchmarks_before_XMLNode_wrappers +46 -0
  43. package/thirdparty/OpenXLSX/Benchmarks/2024-07-29-benchmarks_with_XMLNode_wrappers_and_namespace_and_stripping +49 -0
  44. package/thirdparty/OpenXLSX/Benchmarks/2024-07-29-benchmarks_with_XMLNode_wrappers_and_namespace_char_support +49 -0
  45. package/thirdparty/OpenXLSX/Benchmarks/2024-07-29-benchmarks_with_XMLNode_wrappers_and_namespace_support +49 -0
  46. package/thirdparty/OpenXLSX/Benchmarks/2024-07-29-benchmarks_with_XMLNode_wrappers_and_namespaced_name_disabled +49 -0
  47. package/thirdparty/OpenXLSX/Benchmarks/2024-08-11-benchmarks_post-XLCellIterator-Rework +46 -0
  48. package/thirdparty/OpenXLSX/Benchmarks/2024-08-14-benchmarks_post-default-row-column-style-support +46 -0
  49. package/thirdparty/OpenXLSX/Benchmarks/2024-09-02-benchmarks +46 -0
  50. package/thirdparty/OpenXLSX/Benchmarks/2024-12-19-benchmarks +46 -0
  51. package/thirdparty/OpenXLSX/Benchmarks/2024-12-30-benchmarks-post-XLSharedStrings-by-ref +46 -0
  52. package/thirdparty/OpenXLSX/Benchmarks/2025-01-09-benchmarks-post-conditionalFormatsAndSheetProtection +46 -0
  53. package/thirdparty/OpenXLSX/Benchmarks/2025-01-10-benchmarks-post-XLCellValue-bugfix +46 -0
  54. package/thirdparty/OpenXLSX/Benchmarks/2025-01-31-benchmarks-post-XLComments-implementation +46 -0
  55. package/thirdparty/OpenXLSX/Benchmarks/2025-02-02-benchmarks-post-XLRowIterator-Rework +46 -0
  56. package/thirdparty/OpenXLSX/Benchmarks/2025-07-20-benchmarks-after-hiding-pugixml-internals +46 -0
  57. package/thirdparty/OpenXLSX/Benchmarks/2025-08-29-benchmarks-after-code-review-with-libzip +46 -0
  58. package/thirdparty/OpenXLSX/Benchmarks/Benchmark.cpp +249 -0
  59. package/thirdparty/OpenXLSX/Benchmarks/CMakeLists.txt +19 -0
  60. package/thirdparty/OpenXLSX/CMakeLists.txt +466 -0
  61. package/thirdparty/OpenXLSX/Documentation/CMakeLists.txt +31 -0
  62. package/thirdparty/OpenXLSX/Documentation/Doxyfile.in +2471 -0
  63. package/thirdparty/OpenXLSX/Documentation/DoxygenLayout.xml +194 -0
  64. package/thirdparty/OpenXLSX/Documentation/customdoxygen.css +1355 -0
  65. package/thirdparty/OpenXLSX/Examples/CMakeLists.txt +103 -0
  66. package/thirdparty/OpenXLSX/Examples/Demo1.cpp +279 -0
  67. package/thirdparty/OpenXLSX/Examples/Demo10.cpp +545 -0
  68. package/thirdparty/OpenXLSX/Examples/Demo1A.cpp +137 -0
  69. package/thirdparty/OpenXLSX/Examples/Demo2.cpp +65 -0
  70. package/thirdparty/OpenXLSX/Examples/Demo3.cpp +89 -0
  71. package/thirdparty/OpenXLSX/Examples/Demo4.cpp +86 -0
  72. package/thirdparty/OpenXLSX/Examples/Demo5.cpp +77 -0
  73. package/thirdparty/OpenXLSX/Examples/Demo6.cpp +103 -0
  74. package/thirdparty/OpenXLSX/Examples/Demo7.cpp +79 -0
  75. package/thirdparty/OpenXLSX/Examples/Demo8.cpp +117 -0
  76. package/thirdparty/OpenXLSX/Examples/Demo9.cpp +363 -0
  77. package/thirdparty/OpenXLSX/Examples/cmake/FindLIBZIP.cmake +61 -0
  78. package/thirdparty/OpenXLSX/Examples/external/CustomZip/CustomZip.hpp +256 -0
  79. package/thirdparty/OpenXLSX/LICENSE.md +29 -0
  80. package/thirdparty/OpenXLSX/Makefile.GNU +530 -0
  81. package/thirdparty/OpenXLSX/Notes/TBDs.txt +16 -0
  82. package/thirdparty/OpenXLSX/Notes/confirmed-TBCs.txt +8 -0
  83. package/thirdparty/OpenXLSX/Notes/styles-missing-support.xml +12 -0
  84. package/thirdparty/OpenXLSX/Notes/todo-list.txt +108 -0
  85. package/thirdparty/OpenXLSX/OpenXLSX/CMakeLists.txt +631 -0
  86. package/thirdparty/OpenXLSX/OpenXLSX/OpenXLSX.hpp +63 -0
  87. package/thirdparty/OpenXLSX/OpenXLSX/OpenXLSXConfig.cmake +11 -0
  88. package/thirdparty/OpenXLSX/OpenXLSX/cmake/bundle_static_library.cmake +198 -0
  89. package/thirdparty/OpenXLSX/OpenXLSX/cmake/patch_pkg_config.cmake +69 -0
  90. package/thirdparty/OpenXLSX/OpenXLSX/headers/IZipArchive.hpp +361 -0
  91. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX-Exports.hpp +12 -0
  92. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLCell.hpp +367 -0
  93. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLCellIterator.hpp +252 -0
  94. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLCellRange.hpp +223 -0
  95. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLCellReference.hpp +317 -0
  96. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLCellValue.hpp +793 -0
  97. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLColor.hpp +232 -0
  98. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLColumn.hpp +159 -0
  99. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLCommandQuery.hpp +228 -0
  100. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLComments.hpp +270 -0
  101. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLConstants.hpp +18 -0
  102. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLContentTypes.hpp +264 -0
  103. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLDateTime.hpp +175 -0
  104. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLDocument.hpp +505 -0
  105. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLDrawing.hpp +452 -0
  106. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLException.hpp +161 -0
  107. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLFormula.hpp +375 -0
  108. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLIterator.hpp +40 -0
  109. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLMergeCells.hpp +216 -0
  110. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLProperties.hpp +348 -0
  111. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLRelationships.hpp +348 -0
  112. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLRow.hpp +721 -0
  113. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLRowData.hpp +488 -0
  114. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLSharedStrings.hpp +204 -0
  115. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLSheet.hpp +1640 -0
  116. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLStyles.hpp +2390 -0
  117. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLTables.hpp +132 -0
  118. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLWorkbook.hpp +404 -0
  119. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLXmlData.hpp +283 -0
  120. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLXmlFile.hpp +194 -0
  121. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLXmlParser.hpp +282 -0
  122. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLXmlParserForwardDeclarations.hpp +85 -0
  123. package/thirdparty/OpenXLSX/OpenXLSX/headers/XLZipArchive.hpp +232 -0
  124. package/thirdparty/OpenXLSX/OpenXLSX/headers/detail/LibZip.hpp +447 -0
  125. package/thirdparty/OpenXLSX/OpenXLSX/headers/detail/OpenXLSXFileSystemTools.hpp +207 -0
  126. package/thirdparty/OpenXLSX/OpenXLSX/headers/detail/Zippy.hpp +1375 -0
  127. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLCell.cpp +340 -0
  128. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLCellIterator.cpp +427 -0
  129. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLCellRange.cpp +221 -0
  130. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLCellReference.cpp +408 -0
  131. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLCellValue.cpp +519 -0
  132. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLColor.cpp +202 -0
  133. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLColumn.cpp +141 -0
  134. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLComments.cpp +637 -0
  135. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLContentTypes.cpp +329 -0
  136. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLDateTime.cpp +269 -0
  137. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLDocument.cpp +1678 -0
  138. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLDrawing.cpp +784 -0
  139. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLFormula.cpp +201 -0
  140. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLMergeCells.cpp +357 -0
  141. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLProperties.cpp +810 -0
  142. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLRelationships.cpp +529 -0
  143. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLRow.cpp +918 -0
  144. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLRowData.cpp +508 -0
  145. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLSharedStrings.cpp +220 -0
  146. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLSheet.cpp +1970 -0
  147. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLStyles.cpp +3014 -0
  148. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLTables.cpp +125 -0
  149. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLWorkbook.cpp +784 -0
  150. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLXmlData.cpp +247 -0
  151. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLXmlFile.cpp +160 -0
  152. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLXmlParser.cpp +261 -0
  153. package/thirdparty/OpenXLSX/OpenXLSX/sources/XLZipArchive.cpp +266 -0
  154. package/thirdparty/OpenXLSX/OpenXLSX/sources/utilities/XLUtilities.hpp +478 -0
  155. package/thirdparty/OpenXLSX/README.md +1279 -0
  156. package/thirdparty/OpenXLSX/Scripts/cmake-cleanup.sh +102 -0
  157. package/thirdparty/OpenXLSX/Scripts/compile.sh +23 -0
  158. package/thirdparty/OpenXLSX/Scripts/demos-cleanup.sh +25 -0
  159. package/thirdparty/OpenXLSX/Scripts/demos-run-all.sh +60 -0
  160. package/thirdparty/OpenXLSX/Scripts/guarded-xml-format.sh +47 -0
  161. package/thirdparty/OpenXLSX/Scripts/make-gnu.sh +11 -0
  162. package/thirdparty/OpenXLSX/Scripts/uninstall-manifest.sh +48 -0
  163. package/thirdparty/OpenXLSX/Scripts/xml-format-all.sh +19 -0
  164. package/thirdparty/OpenXLSX/Scripts/xml-format.sh +38 -0
  165. package/thirdparty/OpenXLSX/Tests/CMakeLists.txt +37 -0
  166. package/thirdparty/OpenXLSX/Tests/catch/catch.hpp +17799 -0
  167. package/thirdparty/OpenXLSX/Tests/catch/catch_reporter_automake.hpp +68 -0
  168. package/thirdparty/OpenXLSX/Tests/catch/catch_reporter_sonarqube.hpp +182 -0
  169. package/thirdparty/OpenXLSX/Tests/catch/catch_reporter_tap.hpp +278 -0
  170. package/thirdparty/OpenXLSX/Tests/catch/catch_reporter_teamcity.hpp +212 -0
  171. package/thirdparty/OpenXLSX/Tests/main.cpp +55 -0
  172. package/thirdparty/OpenXLSX/Tests/testXLCell.cpp +176 -0
  173. package/thirdparty/OpenXLSX/Tests/testXLCellRange.cpp +180 -0
  174. package/thirdparty/OpenXLSX/Tests/testXLCellReference.cpp +160 -0
  175. package/thirdparty/OpenXLSX/Tests/testXLCellValue.cpp +366 -0
  176. package/thirdparty/OpenXLSX/Tests/testXLCellValueProxy.cpp +255 -0
  177. package/thirdparty/OpenXLSX/Tests/testXLColor.cpp +75 -0
  178. package/thirdparty/OpenXLSX/Tests/testXLDateTime.cpp +229 -0
  179. package/thirdparty/OpenXLSX/Tests/testXLDocument.cpp +197 -0
  180. package/thirdparty/OpenXLSX/Tests/testXLFormula.cpp +131 -0
  181. package/thirdparty/OpenXLSX/Tests/testXLRow.cpp +597 -0
  182. package/thirdparty/OpenXLSX/Tests/testXLSheet.cpp +77 -0
  183. package/thirdparty/OpenXLSX/Tests/ziptest-with-libs.cpp +88 -0
  184. package/thirdparty/OpenXLSX/Tests/ziptest.cpp +735 -0
  185. package/thirdparty/OpenXLSX/cmake/get-git-HEAD-ID.cmake +45 -0
  186. package/thirdparty/OpenXLSX/cmake/libopenxlsxCPackOptions.cmake.in +20 -0
  187. package/thirdparty/OpenXLSX/cmake/manage_dependency.cmake +813 -0
  188. package/thirdparty/OpenXLSX/cmake/recursive_library_type_test.cmake +52 -0
  189. package/thirdparty/OpenXLSX/gnu-make-crutch/OpenXLSX-Exports-shared.hpp +42 -0
  190. package/thirdparty/OpenXLSX/gnu-make-crutch/OpenXLSX-Exports-static.hpp +42 -0
  191. package/thirdparty/OpenXLSX/vcpkg.json +24 -0
  192. package/thirdparty/README.md +42 -0
  193. package/thirdparty/miniz/.clang-format +47 -0
  194. package/thirdparty/miniz/.travis.yml +2 -0
  195. package/thirdparty/miniz/CMakeLists.txt +333 -0
  196. package/thirdparty/miniz/CMakePresets.json +31 -0
  197. package/thirdparty/miniz/ChangeLog.md +272 -0
  198. package/thirdparty/miniz/Config.cmake.in +1 -0
  199. package/thirdparty/miniz/LICENSE +22 -0
  200. package/thirdparty/miniz/amalgamate.sh +57 -0
  201. package/thirdparty/miniz/examples/example1.c +105 -0
  202. package/thirdparty/miniz/examples/example2.c +164 -0
  203. package/thirdparty/miniz/examples/example3.c +269 -0
  204. package/thirdparty/miniz/examples/example4.c +102 -0
  205. package/thirdparty/miniz/examples/example5.c +327 -0
  206. package/thirdparty/miniz/examples/example6.c +189 -0
  207. package/thirdparty/miniz/meson.build +21 -0
  208. package/thirdparty/miniz/miniz.c +646 -0
  209. package/thirdparty/miniz/miniz.h +615 -0
  210. package/thirdparty/miniz/miniz.pc.in +13 -0
  211. package/thirdparty/miniz/miniz_common.h +89 -0
  212. package/thirdparty/miniz/miniz_export.h +20 -0
  213. package/thirdparty/miniz/miniz_tdef.c +1602 -0
  214. package/thirdparty/miniz/miniz_tdef.h +199 -0
  215. package/thirdparty/miniz/miniz_tinfl.c +778 -0
  216. package/thirdparty/miniz/miniz_tinfl.h +150 -0
  217. package/thirdparty/miniz/miniz_zip.c +4895 -0
  218. package/thirdparty/miniz/miniz_zip.h +454 -0
  219. package/thirdparty/miniz/readme.md +46 -0
  220. package/thirdparty/miniz/test.sh +36 -0
  221. package/thirdparty/miniz/tests/add_in_place_fuzzer.c +87 -0
  222. package/thirdparty/miniz/tests/catch_amalgamated.cpp +10795 -0
  223. package/thirdparty/miniz/tests/catch_amalgamated.hpp +13143 -0
  224. package/thirdparty/miniz/tests/checksum_fuzzer.c +26 -0
  225. package/thirdparty/miniz/tests/compress_fuzzer.c +91 -0
  226. package/thirdparty/miniz/tests/flush_fuzzer.c +88 -0
  227. package/thirdparty/miniz/tests/fuzz_main.c +55 -0
  228. package/thirdparty/miniz/tests/large_fuzzer.c +133 -0
  229. package/thirdparty/miniz/tests/main.cpp +185 -0
  230. package/thirdparty/miniz/tests/miniz_tdefl_fuzzer.cc +115 -0
  231. package/thirdparty/miniz/tests/miniz_tester.cpp +1881 -0
  232. package/thirdparty/miniz/tests/miniz_zip_validate_fuzzer.cc +71 -0
  233. package/thirdparty/miniz/tests/miniz_zip_writer_fuzzer.cc +96 -0
  234. package/thirdparty/miniz/tests/ossfuzz.sh +48 -0
  235. package/thirdparty/miniz/tests/small_fuzzer.c +126 -0
  236. package/thirdparty/miniz/tests/timer.cpp +152 -0
  237. package/thirdparty/miniz/tests/timer.h +40 -0
  238. package/thirdparty/miniz/tests/uncompress2_fuzzer.c +21 -0
  239. package/thirdparty/miniz/tests/uncompress_fuzzer.c +30 -0
  240. package/thirdparty/miniz/tests/zip.dict +9 -0
  241. package/thirdparty/miniz/tests/zip_fuzzer.c +63 -0
  242. package/thirdparty/pugixml/.codecov.yml +7 -0
  243. package/thirdparty/pugixml/.gitattributes +1 -0
  244. package/thirdparty/pugixml/CMakeLists.txt +330 -0
  245. package/thirdparty/pugixml/LICENSE.md +24 -0
  246. package/thirdparty/pugixml/Makefile +98 -0
  247. package/thirdparty/pugixml/README.md +81 -0
  248. package/thirdparty/pugixml/SECURITY.md +9 -0
  249. package/thirdparty/pugixml/appveyor.yml +50 -0
  250. package/thirdparty/pugixml/docs/config.adoc +7 -0
  251. package/thirdparty/pugixml/docs/images/dom_tree.png +0 -0
  252. package/thirdparty/pugixml/docs/images/vs2005_link1.png +0 -0
  253. package/thirdparty/pugixml/docs/images/vs2005_link2.png +0 -0
  254. package/thirdparty/pugixml/docs/images/vs2005_pch1.png +0 -0
  255. package/thirdparty/pugixml/docs/images/vs2005_pch2.png +0 -0
  256. package/thirdparty/pugixml/docs/images/vs2005_pch3.png +0 -0
  257. package/thirdparty/pugixml/docs/images/vs2005_pch4.png +0 -0
  258. package/thirdparty/pugixml/docs/images/vs2010_link1.png +0 -0
  259. package/thirdparty/pugixml/docs/images/vs2010_link2.png +0 -0
  260. package/thirdparty/pugixml/docs/manual.adoc +3326 -0
  261. package/thirdparty/pugixml/docs/manual.html +6395 -0
  262. package/thirdparty/pugixml/docs/quickstart.adoc +287 -0
  263. package/thirdparty/pugixml/docs/quickstart.html +1107 -0
  264. package/thirdparty/pugixml/docs/samples/character.xml +8 -0
  265. package/thirdparty/pugixml/docs/samples/custom_memory_management.cpp +27 -0
  266. package/thirdparty/pugixml/docs/samples/include.cpp +64 -0
  267. package/thirdparty/pugixml/docs/samples/load_error_handling.cpp +33 -0
  268. package/thirdparty/pugixml/docs/samples/load_file.cpp +16 -0
  269. package/thirdparty/pugixml/docs/samples/load_memory.cpp +66 -0
  270. package/thirdparty/pugixml/docs/samples/load_options.cpp +30 -0
  271. package/thirdparty/pugixml/docs/samples/load_stream.cpp +97 -0
  272. package/thirdparty/pugixml/docs/samples/modify_add.cpp +29 -0
  273. package/thirdparty/pugixml/docs/samples/modify_base.cpp +43 -0
  274. package/thirdparty/pugixml/docs/samples/modify_remove.cpp +27 -0
  275. package/thirdparty/pugixml/docs/samples/save_custom_writer.cpp +116 -0
  276. package/thirdparty/pugixml/docs/samples/save_declaration.cpp +27 -0
  277. package/thirdparty/pugixml/docs/samples/save_file.cpp +17 -0
  278. package/thirdparty/pugixml/docs/samples/save_options.cpp +48 -0
  279. package/thirdparty/pugixml/docs/samples/save_stream.cpp +18 -0
  280. package/thirdparty/pugixml/docs/samples/save_subtree.cpp +26 -0
  281. package/thirdparty/pugixml/docs/samples/text.cpp +35 -0
  282. package/thirdparty/pugixml/docs/samples/transitions.xml +7 -0
  283. package/thirdparty/pugixml/docs/samples/traverse_base.cpp +51 -0
  284. package/thirdparty/pugixml/docs/samples/traverse_iter.cpp +27 -0
  285. package/thirdparty/pugixml/docs/samples/traverse_predicate.cpp +48 -0
  286. package/thirdparty/pugixml/docs/samples/traverse_rangefor.cpp +32 -0
  287. package/thirdparty/pugixml/docs/samples/traverse_walker.cpp +35 -0
  288. package/thirdparty/pugixml/docs/samples/tree.xml +12 -0
  289. package/thirdparty/pugixml/docs/samples/weekly-shift_jis.xml +78 -0
  290. package/thirdparty/pugixml/docs/samples/weekly-utf-16.xml +0 -0
  291. package/thirdparty/pugixml/docs/samples/weekly-utf-8.xml +78 -0
  292. package/thirdparty/pugixml/docs/samples/xgconsole.xml +12 -0
  293. package/thirdparty/pugixml/docs/samples/xpath_error.cpp +43 -0
  294. package/thirdparty/pugixml/docs/samples/xpath_query.cpp +36 -0
  295. package/thirdparty/pugixml/docs/samples/xpath_select.cpp +28 -0
  296. package/thirdparty/pugixml/docs/samples/xpath_variables.cpp +38 -0
  297. package/thirdparty/pugixml/readme.txt +50 -0
  298. package/thirdparty/pugixml/scripts/archive.py +54 -0
  299. package/thirdparty/pugixml/scripts/cocoapods_push.sh +4 -0
  300. package/thirdparty/pugixml/scripts/natvis/pugixml.natvis +77 -0
  301. package/thirdparty/pugixml/scripts/natvis/pugixml_compact.natvis +506 -0
  302. package/thirdparty/pugixml/scripts/nuget/build/native/pugixml-propertiesui.xml +17 -0
  303. package/thirdparty/pugixml/scripts/nuget/build/native/pugixml.targets +28 -0
  304. package/thirdparty/pugixml/scripts/nuget/pugixml.nuspec +20 -0
  305. package/thirdparty/pugixml/scripts/nuget_build.ps1 +60 -0
  306. package/thirdparty/pugixml/scripts/premake4.lua +92 -0
  307. package/thirdparty/pugixml/scripts/pugixml-config.cmake.in +12 -0
  308. package/thirdparty/pugixml/scripts/pugixml.pc.in +11 -0
  309. package/thirdparty/pugixml/scripts/pugixml.podspec +14 -0
  310. package/thirdparty/pugixml/scripts/pugixml.xcodeproj/project.pbxproj +212 -0
  311. package/thirdparty/pugixml/scripts/pugixml_airplay.mkf +13 -0
  312. package/thirdparty/pugixml/scripts/pugixml_codeblocks.cbp +44 -0
  313. package/thirdparty/pugixml/scripts/pugixml_codelite.project +56 -0
  314. package/thirdparty/pugixml/scripts/pugixml_dll.rc +45 -0
  315. package/thirdparty/pugixml/scripts/pugixml_vs2005.vcproj +343 -0
  316. package/thirdparty/pugixml/scripts/pugixml_vs2005_static.vcproj +343 -0
  317. package/thirdparty/pugixml/scripts/pugixml_vs2008.vcproj +339 -0
  318. package/thirdparty/pugixml/scripts/pugixml_vs2008_static.vcproj +339 -0
  319. package/thirdparty/pugixml/scripts/pugixml_vs2010.vcxproj +191 -0
  320. package/thirdparty/pugixml/scripts/pugixml_vs2010_static.vcxproj +191 -0
  321. package/thirdparty/pugixml/scripts/pugixml_vs2013.vcxproj +199 -0
  322. package/thirdparty/pugixml/scripts/pugixml_vs2013_static.vcxproj +199 -0
  323. package/thirdparty/pugixml/scripts/pugixml_vs2015.vcxproj +172 -0
  324. package/thirdparty/pugixml/scripts/pugixml_vs2015_static.vcxproj +176 -0
  325. package/thirdparty/pugixml/scripts/pugixml_vs2017.vcxproj +172 -0
  326. package/thirdparty/pugixml/scripts/pugixml_vs2017_static.vcxproj +176 -0
  327. package/thirdparty/pugixml/scripts/pugixml_vs2019.vcxproj +176 -0
  328. package/thirdparty/pugixml/scripts/pugixml_vs2019_static.vcxproj +180 -0
  329. package/thirdparty/pugixml/scripts/pugixml_vs2022.vcxproj +176 -0
  330. package/thirdparty/pugixml/scripts/pugixml_vs2022_static.vcxproj +180 -0
  331. package/thirdparty/pugixml/scripts/pugixml_vs2026.vcxproj +176 -0
  332. package/thirdparty/pugixml/scripts/pugixml_vs2026_static.vcxproj +180 -0
  333. package/thirdparty/pugixml/scripts/sbom.cdx.json +47 -0
  334. package/thirdparty/pugixml/src/pugiconfig.hpp +81 -0
  335. package/thirdparty/pugixml/src/pugixml.cpp +13776 -0
  336. package/thirdparty/pugixml/src/pugixml.hpp +1604 -0
  337. package/thirdparty/pugixml/tests/allocator.cpp +175 -0
  338. package/thirdparty/pugixml/tests/allocator.hpp +10 -0
  339. package/thirdparty/pugixml/tests/autotest-appveyor.ps1 +93 -0
  340. package/thirdparty/pugixml/tests/cmake-appveyor.ps1 +57 -0
  341. package/thirdparty/pugixml/tests/data/empty.xml +0 -0
  342. package/thirdparty/pugixml/tests/data/large.xml +1 -0
  343. package/thirdparty/pugixml/tests/data/latintest_latin1.xml +1 -0
  344. package/thirdparty/pugixml/tests/data/latintest_utf8.xml +1 -0
  345. package/thirdparty/pugixml/tests/data/multiline.xml +3 -0
  346. package/thirdparty/pugixml/tests/data/small.xml +1 -0
  347. package/thirdparty/pugixml/tests/data/truncation.xml +19 -0
  348. package/thirdparty/pugixml/tests/data/utftest_utf16_be.xml +0 -0
  349. package/thirdparty/pugixml/tests/data/utftest_utf16_be_bom.xml +0 -0
  350. package/thirdparty/pugixml/tests/data/utftest_utf16_be_clean.xml +0 -0
  351. package/thirdparty/pugixml/tests/data/utftest_utf16_be_nodecl.xml +0 -0
  352. package/thirdparty/pugixml/tests/data/utftest_utf16_le.xml +0 -0
  353. package/thirdparty/pugixml/tests/data/utftest_utf16_le_bom.xml +0 -0
  354. package/thirdparty/pugixml/tests/data/utftest_utf16_le_clean.xml +0 -0
  355. package/thirdparty/pugixml/tests/data/utftest_utf16_le_nodecl.xml +0 -0
  356. package/thirdparty/pugixml/tests/data/utftest_utf32_be.xml +0 -0
  357. package/thirdparty/pugixml/tests/data/utftest_utf32_be_bom.xml +0 -0
  358. package/thirdparty/pugixml/tests/data/utftest_utf32_be_clean.xml +0 -0
  359. package/thirdparty/pugixml/tests/data/utftest_utf32_be_nodecl.xml +0 -0
  360. package/thirdparty/pugixml/tests/data/utftest_utf32_le.xml +0 -0
  361. package/thirdparty/pugixml/tests/data/utftest_utf32_le_bom.xml +0 -0
  362. package/thirdparty/pugixml/tests/data/utftest_utf32_le_clean.xml +0 -0
  363. package/thirdparty/pugixml/tests/data/utftest_utf32_le_nodecl.xml +0 -0
  364. package/thirdparty/pugixml/tests/data/utftest_utf8.xml +87 -0
  365. package/thirdparty/pugixml/tests/data/utftest_utf8_bom.xml +87 -0
  366. package/thirdparty/pugixml/tests/data/utftest_utf8_clean.xml +84 -0
  367. package/thirdparty/pugixml/tests/data/utftest_utf8_nodecl.xml +86 -0
  368. package/thirdparty/pugixml/tests/data//321/202/320/265/321/201/321/202.xml +1 -0
  369. package/thirdparty/pugixml/tests/data_fuzz_parse/basic.xml +1 -0
  370. package/thirdparty/pugixml/tests/data_fuzz_parse/doctype.xml +1 -0
  371. package/thirdparty/pugixml/tests/data_fuzz_parse/refs.xml +1 -0
  372. package/thirdparty/pugixml/tests/data_fuzz_parse/types.xml +1 -0
  373. package/thirdparty/pugixml/tests/data_fuzz_parse/utf16.xml +0 -0
  374. package/thirdparty/pugixml/tests/data_fuzz_parse/utf32.xml +0 -0
  375. package/thirdparty/pugixml/tests/data_fuzz_xpath/basic.xpath +1 -0
  376. package/thirdparty/pugixml/tests/data_fuzz_xpath/functions.xpath +1 -0
  377. package/thirdparty/pugixml/tests/data_fuzz_xpath/math.xpath +1 -0
  378. package/thirdparty/pugixml/tests/data_fuzz_xpath/path.xpath +1 -0
  379. package/thirdparty/pugixml/tests/data_fuzz_xpath/predicate.xpath +1 -0
  380. package/thirdparty/pugixml/tests/fuzz_parse.cpp +14 -0
  381. package/thirdparty/pugixml/tests/fuzz_parse.dict +72 -0
  382. package/thirdparty/pugixml/tests/fuzz_setup.sh +11 -0
  383. package/thirdparty/pugixml/tests/fuzz_xpath.cpp +46 -0
  384. package/thirdparty/pugixml/tests/fuzz_xpath.dict +72 -0
  385. package/thirdparty/pugixml/tests/helpers.hpp +114 -0
  386. package/thirdparty/pugixml/tests/main.cpp +218 -0
  387. package/thirdparty/pugixml/tests/test.cpp +220 -0
  388. package/thirdparty/pugixml/tests/test.hpp +175 -0
  389. package/thirdparty/pugixml/tests/test_compact.cpp +150 -0
  390. package/thirdparty/pugixml/tests/test_deprecated.cpp +25 -0
  391. package/thirdparty/pugixml/tests/test_document.cpp +1910 -0
  392. package/thirdparty/pugixml/tests/test_dom_modify.cpp +2122 -0
  393. package/thirdparty/pugixml/tests/test_dom_text.cpp +601 -0
  394. package/thirdparty/pugixml/tests/test_dom_traverse.cpp +1481 -0
  395. package/thirdparty/pugixml/tests/test_header_guard.cpp +3 -0
  396. package/thirdparty/pugixml/tests/test_header_iosfwd_1.cpp +3 -0
  397. package/thirdparty/pugixml/tests/test_header_iosfwd_2.cpp +3 -0
  398. package/thirdparty/pugixml/tests/test_header_iostream_1.cpp +3 -0
  399. package/thirdparty/pugixml/tests/test_header_iostream_2.cpp +3 -0
  400. package/thirdparty/pugixml/tests/test_header_only_1.cpp +21 -0
  401. package/thirdparty/pugixml/tests/test_header_only_2.cpp +21 -0
  402. package/thirdparty/pugixml/tests/test_header_string_1.cpp +3 -0
  403. package/thirdparty/pugixml/tests/test_header_string_2.cpp +3 -0
  404. package/thirdparty/pugixml/tests/test_header_string_iostream.cpp +5 -0
  405. package/thirdparty/pugixml/tests/test_memory.cpp +303 -0
  406. package/thirdparty/pugixml/tests/test_parse.cpp +1463 -0
  407. package/thirdparty/pugixml/tests/test_parse_doctype.cpp +366 -0
  408. package/thirdparty/pugixml/tests/test_unicode.cpp +152 -0
  409. package/thirdparty/pugixml/tests/test_version.cpp +5 -0
  410. package/thirdparty/pugixml/tests/test_write.cpp +757 -0
  411. package/thirdparty/pugixml/tests/test_xpath.cpp +833 -0
  412. package/thirdparty/pugixml/tests/test_xpath_api.cpp +646 -0
  413. package/thirdparty/pugixml/tests/test_xpath_functions.cpp +844 -0
  414. package/thirdparty/pugixml/tests/test_xpath_operators.cpp +566 -0
  415. package/thirdparty/pugixml/tests/test_xpath_parse.cpp +428 -0
  416. package/thirdparty/pugixml/tests/test_xpath_paths.cpp +787 -0
  417. package/thirdparty/pugixml/tests/test_xpath_paths_abbrev_w3c.cpp +219 -0
  418. package/thirdparty/pugixml/tests/test_xpath_paths_w3c.cpp +312 -0
  419. package/thirdparty/pugixml/tests/test_xpath_variables.cpp +683 -0
  420. package/thirdparty/pugixml/tests/test_xpath_xalan_1.cpp +411 -0
  421. package/thirdparty/pugixml/tests/test_xpath_xalan_2.cpp +417 -0
  422. package/thirdparty/pugixml/tests/test_xpath_xalan_3.cpp +321 -0
  423. package/thirdparty/pugixml/tests/test_xpath_xalan_4.cpp +300 -0
  424. package/thirdparty/pugixml/tests/test_xpath_xalan_5.cpp +295 -0
  425. package/thirdparty/pugixml/tests/writer_string.cpp +79 -0
  426. package/thirdparty/pugixml/tests/writer_string.hpp +27 -0
  427. package/ios/dummy.swift +0 -2
  428. package/scripts/prepare-openxlsx.js +0 -109
@@ -0,0 +1,1481 @@
1
+ #define _CRT_SECURE_NO_WARNINGS
2
+ #define _SCL_SECURE_NO_WARNINGS
3
+ #define _SCL_SECURE_NO_DEPRECATE
4
+
5
+ #include "test.hpp"
6
+
7
+ #include <string.h>
8
+ #include <stdio.h>
9
+ #include <wchar.h>
10
+
11
+ #include <utility>
12
+ #include <vector>
13
+ #include <iterator>
14
+ #include <string>
15
+
16
+ #include "helpers.hpp"
17
+
18
+ using namespace pugi;
19
+
20
+ #ifdef PUGIXML_NO_STL
21
+ template <typename I> static I move_iter(I base, int n)
22
+ {
23
+ if (n > 0) while (n--) ++base;
24
+ else while (n++) --base;
25
+ return base;
26
+ }
27
+ #else
28
+ template <typename I> static I move_iter(I base, int n)
29
+ {
30
+ std::advance(base, n);
31
+ return base;
32
+ }
33
+ #endif
34
+
35
+ TEST_XML(dom_attr_bool_ops, "<node attr='1'/>")
36
+ {
37
+ generic_bool_ops_test(doc.child(STR("node")).attribute(STR("attr")));
38
+ }
39
+
40
+ TEST_XML(dom_attr_eq_ops, "<node attr1='1' attr2='2'/>")
41
+ {
42
+ generic_eq_ops_test(doc.child(STR("node")).attribute(STR("attr1")), doc.child(STR("node")).attribute(STR("attr2")));
43
+ }
44
+
45
+ TEST_XML(dom_attr_rel_ops, "<node attr1='1' attr2='2'/>")
46
+ {
47
+ generic_rel_ops_test(doc.child(STR("node")).attribute(STR("attr1")), doc.child(STR("node")).attribute(STR("attr2")));
48
+ }
49
+
50
+ TEST_XML(dom_attr_empty, "<node attr='1'/>")
51
+ {
52
+ generic_empty_test(doc.child(STR("node")).attribute(STR("attr")));
53
+ }
54
+
55
+ TEST_XML(dom_attr_next_previous_attribute, "<node attr1='1' attr2='2' />")
56
+ {
57
+ xml_attribute attr1 = doc.child(STR("node")).attribute(STR("attr1"));
58
+ xml_attribute attr2 = doc.child(STR("node")).attribute(STR("attr2"));
59
+
60
+ CHECK(attr1.next_attribute() == attr2);
61
+ CHECK(attr2.next_attribute() == xml_attribute());
62
+
63
+ CHECK(attr1.previous_attribute() == xml_attribute());
64
+ CHECK(attr2.previous_attribute() == attr1);
65
+
66
+ CHECK(xml_attribute().next_attribute() == xml_attribute());
67
+ CHECK(xml_attribute().previous_attribute() == xml_attribute());
68
+ }
69
+
70
+ TEST_XML(dom_attr_name_value, "<node attr='1'/>")
71
+ {
72
+ xml_attribute attr = doc.child(STR("node")).attribute(STR("attr"));
73
+
74
+ CHECK_NAME_VALUE(attr, STR("attr"), STR("1"));
75
+ CHECK_NAME_VALUE(xml_attribute(), STR(""), STR(""));
76
+ }
77
+
78
+ TEST_XML(dom_attr_as_string, "<node attr='1'/>")
79
+ {
80
+ xml_attribute attr = doc.child(STR("node")).attribute(STR("attr"));
81
+
82
+ CHECK_STRING(attr.as_string(), STR("1"));
83
+ CHECK_STRING(xml_attribute().as_string(), STR(""));
84
+ }
85
+
86
+ TEST_XML(dom_attr_as_int, "<node attr1='1' attr2='-1' attr3='-2147483648' attr4='2147483647' attr5='0'/>")
87
+ {
88
+ xml_node node = doc.child(STR("node"));
89
+
90
+ CHECK(xml_attribute().as_int() == 0);
91
+ CHECK(node.attribute(STR("attr1")).as_int() == 1);
92
+ CHECK(node.attribute(STR("attr2")).as_int() == -1);
93
+ CHECK(node.attribute(STR("attr3")).as_int() == -2147483647 - 1);
94
+ CHECK(node.attribute(STR("attr4")).as_int() == 2147483647);
95
+ CHECK(node.attribute(STR("attr5")).as_int() == 0);
96
+ }
97
+
98
+ TEST_XML(dom_attr_as_int_hex, "<node attr1='0777' attr2='0x5ab' attr3='0XFf' attr4='-0x20' attr5='-0x80000000' attr6='0x'/>")
99
+ {
100
+ xml_node node = doc.child(STR("node"));
101
+
102
+ CHECK(node.attribute(STR("attr1")).as_int() == 777); // no octal support! intentional
103
+ CHECK(node.attribute(STR("attr2")).as_int() == 1451);
104
+ CHECK(node.attribute(STR("attr3")).as_int() == 255);
105
+ CHECK(node.attribute(STR("attr4")).as_int() == -32);
106
+ CHECK(node.attribute(STR("attr5")).as_int() == -2147483647 - 1);
107
+ CHECK(node.attribute(STR("attr6")).as_int() == 0);
108
+ }
109
+
110
+ TEST_XML(dom_attr_as_uint, "<node attr1='0' attr2='1' attr3='2147483647' attr4='4294967295' attr5='0'/>")
111
+ {
112
+ xml_node node = doc.child(STR("node"));
113
+
114
+ CHECK(xml_attribute().as_uint() == 0);
115
+ CHECK(node.attribute(STR("attr1")).as_uint() == 0);
116
+ CHECK(node.attribute(STR("attr2")).as_uint() == 1);
117
+ CHECK(node.attribute(STR("attr3")).as_uint() == 2147483647);
118
+ CHECK(node.attribute(STR("attr4")).as_uint() == 4294967295u);
119
+ CHECK(node.attribute(STR("attr5")).as_uint() == 0);
120
+ }
121
+
122
+ TEST_XML(dom_attr_as_uint_hex, "<node attr1='0777' attr2='0x5ab' attr3='0XFf' attr4='0x20' attr5='0xFFFFFFFF' attr6='0x'/>")
123
+ {
124
+ xml_node node = doc.child(STR("node"));
125
+
126
+ CHECK(node.attribute(STR("attr1")).as_uint() == 777); // no octal support! intentional
127
+ CHECK(node.attribute(STR("attr2")).as_uint() == 1451);
128
+ CHECK(node.attribute(STR("attr3")).as_uint() == 255);
129
+ CHECK(node.attribute(STR("attr4")).as_uint() == 32);
130
+ CHECK(node.attribute(STR("attr5")).as_uint() == 4294967295u);
131
+ CHECK(node.attribute(STR("attr6")).as_uint() == 0);
132
+ }
133
+
134
+ TEST_XML(dom_attr_as_integer_space, "<node attr1=' \t1234' attr2='\t 0x123' attr3='- 16' attr4='- 0x10'/>")
135
+ {
136
+ xml_node node = doc.child(STR("node"));
137
+
138
+ CHECK(node.attribute(STR("attr1")).as_int() == 1234);
139
+ CHECK(node.attribute(STR("attr2")).as_int() == 291);
140
+ CHECK(node.attribute(STR("attr3")).as_int() == 0);
141
+ CHECK(node.attribute(STR("attr4")).as_int() == 0);
142
+
143
+ #ifdef PUGIXML_HAS_LONG_LONG
144
+ CHECK(node.attribute(STR("attr1")).as_llong() == 1234);
145
+ #endif
146
+ }
147
+
148
+ TEST_XML(dom_attr_as_float, "<node attr1='0' attr2='1' attr3='0.12' attr4='-5.1' attr5='3e-4' attr6='3.14159265358979323846'/>")
149
+ {
150
+ xml_node node = doc.child(STR("node"));
151
+
152
+ CHECK(xml_attribute().as_float() == 0);
153
+ CHECK_DOUBLE(double(node.attribute(STR("attr1")).as_float()), 0);
154
+ CHECK_DOUBLE(double(node.attribute(STR("attr2")).as_float()), 1);
155
+ CHECK_DOUBLE(double(node.attribute(STR("attr3")).as_float()), 0.12);
156
+ CHECK_DOUBLE(double(node.attribute(STR("attr4")).as_float()), -5.1);
157
+ CHECK_DOUBLE(double(node.attribute(STR("attr5")).as_float()), 3e-4);
158
+ CHECK_DOUBLE(double(node.attribute(STR("attr6")).as_float()), 3.14159265358979323846);
159
+ }
160
+
161
+ TEST_XML(dom_attr_as_double, "<node attr1='0' attr2='1' attr3='0.12' attr4='-5.1' attr5='3e-4' attr6='3.14159265358979323846'/>")
162
+ {
163
+ xml_node node = doc.child(STR("node"));
164
+
165
+ CHECK(xml_attribute().as_double() == 0);
166
+ CHECK_DOUBLE(node.attribute(STR("attr1")).as_double(), 0);
167
+ CHECK_DOUBLE(node.attribute(STR("attr2")).as_double(), 1);
168
+ CHECK_DOUBLE(node.attribute(STR("attr3")).as_double(), 0.12);
169
+ CHECK_DOUBLE(node.attribute(STR("attr4")).as_double(), -5.1);
170
+ CHECK_DOUBLE(node.attribute(STR("attr5")).as_double(), 3e-4);
171
+ CHECK_DOUBLE(node.attribute(STR("attr6")).as_double(), 3.14159265358979323846);
172
+ }
173
+
174
+ TEST_XML(dom_attr_as_bool, "<node attr1='0' attr2='1' attr3='true' attr4='True' attr5='Yes' attr6='yes' attr7='false'/>")
175
+ {
176
+ xml_node node = doc.child(STR("node"));
177
+
178
+ CHECK(!xml_attribute().as_bool());
179
+ CHECK(!node.attribute(STR("attr1")).as_bool());
180
+ CHECK(node.attribute(STR("attr2")).as_bool());
181
+ CHECK(node.attribute(STR("attr3")).as_bool());
182
+ CHECK(node.attribute(STR("attr4")).as_bool());
183
+ CHECK(node.attribute(STR("attr5")).as_bool());
184
+ CHECK(node.attribute(STR("attr6")).as_bool());
185
+ CHECK(!node.attribute(STR("attr7")).as_bool());
186
+
187
+ xml_attribute attr = node.append_attribute(STR("attr8"));
188
+ CHECK(attr.as_bool(true) == true);
189
+ }
190
+
191
+ #ifdef PUGIXML_HAS_LONG_LONG
192
+ TEST_XML(dom_attr_as_llong, "<node attr1='1' attr2='-1' attr3='-9223372036854775808' attr4='9223372036854775807' attr5='0'/>")
193
+ {
194
+ xml_node node = doc.child(STR("node"));
195
+
196
+ CHECK(xml_attribute().as_llong() == 0);
197
+ CHECK(node.attribute(STR("attr1")).as_llong() == 1);
198
+ CHECK(node.attribute(STR("attr2")).as_llong() == -1);
199
+ CHECK(node.attribute(STR("attr3")).as_llong() == -9223372036854775807ll - 1);
200
+ CHECK(node.attribute(STR("attr4")).as_llong() == 9223372036854775807ll);
201
+ CHECK(node.attribute(STR("attr5")).as_llong() == 0);
202
+ }
203
+
204
+ TEST_XML(dom_attr_as_llong_hex, "<node attr1='0777' attr2='0x5ab' attr3='0XFf' attr4='-0x20' attr5='-0x8000000000000000' attr6='0x'/>")
205
+ {
206
+ xml_node node = doc.child(STR("node"));
207
+
208
+ CHECK(node.attribute(STR("attr1")).as_llong() == 777); // no octal support! intentional
209
+ CHECK(node.attribute(STR("attr2")).as_llong() == 1451);
210
+ CHECK(node.attribute(STR("attr3")).as_llong() == 255);
211
+ CHECK(node.attribute(STR("attr4")).as_llong() == -32);
212
+ CHECK(node.attribute(STR("attr5")).as_llong() == -9223372036854775807ll - 1);
213
+ CHECK(node.attribute(STR("attr6")).as_llong() == 0);
214
+ }
215
+
216
+ TEST_XML(dom_attr_as_ullong, "<node attr1='0' attr2='1' attr3='9223372036854775807' attr4='18446744073709551615' attr5='0'/>")
217
+ {
218
+ xml_node node = doc.child(STR("node"));
219
+
220
+ CHECK(xml_attribute().as_ullong() == 0);
221
+ CHECK(node.attribute(STR("attr1")).as_ullong() == 0);
222
+ CHECK(node.attribute(STR("attr2")).as_ullong() == 1);
223
+ CHECK(node.attribute(STR("attr3")).as_ullong() == 9223372036854775807ull);
224
+ CHECK(node.attribute(STR("attr4")).as_ullong() == 18446744073709551615ull);
225
+ CHECK(node.attribute(STR("attr5")).as_ullong() == 0);
226
+ }
227
+
228
+ TEST_XML(dom_attr_as_ullong_hex, "<node attr1='0777' attr2='0x5ab' attr3='0XFf' attr4='0x20' attr5='0xFFFFFFFFFFFFFFFF' attr6='0x'/>")
229
+ {
230
+ xml_node node = doc.child(STR("node"));
231
+
232
+ CHECK(node.attribute(STR("attr1")).as_ullong() == 777); // no octal support! intentional
233
+ CHECK(node.attribute(STR("attr2")).as_ullong() == 1451);
234
+ CHECK(node.attribute(STR("attr3")).as_ullong() == 255);
235
+ CHECK(node.attribute(STR("attr4")).as_ullong() == 32);
236
+ CHECK(node.attribute(STR("attr5")).as_ullong() == 18446744073709551615ull);
237
+ CHECK(node.attribute(STR("attr6")).as_ullong() == 0);
238
+ }
239
+ #endif
240
+
241
+ TEST(dom_attr_defaults)
242
+ {
243
+ xml_attribute attr;
244
+
245
+ CHECK_STRING(attr.as_string(STR("foo")), STR("foo"));
246
+ CHECK(attr.as_int(42) == 42);
247
+ CHECK(attr.as_uint(42) == 42);
248
+ CHECK(attr.as_double(42) == 42);
249
+ CHECK(attr.as_float(42) == 42);
250
+ CHECK(attr.as_bool(true) == true);
251
+
252
+ #ifdef PUGIXML_HAS_LONG_LONG
253
+ CHECK(attr.as_llong(42) == 42);
254
+ CHECK(attr.as_ullong(42) == 42);
255
+ #endif
256
+ }
257
+
258
+ TEST_XML(dom_attr_iterator, "<node><node1 attr1='0'/><node2 attr1='0' attr2='1'/><node3/></node>")
259
+ {
260
+ xml_node node1 = doc.child(STR("node")).child(STR("node1"));
261
+ xml_node node2 = doc.child(STR("node")).child(STR("node2"));
262
+ xml_node node3 = doc.child(STR("node")).child(STR("node3"));
263
+
264
+ CHECK(xml_node().attributes_begin() == xml_attribute_iterator());
265
+ CHECK(xml_node().attributes_end() == xml_attribute_iterator());
266
+
267
+ CHECK(node1.attributes_begin() == xml_attribute_iterator(node1.attribute(STR("attr1")), node1));
268
+ CHECK(move_iter(node1.attributes_begin(), 1) == node1.attributes_end());
269
+ CHECK(move_iter(node1.attributes_end(), -1) == node1.attributes_begin());
270
+ CHECK(*node1.attributes_begin() == node1.attribute(STR("attr1")));
271
+ CHECK_STRING(node1.attributes_begin()->name(), STR("attr1"));
272
+
273
+ CHECK(move_iter(node2.attributes_begin(), 2) == node2.attributes_end());
274
+ CHECK(move_iter(node2.attributes_end(), -2) == node2.attributes_begin());
275
+
276
+ CHECK(node3.attributes_begin() != xml_attribute_iterator());
277
+ CHECK(node3.attributes_begin() == node3.attributes_end());
278
+
279
+ xml_attribute_iterator it = xml_attribute_iterator(node2.attribute(STR("attr2")), node2);
280
+ xml_attribute_iterator itt = it;
281
+
282
+ CHECK(itt++ == it);
283
+ CHECK(itt == node2.attributes_end());
284
+
285
+ CHECK(itt-- == node2.attributes_end());
286
+ CHECK(itt == it);
287
+
288
+ CHECK(++itt == node2.attributes_end());
289
+ CHECK(itt == node2.attributes_end());
290
+
291
+ CHECK(--itt == it);
292
+ CHECK(itt == it);
293
+
294
+ CHECK(++itt != it);
295
+ }
296
+
297
+ TEST_XML(dom_attr_iterator_end, "<node><node1 attr1='0'/><node2 attr1='0' attr2='1'/><node3/></node>")
298
+ {
299
+ xml_node node1 = doc.child(STR("node")).child(STR("node1"));
300
+ xml_node node2 = doc.child(STR("node")).child(STR("node2"));
301
+ xml_node node3 = doc.child(STR("node")).child(STR("node3"));
302
+
303
+ CHECK(node1.attributes_end() != node2.attributes_end() && node1.attributes_end() != node3.attributes_end() && node2.attributes_end() != node3.attributes_end());
304
+ CHECK(node1.attributes_end() != xml_attribute_iterator() && node2.attributes_end() != xml_attribute_iterator() && node3.attributes_end() != xml_attribute_iterator());
305
+ }
306
+
307
+ TEST_XML(dom_attr_iterator_invalidate, "<node><node1 attr1='0'/><node2 attr1='0' attr2='1'/><node3/></node>")
308
+ {
309
+ xml_node node2 = doc.child(STR("node")).child(STR("node2"));
310
+
311
+ xml_attribute_iterator it1 = node2.attributes_begin();
312
+ xml_attribute_iterator it2 = move_iter(it1, 1);
313
+ xml_attribute_iterator it3 = move_iter(it2, 1);
314
+
315
+ CHECK(it3 == node2.attributes_end());
316
+
317
+ // removing attr2, it2 is invalid now, it3 is still past-the-end
318
+ node2.remove_attribute(*it2);
319
+
320
+ CHECK(node2.attributes_end() == it3);
321
+ CHECK(move_iter(it1, 1) == it3);
322
+ CHECK(move_iter(it3, -1) == it1);
323
+ CHECK_STRING(it1->name(), STR("attr1"));
324
+
325
+ // adding attr2 back, it3 is still past-the-end!
326
+ xml_attribute_iterator it2new = xml_attribute_iterator(node2.append_attribute(STR("attr2-new")), node2);
327
+
328
+ CHECK(node2.attributes_end() == it3);
329
+ CHECK(move_iter(it1, 1) == it2new);
330
+ CHECK(move_iter(it2new, 1) == it3);
331
+ CHECK(move_iter(it3, -1) == it2new);
332
+ CHECK_STRING(it2new->name(), STR("attr2-new"));
333
+
334
+ // removing both attributes, it3 is now equal to the begin
335
+ node2.remove_attribute(*it1);
336
+ node2.remove_attribute(*it2new);
337
+ CHECK(!node2.first_attribute());
338
+
339
+ CHECK(node2.attributes_begin() == it3);
340
+ CHECK(node2.attributes_end() == it3);
341
+ }
342
+
343
+ TEST_XML(dom_attr_iterator_const, "<node attr1='0' attr2='1'/>")
344
+ {
345
+ xml_node node = doc.child(STR("node"));
346
+
347
+ const xml_attribute_iterator i1 = node.attributes_begin();
348
+ const xml_attribute_iterator i2 = ++xml_attribute_iterator(i1);
349
+ const xml_attribute_iterator i3 = ++xml_attribute_iterator(i2);
350
+
351
+ CHECK(*i1 == node.attribute(STR("attr1")));
352
+ CHECK(*i2 == node.attribute(STR("attr2")));
353
+ CHECK(i3 == node.attributes_end());
354
+
355
+ CHECK_STRING(i1->name(), STR("attr1"));
356
+ CHECK_STRING(i2->name(), STR("attr2"));
357
+ }
358
+
359
+ TEST_XML(dom_node_bool_ops, "<node/>")
360
+ {
361
+ generic_bool_ops_test(doc.child(STR("node")));
362
+ }
363
+
364
+ TEST_XML(dom_node_eq_ops, "<node><node1/><node2/></node>")
365
+ {
366
+ generic_eq_ops_test(doc.child(STR("node")).child(STR("node1")), doc.child(STR("node")).child(STR("node2")));
367
+ }
368
+
369
+ TEST_XML(dom_node_rel_ops, "<node><node1/><node2/></node>")
370
+ {
371
+ generic_rel_ops_test(doc.child(STR("node")).child(STR("node1")), doc.child(STR("node")).child(STR("node2")));
372
+ }
373
+
374
+ TEST_XML(dom_node_empty, "<node/>")
375
+ {
376
+ generic_empty_test(doc.child(STR("node")));
377
+ }
378
+
379
+ TEST_XML(dom_node_iterator, "<node><node1><child1/></node1><node2><child1/><child2/></node2><node3/></node>")
380
+ {
381
+ xml_node node1 = doc.child(STR("node")).child(STR("node1"));
382
+ xml_node node2 = doc.child(STR("node")).child(STR("node2"));
383
+ xml_node node3 = doc.child(STR("node")).child(STR("node3"));
384
+
385
+ CHECK(xml_node().begin() == xml_node_iterator());
386
+ CHECK(xml_node().end() == xml_node_iterator());
387
+
388
+ CHECK(node1.begin() == xml_node_iterator(node1.child(STR("child1"))));
389
+ CHECK(move_iter(node1.begin(), 1) == node1.end());
390
+ CHECK(move_iter(node1.end(), -1) == node1.begin());
391
+ CHECK(*node1.begin() == node1.child(STR("child1")));
392
+ CHECK_STRING(node1.begin()->name(), STR("child1"));
393
+
394
+ CHECK(move_iter(node2.begin(), 2) == node2.end());
395
+ CHECK(move_iter(node2.end(), -2) == node2.begin());
396
+
397
+ CHECK(node3.begin() != xml_node_iterator());
398
+ CHECK(node3.begin() == node3.end());
399
+
400
+ xml_node_iterator it = node2.child(STR("child2"));
401
+ xml_node_iterator itt = it;
402
+
403
+ CHECK(itt++ == it);
404
+ CHECK(itt == node2.end());
405
+
406
+ CHECK(itt-- == node2.end());
407
+ CHECK(itt == it);
408
+
409
+ CHECK(++itt == node2.end());
410
+ CHECK(itt == node2.end());
411
+
412
+ CHECK(--itt == it);
413
+ CHECK(itt == it);
414
+
415
+ CHECK(++itt != it);
416
+ }
417
+
418
+ TEST_XML(dom_node_iterator_end, "<node><node1><child1/></node1><node2><child1/><child2/></node2><node3/></node>")
419
+ {
420
+ xml_node node1 = doc.child(STR("node")).child(STR("node1"));
421
+ xml_node node2 = doc.child(STR("node")).child(STR("node2"));
422
+ xml_node node3 = doc.child(STR("node")).child(STR("node3"));
423
+
424
+ CHECK(node1.end() != node2.end() && node1.end() != node3.end() && node2.end() != node3.end());
425
+ CHECK(node1.end() != xml_node_iterator() && node2.end() != xml_node_iterator() && node3.end() != xml_node_iterator());
426
+ }
427
+
428
+ TEST_XML(dom_node_iterator_invalidate, "<node><node1><child1/></node1><node2><child1/><child2/></node2><node3/></node>")
429
+ {
430
+ xml_node node2 = doc.child(STR("node")).child(STR("node2"));
431
+
432
+ xml_node_iterator it1 = node2.begin();
433
+ xml_node_iterator it2 = move_iter(it1, 1);
434
+ xml_node_iterator it3 = move_iter(it2, 1);
435
+
436
+ CHECK(it3 == node2.end());
437
+
438
+ // removing child2, it2 is invalid now, it3 is still past-the-end
439
+ node2.remove_child(*it2);
440
+
441
+ CHECK(node2.end() == it3);
442
+ CHECK(move_iter(it1, 1) == it3);
443
+ CHECK(move_iter(it3, -1) == it1);
444
+ CHECK_STRING(it1->name(), STR("child1"));
445
+
446
+ // adding attr2 back, it3 is still past-the-end!
447
+ xml_node_iterator it2new = node2.append_child();
448
+ it2new->set_name(STR("child2-new"));
449
+
450
+ CHECK(node2.end() == it3);
451
+ CHECK(move_iter(it1, 1) == it2new);
452
+ CHECK(move_iter(it2new, 1) == it3);
453
+ CHECK(move_iter(it3, -1) == it2new);
454
+ CHECK_STRING(it2new->name(), STR("child2-new"));
455
+
456
+ // removing both nodes, it3 is now equal to the begin
457
+ node2.remove_child(*it1);
458
+ node2.remove_child(*it2new);
459
+ CHECK(!node2.first_child());
460
+
461
+ CHECK(node2.begin() == it3);
462
+ CHECK(node2.end() == it3);
463
+ }
464
+
465
+ TEST_XML(dom_node_iterator_const, "<node><child1/><child2/></node>")
466
+ {
467
+ xml_node node = doc.child(STR("node"));
468
+
469
+ const xml_node_iterator i1 = node.begin();
470
+ const xml_node_iterator i2 = ++xml_node_iterator(i1);
471
+ const xml_node_iterator i3 = ++xml_node_iterator(i2);
472
+
473
+ CHECK(*i1 == node.child(STR("child1")));
474
+ CHECK(*i2 == node.child(STR("child2")));
475
+ CHECK(i3 == node.end());
476
+
477
+ CHECK_STRING(i1->name(), STR("child1"));
478
+ CHECK_STRING(i2->name(), STR("child2"));
479
+ }
480
+
481
+ TEST_XML(dom_node_parent, "<node><child/></node>")
482
+ {
483
+ CHECK(xml_node().parent() == xml_node());
484
+ CHECK(doc.child(STR("node")).child(STR("child")).parent() == doc.child(STR("node")));
485
+ CHECK(doc.child(STR("node")).parent() == doc);
486
+ }
487
+
488
+ TEST_XML(dom_node_root, "<node><child/></node>")
489
+ {
490
+ CHECK(xml_node().root() == xml_node());
491
+ CHECK(doc.child(STR("node")).child(STR("child")).root() == doc);
492
+ CHECK(doc.child(STR("node")).root() == doc);
493
+ }
494
+
495
+ TEST_XML_FLAGS(dom_node_type, "<?xml?><!DOCTYPE><?pi?><!--comment--><node>pcdata<![CDATA[cdata]]></node>", parse_default | parse_pi | parse_comments | parse_declaration | parse_doctype)
496
+ {
497
+ CHECK(xml_node().type() == node_null);
498
+ CHECK(doc.type() == node_document);
499
+
500
+ xml_node_iterator it = doc.begin();
501
+
502
+ CHECK((it++)->type() == node_declaration);
503
+ CHECK((it++)->type() == node_doctype);
504
+ CHECK((it++)->type() == node_pi);
505
+ CHECK((it++)->type() == node_comment);
506
+ CHECK((it++)->type() == node_element);
507
+
508
+ xml_node_iterator cit = doc.child(STR("node")).begin();
509
+
510
+ CHECK((cit++)->type() == node_pcdata);
511
+ CHECK((cit++)->type() == node_cdata);
512
+ }
513
+
514
+ TEST_XML_FLAGS(dom_node_name_value, "<?xml?><!DOCTYPE id><?pi?><!--comment--><node>pcdata<![CDATA[cdata]]></node>", parse_default | parse_pi | parse_comments | parse_declaration | parse_doctype)
515
+ {
516
+ CHECK_NAME_VALUE(xml_node(), STR(""), STR(""));
517
+ CHECK_NAME_VALUE(doc, STR(""), STR(""));
518
+
519
+ xml_node_iterator it = doc.begin();
520
+
521
+ CHECK_NAME_VALUE(*it++, STR("xml"), STR(""));
522
+ CHECK_NAME_VALUE(*it++, STR(""), STR("id"));
523
+ CHECK_NAME_VALUE(*it++, STR("pi"), STR(""));
524
+ CHECK_NAME_VALUE(*it++, STR(""), STR("comment"));
525
+ CHECK_NAME_VALUE(*it++, STR("node"), STR(""));
526
+
527
+ xml_node_iterator cit = doc.child(STR("node")).begin();
528
+
529
+ CHECK_NAME_VALUE(*cit++, STR(""), STR("pcdata"));
530
+ CHECK_NAME_VALUE(*cit++, STR(""), STR("cdata"));
531
+ }
532
+
533
+ TEST_XML(dom_node_child, "<node><child1/><child2/></node>")
534
+ {
535
+ CHECK(xml_node().child(STR("n")) == xml_node());
536
+
537
+ CHECK(doc.child(STR("n")) == xml_node());
538
+ CHECK_NAME_VALUE(doc.child(STR("node")), STR("node"), STR(""));
539
+ CHECK(doc.child(STR("node")).child(STR("child2")) == doc.child(STR("node")).last_child());
540
+ }
541
+
542
+ #ifdef PUGIXML_HAS_STRING_VIEW
543
+ TEST_XML(dom_node_child_stringview, "<node><child1/><child2/></node>")
544
+ {
545
+ CHECK(xml_node().child(string_view_t(STR("n"))) == xml_node());
546
+ CHECK(doc.child(string_view_t()) == xml_node());
547
+ CHECK(doc.child(string_view_t(STR("n"))) == xml_node());
548
+
549
+ xml_node node = doc.child(string_view_t(STR("node")));
550
+ CHECK_NAME_VALUE(node, STR("node"), STR(""));
551
+ CHECK(node.child(string_view_t(STR("child2"))) == node.last_child());
552
+
553
+ // verify only the characters in the view of the string view are included in the comparison
554
+ CHECK_NAME_VALUE(doc.child(string_view_t(STR("node_andextratext"), 4)), STR("node"), STR(""));
555
+ CHECK(doc.child(string_view_t(STR("node"), 2)) == xml_node());
556
+ }
557
+
558
+ TEST_XML(dom_node_child_interior_null, "<node><child1/><child2/></node>")
559
+ {
560
+ const char_t name[] = STR("node\0extra");
561
+ size_t len = (sizeof(name) / sizeof(char_t)) - 1;
562
+ CHECK(len == 10);
563
+
564
+ xml_node node = doc.child(string_view_t(name, 4)); // "node" view excluding null
565
+ CHECK_NAME_VALUE(node, STR("node"), STR(""));
566
+ CHECK(doc.child(string_view_t(name, 5)) == xml_node()); // "node\0" view including null
567
+ CHECK(doc.child(string_view_t(name, len)) == xml_node()); // "node\0extra" view
568
+
569
+ node.set_name(string_view_t(name, len));
570
+ CHECK_NODE(doc, STR("<node><child1/><child2/></node>"));
571
+ CHECK_NAME_VALUE(node, STR("node"), STR(""));
572
+ CHECK_NAME_VALUE(doc.child(string_view_t(name, 4)), STR("node"), STR("")); // "node" view excluding null
573
+ CHECK(doc.child(string_view_t(name, 5)) == xml_node()); // "node\0" view including null
574
+ CHECK(doc.child(string_view_t(name, len)) == xml_node()); // "node\0extra" view
575
+ }
576
+ #endif
577
+
578
+ TEST_XML(dom_node_attribute, "<node attr1='0' attr2='1'/>")
579
+ {
580
+ CHECK(xml_node().attribute(STR("a")) == xml_attribute());
581
+
582
+ xml_node node = doc.child(STR("node"));
583
+
584
+ CHECK(node.attribute(STR("n")) == xml_attribute());
585
+ CHECK_NAME_VALUE(node.attribute(STR("attr1")), STR("attr1"), STR("0"));
586
+ CHECK(node.attribute(STR("attr2")) == node.last_attribute());
587
+ }
588
+
589
+ #ifdef PUGIXML_HAS_STRING_VIEW
590
+ TEST_XML(dom_node_attribute_stringview, "<node attr1='0' attr2='1'/>")
591
+ {
592
+ CHECK(xml_node().attribute(string_view_t(STR("a"))) == xml_attribute());
593
+
594
+ xml_node node = doc.child(string_view_t(STR("node")));
595
+
596
+ CHECK(node.attribute(string_view_t()) == xml_attribute());
597
+ CHECK(node.attribute(string_view_t(STR("n"))) == xml_attribute());
598
+ CHECK_NAME_VALUE(node.attribute(string_view_t(STR("attr1"))), STR("attr1"), STR("0"));
599
+ CHECK(node.attribute(string_view_t(STR("attr2"))) == node.last_attribute());
600
+
601
+ // verify only the characters in the view of the string view are included in the comparison
602
+ CHECK_NAME_VALUE(node.attribute(string_view_t(STR("attr1_andextratext"), 5)), STR("attr1"), STR("0"));
603
+ CHECK(node.attribute(string_view_t(STR("attr1"), 2)) == xml_attribute());
604
+ }
605
+
606
+ TEST_XML(dom_node_attribute_interior_null, "<node attr1='0' attr2='1'/>")
607
+ {
608
+ xml_node node = doc.child(STR("node"));
609
+ CHECK_NAME_VALUE(node, STR("node"), STR(""));
610
+
611
+ const char_t name[] = STR("attr2\0extra");
612
+ size_t len = (sizeof(name) / sizeof(char_t)) - 1;
613
+ CHECK(len == 11);
614
+ CHECK_NAME_VALUE(node.attribute(string_view_t(name, 5)), STR("attr2"), STR("1")); // "attr2" view excluding null
615
+ CHECK(node.attribute(string_view_t(name, 6)) == xml_attribute()); // "attr2\0" view including null
616
+ CHECK(node.attribute(string_view_t(name, len)) == xml_attribute()); // "attr2\0extra" view
617
+
618
+ xml_attribute attr = node.attribute(STR("attr2"));
619
+ CHECK_NAME_VALUE(attr, STR("attr2"), STR("1"));
620
+ attr.set_name(string_view_t(name, len));
621
+
622
+ CHECK_NODE(doc, STR("<node attr1=\"0\" attr2=\"1\"/>"));
623
+ CHECK_NAME_VALUE(node.attribute(string_view_t(name, 5)), STR("attr2"), STR("1")); // "attr2" view excluding null
624
+ CHECK(node.attribute(string_view_t(name, 6)) == xml_attribute()); // "attr2\0" view including null
625
+ CHECK(node.attribute(string_view_t(name, len)) == xml_attribute()); // "attr2\0extra" view
626
+ }
627
+ #endif
628
+
629
+ TEST_XML(dom_node_next_previous_sibling, "<node><child1/><child2/><child3/></node>")
630
+ {
631
+ CHECK(xml_node().next_sibling() == xml_node());
632
+ CHECK(xml_node().next_sibling(STR("n")) == xml_node());
633
+
634
+ CHECK(xml_node().previous_sibling() == xml_node());
635
+ CHECK(xml_node().previous_sibling(STR("n")) == xml_node());
636
+
637
+ xml_node child1 = doc.child(STR("node")).child(STR("child1"));
638
+ xml_node child2 = doc.child(STR("node")).child(STR("child2"));
639
+ xml_node child3 = doc.child(STR("node")).child(STR("child3"));
640
+
641
+ CHECK(child1.next_sibling() == child2);
642
+ CHECK(child3.next_sibling() == xml_node());
643
+
644
+ CHECK(child1.previous_sibling() == xml_node());
645
+ CHECK(child3.previous_sibling() == child2);
646
+
647
+ CHECK(child1.next_sibling(STR("child3")) == child3);
648
+ CHECK(child1.next_sibling(STR("child")) == xml_node());
649
+ #ifdef PUGIXML_HAS_STRING_VIEW
650
+ CHECK(child1.next_sibling(string_view_t(STR("child3"))) == child3);
651
+ CHECK(child1.next_sibling(string_view_t(STR("child"))) == xml_node());
652
+ #endif
653
+
654
+ CHECK(child3.previous_sibling(STR("child1")) == child1);
655
+ CHECK(child3.previous_sibling(STR("child")) == xml_node());
656
+ #ifdef PUGIXML_HAS_STRING_VIEW
657
+ CHECK(child3.previous_sibling(string_view_t(STR("child1"))) == child1);
658
+ CHECK(child3.previous_sibling(string_view_t(STR("child"))) == xml_node());
659
+ #endif
660
+ }
661
+
662
+ TEST_XML(dom_node_child_value, "<node><novalue/><child1>value1</child1><child2>value2<n/></child2><child3><![CDATA[value3]]></child3>value4</node>")
663
+ {
664
+ CHECK_STRING(xml_node().child_value(), STR(""));
665
+ CHECK_STRING(xml_node().child_value(STR("n")), STR(""));
666
+
667
+ xml_node node = doc.child(STR("node"));
668
+
669
+ CHECK_STRING(node.child_value(), STR("value4"));
670
+ CHECK_STRING(node.child(STR("child1")).child_value(), STR("value1"));
671
+ CHECK_STRING(node.child(STR("child2")).child_value(), STR("value2"));
672
+ CHECK_STRING(node.child(STR("child3")).child_value(), STR("value3"));
673
+ CHECK_STRING(node.child_value(STR("child3")), STR("value3"));
674
+ CHECK_STRING(node.child_value(STR("novalue")), STR(""));
675
+ }
676
+
677
+ TEST_XML(dom_node_first_last_attribute, "<node attr1='0' attr2='1'/>")
678
+ {
679
+ xml_node node = doc.child(STR("node"));
680
+
681
+ CHECK(node.first_attribute() == node.attribute(STR("attr1")));
682
+ CHECK(node.last_attribute() == node.attribute(STR("attr2")));
683
+
684
+ CHECK(xml_node().first_attribute() == xml_attribute());
685
+ CHECK(xml_node().last_attribute() == xml_attribute());
686
+
687
+ CHECK(doc.first_attribute() == xml_attribute());
688
+ CHECK(doc.last_attribute() == xml_attribute());
689
+ }
690
+
691
+ TEST_XML(dom_node_first_last_child, "<node><child1/><child2/></node>")
692
+ {
693
+ xml_node node = doc.child(STR("node"));
694
+
695
+ CHECK(node.first_child() == node.child(STR("child1")));
696
+ CHECK(node.last_child() == node.child(STR("child2")));
697
+
698
+ CHECK(xml_node().first_child() == xml_node());
699
+ CHECK(xml_node().last_child() == xml_node());
700
+
701
+ CHECK(doc.first_child() == node);
702
+ CHECK(doc.last_child() == node);
703
+ }
704
+
705
+ TEST_XML(dom_node_find_child_by_attribute, "<node><stub attr='value3' /><child1 attr='value1'/><child2 attr='value2'/><child2 attr='value3'/></node>")
706
+ {
707
+ CHECK(xml_node().find_child_by_attribute(STR("name"), STR("attr"), STR("value")) == xml_node());
708
+ CHECK(xml_node().find_child_by_attribute(STR("attr"), STR("value")) == xml_node());
709
+
710
+ xml_node node = doc.child(STR("node"));
711
+
712
+ CHECK(node.find_child_by_attribute(STR("child2"), STR("attr"), STR("value3")) == node.last_child());
713
+ CHECK(node.find_child_by_attribute(STR("child2"), STR("attr3"), STR("value3")) == xml_node());
714
+ CHECK(node.find_child_by_attribute(STR("attr"), STR("value2")) == node.child(STR("child2")));
715
+ CHECK(node.find_child_by_attribute(STR("attr3"), STR("value")) == xml_node());
716
+ }
717
+
718
+ TEST(dom_node_find_child_by_attribute_null)
719
+ {
720
+ xml_document doc;
721
+ xml_node node0 = doc.append_child();
722
+ xml_node node1 = doc.append_child(STR("a"));
723
+ xml_node node2 = doc.append_child(STR("a"));
724
+ xml_node node3 = doc.append_child(STR("a"));
725
+
726
+ (void)node0;
727
+
728
+ // this adds an attribute with null name and/or value in the internal representation
729
+ node1.append_attribute(STR(""));
730
+ node2.append_attribute(STR("id"));
731
+ node3.append_attribute(STR("id")) = STR("1");
732
+
733
+ // make sure find_child_by_attribute works if name/value is null
734
+ CHECK(doc.find_child_by_attribute(STR("unknown"), STR("wrong")) == xml_node());
735
+ CHECK(doc.find_child_by_attribute(STR("id"), STR("wrong")) == xml_node());
736
+ CHECK(doc.find_child_by_attribute(STR("id"), STR("")) == node2);
737
+ CHECK(doc.find_child_by_attribute(STR("id"), STR("1")) == node3);
738
+
739
+ CHECK(doc.find_child_by_attribute(STR("a"), STR("unknown"), STR("wrong")) == xml_node());
740
+ CHECK(doc.find_child_by_attribute(STR("a"), STR("id"), STR("wrong")) == xml_node());
741
+ CHECK(doc.find_child_by_attribute(STR("a"), STR("id"), STR("")) == node2);
742
+ CHECK(doc.find_child_by_attribute(STR("a"), STR("id"), STR("1")) == node3);
743
+ }
744
+
745
+ struct find_predicate_const
746
+ {
747
+ bool result;
748
+
749
+ find_predicate_const(bool result_): result(result_)
750
+ {
751
+ }
752
+
753
+ template <typename T> bool operator()(const T&) const
754
+ {
755
+ return result;
756
+ }
757
+ };
758
+
759
+ struct find_predicate_prefix
760
+ {
761
+ const char_t* prefix;
762
+
763
+ find_predicate_prefix(const char_t* prefix_): prefix(prefix_)
764
+ {
765
+ }
766
+
767
+ template <typename T> bool operator()(const T& obj) const
768
+ {
769
+ #ifdef PUGIXML_WCHAR_MODE
770
+ // can't use wcsncmp here because of a bug in DMC
771
+ return std::basic_string<char_t>(obj.name()).compare(0, wcslen(prefix), prefix) == 0;
772
+ #else
773
+ return strncmp(obj.name(), prefix, strlen(prefix)) == 0;
774
+ #endif
775
+ }
776
+ };
777
+
778
+ TEST_XML(dom_node_find_attribute, "<node attr1='0' attr2='1'/>")
779
+ {
780
+ CHECK(xml_node().find_attribute(find_predicate_const(true)) == xml_attribute());
781
+
782
+ xml_node node = doc.child(STR("node"));
783
+
784
+ CHECK(doc.find_attribute(find_predicate_const(true)) == xml_attribute());
785
+ CHECK(node.find_attribute(find_predicate_const(true)) == node.first_attribute());
786
+ CHECK(node.find_attribute(find_predicate_const(false)) == xml_attribute());
787
+ CHECK(node.find_attribute(find_predicate_prefix(STR("attr2"))) == node.last_attribute());
788
+ CHECK(node.find_attribute(find_predicate_prefix(STR("attr"))) == node.first_attribute());
789
+ }
790
+
791
+ TEST_XML(dom_node_find_child, "<node><child1/><child2/></node>")
792
+ {
793
+ CHECK(xml_node().find_child(find_predicate_const(true)) == xml_node());
794
+
795
+ xml_node node = doc.child(STR("node"));
796
+
797
+ CHECK(node.child(STR("node")).child(STR("child1")).find_child(find_predicate_const(true)) == xml_node());
798
+ CHECK(node.find_child(find_predicate_const(true)) == node.first_child());
799
+ CHECK(node.find_child(find_predicate_const(false)) == xml_node());
800
+ CHECK(node.find_child(find_predicate_prefix(STR("child2"))) == node.last_child());
801
+ CHECK(node.find_child(find_predicate_prefix(STR("child"))) == node.first_child());
802
+ }
803
+
804
+ TEST_XML(dom_node_find_node, "<node><child1/><child2/></node>")
805
+ {
806
+ CHECK(xml_node().find_node(find_predicate_const(true)) == xml_node());
807
+
808
+ xml_node node = doc.child(STR("node"));
809
+
810
+ CHECK(node.child(STR("node")).child(STR("child1")).find_node(find_predicate_const(true)) == xml_node());
811
+ CHECK(node.find_node(find_predicate_const(true)) == node.first_child());
812
+ CHECK(node.find_node(find_predicate_const(false)) == xml_node());
813
+ CHECK(node.find_node(find_predicate_prefix(STR("child2"))) == node.last_child());
814
+ CHECK(node.find_node(find_predicate_prefix(STR("child"))) == node.first_child());
815
+ CHECK(doc.find_node(find_predicate_prefix(STR("child"))) == node.first_child());
816
+ CHECK(doc.find_node(find_predicate_prefix(STR("child2"))) == node.last_child());
817
+ CHECK(doc.find_node(find_predicate_prefix(STR("child3"))) == xml_node());
818
+ }
819
+
820
+ #ifndef PUGIXML_NO_STL
821
+ TEST_XML(dom_node_path, "<node><child1>text<child2/></child1></node>")
822
+ {
823
+ CHECK(xml_node().path() == STR(""));
824
+
825
+ CHECK(doc.path() == STR(""));
826
+ CHECK(doc.child(STR("node")).path() == STR("/node"));
827
+ CHECK(doc.child(STR("node")).child(STR("child1")).path() == STR("/node/child1"));
828
+ CHECK(doc.child(STR("node")).child(STR("child1")).child(STR("child2")).path() == STR("/node/child1/child2"));
829
+ CHECK(doc.child(STR("node")).child(STR("child1")).first_child().path() == STR("/node/child1/"));
830
+
831
+ CHECK(doc.child(STR("node")).child(STR("child1")).path('\\') == STR("\\node\\child1"));
832
+
833
+ doc.append_child(node_element);
834
+ CHECK(doc.last_child().path() == STR("/"));
835
+ }
836
+ #endif
837
+
838
+ TEST_XML(dom_node_first_element_by_path, "<node><child1>text<child2/></child1></node>")
839
+ {
840
+ CHECK(xml_node().first_element_by_path(STR("/")) == xml_node());
841
+ CHECK(xml_node().first_element_by_path(STR("a")) == xml_node());
842
+
843
+ CHECK(doc.first_element_by_path(STR("")) == doc);
844
+ CHECK(doc.first_element_by_path(STR("/")) == doc);
845
+
846
+ CHECK(doc.first_element_by_path(STR("/node/")) == doc.child(STR("node")));
847
+ CHECK(doc.first_element_by_path(STR("node/")) == doc.child(STR("node")));
848
+ CHECK(doc.first_element_by_path(STR("node")) == doc.child(STR("node")));
849
+ CHECK(doc.first_element_by_path(STR("/node")) == doc.child(STR("node")));
850
+
851
+ #ifndef PUGIXML_NO_STL
852
+ CHECK(doc.first_element_by_path(STR("/node/child1/child2")).path() == STR("/node/child1/child2"));
853
+ #endif
854
+
855
+ CHECK(doc.first_element_by_path(STR("/node/child2")) == xml_node());
856
+
857
+ CHECK(doc.first_element_by_path(STR("\\node\\child1"), '\\') == doc.child(STR("node")).child(STR("child1")));
858
+
859
+ CHECK(doc.child(STR("node")).first_element_by_path(STR("..")) == doc);
860
+ CHECK(doc.child(STR("node")).first_element_by_path(STR(".")) == doc.child(STR("node")));
861
+
862
+ CHECK(doc.child(STR("node")).first_element_by_path(STR("../node/./child1/../.")) == doc.child(STR("node")));
863
+
864
+ CHECK(doc.child(STR("node")).first_element_by_path(STR("child1")) == doc.child(STR("node")).child(STR("child1")));
865
+ CHECK(doc.child(STR("node")).first_element_by_path(STR("child1/")) == doc.child(STR("node")).child(STR("child1")));
866
+ CHECK(doc.child(STR("node")).first_element_by_path(STR("child")) == xml_node());
867
+ CHECK(doc.child(STR("node")).first_element_by_path(STR("child11")) == xml_node());
868
+
869
+ CHECK(doc.first_element_by_path(STR("//node")) == doc.child(STR("node")));
870
+ }
871
+
872
+ struct test_walker: xml_tree_walker
873
+ {
874
+ std::basic_string<char_t> log;
875
+ unsigned int call_count;
876
+ unsigned int stop_count;
877
+
878
+ test_walker(unsigned int stop_count_ = 0): call_count(0), stop_count(stop_count_)
879
+ {
880
+ }
881
+
882
+ std::basic_string<char_t> depthstr() const
883
+ {
884
+ char buf[32];
885
+
886
+ #if __cplusplus >= 201103 || defined(__APPLE__) // Xcode 14 warns about use of sprintf in C++98 builds
887
+ snprintf(buf, sizeof(buf), "%d", depth());
888
+ #else
889
+ sprintf(buf, "%d", depth());
890
+ #endif
891
+
892
+ #ifdef PUGIXML_WCHAR_MODE
893
+ wchar_t wbuf[32];
894
+ std::copy(buf, buf + strlen(buf) + 1, &wbuf[0]);
895
+
896
+ return std::basic_string<char_t>(wbuf);
897
+ #else
898
+ return std::basic_string<char_t>(buf);
899
+ #endif
900
+ }
901
+
902
+ bool begin(xml_node& node) PUGIXML_OVERRIDE
903
+ {
904
+ log += STR("|");
905
+ log += depthstr();
906
+ log += STR(" <");
907
+ log += node.name();
908
+ log += STR("=");
909
+ log += node.value();
910
+
911
+ return ++call_count != stop_count && xml_tree_walker::begin(node);
912
+ }
913
+
914
+ bool for_each(xml_node& node) PUGIXML_OVERRIDE
915
+ {
916
+ log += STR("|");
917
+ log += depthstr();
918
+ log += STR(" !");
919
+ log += node.name();
920
+ log += STR("=");
921
+ log += node.value();
922
+
923
+ return ++call_count != stop_count && xml_tree_walker::end(node);
924
+ }
925
+
926
+ bool end(xml_node& node) PUGIXML_OVERRIDE
927
+ {
928
+ log += STR("|");
929
+ log += depthstr();
930
+ log += STR(" >");
931
+ log += node.name();
932
+ log += STR("=");
933
+ log += node.value();
934
+
935
+ return ++call_count != stop_count;
936
+ }
937
+ };
938
+
939
+ TEST_XML(dom_node_traverse, "<node><child>text</child></node>")
940
+ {
941
+ test_walker walker;
942
+
943
+ CHECK(doc.traverse(walker));
944
+
945
+ CHECK(walker.call_count == 5);
946
+ CHECK(walker.log == STR("|-1 <=|0 !node=|1 !child=|2 !=text|-1 >="));
947
+ }
948
+
949
+ TEST_XML(dom_node_traverse_siblings, "<node><child/><child>text</child><child/></node>")
950
+ {
951
+ test_walker walker;
952
+
953
+ CHECK(doc.traverse(walker));
954
+
955
+ CHECK(walker.call_count == 7);
956
+ CHECK(walker.log == STR("|-1 <=|0 !node=|1 !child=|1 !child=|2 !=text|1 !child=|-1 >="));
957
+ }
958
+
959
+ TEST(dom_node_traverse_empty)
960
+ {
961
+ test_walker walker;
962
+
963
+ CHECK(xml_node().traverse(walker));
964
+
965
+ CHECK(walker.call_count == 2);
966
+ CHECK(walker.log == STR("|-1 <=|-1 >="));
967
+ }
968
+
969
+ TEST_XML(dom_node_traverse_child, "<node><child>text</child></node><another>node</another>")
970
+ {
971
+ test_walker walker;
972
+
973
+ CHECK(doc.child(STR("node")).traverse(walker));
974
+
975
+ CHECK(walker.call_count == 4);
976
+ CHECK(walker.log == STR("|-1 <node=|0 !child=|1 !=text|-1 >node="));
977
+ }
978
+
979
+ TEST_XML(dom_node_traverse_stop_begin, "<node><child>text</child></node>")
980
+ {
981
+ test_walker walker(1);
982
+
983
+ CHECK(!doc.traverse(walker));
984
+
985
+ CHECK(walker.call_count == 1);
986
+ CHECK(walker.log == STR("|-1 <="));
987
+ }
988
+
989
+ TEST_XML(dom_node_traverse_stop_for_each, "<node><child>text</child></node>")
990
+ {
991
+ test_walker walker(3);
992
+
993
+ CHECK(!doc.traverse(walker));
994
+
995
+ CHECK(walker.call_count == 3);
996
+ CHECK(walker.log == STR("|-1 <=|0 !node=|1 !child="));
997
+ }
998
+
999
+ TEST_XML(dom_node_traverse_stop_end, "<node><child>text</child></node>")
1000
+ {
1001
+ test_walker walker(5);
1002
+
1003
+ CHECK(!doc.traverse(walker));
1004
+
1005
+ CHECK(walker.call_count == 5);
1006
+ CHECK(walker.log == STR("|-1 <=|0 !node=|1 !child=|2 !=text|-1 >="));
1007
+ }
1008
+
1009
+ TEST_XML_FLAGS(dom_offset_debug, "<?xml?><!DOCTYPE><?pi?><!--comment--><node>pcdata<![CDATA[cdata]]></node>", parse_default | parse_pi | parse_comments | parse_declaration | parse_doctype)
1010
+ {
1011
+ CHECK(xml_node().offset_debug() == -1);
1012
+ CHECK(doc.offset_debug() == 0);
1013
+
1014
+ xml_node_iterator it = doc.begin();
1015
+
1016
+ CHECK((it++)->offset_debug() == 2);
1017
+ CHECK((it++)->offset_debug() == 16);
1018
+ CHECK((it++)->offset_debug() == 19);
1019
+ CHECK((it++)->offset_debug() == 27);
1020
+ CHECK((it++)->offset_debug() == 38);
1021
+
1022
+ xml_node_iterator cit = doc.child(STR("node")).begin();
1023
+
1024
+ CHECK((cit++)->offset_debug() == 43);
1025
+ CHECK((cit++)->offset_debug() == 58);
1026
+ }
1027
+
1028
+ TEST(dom_offset_debug_encoding)
1029
+ {
1030
+ char buf[] = { 0, '<', 0, 'n', 0, '/', 0, '>' };
1031
+
1032
+ xml_document doc;
1033
+ CHECK(doc.load_buffer(buf, sizeof(buf)));
1034
+
1035
+ CHECK(doc.offset_debug() == 0);
1036
+ CHECK(doc.first_child().offset_debug() == 1);
1037
+ }
1038
+
1039
+ TEST_XML(dom_offset_debug_append, "<node/>")
1040
+ {
1041
+ xml_node c1 = doc.first_child();
1042
+ xml_node c2 = doc.append_child(STR("node"));
1043
+ xml_node c3 = doc.append_child(node_pcdata);
1044
+
1045
+ CHECK(doc.offset_debug() == 0);
1046
+ CHECK(c1.offset_debug() == 1);
1047
+ CHECK(c2.offset_debug() == -1);
1048
+ CHECK(c3.offset_debug() == -1);
1049
+
1050
+ c1.set_name(STR("nodenode"));
1051
+ CHECK(c1.offset_debug() == -1);
1052
+ }
1053
+
1054
+ TEST_XML(dom_offset_debug_append_buffer, "<node/>")
1055
+ {
1056
+ CHECK(doc.offset_debug() == 0);
1057
+ CHECK(doc.first_child().offset_debug() == 1);
1058
+
1059
+ CHECK(doc.append_buffer("<node/>", 7));
1060
+ CHECK(doc.offset_debug() == -1);
1061
+ CHECK(doc.first_child().offset_debug() == -1);
1062
+ CHECK(doc.last_child().offset_debug() == -1);
1063
+ }
1064
+
1065
+ TEST_XML(dom_internal_object, "<node attr='value'>value</node>")
1066
+ {
1067
+ xml_node node = doc.child(STR("node"));
1068
+ xml_attribute attr = node.first_attribute();
1069
+ xml_node value = node.first_child();
1070
+
1071
+ CHECK(xml_node().internal_object() == 0);
1072
+ CHECK(xml_attribute().internal_object() == 0);
1073
+
1074
+ CHECK(node.internal_object() != 0);
1075
+ CHECK(value.internal_object() != 0);
1076
+ CHECK(node.internal_object() != value.internal_object());
1077
+
1078
+ CHECK(attr.internal_object() != 0);
1079
+
1080
+ xml_node node_copy = node;
1081
+ CHECK(node_copy.internal_object() == node.internal_object());
1082
+
1083
+ xml_attribute attr_copy = attr;
1084
+ CHECK(attr_copy.internal_object() == attr.internal_object());
1085
+ }
1086
+
1087
+ TEST_XML(dom_hash_value, "<node attr='value'>value</node>")
1088
+ {
1089
+ xml_node node = doc.child(STR("node"));
1090
+ xml_attribute attr = node.first_attribute();
1091
+ xml_node value = node.first_child();
1092
+
1093
+ CHECK(xml_node().hash_value() == 0);
1094
+ CHECK(xml_attribute().hash_value() == 0);
1095
+
1096
+ CHECK(node.hash_value() != 0);
1097
+ CHECK(value.hash_value() != 0);
1098
+ CHECK(node.hash_value() != value.hash_value());
1099
+
1100
+ CHECK(attr.hash_value() != 0);
1101
+
1102
+ xml_node node_copy = node;
1103
+ CHECK(node_copy.hash_value() == node.hash_value());
1104
+
1105
+ xml_attribute attr_copy = attr;
1106
+ CHECK(attr_copy.hash_value() == attr.hash_value());
1107
+ }
1108
+
1109
+ TEST_XML(dom_node_named_iterator, "<node><node1><child/></node1><node2><child/><child/></node2><node3/><node4><child/><x/></node4></node>")
1110
+ {
1111
+ xml_node node1 = doc.child(STR("node")).child(STR("node1"));
1112
+ xml_node node2 = doc.child(STR("node")).child(STR("node2"));
1113
+ xml_node node3 = doc.child(STR("node")).child(STR("node3"));
1114
+ xml_node node4 = doc.child(STR("node")).child(STR("node4"));
1115
+
1116
+ CHECK(xml_named_node_iterator(xml_node(), STR("child")) == xml_named_node_iterator());
1117
+
1118
+ xml_object_range<xml_named_node_iterator> r1 = node1.children(STR("child"));
1119
+ xml_object_range<xml_named_node_iterator> r2 = node2.children(STR("child"));
1120
+ xml_object_range<xml_named_node_iterator> r3 = node3.children(STR("child"));
1121
+ xml_object_range<xml_named_node_iterator> r4 = node4.children(STR("child"));
1122
+
1123
+ CHECK(r1.begin() != r1.end());
1124
+ CHECK(*r1.begin() == node1.first_child());
1125
+ CHECK(r1.begin() == move_iter(r1.end(), -1));
1126
+ CHECK(move_iter(r1.begin(), 1) == r1.end());
1127
+
1128
+ CHECK(r2.begin() != r2.end());
1129
+ CHECK(*r2.begin() == node2.first_child());
1130
+ CHECK(*move_iter(r2.begin(), 1) == node2.last_child());
1131
+ CHECK(r2.begin() == move_iter(r2.end(), -2));
1132
+ CHECK(move_iter(r2.begin(), 1) == move_iter(r2.end(), -1));
1133
+ CHECK(move_iter(r2.begin(), 2) == r2.end());
1134
+
1135
+ CHECK(r3.begin() == r3.end());
1136
+ CHECK(!(r3.begin() != r3.end()));
1137
+
1138
+ CHECK(r4.begin() != r4.end());
1139
+ CHECK(*r4.begin() == node4.first_child());
1140
+ CHECK(r4.begin() == move_iter(r4.end(), -1));
1141
+ CHECK(move_iter(r4.begin(), 1) == r4.end());
1142
+
1143
+ xml_named_node_iterator it = r1.begin();
1144
+ xml_named_node_iterator itt = it;
1145
+
1146
+ CHECK(itt == it);
1147
+
1148
+ CHECK(itt++ == it);
1149
+ CHECK(itt == r1.end());
1150
+
1151
+ CHECK(itt != it);
1152
+ CHECK(itt == ++it);
1153
+
1154
+ CHECK(itt-- == r1.end());
1155
+ CHECK(itt == r1.begin());
1156
+
1157
+ CHECK(itt->offset_debug() == 14);
1158
+ }
1159
+
1160
+ TEST_XML(dom_node_children_attributes, "<node1 attr1='value1' attr2='value2' /><node2 />")
1161
+ {
1162
+ xml_object_range<xml_node_iterator> r1 = doc.children();
1163
+
1164
+ CHECK(r1.begin() == doc.begin());
1165
+ CHECK(r1.end() == doc.end());
1166
+
1167
+ xml_object_range<xml_node_iterator> r2 = xml_node().children();
1168
+
1169
+ CHECK(r2.begin() == xml_node_iterator());
1170
+ CHECK(r2.end() == xml_node_iterator());
1171
+
1172
+ xml_node node = doc.child(STR("node1"));
1173
+
1174
+ xml_object_range<xml_attribute_iterator> r3 = node.attributes();
1175
+
1176
+ CHECK(r3.begin() == node.attributes_begin());
1177
+ CHECK(r3.end() == node.attributes_end());
1178
+
1179
+ xml_object_range<xml_attribute_iterator> r4 = xml_node().attributes();
1180
+
1181
+ CHECK(r4.begin() == xml_attribute_iterator());
1182
+ CHECK(r4.end() == xml_attribute_iterator());
1183
+ }
1184
+
1185
+ TEST_XML(dom_unspecified_bool_coverage, "<node attr='value'>text</node>")
1186
+ {
1187
+ xml_node node = doc.first_child();
1188
+
1189
+ CHECK(node);
1190
+ static_cast<void (*)(xml_node***)>(node)(0);
1191
+
1192
+ CHECK(node.first_attribute());
1193
+ static_cast<void (*)(xml_attribute***)>(node.first_attribute())(0);
1194
+
1195
+ CHECK(node.text());
1196
+ static_cast<void (*)(xml_text***)>(node.text())(0);
1197
+
1198
+ #ifndef PUGIXML_NO_XPATH
1199
+ xpath_query q(STR("/node"));
1200
+
1201
+ CHECK(q);
1202
+ static_cast<void (*)(xpath_query***)>(q)(0);
1203
+
1204
+ xpath_node qn = q.evaluate_node(doc);
1205
+
1206
+ CHECK(qn);
1207
+ static_cast<void (*)(xpath_node***)>(qn)(0);
1208
+ #endif
1209
+ }
1210
+
1211
+ #if __cplusplus >= 201103
1212
+ TEST_XML(dom_ranged_for, "<node attr1='1' attr2='2'><test>3</test><fake>5</fake><test>4</test></node>")
1213
+ {
1214
+ int index = 1;
1215
+
1216
+ for (xml_node n: doc.children())
1217
+ {
1218
+ for (xml_attribute a: n.attributes())
1219
+ {
1220
+ CHECK(a.as_int() == index);
1221
+ index++;
1222
+ }
1223
+
1224
+ for (xml_node c: n.children(STR("test")))
1225
+ {
1226
+ CHECK(c.text().as_int() == index);
1227
+ index++;
1228
+ }
1229
+ }
1230
+
1231
+ CHECK(index == 5);
1232
+ }
1233
+ #endif
1234
+
1235
+ TEST_XML(dom_node_attribute_hinted, "<node attr1='1' attr2='2' attr3='3' />")
1236
+ {
1237
+ xml_node node = doc.first_child();
1238
+ xml_attribute attr1 = node.attribute(STR("attr1"));
1239
+ xml_attribute attr2 = node.attribute(STR("attr2"));
1240
+ xml_attribute attr3 = node.attribute(STR("attr3"));
1241
+
1242
+ xml_attribute hint;
1243
+ CHECK(!xml_node().attribute(STR("test"), hint) && !hint);
1244
+
1245
+ CHECK(node.attribute(STR("attr2"), hint) == attr2 && hint == attr3);
1246
+ CHECK(node.attribute(STR("attr3"), hint) == attr3 && !hint);
1247
+
1248
+ CHECK(node.attribute(STR("attr1"), hint) == attr1 && hint == attr2);
1249
+ CHECK(node.attribute(STR("attr2"), hint) == attr2 && hint == attr3);
1250
+ CHECK(node.attribute(STR("attr1"), hint) == attr1 && hint == attr2);
1251
+ CHECK(node.attribute(STR("attr1"), hint) == attr1 && hint == attr2);
1252
+
1253
+ CHECK(!node.attribute(STR("attr"), hint) && hint == attr2);
1254
+ }
1255
+
1256
+ #ifdef PUGIXML_HAS_STRING_VIEW
1257
+ TEST_XML(dom_node_attribute_hinted_stringview, "<node attr1='1' attr2='2' attr3='3' />")
1258
+ {
1259
+ xml_node node = doc.first_child();
1260
+ string_view_t a1name = string_view_t(STR("attr1"));
1261
+ string_view_t a2name = string_view_t(STR("attr2"));
1262
+ string_view_t a3name = string_view_t(STR("attr3"));
1263
+ xml_attribute attr1 = node.attribute(a1name);
1264
+ xml_attribute attr2 = node.attribute(a2name);
1265
+ xml_attribute attr3 = node.attribute(a3name);
1266
+
1267
+ xml_attribute hint;
1268
+ CHECK(!xml_node().attribute(string_view_t(string_view_t(STR("test"))), hint) && !hint);
1269
+
1270
+ CHECK(node.attribute(a2name, hint) == attr2 && hint == attr3);
1271
+ CHECK(node.attribute(a3name, hint) == attr3 && !hint);
1272
+
1273
+ CHECK(node.attribute(a1name, hint) == attr1 && hint == attr2);
1274
+ CHECK(node.attribute(a2name, hint) == attr2 && hint == attr3);
1275
+ CHECK(node.attribute(a1name, hint) == attr1 && hint == attr2);
1276
+ CHECK(node.attribute(a1name, hint) == attr1 && hint == attr2);
1277
+
1278
+ CHECK(!node.attribute(string_view_t(), hint) && hint == attr2);
1279
+ CHECK(!node.attribute(string_view_t(STR("attr1"), 4), hint) && hint == attr2); // "attr"
1280
+ CHECK(node.attribute(string_view_t(STR("attr3_extra"), 5), hint) == attr3 && !hint); // "attr3"
1281
+ }
1282
+
1283
+ TEST_XML(dom_node_attribute_hint_interior_null, "<node attr1='1' attr2='2' attr3='3' />")
1284
+ {
1285
+ xml_node node = doc.first_child();
1286
+
1287
+ xml_attribute attr1 = node.attribute(STR("attr1"));
1288
+ xml_attribute attr2 = node.attribute(STR("attr2"));
1289
+ xml_attribute attr3 = node.attribute(STR("attr3"));
1290
+
1291
+ CHECK(node && attr1 && attr2 && attr3);
1292
+
1293
+ const char_t name[] = STR("attr2\0extra");
1294
+ size_t len = (sizeof(name) / sizeof(char_t)) - 1;
1295
+ CHECK(len == 11);
1296
+
1297
+ xml_attribute hint;
1298
+ CHECK(node.attribute(string_view_t(name, 5), hint) == attr2 && hint == attr3); // "attr2"
1299
+ CHECK(node.attribute(string_view_t(name, 5), hint) == attr2 && hint == attr3); // "attr2"
1300
+
1301
+ CHECK(!node.attribute(string_view_t(name, 6), hint) && hint == attr3); // "attr2\0"
1302
+ CHECK(!node.attribute(string_view_t(name, len), hint) && hint == attr3); // "attr2\0extra"
1303
+
1304
+ attr2.set_name(string_view_t(name, len)); // attr2\0extra
1305
+
1306
+ CHECK(node.attribute(string_view_t(name, 5), hint) == attr2 && hint == attr3); // "attr2"
1307
+ CHECK(node.attribute(string_view_t(name, 5), hint) == attr2 && hint == attr3); // "attr2"
1308
+
1309
+ CHECK(!node.attribute(string_view_t(name, 6), hint) && hint == attr3); // "attr2\0"
1310
+ CHECK(!node.attribute(string_view_t(name, len), hint) && hint == attr3); // "attr2\0extra"
1311
+ }
1312
+ #endif
1313
+
1314
+ TEST_XML(dom_as_int_overflow, "<node attr1='-2147483649' attr2='2147483648' attr3='-4294967296' />")
1315
+ {
1316
+ xml_node node = doc.child(STR("node"));
1317
+
1318
+ CHECK(node.attribute(STR("attr1")).as_int() == -2147483647 - 1);
1319
+ CHECK(node.attribute(STR("attr2")).as_int() == 2147483647);
1320
+ CHECK(node.attribute(STR("attr3")).as_int() == -2147483647 - 1);
1321
+ }
1322
+
1323
+ TEST_XML(dom_as_uint_overflow, "<node attr1='-1' attr2='4294967296' attr3='5294967295' attr4='21474836479' />")
1324
+ {
1325
+ xml_node node = doc.child(STR("node"));
1326
+
1327
+ CHECK(node.attribute(STR("attr1")).as_uint() == 0);
1328
+ CHECK(node.attribute(STR("attr2")).as_uint() == 4294967295u);
1329
+ CHECK(node.attribute(STR("attr3")).as_uint() == 4294967295u);
1330
+ CHECK(node.attribute(STR("attr4")).as_uint() == 4294967295u);
1331
+ }
1332
+
1333
+ TEST_XML(dom_as_int_hex_overflow, "<node attr1='-0x80000001' attr2='0x80000000' />")
1334
+ {
1335
+ xml_node node = doc.child(STR("node"));
1336
+
1337
+ CHECK(node.attribute(STR("attr1")).as_int() == -2147483647 - 1);
1338
+ CHECK(node.attribute(STR("attr2")).as_int() == 2147483647);
1339
+ }
1340
+
1341
+ TEST_XML(dom_as_uint_hex_overflow, "<node attr1='-0x1' attr2='0x100000000' attr3='0x123456789' />")
1342
+ {
1343
+ xml_node node = doc.child(STR("node"));
1344
+
1345
+ CHECK(node.attribute(STR("attr1")).as_uint() == 0);
1346
+ CHECK(node.attribute(STR("attr2")).as_uint() == 4294967295u);
1347
+ CHECK(node.attribute(STR("attr3")).as_uint() == 4294967295u);
1348
+ }
1349
+
1350
+ TEST_XML(dom_as_int_many_digits, "<node attr1='0000000000000000000000000000000000000000000000001' />")
1351
+ {
1352
+ xml_node node = doc.child(STR("node"));
1353
+
1354
+ CHECK(node.attribute(STR("attr1")).as_int() == 1);
1355
+ CHECK(node.attribute(STR("attr1")).as_uint() == 1);
1356
+ }
1357
+
1358
+ TEST_XML(dom_as_int_hex_many_digits, "<node attr1='0x0000000000000000000000000000000000000000000000001' />")
1359
+ {
1360
+ xml_node node = doc.child(STR("node"));
1361
+
1362
+ CHECK(node.attribute(STR("attr1")).as_int() == 1);
1363
+ CHECK(node.attribute(STR("attr1")).as_uint() == 1);
1364
+ }
1365
+
1366
+ #ifdef PUGIXML_HAS_LONG_LONG
1367
+ TEST_XML(dom_as_llong_overflow, "<node attr1='-9223372036854775809' attr2='9223372036854775808' attr3='-18446744073709551616' />")
1368
+ {
1369
+ xml_node node = doc.child(STR("node"));
1370
+
1371
+ CHECK(node.attribute(STR("attr1")).as_llong() == -9223372036854775807ll - 1);
1372
+ CHECK(node.attribute(STR("attr2")).as_llong() == 9223372036854775807ll);
1373
+ CHECK(node.attribute(STR("attr3")).as_llong() == -9223372036854775807ll - 1);
1374
+ }
1375
+
1376
+ TEST_XML(dom_as_ullong_overflow, "<node attr1='-1' attr2='18446744073709551616' attr3='28446744073709551615' attr4='166020696663385964543' />")
1377
+ {
1378
+ xml_node node = doc.child(STR("node"));
1379
+
1380
+ CHECK(node.attribute(STR("attr1")).as_ullong() == 0);
1381
+ CHECK(node.attribute(STR("attr2")).as_ullong() == 18446744073709551615ull);
1382
+ CHECK(node.attribute(STR("attr3")).as_ullong() == 18446744073709551615ull);
1383
+ CHECK(node.attribute(STR("attr4")).as_ullong() == 18446744073709551615ull);
1384
+ }
1385
+
1386
+ TEST_XML(dom_as_llong_hex_overflow, "<node attr1='-0x8000000000000001' attr2='0x8000000000000000' />")
1387
+ {
1388
+ xml_node node = doc.child(STR("node"));
1389
+
1390
+ CHECK(node.attribute(STR("attr1")).as_llong() == -9223372036854775807ll - 1);
1391
+ CHECK(node.attribute(STR("attr2")).as_llong() == 9223372036854775807ll);
1392
+ }
1393
+
1394
+ TEST_XML(dom_as_ullong_hex_overflow, "<node attr1='-0x1' attr2='0x10000000000000000' attr3='0x12345678923456789' />")
1395
+ {
1396
+ xml_node node = doc.child(STR("node"));
1397
+
1398
+ CHECK(node.attribute(STR("attr1")).as_ullong() == 0);
1399
+ CHECK(node.attribute(STR("attr2")).as_ullong() == 18446744073709551615ull);
1400
+ CHECK(node.attribute(STR("attr3")).as_ullong() == 18446744073709551615ull);
1401
+ }
1402
+
1403
+ TEST_XML(dom_as_llong_many_digits, "<node attr1='0000000000000000000000000000000000000000000000001' />")
1404
+ {
1405
+ xml_node node = doc.child(STR("node"));
1406
+
1407
+ CHECK(node.attribute(STR("attr1")).as_llong() == 1);
1408
+ CHECK(node.attribute(STR("attr1")).as_ullong() == 1);
1409
+ }
1410
+
1411
+ TEST_XML(dom_as_llong_hex_many_digits, "<node attr1='0x0000000000000000000000000000000000000000000000001' />")
1412
+ {
1413
+ xml_node node = doc.child(STR("node"));
1414
+
1415
+ CHECK(node.attribute(STR("attr1")).as_llong() == 1);
1416
+ CHECK(node.attribute(STR("attr1")).as_ullong() == 1);
1417
+ }
1418
+ #endif
1419
+
1420
+ TEST_XML(dom_as_int_plus, "<node attr1='+1' attr2='+0xa' />")
1421
+ {
1422
+ xml_node node = doc.child(STR("node"));
1423
+
1424
+ CHECK(node.attribute(STR("attr1")).as_int() == 1);
1425
+ CHECK(node.attribute(STR("attr1")).as_uint() == 1);
1426
+ CHECK(node.attribute(STR("attr2")).as_int() == 10);
1427
+ CHECK(node.attribute(STR("attr2")).as_uint() == 10);
1428
+
1429
+ #ifdef PUGIXML_HAS_LONG_LONG
1430
+ CHECK(node.attribute(STR("attr1")).as_llong() == 1);
1431
+ CHECK(node.attribute(STR("attr1")).as_ullong() == 1);
1432
+ CHECK(node.attribute(STR("attr2")).as_llong() == 10);
1433
+ CHECK(node.attribute(STR("attr2")).as_ullong() == 10);
1434
+ #endif
1435
+ }
1436
+
1437
+ TEST(dom_node_anonymous)
1438
+ {
1439
+ xml_document doc;
1440
+ doc.append_child(node_element);
1441
+ doc.append_child(node_element);
1442
+ doc.append_child(node_pcdata);
1443
+
1444
+ CHECK(doc.child(STR("node")) == xml_node());
1445
+ CHECK(doc.first_child().next_sibling(STR("node")) == xml_node());
1446
+ CHECK(doc.last_child().previous_sibling(STR("node")) == xml_node());
1447
+ CHECK_STRING(doc.child_value(), STR(""));
1448
+ CHECK_STRING(doc.last_child().child_value(), STR(""));
1449
+ }
1450
+
1451
+ TEST_XML(dom_node_anonymous_child, "<node></node>")
1452
+ {
1453
+ xml_node node = doc.child(STR("node"));
1454
+ CHECK_NAME_VALUE(node, STR("node"), STR(""));
1455
+ node.set_name(STR(""));
1456
+ CHECK_NODE(doc, STR("<:anonymous/>"));
1457
+ CHECK(doc.first_child() != xml_node());
1458
+ CHECK_NAME_VALUE(doc.first_child(), STR(""), STR(""));
1459
+
1460
+ // searching for empty string does not find a node with empty name
1461
+ CHECK(doc.child(STR("")) == xml_node());
1462
+ #ifdef PUGIXML_HAS_STRING_VIEW
1463
+ CHECK(doc.child(string_view_t()) == xml_node());
1464
+ CHECK(doc.child(string_view_t(STR("hi"), 0)) == xml_node());
1465
+ #endif
1466
+ }
1467
+
1468
+ TEST_XML(dom_node_anonymous_attribute, "<node attr='0'/>")
1469
+ {
1470
+ xml_attribute attr = doc.first_child().attribute(STR("attr"));
1471
+ CHECK(attr != xml_attribute());
1472
+ attr.set_name(STR(""));
1473
+ CHECK_NODE(doc, STR("<node :anonymous=\"0\"/>"));
1474
+ CHECK_NAME_VALUE(doc.first_child().first_attribute(), STR(""), STR("0"));
1475
+
1476
+ CHECK(doc.first_child().attribute(STR("")) == xml_attribute());
1477
+ #ifdef PUGIXML_HAS_STRING_VIEW
1478
+ CHECK(doc.first_child().attribute(string_view_t()) == xml_attribute());
1479
+ CHECK(doc.first_child().attribute(string_view_t(STR("hi"), 0)) == xml_attribute());
1480
+ #endif
1481
+ }