5 #define YUILogComponent "gtk"
6 #include <yui/Libyui_config.h>
15 fprintf (stderr,
"Test map KB accels\t");
30 for (
int i = 0; aTests[i].in; i++) {
31 std::string mapped = YGUtils::mapKBAccel(aTests[i].in);
32 if (mapped != aTests[i].out) {
33 fprintf (stderr,
"Mis-mapped accel '%s' vs '%s'\n",
34 mapped.c_str(), aTests[i].out);
37 fprintf (stderr,
"%d ", i);
39 fprintf (stderr,
"\n");
43 #include "ygtkrichtext.h"
45 bool testParse(
const char *xml)
48 GMarkupParser parser = { 0, };
49 GMarkupParseContext *ctx = g_markup_parse_context_new (&parser, GMarkupParseFlags (0), NULL, NULL);
51 if (!g_markup_parse_context_parse (ctx, xml, -1, &error))
53 fprintf (stderr,
"Invalid XML: '%s'\n '%s'\n", xml, error->message);
56 g_markup_parse_context_free (ctx);
61 bool testXHtmlConvert()
63 fprintf (stderr,
"Test HTML->XML rewrite \t");
69 {
"<p>foo</p>",
"<body><p>foo</p></body>" },
71 {
"some text",
"<body>some text</body>" },
73 {
"<foo baa=Baz></foo>",
"<body><foo baa=\"Baz\"></foo></body>" },
75 {
"<br>",
"<body><br/></body>" },
76 {
"<hr>",
"<body><hr/></body>" },
78 {
"<p>Foo</P>",
"<body><p>Foo</p></body>" },
80 {
"<p>",
"<body><p></p></body>" },
81 {
"<b>unclosed",
"<body><b>unclosed</b></body>" },
82 {
"<b><i>bold</i>",
"<body><b><i>bold</i></b></body>" },
83 {
"<i><i>bold</i>",
"<body><i><i>bold</i></i></body>" },
84 {
"<unclosed foo=baa>",
85 "<body><unclosed foo=\"baa\"></unclosed></body>" },
87 {
"<i>Some<p>text<p> here<p></i>",
88 "<body><i>Some<p>text</p><p> here</p><p></p></i></body>" },
89 {
"<ul><li>foo<li>baa",
90 "<body><ul><li>foo</li><li>baa</li></ul></body>" },
91 {
"no outer<p>unclosed<p>several<b>unclosed bold",
92 "<body>no outer<p>unclosed</p><p>several<b>unclosed bold</b></p></body>" },
94 {
"we need <b>to <!-- really need to? --> do something</b> about it.",
95 "<body>we need <b>to do something</b> about it.</body>" },
96 {
"&",
"<body>&</body>" },
97 {
"&",
"<body>&amp</body>" },
98 {
"& foo",
"<body>& foo</body>" },
99 {
"& foo",
"<body>&amp foo</body>" },
100 {
"<pre>https://foo.com/regsvc-1.0/?lang=de-DE&guid=1529f49dc701449fbd854aebf7e40806&command=interactive</pre>\n",
101 "<body><pre>https://foo.com/regsvc-1.0/?lang=de-DE&guid=1529f49dc701449fbd854aebf7e40806&command=interactive</pre> </body>" },
104 for (
int i = 0; aTests[i].in; i++) {
105 gchar *out = ygutils_convert_to_xhtml (aTests[i].in);
106 if (strcmp (out, aTests[i].out)) {
107 fprintf (stderr,
"Mis-converted entry %d XML '%s' should be '%s'\n",
108 i, out, aTests[i].out);
111 if (!testParse (out))
114 fprintf (stderr,
"%d ", i);
117 fprintf (stderr,
"\n");
121 bool testMarkupEscape()
123 fprintf (stderr,
"Test markup escape\t");
129 {
"< text />",
"< text />" },
130 {
"um\ndois\ntres",
"um\ndois\ntres" },
133 for (
int i = 0; aTests[i].in; i++) {
134 std::string out (YGUtils::escapeMarkup (aTests[i].in));
135 if (out != aTests[i].out) {
136 fprintf (stderr,
"Mis-converted entry %d XML '%s' should be '%s'\n",
137 i, out.c_str(), aTests[i].out);
140 fprintf (stderr,
"%d ", i);
142 fprintf (stderr,
"\n");
148 fprintf (stderr,
"Test truncate\t");
154 {
"this-is-a-very-long-and-tedious-string",
"this-is-a-very-lo...", 20, 1 },
155 {
"this-is-a-very-long-and-tedious-string",
"...nd-tedious-string", 20, -1 },
156 {
"this-is-a-very-long-and-tedious-string",
"this-is-a...s-string", 20, 0 },
157 {
"this-is-a-very-long-and-tedious-string2",
"this-is-...s-string2", 20, 0 },
158 {
"abc",
"abc", 3, 1 },
159 {
"abcd",
"...", 3, 1 },
160 {
"abcd",
"...", 3, -1 },
161 {
"abcd",
"...", 3, 0 },
162 {
"abcdef",
"a...", 4, 0 },
163 {
"áéíóúçö",
"áé...", 5, 1 },
164 {
"áéíóúçö",
"áéí...", 6, 1 },
165 {
"áéíóúçö",
"...çö", 5, -1 },
166 {
"áéíóúçö",
"...úçö", 6, -1 },
167 {
"áéíóúçö",
"á...ö", 5, 0 },
168 {
"áéíóúçö",
"á...çö", 6, 0 },
169 {
"áéíóú",
"áéíóú", 5, 0 },
172 for (
int i = 0; aTests[i].in; i++) {
173 std::string out = YGUtils::truncate (aTests[i].in, aTests[i].length, aTests[i].pos);
174 if (out != aTests[i].out) {
175 fprintf (stderr,
"Mis-converted entry %d truncate '%s' should be '%s'\n",
176 i, out.c_str(), aTests[i].out);
179 fprintf (stderr,
"%d ", i);
181 fprintf (stderr,
"\n");
187 fprintf (stderr,
"Test headerize\t");
193 {
"test",
"test", FALSE },
194 {
"<h1>Purpose</h1><p>This tool lets you install, remove, and update applications.</p><p>openSUSE's software management",
195 "This tool lets you install, remove, and update applications.", TRUE },
196 {
"\n<p><big><b>Section List</b></big><br>\n<P>From <B>Other</B>,\nyou can manually edit the boot loader configuration files, clear the current\n"
197 "configuration and propose a new configuration, start from scratch, or reread\nthe configuration saved on your disk. If you have multiple Linux systems installed,",
198 "From Other, you can manually edit the boot loader configuration files, clear the current configuration and "
199 "propose a new configuration, start from scratch, or reread the configuration saved on your disk.", TRUE },
200 {
"<p><big><b>Sound Cards</b><big></p><P>Select an unconfigured card from the list and press <B>Edit</B> to\nconfigure it. If the card was not detected, press <B>Add</B> and\nconfigure the card manually.</P>",
201 "Select an unconfigured card from the list and press Edit to configure it.", TRUE },
202 {
"\n<p><b><big>Service Start</big></b><br>\nTo start the service every time your computer is booted, set\n"
203 "<b>Enable firewall</b>. Otherwise set <b>Disable firewall</b>.</p>\n<p><b><big>Switch On or Off</big></b><br>",
204 "To start the service every time your computer is booted, set Enable firewall.", TRUE },
207 for (
int i = 0; aTests[i].in; i++) {
208 gboolean cut = FALSE;
209 char *out = ygutils_headerize_help (aTests[i].in, &cut);
210 if (strcmp (aTests[i].out, out)) {
211 fprintf (stderr,
"Mis-headerized test %d:\n-- \n%s\n-- should be --\n%s\n-- xhtml --\n%s\n-- \n",
212 i, out, aTests[i].out, ygutils_convert_to_xhtml (aTests[i].in));
215 if (!!aTests[i].cut != !!cut)
216 fprintf (stderr,
"Mis-labelled as cut (%d)\n", !!cut);
217 fprintf (stderr,
"%d ", i);
219 fprintf (stderr,
"\n");
223 int main (
int argc,
char **argv)
225 bool bSuccess =
true;
227 bSuccess &= testMapKBAccel();
228 bSuccess &= testXHtmlConvert();
229 bSuccess &= testMarkupEscape();
230 bSuccess &= testTruncate();
231 bSuccess &= testHeaderize();