Move markup parse tests to the test framework

This commit is contained in:
Matthias Clasen
2010-07-29 20:52:31 -04:00
parent aa196c60df
commit 03be0d7237
105 changed files with 385 additions and 267 deletions

View File

@@ -112,9 +112,9 @@ test_programs = \
unicode-caseconv \
unicode-encoding
test_scripts = run-markup-tests.sh run-collate-tests.sh run-bookmark-test.sh run-assert-msg-test.sh
test_scripts = run-collate-tests.sh run-bookmark-test.sh run-assert-msg-test.sh
test_script_support_programs = markup-test unicode-collate bookmarkfile-test
test_script_support_programs = unicode-collate bookmarkfile-test
check_PROGRAMS = $(test_programs) $(test_script_support_programs)
@@ -141,7 +141,6 @@ gio_test_LDADD = $(progs_ldadd)
iochannel_test_LDADD = $(progs_ldadd)
list_test_LDADD = $(progs_ldadd)
mainloop_test_LDADD = $(thread_ldadd)
markup_test_LDADD = $(progs_ldadd)
mapping_test_LDADD = $(progs_ldadd)
module_test_LDADD = $(module_ldadd) $(module_test_exp)
module_test_LDFLAGS = $(G_MODULE_LDFLAGS)
@@ -180,9 +179,6 @@ dist-hook: $(BUILT_EXTRA_DIST)
for f in $$files; do \
if test -f $$f; then d=.; else d=$(srcdir); fi; \
cp $$d/$$f $(distdir) || exit 1; done
mkdir $(distdir)/markups; \
for f in $(srcdir)/markups/* ; do \
cp $$f $(distdir)/markups; done
mkdir $(distdir)/collate; \
for f in $(srcdir)/collate/* ; do \
if test -f $$f; then cp $$f $(distdir)/collate; fi; done

View File

@@ -1,214 +0,0 @@
#undef G_DISABLE_ASSERT
#undef G_LOG_DOMAIN
#include <stdio.h>
#include <glib.h>
static int depth = 0;
static void
indent (int extra)
{
int i = 0;
while (i < depth)
{
fputs (" ", stdout);
++i;
}
}
static void
start_element_handler (GMarkupParseContext *context,
const gchar *element_name,
const gchar **attribute_names,
const gchar **attribute_values,
gpointer user_data,
GError **error)
{
int i;
indent (0);
printf ("ELEMENT '%s'\n", element_name);
i = 0;
while (attribute_names[i] != NULL)
{
indent (1);
printf ("%s=\"%s\"\n",
attribute_names[i],
attribute_values[i]);
++i;
}
++depth;
}
static void
end_element_handler (GMarkupParseContext *context,
const gchar *element_name,
gpointer user_data,
GError **error)
{
--depth;
indent (0);
printf ("END '%s'\n", element_name);
}
static void
text_handler (GMarkupParseContext *context,
const gchar *text,
gsize text_len,
gpointer user_data,
GError **error)
{
indent (0);
printf ("TEXT '%.*s'\n", (int)text_len, text);
}
static void
passthrough_handler (GMarkupParseContext *context,
const gchar *passthrough_text,
gsize text_len,
gpointer user_data,
GError **error)
{
indent (0);
printf ("PASS '%.*s'\n", (int)text_len, passthrough_text);
}
static void
error_handler (GMarkupParseContext *context,
GError *error,
gpointer user_data)
{
fprintf (stderr, " %s\n", error->message);
}
static const GMarkupParser parser = {
start_element_handler,
end_element_handler,
text_handler,
passthrough_handler,
error_handler
};
static const GMarkupParser silent_parser = {
NULL,
NULL,
NULL,
NULL,
error_handler
};
static int
test_in_chunks (const gchar *contents,
gint length,
gint chunk_size)
{
GMarkupParseContext *context;
int i = 0;
context = g_markup_parse_context_new (&silent_parser, 0, NULL, NULL);
while (i < length)
{
int this_chunk = MIN (length - i, chunk_size);
if (!g_markup_parse_context_parse (context,
contents + i,
this_chunk,
NULL))
{
g_markup_parse_context_free (context);
return 1;
}
i += this_chunk;
}
if (!g_markup_parse_context_end_parse (context, NULL))
{
g_markup_parse_context_free (context);
return 1;
}
g_markup_parse_context_free (context);
return 0;
}
static int
test_file (const gchar *filename)
{
gchar *contents;
gsize length;
GError *error;
GMarkupParseContext *context;
error = NULL;
if (!g_file_get_contents (filename,
&contents,
&length,
&error))
{
fprintf (stderr, "%s\n", error->message);
g_error_free (error);
return 1;
}
context = g_markup_parse_context_new (&parser, 0, NULL, NULL);
if (!g_markup_parse_context_parse (context, contents, length, NULL))
{
g_markup_parse_context_free (context);
return 1;
}
if (!g_markup_parse_context_end_parse (context, NULL))
{
g_markup_parse_context_free (context);
return 1;
}
g_markup_parse_context_free (context);
/* A byte at a time */
if (test_in_chunks (contents, length, 1) != 0)
return 1;
/* 2 bytes */
if (test_in_chunks (contents, length, 2) != 0)
return 1;
/*5 bytes */
if (test_in_chunks (contents, length, 5) != 0)
return 1;
/* 12 bytes */
if (test_in_chunks (contents, length, 12) != 0)
return 1;
/* 1024 bytes */
if (test_in_chunks (contents, length, 1024) != 0)
return 1;
return 0;
}
int
main (int argc,
char *argv[])
{
if (argc > 1)
return test_file (argv[1]);
else
{
fprintf (stderr, "Give a markup file on the command line\n");
return 1;
}
}

