tests: Verify that wayland_scanner can catch bad identifiers
The test runs wayland_scanner on a set of XML protocol files which have malformed element names, and confirms that an error is produced and indicates the correct line. Copyright notifications are not included in the test files, as they are not code; of course, the project license still applies. Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
This commit is contained in:
parent
6ce4bbb3dd
commit
6db761d162
|
@ -291,6 +291,13 @@ exec_fd_leak_checker_LDADD = libtest-helpers.la
|
|||
|
||||
EXTRA_DIST += tests/scanner-test.sh \
|
||||
protocol/tests.xml \
|
||||
tests/data/bad-identifier-arg.xml \
|
||||
tests/data/bad-identifier-entry.xml \
|
||||
tests/data/bad-identifier-enum.xml \
|
||||
tests/data/bad-identifier-event.xml \
|
||||
tests/data/bad-identifier-interface.xml \
|
||||
tests/data/bad-identifier-protocol.xml \
|
||||
tests/data/bad-identifier-request.xml \
|
||||
tests/data/example.xml \
|
||||
tests/data/example-client.h \
|
||||
tests/data/example-server.h \
|
||||
|
|
10
tests/data/bad-identifier-arg.xml
Normal file
10
tests/data/bad-identifier-arg.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<protocol name="the_protocol">
|
||||
<interface name="the_interface" version="1">
|
||||
<description summary="the summary">
|
||||
</description>
|
||||
<request name="the_request">
|
||||
<arg name="" type="uint"/>
|
||||
</request>
|
||||
</interface>
|
||||
</protocol>
|
11
tests/data/bad-identifier-entry.xml
Normal file
11
tests/data/bad-identifier-entry.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<protocol name="the_protocol">
|
||||
<interface name="the_interface" version="1">
|
||||
<description summary="the summary">
|
||||
</description>
|
||||
<enum name="4the_enum">
|
||||
<entry name="60_seconds" value="1" summary="this is the first"/>
|
||||
<entry name="invalid entry" value="2" summary="this is the first"/>
|
||||
</enum>
|
||||
</interface>
|
||||
</protocol>
|
10
tests/data/bad-identifier-enum.xml
Normal file
10
tests/data/bad-identifier-enum.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<protocol name="the_protocol">
|
||||
<interface name="the_interface" version="1">
|
||||
<description summary="the summary">
|
||||
</description>
|
||||
<enum name="the-enum">
|
||||
<entry name="the_entry" value="0" summary="entry summary"/>
|
||||
</enum>
|
||||
</interface>
|
||||
</protocol>
|
8
tests/data/bad-identifier-event.xml
Normal file
8
tests/data/bad-identifier-event.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<protocol name="the_protocol">
|
||||
<interface name="the_interface" version="1">
|
||||
<description summary="the summary">
|
||||
</description>
|
||||
<event name="theΔevent"/>
|
||||
</interface>
|
||||
</protocol>
|
8
tests/data/bad-identifier-interface.xml
Normal file
8
tests/data/bad-identifier-interface.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<protocol name="the_protocol">
|
||||
<interface name="inter face" version="1">
|
||||
<description summary="the summary">
|
||||
</description>
|
||||
<event name="the_event"/>
|
||||
</interface>
|
||||
</protocol>
|
8
tests/data/bad-identifier-protocol.xml
Normal file
8
tests/data/bad-identifier-protocol.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<protocol name="1badprotocol">
|
||||
<interface name="required_interface" version="13">
|
||||
<description summary="required summary">
|
||||
</description>
|
||||
<event name="requied_event"/>
|
||||
</interface>
|
||||
</protocol>
|
10
tests/data/bad-identifier-request.xml
Normal file
10
tests/data/bad-identifier-request.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<protocol name="the_protocol">
|
||||
<interface name="the_interface" version="1">
|
||||
<description summary="the summary">
|
||||
</description>
|
||||
<request name="req-west">
|
||||
<arg name="the_arg" type="uint"/>
|
||||
</request>
|
||||
</interface>
|
||||
</protocol>
|
|
@ -36,6 +36,20 @@ generate_and_compare() {
|
|||
fail "$2 -> $3"
|
||||
}
|
||||
|
||||
verify_error() {
|
||||
echo
|
||||
echo "Checking that reading $1 gives an error on line $3"
|
||||
|
||||
[ -f "$TEST_DATA_DIR/$1" ] || hard_fail "$1 not present"
|
||||
|
||||
# Confirm failure error code
|
||||
"$WAYLAND_SCANNER" server-header < "$TEST_DATA_DIR/$1" >/dev/null 2>"$TEST_OUTPUT_DIR/$2" && \
|
||||
fail "$1 return code check"
|
||||
|
||||
# Verify that an error is produced at the correct line
|
||||
grep -q "<stdin>:$3: error:" "$TEST_OUTPUT_DIR/$2" && echo "$1 PASS" || fail "$1 line number check"
|
||||
}
|
||||
|
||||
generate_and_compare "code" "example.xml" "example-code.c"
|
||||
generate_and_compare "client-header" "example.xml" "example-client.h"
|
||||
generate_and_compare "server-header" "example.xml" "example-server.h"
|
||||
|
@ -52,4 +66,13 @@ generate_and_compare "-c server-header" "small.xml" "small-server-core.h"
|
|||
generate_and_compare "code" "small.xml" "small-code.c"
|
||||
generate_and_compare "public-code" "small.xml" "small-code.c"
|
||||
generate_and_compare "private-code" "small.xml" "small-private-code.c"
|
||||
|
||||
verify_error "bad-identifier-arg.xml" "bad-identifier-arg.log" 7
|
||||
verify_error "bad-identifier-entry.xml" "bad-identifier-entry.log" 8
|
||||
verify_error "bad-identifier-enum.xml" "bad-identifier-enum.log" 6
|
||||
verify_error "bad-identifier-event.xml" "bad-identifier-event.log" 6
|
||||
verify_error "bad-identifier-interface.xml" "bad-identifier-interface.log" 3
|
||||
verify_error "bad-identifier-protocol.xml" "bad-identifier-protocol.log" 2
|
||||
verify_error "bad-identifier-request.xml" "bad-identifier-request.log" 6
|
||||
|
||||
exit $RETCODE
|
||||
|
|
Loading…
Reference in New Issue
Block a user