From 6db761d16229084e576848967402d30b656e2dbf Mon Sep 17 00:00:00 2001 From: Manuel Stoeckl Date: Sat, 13 Apr 2019 18:33:06 -0400 Subject: [PATCH] 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 --- Makefile.am | 7 +++++++ tests/data/bad-identifier-arg.xml | 10 ++++++++++ tests/data/bad-identifier-entry.xml | 11 +++++++++++ tests/data/bad-identifier-enum.xml | 10 ++++++++++ tests/data/bad-identifier-event.xml | 8 ++++++++ tests/data/bad-identifier-interface.xml | 8 ++++++++ tests/data/bad-identifier-protocol.xml | 8 ++++++++ tests/data/bad-identifier-request.xml | 10 ++++++++++ tests/scanner-test.sh | 23 +++++++++++++++++++++++ 9 files changed, 95 insertions(+) create mode 100644 tests/data/bad-identifier-arg.xml create mode 100644 tests/data/bad-identifier-entry.xml create mode 100644 tests/data/bad-identifier-enum.xml create mode 100644 tests/data/bad-identifier-event.xml create mode 100644 tests/data/bad-identifier-interface.xml create mode 100644 tests/data/bad-identifier-protocol.xml create mode 100644 tests/data/bad-identifier-request.xml diff --git a/Makefile.am b/Makefile.am index 489f5818..a41f959c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/tests/data/bad-identifier-arg.xml b/tests/data/bad-identifier-arg.xml new file mode 100644 index 00000000..ac2a6b76 --- /dev/null +++ b/tests/data/bad-identifier-arg.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/tests/data/bad-identifier-entry.xml b/tests/data/bad-identifier-entry.xml new file mode 100644 index 00000000..6ea2fae0 --- /dev/null +++ b/tests/data/bad-identifier-entry.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/tests/data/bad-identifier-enum.xml b/tests/data/bad-identifier-enum.xml new file mode 100644 index 00000000..3225384e --- /dev/null +++ b/tests/data/bad-identifier-enum.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/tests/data/bad-identifier-event.xml b/tests/data/bad-identifier-event.xml new file mode 100644 index 00000000..9708e3bc --- /dev/null +++ b/tests/data/bad-identifier-event.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/tests/data/bad-identifier-interface.xml b/tests/data/bad-identifier-interface.xml new file mode 100644 index 00000000..17404c5e --- /dev/null +++ b/tests/data/bad-identifier-interface.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/tests/data/bad-identifier-protocol.xml b/tests/data/bad-identifier-protocol.xml new file mode 100644 index 00000000..7a172045 --- /dev/null +++ b/tests/data/bad-identifier-protocol.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/tests/data/bad-identifier-request.xml b/tests/data/bad-identifier-request.xml new file mode 100644 index 00000000..a68c8aac --- /dev/null +++ b/tests/data/bad-identifier-request.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/tests/scanner-test.sh b/tests/scanner-test.sh index ff250894..35ba0473 100755 --- a/tests/scanner-test.sh +++ b/tests/scanner-test.sh @@ -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 ":$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