View File

@@ -1,37 +0,0 @@
PASS '<!-- Comment -->'
PASS '<?PI ?>'
ELEMENT 'foobar'
TEXT '
'
ELEMENT 'e1'
TEXT 'Hi & this is some text inside an element Two 'E' chars as character refs: E E and some 'J': J J'
END 'e1'
TEXT '
'
ELEMENT 'e2:foo'
TEXT ' Text '
ELEMENT 'childfree'
END 'childfree'
TEXT ' with some '
ELEMENT 'nested'
TEXT 'nested elements'
END 'nested'
TEXT ' and entities "& < >> ' and whitespace '
END 'e2:foo'
TEXT '
'
ELEMENT 'tag'
ab="fo<o"
bar="foo"
baz="blah"
TEXT 'This element has attributes'
END 'tag'
TEXT '
'
ELEMENT 'nochildren'
a="b"
xyz="qrs"
END 'nochildren'
TEXT '
'
END 'foobar'

View File

@@ -1,6 +0,0 @@
ELEMENT 'foo'
bar="baz"
bar2="baz2"
bar3="baz3"
TEXT 'data'
END 'foo'

View File

@@ -1,3 +0,0 @@
ELEMENT 'foo'
TEXT 'data'
END 'foo'

View File

@@ -1,51 +0,0 @@
ELEMENT 'foobar'
TEXT '
Παν語
This is a list of ways to say hello in various languages. Its purpose is to illustrate a number of scripts.
(Converted into UTF-8)
---------------------------------------------------------
Arabic السلام عليكم
Czech (česky) Dobrý den
Danish (Dansk) Hej, Goddag
English Hello
Esperanto Saluton
Estonian Tere, Tervist
FORTRAN PROGRAM
Finnish (Suomi) Hei
French (Français) Bonjour, Salut
German (Deutsch Nord) Guten Tag
German (Deutsch Süd) Grüß Gott
Greek (Ελληνικά) Γειά σας
Hebrew שלום
Hindi नमस्ते, नमस्कार।
Italiano Ciao, Buon giorno
Maltese Ċaw, Saħħa
Nederlands, Vlaams Hallo, Dag
Norwegian (Norsk) Hei, God dag
Polish Dzień dobry, Hej
Russian (Русский) Здравствуйте!
Slovak Dobrý deň
Spanish (Español) ¡Hola!
Swedish (Svenska) Hej, Goddag
Thai (ภาษาไทย) สวัสดีครับ, สวัสดีค่ะ
Turkish (Türkçe) Merhaba
Vietnamese (Tiếng Việt) Xin Chào
Yiddish (ײַדישע) דאָס הײַזעלע
Japanese (日本語) こんにちは, コンニチハ
Chinese (中文,普通话,汉语) 你好
Cantonese (粵語,廣東話) 早晨, 你好
Korean (한글) 안녕하세요, 안녕하십니까
Difference among chinese characters in GB, JIS, KSC, BIG5:
GB -- 元气 开发
JIS -- 元気 開発
KSC -- 元氣 開發
BIG5 -- 元氣 開發
'
END 'foobar'

