]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-11442 [core] added test helpers for constructing XML objects
authorChris Rienzo <chris@signalwire.com>
Sat, 6 Oct 2018 03:26:04 +0000 (03:26 +0000)
committerChris Rienzo <chris@signalwire.com>
Thu, 20 Dec 2018 15:17:15 +0000 (10:17 -0500)
src/include/test/switch_test.h

index 2496cf1f5ee6105bd8b65cc2bf13e98492ec7210..4fd2c33e3027b01ff856cc59fa25d16363e4a94f 100644 (file)
@@ -522,6 +522,40 @@ static void fst_session_park(switch_core_session_t *session)
        switch_safe_free(stream.data); \
 }
 
+#define fst_xml_start() \
+       switch_stream_handle_t fst_xml_stream = { 0 }; \
+       SWITCH_STANDARD_STREAM(fst_xml_stream);
+       int fst_tag_children = 0;
+       int fst_tag_body = 0;
+
+#define fst_xml_open_tag(tag_name) \
+       fst_xml_stream.write_function(&fst_xml_stream, "<%s", #tag_name); \
+       fst_tag_children++;
+
+#define fst_xml_attr(attr) \
+       if (!zstr(attr)) fst_xml_stream.write_function(&fst_xml_stream, " %s=\"%s\"", #attr, attr);
+
+#define fst_xml_close_tag(tag_name) \
+       --fst_tag_children; \
+       if (fst_tag_children > 0 || fst_tag_body) { \
+               fst_xml_stream.write_function(&fst_xml_stream, "</%s>", #tag_name); \
+       } else { \
+               fst_xml_stream.write_function(&fst_xml_stream, "/>"); \
+       } \
+       fst_tag_body = 0;
+
+#define fst_xml_body(body) \
+       if (fst_tag_body) { \
+               fst_xml_stream.write_function(&fst_xml_stream "%s", body); \
+       } else { \
+               fst_tag_body = 1; \
+               fst_xml_stream.write_function(&fst_xml_stream, ">%s", body); \
+       }
+
+#define fst_xml_end() \
+       switch_xml_parse_str_dynamic((char *)fst_xml_stream.data, SWITCH_FALSE);
+
+
 /**
  * Parse JSON file and save to varname
  *