2
0

switch_xml.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  3. * Copyright (C) 2005-2019, Anthony Minessale II <anthm@freeswitch.org>
  4. *
  5. * Version: MPL 1.1
  6. *
  7. * The contents of this file are subject to the Mozilla Public License Version
  8. * 1.1 (the "License"); you may not use this file except in compliance with
  9. * the License. You may obtain a copy of the License at
  10. * http://www.mozilla.org/MPL/
  11. *
  12. * Software distributed under the License is distributed on an "AS IS" basis,
  13. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14. * for the specific language governing rights and limitations under the
  15. * License.
  16. *
  17. * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  18. *
  19. * The Initial Developer of the Original Code is
  20. * Anthony Minessale II <anthm@freeswitch.org>
  21. * Portions created by the Initial Developer are Copyright (C)
  22. * the Initial Developer. All Rights Reserved.
  23. *
  24. * Contributor(s):
  25. * Chris Rienzo <chris@signalwire.com>
  26. * Seven Du <dujinfang@gmail.com>
  27. *
  28. *
  29. * switch_xml.c -- tests core xml functions
  30. *
  31. */
  32. #include <switch.h>
  33. #include <stdlib.h>
  34. #include <test/switch_test.h>
  35. FST_MINCORE_BEGIN("./conf")
  36. {
  37. FST_SUITE_BEGIN(switch_xml)
  38. {
  39. FST_SETUP_BEGIN()
  40. {
  41. }
  42. FST_SETUP_END()
  43. FST_TEARDOWN_BEGIN()
  44. {
  45. }
  46. FST_TEARDOWN_END()
  47. FST_TEST_BEGIN(test_cdata)
  48. {
  49. const char *text = "<xml><![CDATA[Tom & Jerry]]></xml>";
  50. switch_xml_t xml = switch_xml_parse_str_dynamic((char *)text, SWITCH_TRUE);
  51. fst_requires(xml);
  52. fst_check(xml->flags & SWITCH_XML_CDATA);
  53. switch_xml_free(xml);
  54. text = "<xml><tag><![CDATA[Tom & Jerry]]></tag></xml>";
  55. xml = switch_xml_parse_str_dynamic((char *)text, SWITCH_TRUE);
  56. fst_requires(xml);
  57. fst_check((xml->flags & SWITCH_XML_CDATA) == 0);
  58. fst_check_string_equals(xml->child->name, "tag");
  59. fst_check(xml->child->flags & SWITCH_XML_CDATA);
  60. switch_xml_free(xml);
  61. }
  62. FST_TEST_END()
  63. FST_TEST_BEGIN(test_utf_8)
  64. {
  65. const char *text = "<xml>Voulez-Vous Parler Français</xml>";
  66. switch_xml_t xml = switch_xml_parse_str_dynamic((char *)text, SWITCH_TRUE);
  67. char *xml_string = NULL;
  68. fst_requires(xml);
  69. xml_string = switch_xml_toxml(xml, SWITCH_FALSE);
  70. fst_requires(xml_string);
  71. fst_check_string_equals(xml_string, "<xml>Voulez-Vous Parler Fran&#xE7;ais</xml>\n");
  72. free(xml_string);
  73. xml_string = switch_xml_toxml_ex(xml, SWITCH_FALSE, SWITCH_FALSE);
  74. fst_requires(xml_string);
  75. fst_check_string_equals(xml_string, "<xml>Voulez-Vous Parler Français</xml>\n");
  76. switch_xml_free(xml);
  77. free(xml_string);
  78. text = "<xml>你好,中文</xml>";
  79. xml = switch_xml_parse_str_dynamic((char *)text, SWITCH_TRUE);
  80. fst_requires(xml);
  81. xml_string = switch_xml_toxml(xml, SWITCH_FALSE);
  82. fst_requires(xml_string);
  83. fst_check_string_equals(xml_string, "<xml>&#x4F60;&#x597D;&#xFF0C;&#x4E2D;&#x6587;</xml>\n");
  84. free(xml_string);
  85. xml_string = switch_xml_toxml_ex(xml, SWITCH_FALSE, SWITCH_FALSE);
  86. fst_requires(xml_string);
  87. fst_check_string_equals(xml_string, "<xml>你好,中文</xml>\n");
  88. switch_xml_free(xml);
  89. free(xml_string);
  90. text = "<xml><tag><![CDATA[Voulez-Vous Parler Français]]></tag></xml>";
  91. xml = switch_xml_parse_str_dynamic((char *)text, SWITCH_TRUE);
  92. fst_requires(xml);
  93. xml_string = switch_xml_toxml(xml, SWITCH_FALSE);
  94. fst_requires(xml_string);
  95. fst_check_string_equals(xml_string, "<xml>\n <tag>Voulez-Vous Parler Fran&#xE7;ais</tag>\n</xml>\n");
  96. free(xml_string);
  97. xml_string = switch_xml_toxml_ex(xml, SWITCH_FALSE, SWITCH_FALSE);
  98. fst_requires(xml_string);
  99. fst_check_string_equals(xml_string, "<xml>\n <tag>Voulez-Vous Parler Français</tag>\n</xml>\n");
  100. switch_xml_free(xml);
  101. free(xml_string);
  102. }
  103. FST_TEST_END()
  104. }
  105. FST_SUITE_END()
  106. }
  107. FST_MINCORE_END()