View File

@@ -1,61 +0,0 @@
ELEMENT 'foo'
TEXT '
'
ELEMENT 'bar'
a="1"
END 'bar'
TEXT '
'
ELEMENT 'bar'
a="1"
b="2"
END 'bar'
TEXT '
'
ELEMENT 'bar'
a="1"
b="2"
c="3"
END 'bar'
TEXT '
'
ELEMENT 'bar'
a="1"
b="2"
c="3"
d="4"
END 'bar'
TEXT '
'
ELEMENT 'bar'
a="1"
b="2"
c="3"
d="4"
e="5"
END 'bar'
TEXT '
'
ELEMENT 'bar'
a="1"
b="2"
c="3"
d="4"
e="5"
f="6"
END 'bar'
TEXT '
'
ELEMENT 'bar'
a="1"
b="2"
c="3"
END 'bar'
TEXT '
'
ELEMENT 'bar'
a="1"
END 'bar'
TEXT '
'
END 'foo'

View File

@@ -1,29 +0,0 @@
ELEMENT 'foo'
TEXT '
'
ELEMENT 'bar'
a="1"
END 'bar'
TEXT '
'
ELEMENT 'bar'
a="2"
END 'bar'
TEXT '
'
ELEMENT 'bar'
a="3""
END 'bar'
TEXT '
'
ELEMENT 'bar'
a="4'"
END 'bar'
TEXT '
'
ELEMENT 'bar'
a="5''''"
END 'bar'
TEXT '
'
END 'foo'

View File

@@ -1,4 +0,0 @@
PASS '<?xml version="1.0" ?>'
ELEMENT 'foo'
TEXT ''
END 'foo'

View File

@@ -1,6 +0,0 @@
PASS '<!DOCTYPE foo "foo" [
<!ELEMENT foo ANY >
]>'
ELEMENT 'foo'
TEXT ''
END 'foo'

View File

@@ -1,4 +0,0 @@
PASS '<!-- a comment -->'
ELEMENT 'foo'
TEXT ''
END 'foo'

View File

@@ -1,5 +0,0 @@
ELEMENT 'foo'
TEXT ''
PASS '<![CDATA[ some <<<<>>>> CDATA ]]>'
TEXT ''
END 'foo'

View File

@@ -1,3 +0,0 @@
ELEMENT 'foo'
TEXT 'data'
END 'foo'

View File

@@ -1,2 +0,0 @@
<foo>
</|foo>

View File

@@ -1,4 +0,0 @@
<foo>
<bar>
</foo>
</bar>

View File

@@ -1 +0,0 @@
</foo>

View File

@@ -1 +0,0 @@
</foo|>

View File

@@ -1,2 +0,0 @@
<foo>
<

View File

@@ -1,3 +0,0 @@
<foo>
<bar>
</bar>

View File

@@ -1 +0,0 @@
<foo/

View File

@@ -1 +0,0 @@
<fo

View File

@@ -1 +0,0 @@
<foo bar

View File

@@ -1 +0,0 @@
<foo

View File

@@ -1 +0,0 @@
<EFBFBD>ν

View File

@@ -1 +0,0 @@
<foo bar=

View File

@@ -1 +0,0 @@
<foo bar="fdsf

View File

@@ -1 +0,0 @@
<foo>

View File

@@ -1,2 +0,0 @@
<foo>
<fo

View File

@@ -1 +0,0 @@
<!-- dfklsjdf;kljsdf;ljk document ends here

View File

@@ -1 +0,0 @@
<? document ending unexpectedly

View File

@@ -1 +0,0 @@
<foo>&;</foo>

