From f9b01094edbbe55cab5106084e2fa22461ce36fe Mon Sep 17 00:00:00 2001 From: Tomas Mlcoch Date: Tue, 5 Aug 2014 10:25:18 +0200 Subject: [PATCH] xml_dump_updateinfo: Fix cr_xml_dump_updaterecord() (remove element) --- src/xml_dump_updateinfo.c | 19 ++++++++++++------- tests/python/tests/test_updaterecord.py | 32 +++++++++++++++----------------- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/xml_dump_updateinfo.c b/src/xml_dump_updateinfo.c index 6900dc2..3ed449d 100644 --- a/src/xml_dump_updateinfo.c +++ b/src/xml_dump_updateinfo.c @@ -29,7 +29,7 @@ #include "xml_dump.h" #include "xml_dump_internal.h" -#define INDENT 4 +#define INDENT 2 void cr_xml_dump_updatecollectionpackages(xmlNodePtr collection, GSList *packages) @@ -104,16 +104,20 @@ cr_xml_dump_updateinforecord_references(xmlNodePtr update, GSList *refs) } } -void +xmlNodePtr cr_xml_dump_updateinforecord_internal(xmlNodePtr root, cr_UpdateRecord *rec) { xmlNodePtr update, node; if (!rec) - return; + return NULL; // Update element - update = xmlNewChild(root, NULL, BAD_CAST "update", NULL); + if (!root) + update = xmlNewNode(NULL, BAD_CAST "update"); + else + update = xmlNewChild(root, NULL, BAD_CAST "update", NULL); + cr_xmlNewProp_c(update, BAD_CAST "from", BAD_CAST rec->from); cr_xmlNewProp_c(update, BAD_CAST "status", BAD_CAST rec->status); cr_xmlNewProp_c(update, BAD_CAST "type", BAD_CAST rec->type); @@ -145,6 +149,8 @@ cr_xml_dump_updateinforecord_internal(xmlNodePtr root, cr_UpdateRecord *rec) // Pkglist cr_xml_dump_updateinforecord_pkglist(update, rec->collections); + + return update; } @@ -213,10 +219,9 @@ cr_xml_dump_updaterecord(cr_UpdateRecord *rec, GError **err) return NULL; } - root = xmlNewNode(NULL, BAD_CAST "delta"); - cr_xml_dump_updateinforecord_internal(root, rec); + root = cr_xml_dump_updateinforecord_internal(NULL, rec); // xmlNodeDump seems to be a little bit faster than xmlDocDumpFormatMemory - xmlNodeDump(buf, NULL, root, 2, FORMAT_XML); + xmlNodeDump(buf, NULL, root, 1, FORMAT_XML); assert(buf->content); // First line in the buf is not indented, we must indent it by ourself result = g_malloc(sizeof(char *) * buf->use + INDENT + 1); diff --git a/tests/python/tests/test_updaterecord.py b/tests/python/tests/test_updaterecord.py index ebcfede..b407221 100644 --- a/tests/python/tests/test_updaterecord.py +++ b/tests/python/tests/test_updaterecord.py @@ -107,21 +107,19 @@ class TestCaseUpdateRecord(unittest.TestCase): xml = cr.xml_dump_updaterecord(rec) self.assertEqual(xml, -""" - - id - title - - - rights - release - pushcount - severity - summary - description - solution - - - - +""" + id + title + + + rights + release + pushcount + severity + summary + description + solution + + + """) -- 2.7.4