1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* test-xml.c: Test libxml2 wrappers
*
* Copyright (C) 2015 Morten Welinder <terra@gnome.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
* USA
*/
#include <stdio.h>
#include <gsf/gsf.h>
static int
test_xml_indent (void)
{
GsfOutput *mem = gsf_output_memory_new ();
GsfXMLOut *xml = gsf_xml_out_new (mem);
const char *data;
gboolean pprint;
int err;
const char *expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<outer>\n"
" <data/>\n"
" <data attr=\"val\"/>\n"
" <data>text</data>\n"
" <data>\n"
" <inner>text</inner>\n"
" </data>\n"
" <data>text</data>\n"
" <data><inner>text</inner></data>\n"
"</outer>\n";
gsf_xml_out_start_element (xml, "outer");
gsf_xml_out_start_element (xml, "data");
gsf_xml_out_end_element (xml);
gsf_xml_out_start_element (xml, "data");
gsf_xml_out_add_cstr_unchecked (xml, "attr", "val");
gsf_xml_out_end_element (xml);
gsf_xml_out_start_element (xml, "data");
gsf_xml_out_add_cstr_unchecked (xml, NULL, "text");
gsf_xml_out_end_element (xml);
gsf_xml_out_start_element (xml, "data");
gsf_xml_out_start_element (xml, "inner");
gsf_xml_out_add_cstr_unchecked (xml, NULL, "text");
gsf_xml_out_end_element (xml);
gsf_xml_out_end_element (xml);
gsf_xml_out_start_element (xml, "data");
pprint = gsf_xml_out_set_pretty_print (xml, FALSE);
gsf_xml_out_add_cstr_unchecked (xml, NULL, "text");
gsf_xml_out_set_pretty_print (xml, pprint);
gsf_xml_out_end_element (xml);
gsf_xml_out_start_element (xml, "data");
pprint = gsf_xml_out_set_pretty_print (xml, FALSE);
gsf_xml_out_start_element (xml, "inner");
gsf_xml_out_add_cstr_unchecked (xml, NULL, "text");
gsf_xml_out_end_element (xml);
gsf_xml_out_set_pretty_print (xml, pprint);
gsf_xml_out_end_element (xml);
gsf_xml_out_end_element (xml);
g_object_unref (xml);
data = (const char *)gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (mem));
g_printerr ("Got\n%s\n", data);
err = !g_str_equal (data, expected);
if (err)
g_printerr ("Expected\n%s\n", expected);
g_object_unref (mem);
return err;
}
int
main (int argc, char *argv[])
{
int res;
(void)argc;
(void)argv;
gsf_init ();
res = test_xml_indent ();
gsf_shutdown ();
return res;
}
|