View File

@@ -1 +0,0 @@
<foo>&|;</foo>

View File

@@ -1 +0,0 @@
<foo>&am|;</foo>

View File

@@ -1 +0,0 @@
<foo>&bar;</foo>

View File

@@ -1,49 +0,0 @@
<foobar>
Παν語
This is a list of ways to say hello in various languages. Its purpose is to illustrate a number of scripts.
(Converted into UTF-8)
---------------------------------------------------------
Arabic السلام عليكم
Czech (česky) Dobrý den
Danish (Dansk) Hej, Goddag
English Hello
Esperanto Saluton
Estonian Tere, Tervist
FORTRAN PROGRAM
Finnish (Suomi) Hei
French (Français) Bonjour, Salut
German (Deutsch Nord) Guten Tag
German (Deutsch Süd) Grüß Gott
Greek (Ελληνικά) Γειά σας
Hebrew שלום
Hindi नमस्ते, <20><>मस्कार।
Italiano Ciao, Buon giorno
Maltese Ċaw, Saħħa
Nederlands, Vlaams Hallo, Dag
Norwegian (Norsk) Hei, God dag
Polish Dzień dobry, Hej
Russian (Русский) Здравствуйте!
Slovak Dobrý deň
Spanish (Español) ¡Hola!
Swedish (Svenska) Hej, Goddag
Thai (ภาษาไทย) สวัสดีครับ, สวัสดีค่ะ
Turkish (Türkçe) Merhaba
Vietnamese (Tiếng Việt) Xin Chào
Yiddish (ײַדישע) דאָס הײַזעלע
Japanese (日本語) こんにちは, コンニチハ
Chinese (中文,普通话,汉语) 你好
Cantonese (粵語,廣東話) 早晨, 你好
Korean (한글) 안녕하세요, 안녕하십니까
Difference among chinese characters in GB, JIS, KSC, BIG5:
GB -- 元气 开发
JIS -- 元気 開発
KSC -- 元氣 開發
BIG5 -- 元氣 開發
</foobar>

View File

@@ -1 +0,0 @@
<foo>&sdfkljsdsdfsdfsdfsdf</foo>

View File

@@ -1 +0,0 @@
<foo>&#34592348345343453453455645765736575865767;</foo>

View File

@@ -1 +0,0 @@
<foo>&#x0;</foo>

View File

@@ -1 +0,0 @@
<foo>&#;</foo>

View File

@@ -1 +0,0 @@
<foo>&#234234</foo>

View File

@@ -1 +0,0 @@
<foo>gedit&</foo>

View File

@@ -1 +0,0 @@
<foo><3E></foo><^$non-carriage-null-fail|>

View File

@@ -1 +0,0 @@
< foo>

View File

@@ -1 +0,0 @@
<foo>data< /foo>

View File

@@ -1 +0,0 @@
<foo>data</ foo>

View File

@@ -1 +0,0 @@
foo

View File

@@ -1 +0,0 @@
<bla>&unknownentityname;</bla>

View File

@@ -1,2 +0,0 @@
<|foo>
</|foo>

View File

@@ -1,2 +0,0 @@
<foo|>
</foo>

View File

@@ -1,2 +0,0 @@
<foo bar}"baz">
</foo>

View File

@@ -1,2 +0,0 @@
<foo/}>
</foo>

View File

@@ -1,2 +0,0 @@
<foo bar={baz">
</foo>

View File

@@ -1,9 +0,0 @@
<!-- Comment -->
<?PI ?>
<foobar>
<e1>Hi &amp; this is some text inside an element Two 'E' chars as character refs: &#69; &#x45; and some 'J': &#74; &#x4A;</e1>
<e2:foo> Text <childfree/> with some <nested>nested elements</nested> and entities &quot;&amp; &lt; &gt;&gt; &apos; and whitespace </e2:foo>
<tag ab="fo&lt;o" bar="foo" baz="blah">This element has attributes</tag>
<nochildren a="b" xyz="qrs"/>
</foobar>

View File

@@ -1,6 +0,0 @@
<foo
bar="baz"
bar2 = "baz2"
bar3 =
"baz3"
>data</foo>

View File

@@ -1,2 +0,0 @@
<foo
>data</foo>

View File

@@ -1,49 +0,0 @@
<foobar>
Παν語
This is a list of ways to say hello in various languages. Its purpose is to illustrate a number of scripts.
(Converted into UTF-8)
---------------------------------------------------------
Arabic السلام عليكم
Czech (česky) Dobrý den
Danish (Dansk) Hej, Goddag
English Hello
Esperanto Saluton
Estonian Tere, Tervist
FORTRAN PROGRAM
Finnish (Suomi) Hei
French (Français) Bonjour, Salut
German (Deutsch Nord) Guten Tag
German (Deutsch Süd) Grüß Gott
Greek (Ελληνικά) Γειά σας
Hebrew שלום
Hindi नमस्ते, नमस्कार।
Italiano Ciao, Buon giorno
Maltese Ċaw, Saħħa
Nederlands, Vlaams Hallo, Dag
Norwegian (Norsk) Hei, God dag
Polish Dzień dobry, Hej
Russian (Русский) Здравствуйте!
Slovak Dobrý deň
Spanish (Español) ¡Hola!
Swedish (Svenska) Hej, Goddag
Thai (ภาษาไทย) สวัสดีครับ, สวัสดีค่ะ
Turkish (Türkçe) Merhaba
Vietnamese (Tiếng Việt) Xin Chào
Yiddish (ײַדישע) דאָס הײַזעלע
Japanese (日本語) こんにちは, コンニチハ
Chinese (中文,普通话,汉语) 你好
Cantonese (粵語,廣東話) 早晨, 你好
Korean (한글) 안녕하세요, 안녕하십니까
Difference among chinese characters in GB, JIS, KSC, BIG5:
GB -- 元气 开发
JIS -- 元気 開発
KSC -- 元氣 開發
BIG5 -- 元氣 開發
</foobar>

View File

@@ -1,10 +0,0 @@
<foo>
<bar a="1"/>
<bar a="1" b="2"/>
<bar a="1" b="2" c="3"/>
<bar a="1" b="2" c="3" d="4"/>
<bar a="1" b="2" c="3" d="4" e="5"/>
<bar a="1" b="2" c="3" d="4" e="5" f="6"/>
<bar a="1" b="2" c="3"/>
<bar a="1"/>
</foo>

View File

@@ -1,8 +0,0 @@
<foo>
<bar a='1'/>
<bar a="2"/>
<bar a='3"'/>
<bar a="4'"/>
<bar a="5''''"/>
</foo>

View File

@@ -1,2 +0,0 @@
<?xml version="1.0" ?>
<foo></foo>

View File

@@ -1,4 +0,0 @@
<!DOCTYPE foo "foo" [
<!ELEMENT foo ANY >
]>
<foo></foo>

View File

@@ -1,2 +0,0 @@
<!-- a comment -->
<foo></foo>

View File

@@ -1 +0,0 @@
<foo><![CDATA[ some <<<<>>>> CDATA ]]></foo>

View File

@@ -1,2 +0,0 @@
<foo>data</foo
>

View File

@@ -1,41 +0,0 @@
#! /bin/sh
fail ()
{
echo "Test failed: $*"
exit 1
}
echo_v ()
{
if [ "$verbose" = "1" ]; then
echo "$*"
fi
}
error_out=/dev/null
if [ "$1" = "-v" ]; then
verbose=1
error_out=/dev/stderr
fi
for I in ${srcdir:-.}/markups/fail-*.gmarkup; do
echo_v "Parsing $I, should fail"
./markup-test $I > /dev/null 2> $error_out && fail "failed to generate error on $I"
if test "$?" != "1"; then
fail "unexpected error on $I"
fi
done
I=1
while test $I -lt 100 ; do
F=${srcdir:-.}/markups/valid-$I.gmarkup
if [ -f $F ] ; then
echo_v "Parsing $F, should succeed"
./markup-test $F > actual 2> $error_out || fail "failed on $F"
diff ${srcdir:-.}/markups/expected-$I actual || fail "unexpected output on $F"
rm actual
fi
I=`expr $I + 1`
done
echo_v "All tests passed."